Search in sources :

Example 1 with XppDriver

use of com.thoughtworks.xstream.io.xml.XppDriver in project camel by apache.

the class DefaultCompositeApiClient method configureXStream.

static XStream configureXStream() {
    final PureJavaReflectionProvider reflectionProvider = new PureJavaReflectionProvider(new FieldDictionary(new AnnotationFieldKeySorter()));
    final XppDriver hierarchicalStreamDriver = new XppDriver(new NoNameCoder()) {

        @Override
        public HierarchicalStreamWriter createWriter(final Writer out) {
            return new CompactWriter(out, getNameCoder());
        }
    };
    final XStream xStream = new XStream(reflectionProvider, hierarchicalStreamDriver);
    xStream.aliasSystemAttribute(null, "class");
    xStream.ignoreUnknownElements();
    XStreamUtils.addDefaultPermissions(xStream);
    xStream.registerConverter(new DateTimeConverter());
    xStream.setMarshallingStrategy(new TreeMarshallingStrategy());
    xStream.processAnnotations(ADDITIONAL_TYPES);
    return xStream;
}
Also used : AnnotationFieldKeySorter(org.apache.camel.component.salesforce.api.dto.AnnotationFieldKeySorter) TreeMarshallingStrategy(com.thoughtworks.xstream.core.TreeMarshallingStrategy) CompactWriter(com.thoughtworks.xstream.io.xml.CompactWriter) XppDriver(com.thoughtworks.xstream.io.xml.XppDriver) XStream(com.thoughtworks.xstream.XStream) FieldDictionary(com.thoughtworks.xstream.converters.reflection.FieldDictionary) DateTimeConverter(org.apache.camel.component.salesforce.api.utils.DateTimeConverter) NoNameCoder(com.thoughtworks.xstream.io.naming.NoNameCoder) HierarchicalStreamWriter(com.thoughtworks.xstream.io.HierarchicalStreamWriter) ObjectWriter(com.fasterxml.jackson.databind.ObjectWriter) Writer(java.io.Writer) CompactWriter(com.thoughtworks.xstream.io.xml.CompactWriter) PureJavaReflectionProvider(com.thoughtworks.xstream.converters.reflection.PureJavaReflectionProvider)

Example 2 with XppDriver

use of com.thoughtworks.xstream.io.xml.XppDriver in project camel by apache.

the class ApprovalRequestsTest method shouldSerializeAsXml.

@Test
public void shouldSerializeAsXml() {
    final String xml = //
    "<ProcessApprovalRequest>" + //
    "<requests>" + //
    "<actionType>Submit</actionType>" + //
    "<contextActorId>005D00000015rZy</contextActorId>" + //
    "<contextId>001D000000I8mIm</contextId>" + //
    "<comments>this is a test 1</comments>" + //
    "<nextApproverIds>005D00000015rY9</nextApproverIds>" + //
    "<processDefinitionNameOrId>PTO_Request_Process</processDefinitionNameOrId>" + //
    "<skipEntryCriteria>true</skipEntryCriteria>" + //
    "</requests>" + //
    "<requests>" + //
    "<actionType>Submit</actionType>" + //
    "<contextActorId>005D00000015rZy</contextActorId>" + //
    "<contextId>001D000000I8dIm</contextId>" + //
    "<comments>this is a test 2</comments>" + //
    "<nextApproverIds>005D00000015xY9</nextApproverIds>" + //
    "<processDefinitionNameOrId>PTO_Request_Process</processDefinitionNameOrId>" + //
    "<skipEntryCriteria>true</skipEntryCriteria>" + //
    "</requests>" + "</ProcessApprovalRequest>";
    final XStream xStream = new XStream(new XppDriver(new NoNameCoder()) {

        @Override
        public HierarchicalStreamWriter createWriter(final Writer out) {
            return new CompactWriter(out, getNameCoder());
        }
    });
    xStream.ignoreUnknownElements();
    XStreamUtils.addDefaultPermissions(xStream);
    xStream.registerConverter(new DateTimeConverter());
    xStream.processAnnotations(ApprovalRequests.class);
    final String serialized = xStream.toXML(requests);
    assertEquals("Approval requests should serialize as XML", xml, serialized);
}
Also used : CompactWriter(com.thoughtworks.xstream.io.xml.CompactWriter) XppDriver(com.thoughtworks.xstream.io.xml.XppDriver) HierarchicalStreamWriter(com.thoughtworks.xstream.io.HierarchicalStreamWriter) XStream(com.thoughtworks.xstream.XStream) DateTimeConverter(org.apache.camel.component.salesforce.api.utils.DateTimeConverter) NoNameCoder(com.thoughtworks.xstream.io.naming.NoNameCoder) HierarchicalStreamWriter(com.thoughtworks.xstream.io.HierarchicalStreamWriter) Writer(java.io.Writer) CompactWriter(com.thoughtworks.xstream.io.xml.CompactWriter) Test(org.junit.Test)

