Search in sources :

Example 16 with XStream

use of com.thoughtworks.xstream.XStream in project camel by apache.

the class XStreamDataFormatPermissionsTest method testDenyAndAllowDeny.

@Test
public void testDenyAndAllowDeny() {
    XStreamDataFormat xStreamDataFormat = new XStreamDataFormat();
    xStreamDataFormat.setPermissions("-org.apache.camel.dataformat.xstream.*,org.apache.camel.dataformat.xstream.PurchaseOrder");
    XStream xStream = xStreamDataFormat.createXStream(context.getClassResolver(), context.getApplicationContextClassLoader());
    Object po = xStream.fromXML(XML_PURCHASE_ORDER);
    assertNotNull(po);
    po = xStream.fromXML(XML_PURCHASE_ORDERS_LIST);
    assertNotNull(po);
}
Also used : XStream(com.thoughtworks.xstream.XStream) Test(org.junit.Test)

Example 17 with XStream

use of com.thoughtworks.xstream.XStream in project camel by apache.

the class XStreamDataFormatPermissionsTest method testAllowAny.

@Test
public void testAllowAny() {
    XStreamDataFormat xStreamDataFormat = new XStreamDataFormat();
    xStreamDataFormat.setPermissions("*");
    XStream xStream = xStreamDataFormat.createXStream(context.getClassResolver(), context.getApplicationContextClassLoader());
    Object po = xStream.fromXML(XML_PURCHASE_ORDER);
    assertNotNull(po);
    po = xStream.fromXML(XML_PURCHASE_ORDERS_LIST);
    assertNotNull(po);
}
Also used : XStream(com.thoughtworks.xstream.XStream) Test(org.junit.Test)

Example 18 with XStream

use of com.thoughtworks.xstream.XStream in project hudson-2.x by hudson.

the class XReferenceStoreConverterTest method testChewDocument.

@Test
public void testChewDocument() throws Exception {
    XStream xs = new XStream();
    xs.autodetectAnnotations(true);
    XStreamMarshaller marshaller = new XStreamMarshaller(xs);
    XReferenceStore store = new FileXReferenceStore(marshaller, util.resolveFile("target/test-xref"));
    XReferenceStoreConverter converter = new XReferenceStoreConverter(store, xs.getMapper(), xs.getReflectionProvider());
    xs.registerConverter(converter);
    Document<Record> doc1 = new Document<Record>();
    Record rec1 = new Record("1");
    Entity ent1 = new Entity("1");
    rec1.set(ent1);
    assertNotNull(rec1.entity.holder);
    assertTrue(rec1.entity.holder instanceof XReference.InstanceHolder);
    XReference.InstanceHolder holder1 = (XReference.InstanceHolder) rec1.entity.holder;
    assertNotNull(holder1.instance);
    doc1.records.add(rec1);
    StringWriter buff = new StringWriter();
    marshaller.marshal(doc1, buff);
    System.out.println("XML:\n" + buff);
    Document<Record> doc2 = (Document<Record>) marshaller.unmarshal(new StringReader(buff.toString()));
    assertNotNull(doc2);
    assertNotNull(doc2.records);
    assertEquals(1, doc2.records.size());
    Record rec2 = doc2.records.get(0);
    assertNotNull(rec2.entity);
    System.out.println("ENT REF: " + rec2.entity);
    assertNotNull(rec2.entity.holder);
    assertTrue(rec2.entity.holder instanceof XReferenceStoreConverter.UnmarshalHolder);
    XReferenceStoreConverter.UnmarshalHolder holder2 = (XReferenceStoreConverter.UnmarshalHolder) rec2.entity.holder;
    assertNull(holder2.instance);
    Entity ent2 = rec2.get();
    System.out.println("ENT: " + ent2);
    assertNotNull(ent2);
    assertNotNull(holder2.instance);
    buff = new StringWriter();
    marshaller.marshal(doc2, buff);
    System.out.println("XML\n" + buff);
}
Also used : XStream(com.thoughtworks.xstream.XStream) XStreamMarshaller(org.hudsonci.utils.marshal.XStreamMarshaller) StringWriter(java.io.StringWriter) StringReader(java.io.StringReader) Test(org.junit.Test)

Example 19 with XStream

use of com.thoughtworks.xstream.XStream in project jscs-plugin by idok.

the class JscsLint method read.

public static JscsLint read(String xml) {
    XStream xstream = new XStream();
    xstream.alias("checkstyle", JscsLint.class);
    xstream.useAttributeFor(JscsLint.class, "version");
    xstream.alias("file", File.class);
    xstream.alias("error", Issue.class);
    xstream.addImplicitCollection(File.class, "errors");
    xstream.useAttributeFor(File.class, "name");
    xstream.useAttributeFor(Issue.class, "source");
    xstream.useAttributeFor(Issue.class, "line");
    xstream.useAttributeFor(Issue.class, "column");
    xstream.useAttributeFor(Issue.class, "severity");
    xstream.useAttributeFor(Issue.class, "message");
    JscsLint lint = (JscsLint) xstream.fromXML(xml);
    if (lint.file.errors == null) {
        lint.file.errors = new ArrayList<Issue>();
    }
    return lint;
}
Also used : XStream(com.thoughtworks.xstream.XStream)

