public void addString(String s) { m_buffer.append(s); }
/** * Add an empty element tag (e.g. <foo/>) * @param tagName The name of the tag * @param attributes A Properties file containing the attributes (or null) */ public void addEmptyElement(String tagName, @Nullable Properties attributes) { m_buffer.append(m_currentIndent).append("<").append(tagName); XMLUtils.appendAttributes(m_buffer, attributes); m_buffer.append("/>").append(EOL); }
public void addString(String s) { m_buffer.append(s); }
/** * Add a CDATA tag. */ public void addCDATA(String content) { if (content != null) { //Solution from https://coderanch.com/t/455930/java/Remove-control-characters content = content.replaceAll("[\\p{Cc}&&[^\\r\\n]]", ""); } m_buffer.append(m_currentIndent); if (content == null) { m_buffer.append("<![CDATA[null]]>"); } else if (!content.contains("]]>")) { m_buffer.append("<![CDATA[").append(content).append("]]>"); } else if ("]]>".equals(content)) { // Solution from http://stackoverflow.com/q/223652/4234729 m_buffer.append("<![CDATA[]]]]><![CDATA[>]]>"); } else { // content contains "]]>" String[] subStrings = content.split("]]>"); m_buffer.append("<![CDATA[").append(subStrings[0]).append("]]]]>"); for (int i = 1; i < subStrings.length - 1; i++) { m_buffer.append("<![CDATA[>").append(subStrings[i]).append("]]]]>"); } m_buffer.append("<![CDATA[>").append(subStrings[subStrings.length - 1]).append("]]>"); if (content.endsWith("]]>")) { m_buffer.append("<![CDATA[]]]]>").append("<![CDATA[>]]>"); } } m_buffer.append(EOL); }
public void addComment(String comment) { m_buffer.append(m_currentIndent).append("<!-- " + comment.replaceAll("[-]{2,}", "-") + " -->\n"); }
/** * Add an empty element tag (e.g. <foo/>) * * @param tagName The name of the tag * @param attributes A Properties file containing the attributes (or null) */ public void addEmptyElement(String tagName, @Nullable Properties attributes) { m_buffer.append(m_currentIndent).append("<").append(tagName); XMLUtils.appendAttributes(m_buffer, attributes); m_buffer.append("/>").append(EOL); }
/** * Appends the attributes to result. The attributes are added on a single line * as: key1="value1" key2="value2" ... (a space is added before the first key) * * @param result * the buffer to append attributes to. * @param attributes * the attributes to append (may be null). */ public static void appendAttributes(IBuffer result, Properties attributes) { if (null != attributes) { for (Object element : attributes.entrySet()) { Entry entry = (Entry) element; String key = entry.getKey().toString(); String value = escape(entry.getValue().toString()); result.append(" ").append(key).append("=\"").append(value).append("\""); } } }
public void addComment(String comment) { m_buffer .append(m_currentIndent) .append("<!-- " + comment.replaceAll("[-]{2,}", "-") + " -->\n"); }
/** Add a CDATA tag. */ public void addCDATA(String content) { if (content != null) { // Solution from https://coderanch.com/t/455930/java/Remove-control-characters content = content.replaceAll("[\\p{Cc}&&[^\\r\\n]]", ""); } m_buffer.append(m_currentIndent); if (content == null) { m_buffer.append("<![CDATA[null]]>"); } else if (!content.contains("]]>")) { m_buffer.append("<![CDATA[").append(content).append("]]>"); } else if ("]]>".equals(content)) { // Solution from http://stackoverflow.com/q/223652/4234729 m_buffer.append("<![CDATA[]]]]><![CDATA[>]]>"); } else { // content contains "]]>" String[] subStrings = content.split("]]>"); m_buffer.append("<![CDATA[").append(subStrings[0]).append("]]]]>"); for (int i = 1; i < subStrings.length - 1; i++) { m_buffer.append("<![CDATA[>").append(subStrings[i]).append("]]]]>"); } m_buffer.append("<![CDATA[>").append(subStrings[subStrings.length - 1]).append("]]>"); if (content.endsWith("]]>")) { m_buffer.append("<![CDATA[]]]]>").append("<![CDATA[>]]>"); } } m_buffer.append(EOL); }
public static void xmlRequired(IBuffer result, String sp, String elementName, @Nullable String value, @Nullable Properties attributes) { result.append(xml(sp, elementName, value, attributes)); }
/** * Appends the attributes to result. The attributes are added on a single line as: key1="value1" * key2="value2" ... (a space is added before the first key) * * @param result the buffer to append attributes to. * @param attributes the attributes to append (may be null). */ public static void appendAttributes(IBuffer result, Properties attributes) { if (null != attributes) { for (Object element : attributes.entrySet()) { Entry entry = (Entry) element; String key = entry.getKey().toString(); String value = escape(entry.getValue().toString()); result.append(" ").append(key).append("=\"").append(value).append("\""); } } }
public static void xmlRequired( IBuffer result, String sp, String elementName, @Nullable String value, @Nullable Properties attributes) { result.append(xml(sp, elementName, value, attributes)); }
/** * Generate tag. * An opening and closing tag will be generated even if value is null. * @param name name of the tag * @param content content for this tag (or null) * @param attributes tag attributes (or null) */ static public String xml(String indent, String name, @Nullable String content, @Nullable Properties attributes) { IBuffer result = Buffer.create(); xmlOpen(result, indent, name, attributes, true /* no newline */); if (content != null) { result.append(content); } xmlClose(result, "", name, XMLUtils.extractComment(name, attributes)); return result.toString(); }
/** * Generate tag. An opening and closing tag will be generated even if value is null. * * @param name name of the tag * @param content content for this tag (or null) * @param attributes tag attributes (or null) */ public static String xml( String indent, String name, @Nullable String content, @Nullable Properties attributes) { IBuffer result = Buffer.create(); xmlOpen(result, indent, name, attributes, true /* no newline */); if (content != null) { result.append(content); } xmlClose(result, "", name, XMLUtils.extractComment(name, attributes)); return result.toString(); }