use of com.thoughtworks.xstream.core.util.QuickWriter in project openolat by klemens.
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.core.util.QuickWriter 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.core.util.QuickWriter 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