Example 20 with XStream

use of com.thoughtworks.xstream.XStream in project Openfire by igniterealtime.

the class FormManager method saveDataForm.

private void saveDataForm(Workgroup workgroup) {
    DataForm dataForm = new DataForm(DataForm.Type.form);
    WorkgroupForm form = getWebForm(workgroup);
    if (form.getTitle() != null) {
        dataForm.setTitle(form.getTitle());
    }
    if (form.getDescription() != null) {
        dataForm.addInstruction(form.getDescription());
    }
    List<FormElement> elems = new ArrayList<FormElement>();
    // Add normal elems
    int size = form.getFormElements().size();
    for (int j = 0; j < size; j++) {
        elems.add(form.getFormElementAt(j));
    }
    size = form.getHiddenVars().size();
    for (int k = 0; k < size; k++) {
        elems.add(form.getHiddenVars().get(k));
    }
    size = elems.size();
    for (int i = 0; i < size; i++) {
        FormElement elem = elems.get(i);
        FormField field = dataForm.addField();
        field.setLabel(elem.getLabel());
        field.setVariable(elem.getVariable());
        field.setRequired(elem.isRequired());
        if (elem.getDescription() != null) {
            field.setDescription(elem.getDescription());
        }
        if (elem.getAnswerType() == WorkgroupForm.FormEnum.textarea) {
            field.setType(FormField.Type.text_multi);
        } else if (elem.getAnswerType() == WorkgroupForm.FormEnum.textfield) {
            field.setType(FormField.Type.text_single);
        } else if (elem.getAnswerType() == WorkgroupForm.FormEnum.checkbox) {
            field.setType(FormField.Type.boolean_type);
        } else if (elem.getAnswerType() == WorkgroupForm.FormEnum.radio_button) {
            field.setType(FormField.Type.list_multi);
        } else if (elem.getAnswerType() == WorkgroupForm.FormEnum.dropdown_box) {
            field.setType(FormField.Type.list_single);
        } else if (elem.getAnswerType() == WorkgroupForm.FormEnum.hidden) {
            field.setType(FormField.Type.hidden);
        } else if (elem.getAnswerType() == WorkgroupForm.FormEnum.password) {
            field.setType(FormField.Type.text_private);
        }
        if (elem.getAnswers().size() > 0 && elem.getAnswerType() != WorkgroupForm.FormEnum.hidden) {
            for (String item : elem.getAnswers()) {
                field.addOption(item, item);
            }
        } else if (elem.getAnswers().size() > 0) {
            // Add hidden element values.
            for (String item : elem.getAnswers()) {
                field.addValue(item);
            }
        }
    }
    XStream xstream = new XStream();
    String xmlToSave = xstream.toXML(dataForm);
    DbProperties props = workgroup.getProperties();
    String context = "jive.dataform.wg";
    try {
        props.deleteProperty(context);
        props.setProperty(context, xmlToSave);
    } catch (UnauthorizedException e) {
        Log.error(e.getMessage(), e);
    }
}
Also used : XStream(com.thoughtworks.xstream.XStream) DataForm(org.xmpp.forms.DataForm) ArrayList(java.util.ArrayList) UnauthorizedException(org.jivesoftware.xmpp.workgroup.UnauthorizedException) DbProperties(org.jivesoftware.xmpp.workgroup.DbProperties) FormField(org.xmpp.forms.FormField)

Aggregations

XStream (com.thoughtworks.xstream.XStream)199 Test (org.junit.Test)55 IOException (java.io.IOException)33 InputStream (java.io.InputStream)29 WstxDriver (com.thoughtworks.xstream.io.xml.WstxDriver)22 Metacard (ddf.catalog.data.Metacard)21 DomDriver (com.thoughtworks.xstream.io.xml.DomDriver)17 HashMap (java.util.HashMap)14 ByteArrayInputStream (java.io.ByteArrayInputStream)13 StaxDriver (com.thoughtworks.xstream.io.xml.StaxDriver)12 XStreamUtils.createTrustingXStream (org.kie.soup.commons.xstream.XStreamUtils.createTrustingXStream)12 Matchers.anyString (org.mockito.Matchers.anyString)11 HierarchicalStreamWriter (com.thoughtworks.xstream.io.HierarchicalStreamWriter)10 CswRecordCollection (org.codice.ddf.spatial.ogc.csw.catalog.common.CswRecordCollection)10 FileNotFoundException (java.io.FileNotFoundException)9 Writer (java.io.Writer)8 ArrayList (java.util.ArrayList)8 GmlGeometryConverter (org.codice.ddf.spatial.ogc.wfs.catalog.converter.impl.GmlGeometryConverter)8 XStreamException (com.thoughtworks.xstream.XStreamException)7 MarshallingContext (com.thoughtworks.xstream.converters.MarshallingContext)7