Search in sources :

Example 6 with NoNameCoder

use of com.thoughtworks.xstream.io.naming.NoNameCoder in project ddf by codice.

the class AbstractGmdTransformer method transform.

@Override
public BinaryContent transform(Metacard metacard, Map<String, Serializable> arguments) throws CatalogTransformerException {
    StringWriter stringWriter = new StringWriter();
    Boolean omitXmlDec = null;
    if (MapUtils.isNotEmpty(arguments)) {
        omitXmlDec = (Boolean) arguments.get(CswConstants.OMIT_XML_DECLARATION);
    }
    if (omitXmlDec == null || !omitXmlDec) {
        stringWriter.append("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n");
    }
    PrettyPrintWriter writer = new PrettyPrintWriter(stringWriter, new NoNameCoder());
    MarshallingContext context = new TreeMarshaller(writer, null, null);
    copyArgumentsToContext(context, arguments);
    converterSupplier.get().marshal(metacard, writer, context);
    ByteArrayInputStream bais = new ByteArrayInputStream(stringWriter.toString().getBytes(StandardCharsets.UTF_8));
    return new BinaryContentImpl(bais, CswRecordConverter.XML_MIME_TYPE);
}
Also used : TreeMarshaller(com.thoughtworks.xstream.core.TreeMarshaller) StringWriter(java.io.StringWriter) ByteArrayInputStream(java.io.ByteArrayInputStream) PrettyPrintWriter(com.thoughtworks.xstream.io.xml.PrettyPrintWriter) MarshallingContext(com.thoughtworks.xstream.converters.MarshallingContext) BinaryContentImpl(ddf.catalog.data.impl.BinaryContentImpl) NoNameCoder(com.thoughtworks.xstream.io.naming.NoNameCoder)

Example 7 with NoNameCoder

use of com.thoughtworks.xstream.io.naming.NoNameCoder in project ddf by codice.

the class XStreamAttributeCopier method copyXml.

/**
 * Copies the entire XML element {@code reader} is currently at into {@code writer} and returns a
 * new reader ready to read the copied element. After the call, {@code reader} will be at the end
 * of the element that was copied.
 *
 * <p>If {@code attributeMap} is provided, the attributes will be added to the copy.
 *
 * @param reader the reader currently at the XML element you want to copy
 * @param writer the writer that the element will be copied into
 * @param attributeMap the map of attribute names to values that will be added as attributes of
 *     the copy, may be null
 * @return a new reader ready to read the copied element
 * @throws ConversionException if a parser to use for the new reader can't be created
 */
public static HierarchicalStreamReader copyXml(HierarchicalStreamReader reader, StringWriter writer, Map<String, String> attributeMap) {
    copyElementWithAttributes(reader, new CompactWriter(writer, new NoNameCoder()), attributeMap);
    XmlPullParser parser;
    try {
        parser = XmlPullParserFactory.newInstance().newPullParser();
    } catch (XmlPullParserException e) {
        throw new ConversionException("Unable to create XmlPullParser, cannot parse XML.", e);
    }
    return new XppReader(new InputStreamReader(IOUtils.toInputStream(writer.toString(), StandardCharsets.UTF_8)), parser);
}
Also used : ConversionException(com.thoughtworks.xstream.converters.ConversionException) CompactWriter(com.thoughtworks.xstream.io.xml.CompactWriter) InputStreamReader(java.io.InputStreamReader) XppReader(com.thoughtworks.xstream.io.xml.XppReader) XmlPullParser(org.xmlpull.v1.XmlPullParser) XmlPullParserException(org.xmlpull.v1.XmlPullParserException) NoNameCoder(com.thoughtworks.xstream.io.naming.NoNameCoder)

Example 8 with NoNameCoder

use of com.thoughtworks.xstream.io.naming.NoNameCoder in project ddf by codice.

the class GmdConverterTest method convert.