Example 3 with XppDriver

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

the class TestCswRecordConverter method testUnmarshalNoNamespaceDeclaration.

@Test
public void testUnmarshalNoNamespaceDeclaration() throws IOException, SAXException {
    XStream xstream = new XStream(new XppDriver());
    xstream.registerConverter(converter);
    xstream.alias("Record", MetacardImpl.class);
    xstream.alias("csw:Record", MetacardImpl.class);
    InputStream is = IOUtils.toInputStream(getRecordNoNamespaceDeclaration());
    Metacard mc = (Metacard) xstream.fromXML(is);
    Metacard expectedMetacard = getTestMetacard();
    assertThat(mc, notNullValue());
    assertThat(mc.getContentTypeName(), is(expectedMetacard.getContentTypeName()));
    assertThat(mc.getCreatedDate(), is(expectedMetacard.getCreatedDate()));
    assertThat(mc.getEffectiveDate(), is(expectedMetacard.getEffectiveDate()));
    assertThat(mc.getId(), is(expectedMetacard.getId()));
    assertThat(mc.getModifiedDate(), is(expectedMetacard.getModifiedDate()));
    assertThat(mc.getTitle(), is(expectedMetacard.getTitle()));
    assertThat(mc.getResourceURI(), is(expectedMetacard.getResourceURI()));
}
Also used : Metacard(ddf.catalog.data.Metacard) XppDriver(com.thoughtworks.xstream.io.xml.XppDriver) XStream(com.thoughtworks.xstream.XStream) InputStream(java.io.InputStream) Test(org.junit.Test)

Example 4 with XppDriver

use of com.thoughtworks.xstream.io.xml.XppDriver in project openolat by klemens.

the class InstitutionConfiguration method getInstitutionConfigXStream.

public static XStream getInstitutionConfigXStream() {
    XStream xstream = new XStream(new XppDriver(new NoNameCoder()));
    xstream.alias("configuration", InstitutionConfiguration.class);
    xstream.addImplicitCollection(InstitutionConfiguration.class, "institution", "institution", InstitutionPortletEntry.class);
    xstream.alias("institution", InstitutionPortletEntry.class);
    xstream.addImplicitCollection(InstitutionPortletEntry.class, "polymorphlink", "polymorphlink", PolymorphLink.class);
    xstream.aliasAttribute(InstitutionPortletEntry.class, "shortname", "shortname");
    xstream.alias("logo", Value.class);
    xstream.alias("name", Value.class);
    xstream.alias("url", Value.class);
    xstream.alias("supervisor", InstitutionPortletSupervisorEntry.class);
    xstream.addImplicitCollection(InstitutionPortletEntry.class, "supervisor", "supervisor", InstitutionPortletSupervisorEntry.class);
    xstream.alias("person", Value.class);
    xstream.alias("phone", Value.class);
    xstream.alias("email", Value.class);
    xstream.alias("blog", Value.class);
    // polymorph link
    xstream.alias("polymorphlink", PolymorphLink.class);
    xstream.aliasAttribute(PolymorphLink.class, "defaultId", "default_targetid");
    xstream.aliasAttribute(PolymorphLink.class, "linkType", "type");
    xstream.aliasAttribute(PolymorphLink.class, "linkText", "text");
    // polymorph link element
    xstream.alias("element", PolymorphLinkElement.class);
    xstream.addImplicitCollection(PolymorphLink.class, "element", "element", PolymorphLinkElement.class);
    xstream.aliasAttribute(PolymorphLinkElement.class, "attribute", "attribute");
    xstream.aliasAttribute(PolymorphLinkElement.class, "value", "value");
    xstream.aliasAttribute(PolymorphLinkElement.class, "cond", "condition");
    xstream.aliasAttribute(PolymorphLinkElement.class, "id", "targetid");
    xstream.aliasAttribute(Value.class, "value", "value");
    return xstream;
}
Also used : XppDriver(com.thoughtworks.xstream.io.xml.XppDriver) XStream(com.thoughtworks.xstream.XStream) NoNameCoder(com.thoughtworks.xstream.io.naming.NoNameCoder)

