/** * Pop the last pushed element and throws an AssertionError if it doesn't * match the corresponding tag that was pushed earlier. * * @param tagName The name of the tag this pop() is supposed to match. */ public void pop(String tagName) { m_currentIndent = m_currentIndent.substring(DEFAULT_INDENT_INCREMENT.length()); Tag t = m_tagStack.pop(); if (null != tagName) { if (!tagName.equals(t.tagName)) { // TODO Is it normal to throw an Error here? throw new AssertionError( "Popping the wrong tag: " + t.tagName + " but expected " + tagName); } } String comment = defaultComment; if (comment == null) { comment = XMLUtils.extractComment(tagName, t.properties); } XMLUtils.xmlClose(m_buffer, m_currentIndent, t.tagName, comment); }
public static void xmlOpen(IBuffer result, String indent, String tag, Properties attributes) { xmlOpen(result, indent, tag, attributes, false /* no newline */); }
/** * Add an optional String element to the current tag. If value is null, nothing is * added. * @param tagName The name of the tag * @param value The value for this tag * @param attributes A Properties file containing the attributes (or null) */ public void addOptional(String tagName, @Nullable String value, @Nullable Properties attributes) { if (value != null) { XMLUtils.xmlOptional(m_buffer, m_currentIndent, tagName, 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(); }
public static void xmlOptional(IBuffer result, String sp, String elementName, Boolean value, Properties attributes) { if (null != value) { xmlRequired(result, sp, elementName, value.toString(), attributes); } }
/** * 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 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("\""); } } }
/** * 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(); }
public static void xmlOptional(IBuffer result, String sp, String elementName, @Nullable String value, Properties attributes) { if (null != value) { xmlRequired(result, sp, elementName, value, attributes); } }
public static void xmlOpen(IBuffer result, String indent, String tag, Properties attributes, boolean noNewLine) { result.append(indent).append("<").append(tag); appendAttributes(result, attributes); result.append(">"); if (!noNewLine) { result.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("\""); } } }
/** * Pop the last pushed element and throws an AssertionError if it doesn't match the corresponding * tag that was pushed earlier. * * @param tagName The name of the tag this pop() is supposed to match. */ public void pop(String tagName) { m_currentIndent = m_currentIndent.substring(DEFAULT_INDENT_INCREMENT.length()); Tag t = m_tagStack.pop(); if (null != tagName) { if (!tagName.equals(t.tagName)) { // TODO Is it normal to throw an Error here? throw new AssertionError( "Popping the wrong tag: " + t.tagName + " but expected " + tagName); } } String comment = defaultComment; if (comment == null) { comment = XMLUtils.extractComment(tagName, t.properties); } XMLUtils.xmlClose(m_buffer, m_currentIndent, t.tagName, comment); }
/** * Add an optional Boolean element to the current tag. If value is null, nothing is * added. * @param tagName The name of the tag * @param value The value for this tag * @param attributes A Properties file containing the attributes (or null) */ public void addOptional(String tagName, @Nullable Boolean value, @Nullable Properties attributes) { if (null != value) { XMLUtils.xmlOptional(m_buffer, m_currentIndent, tagName, value.toString(), attributes); } }
/** * Add a required element to the current tag. An opening and closing tag * will be generated even if value is null. * @param tagName The name of the tag * @param value The value for this tag * @param attributes A Properties file containing the attributes (or null) */ public void addRequired(String tagName, @Nullable String value, @Nullable Properties attributes) { XMLUtils.xmlRequired(m_buffer, m_currentIndent, tagName, value, attributes); } public void addRequired(String tagName, @Nullable String value, String... attributes) {
/** * 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 static void xmlOpen(IBuffer result, String indent, String tag, Properties attributes) { xmlOpen(result, indent, tag, attributes, false /* no newline */); }
/** * Add an optional String element to the current tag. If value is null, nothing is added. * * @param tagName The name of the tag * @param value The value for this tag * @param attributes A Properties file containing the attributes (or null) */ public void addOptional(String tagName, @Nullable String value, @Nullable Properties attributes) { if (value != null) { XMLUtils.xmlOptional(m_buffer, m_currentIndent, tagName, value, attributes); } }
public static void xmlOptional( IBuffer result, String sp, String elementName, @Nullable String value, Properties attributes) { if (null != value) { xmlRequired(result, sp, elementName, value, attributes); } }