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));
}
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)));
}
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;
}
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();
}
}
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);
}
}
Aggregations