private String convert(Object object, boolean writeNamespaces) {
    GmdConverter converter = new GmdConverter();
    StringWriter stringWriter = new StringWriter();
    PrettyPrintWriter writer = new PrettyPrintWriter(stringWriter, new NoNameCoder());
    MarshallingContext context = new TreeMarshaller(writer, null, null);
    context.put(CswConstants.WRITE_NAMESPACES, writeNamespaces);
    converter.marshal(object, writer, context);
    return stringWriter.toString();
}
Also used : TreeMarshaller(com.thoughtworks.xstream.core.TreeMarshaller) StringWriter(java.io.StringWriter) PrettyPrintWriter(com.thoughtworks.xstream.io.xml.PrettyPrintWriter) MarshallingContext(com.thoughtworks.xstream.converters.MarshallingContext) NoNameCoder(com.thoughtworks.xstream.io.naming.NoNameCoder)

Example 9 with NoNameCoder

use of com.thoughtworks.xstream.io.naming.NoNameCoder in project ddf by codice.

the class TestGmdConverter method convert.

private String convert(Object object, boolean writeNamespaces) {
    GmdConverter converter = new GmdConverter();
    StringWriter stringWriter = new StringWriter();
    PrettyPrintWriter writer = new PrettyPrintWriter(stringWriter, new NoNameCoder());
    MarshallingContext context = new TreeMarshaller(writer, null, null);
    context.put(CswConstants.WRITE_NAMESPACES, writeNamespaces);
    converter.marshal(object, writer, context);
    return stringWriter.toString();
}
Also used : TreeMarshaller(com.thoughtworks.xstream.core.TreeMarshaller) StringWriter(java.io.StringWriter) PrettyPrintWriter(com.thoughtworks.xstream.io.xml.PrettyPrintWriter) MarshallingContext(com.thoughtworks.xstream.converters.MarshallingContext) NoNameCoder(com.thoughtworks.xstream.io.naming.NoNameCoder)

Example 10 with NoNameCoder

use of com.thoughtworks.xstream.io.naming.NoNameCoder in project ddf by codice.

the class TestGetRecordsResponseConverter method createXStream.

private XStream createXStream(final String elementName) {
    GetRecordsResponseConverter rrConverter = new GetRecordsResponseConverter(mockProvider);
    XStream xstream = new XStream(new StaxDriver(new NoNameCoder()));
    xstream.registerConverter(rrConverter);
    xstream.alias(CswConstants.CSW_NAMESPACE_PREFIX + CswConstants.NAMESPACE_DELIMITER + elementName, CswRecordCollection.class);
    return xstream;
}
Also used : StaxDriver(com.thoughtworks.xstream.io.xml.StaxDriver) XStream(com.thoughtworks.xstream.XStream) NoNameCoder(com.thoughtworks.xstream.io.naming.NoNameCoder)

Aggregations

NoNameCoder (com.thoughtworks.xstream.io.naming.NoNameCoder)13 XStream (com.thoughtworks.xstream.XStream)9 StaxDriver (com.thoughtworks.xstream.io.xml.StaxDriver)4 XppDriver (com.thoughtworks.xstream.io.xml.XppDriver)4 MarshallingContext (com.thoughtworks.xstream.converters.MarshallingContext)3 TreeMarshaller (com.thoughtworks.xstream.core.TreeMarshaller)3 CompactWriter (com.thoughtworks.xstream.io.xml.CompactWriter)3 PrettyPrintWriter (com.thoughtworks.xstream.io.xml.PrettyPrintWriter)3 ByteArrayInputStream (java.io.ByteArrayInputStream)3 StringWriter (java.io.StringWriter)3 HierarchicalStreamWriter (com.thoughtworks.xstream.io.HierarchicalStreamWriter)2 Writer (java.io.Writer)2 JAXBElement (javax.xml.bind.JAXBElement)2 ElementSetNameType (net.opengis.cat.csw.v_2_0_2.ElementSetNameType)2 GetRecordsResponseType (net.opengis.cat.csw.v_2_0_2.GetRecordsResponseType)2 GetRecordsType (net.opengis.cat.csw.v_2_0_2.GetRecordsType)2 ObjectFactory (net.opengis.cat.csw.v_2_0_2.ObjectFactory)2 QueryType (net.opengis.cat.csw.v_2_0_2.QueryType)2 SearchResultsType (net.opengis.cat.csw.v_2_0_2.SearchResultsType)2 DateTimeConverter (org.apache.camel.component.salesforce.api.utils.DateTimeConverter)2