private boolean writeDocument(Document d, Map<String, String> prefixes) { boolean fail = false; Reporter reporter = getReporter(); BufferedWriter bw = null; try { DOMSource source = new DOMSource(d); File[] retOutputFile = new File[1]; bw = new BufferedWriter(new OutputStreamWriter(getOutputStream(retOutputFile), outputEncoding)); StreamResult result = new StreamResult(bw); Transformer t = new TextTransformer(outputEncoding.name(), outputIndent, prefixes, startTagIndentExclusions, endTagIndentExclusions); t.transform(source, result); File outputFile = retOutputFile[0]; reporter.logInfo(reporter.message("i.015", "Wrote TTML ''{0}''.", (outputFile != null) ? outputFile.getAbsolutePath() : uriStandardOutput)); } catch (IOException e) { reporter.logError(e); } catch (TransformerException e) { reporter.logError(e); } finally { if (bw != null) { try { bw.close(); } catch (IOException e) {} } } return !fail && (reporter.getResourceErrors() == 0); }
private void serialize(Writer w, Document d) throws IOException { w.write("<?xml version=\"1.0\""); if (encoding != null) { w.write(" encoding=\""); w.write(encoding.toLowerCase()); w.write('"'); } w.write("?>"); if (indent) w.write('\n'); Element e = d.getDocumentElement(); if (e != null) serialize(w, e); }
private void serialize(Writer w, Text t) throws IOException { serialize(w, t.getWholeText()); }
public void transform(Source source, Result result) throws TransformerException { if (!(source instanceof DOMSource) || !(result instanceof StreamResult)) { throw new IllegalArgumentException(); } Node node = ((DOMSource) source).getNode(); if (!(node instanceof Document)) { throw new IllegalArgumentException(); } try { serialize(((StreamResult) result).getWriter(), (Document) node); } catch (IOException e) { throw new TransformerException(e); } }
QName qn = new QName(ns, ln); w.write('<'); serialize(w, qn); NamedNodeMap attrs = e.getAttributes(); Set<Attr> attrsOrdered = new java.util.TreeSet<Attr>(new Comparator<Attr>() { serialize(w, a); Node node = children.item(i); if (node instanceof Element) { serialize(w, (Element) node); } else if (node instanceof Text) { serialize(w, (Text) node); serialize(w, qn); w.write('>');