Search in sources :

Example 1 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)

Example 2 with XStream

use of com.thoughtworks.xstream.XStream in project eureka by Netflix.

the class XmlCodecTest method testEncodingDecodingWithMetaData.

@Test
public void testEncodingDecodingWithMetaData() throws Exception {
    Applications applications = InstanceInfoGenerator.newBuilder(10, 2).withMetaData(true).build().toApplications();
    XStream xstream = XmlXStream.getInstance();
    String xmlDocument = xstream.toXML(applications);
    Applications decodedApplications = (Applications) xstream.fromXML(xmlDocument);
    assertThat(EurekaEntityComparators.equal(decodedApplications, applications), is(true));
}
Also used : Applications(com.netflix.discovery.shared.Applications) XStream(com.thoughtworks.xstream.XStream) Test(org.junit.Test)

Example 3 with XStream

use of com.thoughtworks.xstream.XStream in project eureka by Netflix.

the class XmlCodecTest method testEncodingDecodingWithoutMetaData.

@Test
public void testEncodingDecodingWithoutMetaData() throws Exception {
    Applications applications = InstanceInfoGenerator.newBuilder(10, 2).withMetaData(false).build().toApplications();
    XStream xstream = XmlXStream.getInstance();
    String xmlDocument = xstream.toXML(applications);
    Applications decodedApplications = (Applications) xstream.fromXML(xmlDocument);
    assertThat(EurekaEntityComparators.equal(decodedApplications, applications), is(true));
}
Also used : Applications(com.netflix.discovery.shared.Applications) XStream(com.thoughtworks.xstream.XStream) Test(org.junit.Test)

Example 4 with XStream

use of com.thoughtworks.xstream.XStream in project intellij-community by JetBrains.

the class HgAnnotateCommandTest method loadEthalonAnnotations.

@BeforeClass
private void loadEthalonAnnotations() throws IOException {
    myPluginRoot = new File(PluginPathManager.getPluginHomePath(HgVcs.VCS_NAME));
    myAnnotateDataDir = new File(myPluginRoot, "testData/annotate");
    myOutputsDir = new File(myAnnotateDataDir, "outputs");
    final File etalonFile = new File(myAnnotateDataDir, "etalon");
    XStream xStream = new XStream();
    FileReader reader = new FileReader(etalonFile);
    try {
        myAnnotations = (List<HgAnnotationLine>) xStream.fromXML(reader);
    } finally {
        reader.close();
    }
}
Also used : HgAnnotationLine(org.zmlx.hg4idea.provider.annotate.HgAnnotationLine) XStream(com.thoughtworks.xstream.XStream) FileReader(java.io.FileReader) File(java.io.File) BeforeClass(org.testng.annotations.BeforeClass)

Example 5 with XStream

use of com.thoughtworks.xstream.XStream in project intellij-community by JetBrains.

the class HgAnnotateCommandTest method generateCorrectAnnotation.

//@Test
public void generateCorrectAnnotation() throws IOException {
    final File etalonFile = new File(myAnnotateDataDir, "etalon");
    File outputFile = new File(myOutputsDir, "hg_1.9.0");
    String output = FileUtil.loadFile(outputFile);
    String[] split = output.split("(\n|\r|\r\n)");
    List<HgAnnotationLine> annotationLines = new ArrayList<>(split.length);
    Pattern pattern = Pattern.compile("\\s*(.+)\\s+(\\d+)\\s+([a-fA-F0-9]+)\\s+(\\d{4}-\\d{2}-\\d{2}):\\s*(\\d+): ?(.*)");
    for (String line : split) {
        Matcher matcher = pattern.matcher(line);
        if (!matcher.matches()) {
            fail("Couldn't parse line [ " + line + " ]");
        }
        String user = matcher.group(1);
        String shortRev = matcher.group(2);
        String fullRev = matcher.group(3);
        String date = matcher.group(4);
        String lineNum = matcher.group(5);
        String content = matcher.group(6);
        annotationLines.add(new HgAnnotationLine(user, HgRevisionNumber.getInstance(shortRev, fullRev), date, Integer.parseInt(lineNum), content));
    }
    XStream xStream = new XStream();
    FileWriter writer = new FileWriter(etalonFile);
    try {
        xStream.toXML(annotationLines, writer);
    } finally {
        writer.close();
    }
}
Also used : Pattern(java.util.regex.Pattern) HgAnnotationLine(org.zmlx.hg4idea.provider.annotate.HgAnnotationLine) Matcher(java.util.regex.Matcher) XStream(com.thoughtworks.xstream.XStream) FileWriter(java.io.FileWriter) ArrayList(java.util.ArrayList) File(java.io.File)

Aggregations

XStream (com.thoughtworks.xstream.XStream)432 Test (org.junit.Test)89 File (java.io.File)61 IOException (java.io.IOException)61 InputStream (java.io.InputStream)56 HashMap (java.util.HashMap)36 WstxDriver (com.thoughtworks.xstream.io.xml.WstxDriver)33 DomDriver (com.thoughtworks.xstream.io.xml.DomDriver)32 Metacard (ddf.catalog.data.Metacard)32 ArrayList (java.util.ArrayList)32 StaxDriver (com.thoughtworks.xstream.io.xml.StaxDriver)29 ByteArrayInputStream (java.io.ByteArrayInputStream)24 HierarchicalStreamWriter (com.thoughtworks.xstream.io.HierarchicalStreamWriter)20 CswRecordCollection (org.codice.ddf.spatial.ogc.csw.catalog.common.CswRecordCollection)20 FileOutputStream (java.io.FileOutputStream)19 Map (java.util.Map)19 List (java.util.List)17 FileNotFoundException (java.io.FileNotFoundException)16 FileWriter (java.io.FileWriter)16 JAXBElement (javax.xml.bind.JAXBElement)16