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