Example 5 with XppDriver

use of com.thoughtworks.xstream.io.xml.XppDriver in project OpenOLAT by OpenOLAT.

the class InstitutionConfiguration method getInstitutionConfigXStream.

public static XStream getInstitutionConfigXStream() {
    XStream xstream = new XStream(new XppDriver(new NoNameCoder()));
    xstream.alias("configuration", InstitutionConfiguration.class);
    xstream.addImplicitCollection(InstitutionConfiguration.class, "institution", "institution", InstitutionPortletEntry.class);
    xstream.alias("institution", InstitutionPortletEntry.class);
    xstream.addImplicitCollection(InstitutionPortletEntry.class, "polymorphlink", "polymorphlink", PolymorphLink.class);
    xstream.aliasAttribute(InstitutionPortletEntry.class, "shortname", "shortname");
    xstream.alias("logo", Value.class);
    xstream.alias("name", Value.class);
    xstream.alias("url", Value.class);
    xstream.alias("supervisor", InstitutionPortletSupervisorEntry.class);
    xstream.addImplicitCollection(InstitutionPortletEntry.class, "supervisor", "supervisor", InstitutionPortletSupervisorEntry.class);
    xstream.alias("person", Value.class);
    xstream.alias("phone", Value.class);
    xstream.alias("email", Value.class);
    xstream.alias("blog", Value.class);
    // polymorph link
    xstream.alias("polymorphlink", PolymorphLink.class);
    xstream.aliasAttribute(PolymorphLink.class, "defaultId", "default_targetid");
    xstream.aliasAttribute(PolymorphLink.class, "linkType", "type");
    xstream.aliasAttribute(PolymorphLink.class, "linkText", "text");
    // polymorph link element
    xstream.alias("element", PolymorphLinkElement.class);
    xstream.addImplicitCollection(PolymorphLink.class, "element", "element", PolymorphLinkElement.class);
    xstream.aliasAttribute(PolymorphLinkElement.class, "attribute", "attribute");
    xstream.aliasAttribute(PolymorphLinkElement.class, "value", "value");
    xstream.aliasAttribute(PolymorphLinkElement.class, "cond", "condition");
    xstream.aliasAttribute(PolymorphLinkElement.class, "id", "targetid");
    xstream.aliasAttribute(Value.class, "value", "value");
    return xstream;
}
Also used : XppDriver(com.thoughtworks.xstream.io.xml.XppDriver) XStream(com.thoughtworks.xstream.XStream) NoNameCoder(com.thoughtworks.xstream.io.naming.NoNameCoder)

Aggregations

XppDriver (com.thoughtworks.xstream.io.xml.XppDriver)13 XStream (com.thoughtworks.xstream.XStream)11 HierarchicalStreamWriter (com.thoughtworks.xstream.io.HierarchicalStreamWriter)5 Writer (java.io.Writer)5 NoNameCoder (com.thoughtworks.xstream.io.naming.NoNameCoder)4 InputStream (java.io.InputStream)4 InputStreamReader (java.io.InputStreamReader)4 DataHolder (com.thoughtworks.xstream.converters.DataHolder)3 QuickWriter (com.thoughtworks.xstream.core.util.QuickWriter)3 PrettyPrintWriter (com.thoughtworks.xstream.io.xml.PrettyPrintWriter)3 Test (org.junit.Test)3 CompactWriter (com.thoughtworks.xstream.io.xml.CompactWriter)2 Metacard (ddf.catalog.data.Metacard)2 BufferedReader (java.io.BufferedReader)2 File (java.io.File)2 FileInputStream (java.io.FileInputStream)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 DateTimeConverter (org.apache.camel.component.salesforce.api.utils.DateTimeConverter)2 ObjectWriter (com.fasterxml.jackson.databind.ObjectWriter)1