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