Search in sources :

Example 1 with StaxDriver

use of com.thoughtworks.xstream.io.xml.StaxDriver in project ddf by codice.

the class TestGetRecordsResponseConverter method testMarshalRecordCollectionFullXml.

@Ignore
public void testMarshalRecordCollectionFullXml() throws UnsupportedEncodingException, JAXBException {
    final int totalResults = 5;
    TransformerManager mockMetacardManager = mock(TransformerManager.class);
    when(mockMetacardManager.getTransformerBySchema(anyString())).thenReturn(new CswRecordConverter(TestCswRecordConverter.getCswMetacardType()));
    GetRecordsResponseConverter rrConverter = new GetRecordsResponseConverter(new CswTransformProvider(mockMetacardManager, null));
    XStream xstream = new XStream(new StaxDriver(new NoNameCoder()));
    xstream.registerConverter(rrConverter);
    xstream.alias(CswConstants.CSW_NAMESPACE_PREFIX + CswConstants.NAMESPACE_DELIMITER + CswConstants.GET_RECORDS_RESPONSE, CswRecordCollection.class);
    GetRecordsType getRecords = new GetRecordsType();
    QueryType query = new QueryType();
    ElementSetNameType set = new ElementSetNameType();
    set.setValue(ElementSetType.FULL);
    query.setElementSetName(set);
    ObjectFactory objectFactory = new ObjectFactory();
    getRecords.setAbstractQuery(objectFactory.createAbstractQuery(query));
    CswRecordCollection collection = createCswRecordCollection(getRecords, totalResults);
    collection.setElementSetType(ElementSetType.FULL);
    String xml = xstream.toXML(collection);
    JAXBElement<GetRecordsResponseType> jaxb = (JAXBElement<GetRecordsResponseType>) getJaxBContext().createUnmarshaller().unmarshal(new ByteArrayInputStream(xml.getBytes("UTF-8")));
    GetRecordsResponseType response = jaxb.getValue();
    // Assert the GetRecordsResponse elements and attributes
    assertThat(response, not(nullValue()));
    SearchResultsType resultsType = response.getSearchResults();
    assertThat(resultsType, not(nullValue()));
    assertThat(resultsType.getElementSet(), is(ElementSetType.FULL));
    assertThat(resultsType.getNumberOfRecordsMatched().intValue(), is(totalResults));
    assertThat(resultsType.getNumberOfRecordsReturned().intValue(), is(totalResults));
    assertThat(resultsType.getRecordSchema(), is(CswConstants.CSW_OUTPUT_SCHEMA));
}
Also used : TransformerManager(org.codice.ddf.spatial.ogc.csw.catalog.common.transformer.TransformerManager) XStream(com.thoughtworks.xstream.XStream) SearchResultsType(net.opengis.cat.csw.v_2_0_2.SearchResultsType) GetRecordsType(net.opengis.cat.csw.v_2_0_2.GetRecordsType) Matchers.anyString(org.mockito.Matchers.anyString) JAXBElement(javax.xml.bind.JAXBElement) NoNameCoder(com.thoughtworks.xstream.io.naming.NoNameCoder) StaxDriver(com.thoughtworks.xstream.io.xml.StaxDriver) ObjectFactory(net.opengis.cat.csw.v_2_0_2.ObjectFactory) ByteArrayInputStream(java.io.ByteArrayInputStream) CswRecordCollection(org.codice.ddf.spatial.ogc.csw.catalog.common.CswRecordCollection) ElementSetNameType(net.opengis.cat.csw.v_2_0_2.ElementSetNameType) GetRecordsResponseType(net.opengis.cat.csw.v_2_0_2.GetRecordsResponseType) QueryType(net.opengis.cat.csw.v_2_0_2.QueryType) Ignore(jdk.nashorn.internal.ir.annotations.Ignore)

Example 2 with StaxDriver

use of com.thoughtworks.xstream.io.xml.StaxDriver in project ddf by codice.

the class AbstractFeatureConverter method copyXml.

protected HierarchicalStreamReader copyXml(HierarchicalStreamReader hreader, StringWriter writer) {
    copier.copy(hreader, new CompactWriter(writer, noNameCoder));
    StaxDriver driver = new WstxDriver();
    return driver.createReader(new ByteArrayInputStream(writer.toString().getBytes(StandardCharsets.UTF_8)));
}
Also used : WstxDriver(com.thoughtworks.xstream.io.xml.WstxDriver) StaxDriver(com.thoughtworks.xstream.io.xml.StaxDriver) CompactWriter(com.thoughtworks.xstream.io.xml.CompactWriter) ByteArrayInputStream(java.io.ByteArrayInputStream)

Example 3 with StaxDriver

use of com.thoughtworks.xstream.io.xml.StaxDriver in project openhab1-addons by openhab.

the class ZWaveProductDatabase method LoadProductFile.

/**
     * Loads the product file relating to the requested version.
     *
     * @param version the required device version
     * @return filename of the product file
     */
