public Feature(Document document) { this.document = document; this.dom = document.getRootElement(); }
public static void write(TargetDefinitionFile target, File file) throws IOException { OutputStream os = new BufferedOutputStream(new FileOutputStream(file)); Document document = target.document; try { String enc = document.getEncoding() != null ? document.getEncoding() : "UTF-8"; Writer w = new OutputStreamWriter(os, enc); XMLWriter xw = new XMLWriter(w); try { document.toXML(xw); } finally { xw.flush(); } } finally { IOUtil.close(os); } }
Document doc = new Document(MyDir + "in.docx"); DocumentBuilder builder = new DocumentBuilder(doc); Table table = (Table)doc.getChild(NodeType.TABLE, 0, true); Cell cell = table.getFirstRow().getFirstCell(); builder.moveTo(cell.getFirstParagraph()); FieldBuilder fbuilder = new FieldBuilder(FieldType.FIELD_FORMULA); fbuilder.addArgument("20000").addSwitch("\\# \"#,##0\"").buildAndInsert(builder.getCurrentParagraph()); doc.updateFields(); doc.save(MyDir + "Out.docx");
//Load the document Document doc = new Document(MyDir + "in.docx"); //Get the first table in the document Table table = (Table)doc.getChild(NodeType.TABLE, 0, true); //Get the first cell of first row Cell cell = (Cell)table.getRows().get(0).getCells().get(0); //Change the color of text for (Run run : (Iterable<Run>)cell.getChildNodes(NodeType.RUN, true)) { run.getFont().setColor(Color.BLUE); } //Save the document doc.save(MyDir + "Out.docx");
/** * Deploys provided pom.xml file under specified groupId, artifactId and version. The contents of the pom is updated * to match specified groupId, artifactId and version. */ public long deployPom(String groupId, String artifactId, String version, File pomTemplate) throws IOException { final Document pom = XMLParser.parse(pomTemplate); pom.getRootElement().getChild("groupId").setText(groupId); pom.getRootElement().getChild("artifactId").setText(artifactId); pom.getRootElement().getChild("version").setText(version); // pom.getRootElement().getChild( "packaging" ).setText( "pom" ); StringWriter buf = new StringWriter(); XMLWriter writer = new XMLWriter(buf); pom.toXML(writer); String body = buf.toString(); HttpEntity pomEntity = new StringEntity(body, ContentType.TEXT_XML); deploy(pomEntity, groupId, artifactId, version, ".pom"); return body.getBytes(Charsets.UTF_8).length; }
public String finish() { return base.toXML(); }
Document doc = new Document (); doc.addNode (docType); doc.addNode (n); if (doc.getRootElement () == null) throw new XMLParseException ("No root element found");
private boolean mergeDoc(Document from, Document to) { Element rootFrom = from.getRootElement(); String appendPath = rootFrom.getAttributeValue("appendPath"); if (appendPath != null) { return appendPath(rootFrom, to, appendPath); } String replacePath = rootFrom.getAttributeValue("replacePath"); if (replacePath != null) { return replacePath(rootFrom, to, replacePath); } Element rootTo; String mergePath = rootFrom.getAttributeValue("mergePath"); if (mergePath != null) { Element child = to.getChild(mergePath); if (child == null) { throw new IllegalStateException("Cannot merge " + name + " to path " + mergePath); } rootTo = child; } else if (rootFrom.getName().equals(to.getRootElement().getName())) { rootTo = to.getRootElement(); } else { return false; } merge(rootFrom, rootTo); return true; }
public Element getChild (String path, Namespace ns) if (getRootElement () == null) return null; if (path.equals (getRootElement ().getName ()) && (ns == null || ns.equals (getRootElement ().getNamespace ())) return getRootElement (); else return null; ns2 = getNamespaces ().getNamespace (prefix); if (ns2 == null) throw new XMLParseException ("Namespace prefix '"+prefix+"' is not defined"); if (!name.equals (getRootElement ().getName ()) || (ns2 != null && !ns2.equals (getRootElement ().getNamespace ())) return getRootElement ().getChild (path.substring (pos+1), ns);
protected Document createExemplarDoc() throws IOException { String exemplar = "io/fabric8/camel/tooling/exemplar.xml"; URL url = findResource(exemplar, null); if (url != null) { return parse(new XMLIOSource(url)); } else { LOG.warn("Could not find file {} on the class path", exemplar); Document d = new Document(); d.addNode(new Element("beans", springNamespace)); return d; } }
public Element getChild (String path) { return getChild (path, null); }
return doc == null ? null : doc.getChild (path, ns); ns2 = getDocument ().getNamespace (prefix); if (ns2 == null) throw new XMLParseException ("Namespace prefix '"+prefix+"' is not defined");
public Document createClone () { return new Document (); }
public void finish(Writer w) throws IOException { base.toXML(new XMLWriter(w)); w.flush(); }
protected Document createExemplarDoc() throws IOException { String exemplar = "io/fabric8/camel/tooling/exemplar.xml"; URL url = findResource(exemplar, null); if (url != null) { return parse(new XMLIOSource(url)); } else { LOG.warn("Could not find file {} on the class path", exemplar); Document d = new Document(); d.addNode(new Element("beans", springNamespace)); return d; } }
Document doc = new Document(MyDir + "document.docx"); // Retrieve the first table in the document. Table table = (Table)doc.getChild(NodeType.TABLE, 0, true); // Clone the last row in the table. Row clonedRow = (Row)table.getLastRow().deepClone(true); // Remove all content from the cloned row's cells. This makes the row ready for // new content to be inserted into. for (Cell cell: clonedRow.getCells()) { cell.getFirstParagraph().getRuns().clear(); cell.getFirstParagraph().appendChild(new Run(doc,"hello text")); } // Add the row to the end of the table. table.appendChild(clonedRow); doc.save(MyDir + "Table.AddCloneRowToTable Out.doc");
public static IU read(File file) throws IOException { FileInputStream is = new FileInputStream(file); try { Document iuDocument = parser.parse(new XMLIOSource(is)); Element root = iuDocument.getChild(UNIT); if (root == null) throw new RuntimeException("No iu found."); IU result = new IU(iuDocument, root); if (result.getId() == null) throw new RuntimeException( String.format("The IU defined in %s is missing an id.", file.getAbsolutePath())); if (result.getVersion() == null) throw new RuntimeException( String.format("The IU defined in %s is missing a version.", file.getAbsolutePath())); return result; } finally { IOUtil.close(is); } }
public Feature( Document document ) { this.document = document; this.dom = document.getRootElement(); }
public static void write(ProductConfiguration product, File file) throws IOException { OutputStream os = new BufferedOutputStream(new FileOutputStream(file)); Document document = product.document; try { String enc = document.getEncoding() != null ? document.getEncoding() : "UTF-8"; Writer w = new OutputStreamWriter(os, enc); XMLWriter xw = new XMLWriter(w); try { document.toXML(xw); } finally { xw.flush(); } } finally { IOUtil.close(os); } }