public ProcessingInstruction(String target, String[] attrs, String[] values) { // Lengths of attributes and values must be the same this.target = target; this.data = new String[attrs.length]; for (int i = 0; i < attrs.length; i++) { data[i] = attributeImage(attrs[i], values[i]); } }
public void cdata(String data) { cdata(data, true); }
public void cdata(String data, boolean escape) { if (this.open) { println('>'); this.open = false; } if (data != null) { printlnIndented(data, escape); } }
public void writeProperties(String propertiesElement, Map<String, String> properties) { if (properties != null && properties.size() > 0) { start(propertiesElement); attribute(COLLECTION_SIZE_ATTRIBUTE, properties.size()); for (Entry<String, String> entry : properties.entrySet()) { writeProperty(entry.getKey(), entry.getValue()); } end(propertiesElement); } }
public void attribute(String name, boolean value, boolean defaultValue) { if (value != defaultValue) { attribute(name, value); } }
private void indent() { for (int i = this.elements.size(); i > 0; i -= 1) { print(this.indent); } }
public void end(String name) { if (this.elements.empty()) { throw new EndWithoutStartError(); } int index = this.elements.search(name); if (index == -1) { throw new EndWithoutStartError(name); } for (int i = 0; i < index; i += 1) { end(); } }
protected static String attributeImage(String name, String value) { if (value == null) { return ""; // optional attribute with no value //$NON-NLS-1$ } return name + "='" + escape(value) + '\''; //$NON-NLS-1$ }
public XMLWriter(OutputStream output, ProcessingInstruction[] piElements) throws UnsupportedEncodingException { this.pw = new PrintWriter(new OutputStreamWriter(output, "UTF8"), false); //$NON-NLS-1$ println(ProcessingInstruction.XML_UTF8); this.elements = new Stack<String>(); this.open = false; this.indent = " "; //$NON-NLS-1$ if (piElements != null) { for (int i = 0; i < piElements.length; i++) { println(piElements[i].toString()); } } }
public void writeProperties(String propertiesElement, Map<String, String> properties) { if (properties != null && properties.size() > 0) { start(propertiesElement); attribute(COLLECTION_SIZE_ATTRIBUTE, properties.size()); for (Entry<String, String> entry : properties.entrySet()) { writeProperty(entry.getKey(), entry.getValue()); } end(propertiesElement); } }
public void cdata(String data, boolean escape) { if (this.open) { println('>'); this.open = false; } if (data != null) { printlnIndented(data, escape); } }
public void attribute(String name, boolean value, boolean defaultValue) { if (value != defaultValue) { attribute(name, value); } }
private void indent() { for (int i = this.elements.size(); i > 0; i -= 1) { print(this.indent); } }