/** * Output the properties as xml output. * @param props the properties to save * @param os the output stream to write to (Note this gets closed) * @throws IOException on error in writing to the stream */ protected void xmlSaveProperties(Properties props, OutputStream os) throws IOException { // create XML document Document doc = getDocumentBuilder().newDocument(); Element rootElement = doc.createElement(PROPERTIES); List<Tuple> sorted = sortProperties(props); // output properties for (Tuple tuple : sorted) { Element propElement = doc.createElement(PROPERTY); propElement.setAttribute(ATTR_NAME, tuple.key); propElement.setAttribute(ATTR_VALUE, tuple.value); rootElement.appendChild(propElement); } try (Writer wri = new OutputStreamWriter(os, "UTF8")) { wri.write("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"); new DOMElementWriter().write(rootElement, wri, 0, "\t"); wri.flush(); } catch (IOException ioe) { throw new BuildException("Unable to write XML file", ioe); } }
boolean hasChildren = (children.getLength() > 0); boolean hasChildElements = false; openElement(element, out, indent, indentWith, hasChildren); out.write(System.lineSeparator()); write((Element) child, out, indent + 1, indentWith); break; out.write(encode(child.getNodeValue())); break; out.write(encode(child.getNodeValue())); out.write("-->"); break; encodedata(out, ((Text) child).getData()); out.write("]]>"); break; closeElement(element, out, indent, indentWith, hasChildElements);
String uri = getNamespaceURI(element); String prefix = nsPrefixMap.get(uri); if (prefix != null && !prefix.isEmpty()) { out.write(":"); removeNSDefinitions(element);
/** * Writes a DOM tree to a stream in UTF8 encoding. Note that * it prepends the <?xml version='1.0' encoding='UTF-8'?> if * the xmlDeclaration field is true. * The indent number is set to 0 and a 2-space indent. * @param root the root element of the DOM tree. * @param out the outputstream to write to. * @throws IOException if an error happens while writing to the stream. */ public void write(Element root, OutputStream out) throws IOException { Writer wri = new OutputStreamWriter(out, "UTF8"); writeXMLDeclaration(wri); write(root, wri, 0, " "); wri.flush(); }
/** * Print out the specified entries. * * @param output writer to which to send output. * @param entries the entries to be written. */ public void printChangeLog(final PrintWriter output, final CVSEntry[] entries) { try { output.println("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"); Document doc = DOMUtils.newDocument(); Element root = doc.createElement("changelog"); DOM_WRITER.openElement(root, output, 0, "\t"); output.println(); for (final CVSEntry entry : entries) { printEntry(doc, output, entry); } DOM_WRITER.closeElement(root, output, 0, "\t", true); output.flush(); output.close(); } catch (IOException e) { throw new BuildException(e); } }
String uri = getNamespaceURI(element); String prefix = nsPrefixMap.get(uri); if (prefix == null) { addNSDefinition(element, uri); out.write(" "); if (namespacePolicy.qualifyAttributes) { String uri = getNamespaceURI(attr); String prefix = nsPrefixMap.get(uri); if (prefix == null) { prefix = NS + (nextPrefix++); nsPrefixMap.put(uri, prefix); addNSDefinition(element, uri); out.write(encodeAttributeValue(attr.getValue())); out.write("\""); out.write(">"); } else { removeNSDefinitions(element); out.write(String.format(" />%n")); out.flush();
/** * Write a single entry to the given writer. * * @param doc Document used to create elements. * @param writer a <code>PrintWriter</code> value * @param entry a <code>CvsTagEntry</code> value */ private void writeTagEntry(Document doc, PrintWriter writer, CvsTagEntry entry) throws IOException { Element ent = doc.createElement("entry"); Element f = DOMUtils.createChildElement(ent, "file"); DOMUtils.appendCDATAElement(f, "name", entry.getFile()); if (entry.getRevision() != null) { DOMUtils.appendTextElement(f, "revision", entry.getRevision()); } if (entry.getPreviousRevision() != null) { DOMUtils.appendTextElement(f, "prevrevision", entry.getPreviousRevision()); } DOM_WRITER.write(ent, writer, 1, "\t"); }
void write(XmlNode xml, OutputStream out) { write(xml, out, new DOMElementWriter()); }
/** * Escape <, >, &, ', " as their entities and * drop characters that are illegal in XML documents. * @param value the string to encode. * @return the encoded string. */ public String encode(String value) { return encode(value, false); }
int illegalCharPos = prevLegalCharPos; while (illegalCharPos < end && isLegalCharacter(value.charAt(illegalCharPos))) { ++illegalCharPos;
/** * Drop characters that are illegal in XML documents. * * <p>Also ensure that we are not including an <code>]]></code> * marker by replacing that sequence with * <code>&#x5d;&#x5d;&gt;</code>.</p> * * <p>See XML 1.0 2.2 <a * href="http://www.w3.org/TR/1998/REC-xml-19980210#charsets"> * http://www.w3.org/TR/1998/REC-xml-19980210#charsets</a> and * 2.7 <a * href="http://www.w3.org/TR/1998/REC-xml-19980210#sec-cdata-sect">http://www.w3.org/TR/1998/REC-xml-19980210#sec-cdata-sect</a>.</p> * @param value the value to be encoded. * @return the encoded value. */ public String encodedata(final String value) { final StringWriter out = new StringWriter(); try { encodedata(out, value); } catch (IOException ex) { throw new RuntimeException(ex); //NOSONAR } return out.toString(); }
DOM_WRITER.write(ent, output, 1, "\t");
root.setAttribute("package", packageNames.stream().collect(Collectors.joining(","))); DOM_WRITER.openElement(root, writer, 0, "\t"); writer.println(); for (CvsTagEntry entry : entries) { writeTagEntry(doc, writer, entry); DOM_WRITER.closeElement(root, writer, 0, "\t", true); writer.flush(); if (writer.checkError()) {
void write(XmlNode xml, OutputStream out) { write(xml, out, new DOMElementWriter()); }
/** * Escape <, >, &, ', " as their entities, \n, * \r and \t as numeric entities and drop characters that are * illegal in XML documents. * @param value the string to encode. * @return the encoded string. */ public String encodeAttributeValue(String value) { return encode(value, true); }
if (isLegalCharacter(c)) { sb.append(c);
+ "\"?>\n\n"); new DOMElementWriter().write(buildElement.element, out, 0, "\t"); out.flush(); } catch (IOException exc) {
void write(XmlNode xml, OutputStream out, DOMElementWriter xmlWriter) { Writer writer = null; try { writer = new BufferedWriter(new OutputStreamWriter(out, CHARSET)); writer.write(XML_HEADER); writer.write(lineSeparator()); xmlWriter.write(xml.target(), writer, 0, INDENT); writer.flush(); } catch (IOException ex) { throw new BuildException("Unable to write log file", ex); } finally { if (!outputStreams.isStandardOutOrErr(out)) close(writer); } } }
/** * Execute the task. */ public void execute() { DOMElementWriter writer = new DOMElementWriter(!append, namespacePolicy.getPolicy()); OutputStream os = null; try { if (file != null) { os = FileUtils.newOutputStream(file.toPath(), append); } else { os = new LogOutputStream(this, Project.MSG_INFO); } Node n = getFragment().getFirstChild(); if (n == null) { throw new BuildException(ERROR_NO_XML); } writer.write((Element) n, os); } catch (BuildException e) { throw e; } catch (Exception e) { throw new BuildException(e); } finally { FileUtils.close(os); } }
void write(XmlNode xml, OutputStream out, DOMElementWriter xmlWriter) { Writer writer = null; try { writer = new BufferedWriter(new OutputStreamWriter(out, CHARSET)); writer.write(XML_HEADER); writer.write(lineSeparator()); xmlWriter.write(xml.target(), writer, 0, INDENT); writer.flush(); } catch (IOException ex) { throw new BuildException("Unable to write log file", ex); } finally { if (!outputStreams.isStandardOutOrErr(out)) close(writer); } } }