/** * Closes the start tag. Usually, it is not necessary to call this, as the other methods in this will do * the right thing as needed. However, this can be called explicitly to allow content or subtags to be written * by a regular write call which bypasses the logic in this. * If a start tag is not currently open this has no effect. */ public XMLWriter closeStartTag() { if (!inOpenStartTag) return this; w(GT); inOpenStartTag=false; return this; }
/** * Writes an attribute by XML.xmlEscape(value.toString(),false) * * @param name the name of the attribute. An exception is thrown if this is null * @param value the value of the attribute. The empty string if the attribute is null or empty */ public XMLWriter forceAttribute(Utf8String name, Object value) { String stringValue = value!=null ? value.toString() : ""; allowAttribute(); return w(SPACE).w(name).w(ATTRIBUTE_START).wTranscode(XML.xmlEscape(stringValue,true)).w(ATTRIBUTE_END); }
/** * Writes an attribute by XML.xmlEscape(value.toString(),false) * * @param name the name of the attribute. An exception is thrown if this is null * @param value the value of the attribute. This method does nothing if the value is null or empty */ public XMLWriter attribute(Utf8String name, String value) { if ((value == null) || value.isEmpty()) return this; allowAttribute(); return w(SPACE).w(name).w(ATTRIBUTE_START).wTranscode(XML.xmlEscape(value, true)).w(ATTRIBUTE_END); }
/** * Writes an attribute by its utf8 value * * @param name the name of the attribute. An exception is thrown if this is null * @param value the value of the attribute. */ public XMLWriter attribute(Utf8String name, long value) { allowAttribute(); return w(SPACE).w(name).w(ATTRIBUTE_START).w(value).w(ATTRIBUTE_END); }
/** * Writes an attribute by its utf8 value * * @param name the name of the attribute. An exception is thrown if this is null * @param value the value of the attribute. */ public XMLWriter attribute(Utf8String name, double value) { allowAttribute(); return w(SPACE).w(name).w(ATTRIBUTE_START).w(value).w(ATTRIBUTE_END); }
/** * Writes an attribute by its utf8 value * * @param name the name of the attribute. An exception is thrown if this is null * @param value the value of the attribute. This method does nothing if the value is null or empty */ public XMLWriter attribute(Utf8String name, boolean value) { allowAttribute(); return w(SPACE).w(name).w(ATTRIBUTE_START).w(value).w(ATTRIBUTE_END); }
/** * Writes an attribute by its utf8 value * * @param name the name of the attribute. An exception is thrown if this is null * @param value the value of the attribute. This method does nothing if the value is null. */ public XMLWriter attribute(Utf8String name, Number value) { if (value == null) return this; allowAttribute(); return w(SPACE).w(name).w(ATTRIBUTE_START).w(value).w(ATTRIBUTE_END); }
private XMLWriter indent() { for (int i=0; i<openTags.size() && i<maxIndentLevel; i++) { w(INDENT); } return this; }
/** * Writes an attribute by its utf8 value * * @param name the name of the attribute. An exception is thrown if this is null * @param value the value of the attribute. This method does nothing if the value is null or empty */ public XMLWriter attribute(Utf8String name, AbstractUtf8Array value) { if (value.isEmpty()) return this; allowAttribute(); return w(SPACE).w(name).w(ATTRIBUTE_START).w(value).w(ATTRIBUTE_END); }
/** * Writes the given string. If markup is us ascii (default), and the wrapped writer encodes in UTF, this will write * the string <b>as is, with no transcoding</b> (for speed). Hence, this should never be used for just any content. * * @return this for consistency */ private final XMLWriter w(String s) { return markupIsAscii ? w(new Utf8String(s)) : w(s); }
public XMLWriter closeTag() { if (openTags.size()<=0) { throw new RuntimeException("Called closeTag() when no tag was open"); } Utf8String lastOpenTag=openTags.remove(openTags.size()-1); if (inOpenStartTag) {// this tag has no content - use short form w(EGT); } else { if (currentIsMultiline) { w(LF).indent(); } w(ELT).w(lastOpenTag).w(GT); } if (openTags.size()==0 || openTags.size()<=maxLineSeparatorLevel) { w(LF); } inOpenStartTag=false; currentIsMultiline=true; // When we go up from a subtag we are at a multiline tag (because it contains subtags) isFirstInParent=false; // the next opened tag will not be first return this; }
/** * Writes the given US-ASCII only string as-is. * If the content is <b>not</b> US-ASCII <i>only</i> this <i>may</i> cause * incorrectly encoded content to be written. * This is faster than using escapedContent as transcoding is skipped. * <p> * The content string <i>must</i> be XML escaped before calling this. * If the content is null this does nothing but closing the start tag. * * @param content the content - output by XML.xmlEscape(content.toString()) * @param multiline whether the content should be treated as multiline, * such that the following end tag should appear on a new line */ public XMLWriter escapedAsciiContent(String content,boolean multiline) { closeStartTag(); if (content==null) return this; if (multiline) currentIsMultiline=true; return w(content); }