private ZWaveDbProductFile LoadProductFile() {
    // If the file is already loaded, then just return the class
    if (productFile != null) {
        return productFile;
    }
    // Have we selected a product?
    if (selProduct == null) {
        return null;
    }
    String cfgFile = selProduct.getConfigFile(productVersion);
    if (cfgFile == null || cfgFile.isEmpty()) {
        return null;
    }
    URL entry = FrameworkUtil.getBundle(ZWaveProductDatabase.class).getEntry("database/" + cfgFile);
    if (entry == null) {
        database = null;
        logger.error("Unable to load ZWave product file: '{}'", cfgFile);
        return null;
    }
    XStream xstream = new XStream(new StaxDriver());
    xstream.alias("Product", ZWaveDbProductFile.class);
    xstream.alias("Configuration", ZWaveDbProductFile.ZWaveDbConfiguration.class);
    xstream.alias("Parameter", ZWaveDbConfigurationParameter.class);
    xstream.alias("Item", ZWaveDbConfigurationListItem.class);
    xstream.alias("Associations", ZWaveDbProductFile.ZWaveDbAssociation.class);
    xstream.alias("Group", ZWaveDbAssociationGroup.class);
    xstream.alias("CommandClass", ZWaveDbProductFile.ZWaveDbCommandClassList.class);
    xstream.alias("Class", ZWaveDbCommandClass.class);
    xstream.processAnnotations(ZWaveDbProductFile.class);
    try {
        // this.Manufacturer = (ZWaveDbManufacturer)
        InputStream x = entry.openStream();
        productFile = (ZWaveDbProductFile) xstream.fromXML(x);
    } catch (IOException e) {
        logger.error("Unable to load ZWave product file '{}' : {}", cfgFile, e.toString());
    }
    return productFile;
}
Also used : StaxDriver(com.thoughtworks.xstream.io.xml.StaxDriver) XStream(com.thoughtworks.xstream.XStream) InputStream(java.io.InputStream) IOException(java.io.IOException) URL(java.net.URL)

Example 4 with StaxDriver

use of com.thoughtworks.xstream.io.xml.StaxDriver in project openhab1-addons by openhab.

the class ZWaveProductDatabase method loadDatabase.

private void loadDatabase() {
    URL entry = FrameworkUtil.getBundle(ZWaveProductDatabase.class).getEntry("database/products.xml");
    if (entry == null) {
        database = null;
        logger.error("Unable to load ZWave product database!");
        return;
    }
    XStream xstream = new XStream(new StaxDriver());
    xstream.alias("Manufacturers", ZWaveDbRoot.class);
    xstream.alias("Manufacturer", ZWaveDbManufacturer.class);
    xstream.alias("Product", ZWaveDbProduct.class);
    xstream.alias("Reference", ZWaveDbProductReference.class);
    xstream.processAnnotations(ZWaveDbRoot.class);
    try {
        // this.Manufacturer = (ZWaveDbManufacturer)
        InputStream x = entry.openStream();
        database = (ZWaveDbRoot) xstream.fromXML(x);
        if (database == null) {
            return;
        }
    } catch (IOException e) {
        e.printStackTrace();
    }
}
Also used : StaxDriver(com.thoughtworks.xstream.io.xml.StaxDriver) XStream(com.thoughtworks.xstream.XStream) InputStream(java.io.InputStream) IOException(java.io.IOException) URL(java.net.URL)

Example 5 with StaxDriver

use of com.thoughtworks.xstream.io.xml.StaxDriver in project groovy by apache.

the class XStreamUtils method serialize.

public static void serialize(final String name, final Object ast) {
    if (name == null || name.length() == 0)
        return;
    XStream xstream = new XStream(new StaxDriver());
    FileWriter astFileWriter = null;
    try {
        File astFile = astFile(name);
        if (astFile == null) {
            System.out.println("File-name for writing " + name + " AST could not be determined!");
            return;
        }
        astFileWriter = new FileWriter(astFile, false);
        xstream.toXML(ast, astFileWriter);
        System.out.println("Written AST to " + name + ".xml");
    } catch (Exception e) {
        System.out.println("Couldn't write to " + name + ".xml");
        e.printStackTrace();
    } finally {
        DefaultGroovyMethods.closeQuietly(astFileWriter);
    }
}
Also used : StaxDriver(com.thoughtworks.xstream.io.xml.StaxDriver) XStream(com.thoughtworks.xstream.XStream) FileWriter(java.io.FileWriter) File(java.io.File)

Aggregations

StaxDriver (com.thoughtworks.xstream.io.xml.StaxDriver)10 XStream (com.thoughtworks.xstream.XStream)8 InputStream (java.io.InputStream)3 NoNameCoder (com.thoughtworks.xstream.io.naming.NoNameCoder)2 ByteArrayInputStream (java.io.ByteArrayInputStream)2 IOException (java.io.IOException)2 URL (java.net.URL)2 Matchers.anyString (org.mockito.Matchers.anyString)2 UnmarshallingContext (com.thoughtworks.xstream.converters.UnmarshallingContext)1 TreeUnmarshaller (com.thoughtworks.xstream.core.TreeUnmarshaller)1 HierarchicalStreamReader (com.thoughtworks.xstream.io.HierarchicalStreamReader)1 Path (com.thoughtworks.xstream.io.path.Path)1 CompactWriter (com.thoughtworks.xstream.io.xml.CompactWriter)1 QNameMap (com.thoughtworks.xstream.io.xml.QNameMap)1 WstxDriver (com.thoughtworks.xstream.io.xml.WstxDriver)1 XppReader (com.thoughtworks.xstream.io.xml.XppReader)1 InputTransformer (ddf.catalog.transform.InputTransformer)1 File (java.io.File)1 FileWriter (java.io.FileWriter)1 StringReader (java.io.StringReader)1