Java Code Examples for com.thoughtworks.xstream.core.util.QuickWriter#write()
The following examples show how to use
com.thoughtworks.xstream.core.util.QuickWriter#write() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MessageUtil.java From jeewx-boot with Apache License 2.0 | 6 votes |
public HierarchicalStreamWriter createWriter(Writer out) { return new PrettyPrintWriter(out) { // 对所有xml节点的转换都增加CDATA标记 boolean cdata = true; @SuppressWarnings("unchecked") public void startNode(String name, Class clazz) { super.startNode(name, clazz); } protected void writeText(QuickWriter writer, String text) { if (cdata) { writer.write("<![CDATA["); writer.write(text); writer.write("]]>"); } else { writer.write(text); } } }; }
Example 2
Source File: WXMessageUtil.java From WeChatEnterprise with Apache License 2.0 | 6 votes |
public HierarchicalStreamWriter createWriter(Writer out) { return new PrettyPrintWriter(out) { // 对所有xml节点的转换都增加CDATA标记 boolean cdata = true; public void startNode(String name, Class clazz) { super.startNode(name, clazz); } protected void writeText(QuickWriter writer, String text) { if (cdata) { writer.write("<![CDATA["); writer.write(text); writer.write("]]>"); } else { writer.write(text); } } }; }
Example 3
Source File: MsgXmlUtil.java From AlipayWechatPlatform with GNU General Public License v3.0 | 6 votes |
public HierarchicalStreamWriter createWriter(Writer out) { return new PrettyPrintWriter(out) { boolean CDATA = true; @SuppressWarnings("rawtypes") public void startNode(String name, Class clazz) { super.startNode(name, clazz); } protected void writeText(QuickWriter writer, String text) { if (CDATA) { writer.write("<![CDATA["); writer.write(text); writer.write("]]>"); } else { writer.write(text); } } }; }
Example 4
Source File: MessageUtils.java From wechat-core with Apache License 2.0 | 6 votes |
/** * 扩展xstream,使其支持CDATA块 */ private static XStream newXStreamInstance() { return new XStream(new XppDriver() { @Override public HierarchicalStreamWriter createWriter(Writer out) { return new PrettyPrintWriter(out) { // 对所有xml节点的转换都增加CDATA标记 boolean cdata = true; @Override protected void writeText(QuickWriter writer, String text) { if (this.cdata) { writer.write("<![CDATA["); writer.write(text); writer.write("]]>"); } else { writer.write(text); } } }; } }); }
Example 5
Source File: MessageUtil.java From jeewx with Apache License 2.0 | 6 votes |
public HierarchicalStreamWriter createWriter(Writer out) { return new PrettyPrintWriter(out) { // 对所有xml节点的转换都增加CDATA标记 boolean cdata = true; @SuppressWarnings("unchecked") public void startNode(String name, Class clazz) { super.startNode(name, clazz); } protected void writeText(QuickWriter writer, String text) { if (cdata) { writer.write("<![CDATA["); writer.write(text); writer.write("]]>"); } else { writer.write(text); } } }; }
Example 6
Source File: MessageUtil.java From jeewx with Apache License 2.0 | 6 votes |
public HierarchicalStreamWriter createWriter(Writer out) { return new PrettyPrintWriter(out) { // 对所有xml节点的转换都增加CDATA标记 boolean cdata = true; @SuppressWarnings("unchecked") public void startNode(String name, Class clazz) { super.startNode(name, clazz); } protected void writeText(QuickWriter writer, String text) { if (cdata) { writer.write("<![CDATA["); writer.write(text); writer.write("]]>"); } else { writer.write(text); } } }; }
Example 7
Source File: QuestionRssEntryFactory.java From mamute with Apache License 2.0 | 6 votes |
private XStream buildXstream() { return new XStream(new XppDriver() { public HierarchicalStreamWriter createWriter(Writer out) { return new PrettyPrintWriter(out) { List<String> cdataFields = asList("title", "author"); boolean cdata = false; public void startNode(String name, Class clazz) { super.startNode(name, clazz); cdata = cdataFields.contains(name); } protected void writeText(QuickWriter writer, String text) { if (cdata) { writer.write("<![CDATA["); writer.write(text); writer.write("]]>"); } else { writer.write(text); } } }; } }); }
Example 8
Source File: GlossaryItemManager.java From olat with Apache License 2.0 | 6 votes |
/** * 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() { @Override public HierarchicalStreamWriter createWriter(Writer out) { return new PrettyPrintWriter(out) { @Override 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); glossaryItemArr = removeEmptyGlossaryItems(glossaryItemArr); XStreamHelper.writeObject(xstream, glossaryFile, glossaryItemArr); }
Example 9
Source File: GlossaryItemManager.java From olat with Apache License 2.0 | 6 votes |
/** * 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() { @Override public HierarchicalStreamWriter createWriter(Writer out) { return new PrettyPrintWriter(out) { @Override 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); glossaryItemArr = removeEmptyGlossaryItems(glossaryItemArr); XStreamHelper.writeObject(xstream, glossaryFile, glossaryItemArr); }
Example 10
Source File: CDATAXppDriver.java From javalite with Apache License 2.0 | 6 votes |
@Override public HierarchicalStreamWriter createWriter(Writer out) { return new PrettyPrintWriter(out) { boolean cdata; @Override public void startNode(String name, Class clazz) { super.startNode(name, clazz); cdata = CharSequence.class.isAssignableFrom(clazz); } @Override protected void writeText(QuickWriter writer, String text) { if(cdata) { writer.write("<![CDATA["); writer.write(text); writer.write("]]>"); } else { writer.write(text); } } }; }
Example 11
Source File: XStreamInitializer.java From weixin-java-tools with Apache License 2.0 | 5 votes |
public static XStream getInstance() { XStream xstream = new XStream(new PureJavaReflectionProvider(), 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(this.PREFIX_CDATA) && text.endsWith(this.SUFFIX_CDATA)) { writer.write(text); } else if (text.startsWith(this.PREFIX_MEDIA_ID) && text.endsWith(this.SUFFIX_MEDIA_ID)) { writer.write(text); } else { super.writeText(writer, text); } } @Override public String encodeNode(String name) { //防止将_转换成__ return name; } }; } }); xstream.ignoreUnknownElements(); xstream.setMode(XStream.NO_REFERENCES); xstream.addPermission(NullPermission.NULL); xstream.addPermission(PrimitiveTypePermission.PRIMITIVES); xstream.setClassLoader(Thread.currentThread().getContextClassLoader()); return xstream; }
Example 12
Source File: XmlUtil.java From weChatRobot with MIT License | 5 votes |
@Override public HierarchicalStreamWriter createWriter(Writer out) { return new PrettyPrintWriter(out) { @Override protected void writeText(QuickWriter writer, String text) { //对所有xml节点的转换都增加CDATA标记 writer.write("<![CDATA["); writer.write(text); writer.write("]]>"); } }; }
Example 13
Source File: GatfPrettyPrintWriter.java From gatf with Apache License 2.0 | 5 votes |
protected void writeText(QuickWriter writer, String text) { if(StringUtils.isBlank(text)) return; if(cdata) { writer.write("<![CDATA["); writer.write(text); writer.write("]]>"); } else { writeText(text, false); } }
Example 14
Source File: XStreamInitializer.java From weixin-java-tools with Apache License 2.0 | 5 votes |
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; }
Example 15
Source File: XmlApiPrintWriter.java From engage-api-client with Apache License 2.0 | 5 votes |
@Override protected void writeText(QuickWriter writer, String text) { if(hasSpecialCharacters(text)) { writer.write(String.format("%s%s%s", CDATA_START, text, CDATA_END)); } else { super.writeText(writer, text); } }