use of com.thoughtworks.xstream.io.xml.PrettyPrintWriter in project ddf by codice.
the class TestCswRecordConverter method testMarshalRecord.
@Test
public void testMarshalRecord() throws IOException, JAXBException, SAXException, XpathException {
Metacard metacard = getTestMetacard();
StringWriter stringWriter = new StringWriter();
PrettyPrintWriter writer = new PrettyPrintWriter(stringWriter);
MarshallingContext context = new TreeMarshaller(writer, null, null);
converter.marshal(metacard, writer, context);
String xml = stringWriter.toString();
assertThat(xml, containsString(CswConstants.CSW_RECORD));
assertRecordXml(xml, metacard, FULL);
}
use of com.thoughtworks.xstream.io.xml.PrettyPrintWriter in project ddf by codice.
the class TestCswRecordConverter method testMarshalSummaryRecord.
@Test
public void testMarshalSummaryRecord() throws IOException, JAXBException, SAXException, XpathException {
Metacard metacard = getTestMetacard();
StringWriter stringWriter = new StringWriter();
PrettyPrintWriter writer = new PrettyPrintWriter(stringWriter);
MarshallingContext context = new TreeMarshaller(writer, null, null);
context.put(CswConstants.ELEMENT_SET_TYPE, ElementSetType.SUMMARY);
converter.marshal(metacard, writer, context);
String xml = stringWriter.toString();
assertThat(xml, containsString(CswConstants.CSW_SUMMARY_RECORD));
assertRecordXml(xml, metacard, SUMMARY);
}
use of com.thoughtworks.xstream.io.xml.PrettyPrintWriter in project ddf by codice.
the class TestGmdConverter method convert.
private String convert(Object object, boolean writeNamespaces) {
GmdConverter converter = new GmdConverter();
StringWriter stringWriter = new StringWriter();
PrettyPrintWriter writer = new PrettyPrintWriter(stringWriter, new NoNameCoder());
MarshallingContext context = new TreeMarshaller(writer, null, null);
context.put(CswConstants.WRITE_NAMESPACES, writeNamespaces);
converter.marshal(object, writer, context);
return stringWriter.toString();
}
use of com.thoughtworks.xstream.io.xml.PrettyPrintWriter in project OpenOLAT by OpenOLAT.
the class GlossaryItemManager method saveToFile.
// TODO:RH:gloss improvement: dtd in xml files
/**
* writes glossary to xml-file
* prepend doc-book dtd:
* <!DOCTYPE glossary PUBLIC "-//OASIS//DTD DocBook XML V4.1.2//EN" "http://www.oasis-open.org/docbook/xml/4.1.2/docbookx.dtd">
*
* @param glossaryFile
* @param glossaryItemArr
*/
private void saveToFile(VFSLeaf glossaryFile, ArrayList<GlossaryItem> glossaryItemArr) {
// cdata-tags should be used instead of strings, overwrite writer.
XStream xstream = new XStream(new XppDriver() {
public HierarchicalStreamWriter createWriter(Writer out) {
return new PrettyPrintWriter(out) {
protected void writeText(QuickWriter writer, String text) {
if (text.contains("<") || text.contains(">") || text.contains("&")) {
writer.write("<![CDATA[");
writer.write(text);
writer.write("]]>");
} else {
writer.write(text);
}
}
};
}
});
xstream.alias(XML_GLOSSARY_ITEM_NAME, GlossaryItem.class);
xstream.alias(XML_REVISION_NAME, Revision.class);
glossaryItemArr = removeEmptyGlossaryItems(glossaryItemArr);
XStreamHelper.writeObject(xstream, glossaryFile, glossaryItemArr);
}
use of com.thoughtworks.xstream.io.xml.PrettyPrintWriter in project weixin-java-tools by chanjarster.
the class XStreamInitializer method getInstance.
public static XStream getInstance() {
XStream xstream = new XStream(new XppDriver() {
@Override
public HierarchicalStreamWriter createWriter(Writer out) {
return new PrettyPrintWriter(out, getNameCoder()) {
protected String PREFIX_CDATA = "<![CDATA[";
protected String SUFFIX_CDATA = "]]>";
protected String PREFIX_MEDIA_ID = "<MediaId>";
protected String SUFFIX_MEDIA_ID = "</MediaId>";
@Override
protected void writeText(QuickWriter writer, String text) {
if (text.startsWith(PREFIX_CDATA) && text.endsWith(SUFFIX_CDATA)) {
writer.write(text);
} else if (text.startsWith(PREFIX_MEDIA_ID) && text.endsWith(SUFFIX_MEDIA_ID)) {
writer.write(text);
} else {
super.writeText(writer, text);
}
}
};
}
});
xstream.ignoreUnknownElements();
xstream.setMode(XStream.NO_REFERENCES);
xstream.addPermission(NullPermission.NULL);
xstream.addPermission(PrimitiveTypePermission.PRIMITIVES);
return xstream;
}
Aggregations