@Override public void setRoot(Document doc, Element root) { doc.setRootElement(root); } }
/** * Pushes an element onto the tree under construction. Allows subclasses to * put content under a dummy root element which is useful for building * content that would otherwise be a non-well formed document. * * @param element * root element under which content will be built */ protected void pushElement(final Element element) { if (atRoot) { currentDocument.setRootElement(element); // XXX should we use a // factory call? atRoot = false; } else { factory.addContent(currentElement, element); } currentElement = element; }
/** * This will create a new <code>Document</code>, * with the supplied <code>{@link Element}</code> * as the root element, the supplied * <code>{@link DocType}</code> declaration, and the specified * base URI. * * @param rootElement <code>Element</code> for document root. * @param docType <code>DocType</code> declaration. * @param baseURI the URI from which this doucment was loaded. * @throws IllegalAddException if the given docType object * is already attached to a document or the given * rootElement already has a parent */ public Document(Element rootElement, DocType docType, String baseURI) { if (rootElement != null) { setRootElement(rootElement); } if (docType != null) { setDocType(docType); } if (baseURI != null) { setBaseURI(baseURI); } }
document.setRootElement(processElementFragment(factory, stream)); break;
final Element emt = processElement(factory, event.asStartElement()); if (current == null) { document.setRootElement(emt); final DocType dt = document.getDocType(); if (dt != null) {
public org.jdom2.Document load(String resourceName) throws FileNotFoundException, OfxAuthoringException { org.jdom2.Document doc = new org.jdom2.Document(); doc.setRootElement(loadElement(resourceName)); return doc; }
@Deprecated public org.jdom2.Document mergeToDoc(File rootFile) throws OfxInternalProcessingException { loadRoot(rootFile); Element rootElement = doc.getRootElement(); Element result = mergeRecursive(rootElement); result.detach(); doc.setRootElement(result); return doc; }
public Document trim(Document doc) throws OfxInternalProcessingException { for(XPath xpath : lXpath) { Element result = mergeRecursive(doc.getRootElement(),xpath); result.detach(); doc.setRootElement(result); } return doc; }
public void deployElement (Element e, String fileName, boolean encrypt, boolean isTransient) throws ISOException, IOException, GeneralSecurityException { e = e.clone (); XMLOutputter out = new XMLOutputter (Format.getPrettyFormat()); Document doc = new Document (); doc.setRootElement(e); File qbean = new File (deployDir, fileName); if (isTransient) { e.setAttribute("instance", getInstanceId().toString()); qbean.deleteOnExit(); } if (encrypt) { doc = encrypt (doc); } try (Writer writer = new BufferedWriter(new FileWriter(qbean))) { out.output(doc, writer); } }
public String merge(String xHtmlText) { Document doc = null; try {doc = JDomUtil.txtToDoc(xHtmlText);} catch (JDOMException e) {logger.error("",e);} Element rootElement = doc.getRootElement(); rootElement.detach(); doc.setRootElement(merge(rootElement)); xHtmlText=JDomUtil.docToTxt(doc); return xHtmlText; }
private Document processTemplate(Template template) throws OfxConfigurationException { Document doc = new Document(); Template templateDef = WikiConfigXmlXpathHelper.getTemplate(templates, template.getName()); Element e = kvTransformator.transform(templateDef,template); doc.setRootElement(e); return doc; }
public Document merge(Document ofxDoc) throws OfxInternalProcessingException { org.jdom2.Document doc = JaxbUtil.toDocument(ofxDoc); for(XPath xpath : lXpath) { Element result = mergeRecursive(doc.getRootElement(),xpath); result.detach(); doc.setRootElement(result); } ofxDoc = (Document)JDomUtil.toJaxb(doc, Document.class); return ofxDoc; }
protected Document encrypt (Document doc) throws GeneralSecurityException, IOException { ByteArrayOutputStream os = new ByteArrayOutputStream (); OutputStreamWriter writer = new OutputStreamWriter (os); XMLOutputter out = new XMLOutputter (Format.getPrettyFormat()); out.output(doc, writer); writer.close (); byte[] crypt = dodes (os.toByteArray(), Cipher.ENCRYPT_MODE); Document secureDoc = new Document (); Element root = new Element (PROTECTED_QBEAN); secureDoc.setRootElement (root); Element secureData = new Element ("data"); root.addContent (secureData); secureData.setText ( ISOUtil.hexString (crypt) ); return secureDoc; }
/** * Serialize an AtomService object into an XML document */ public Document serviceToDocument() { final AtomService service = this; final Document doc = new Document(); final Element root = new Element("service", ATOM_PROTOCOL); doc.setRootElement(root); final List<Workspace> spaces = service.getWorkspaces(); for (final Workspace space : spaces) { root.addContent(space.workspaceToElement()); } return doc; }
private org.jdom2.Document exchangeParagraphByTemplate(org.jdom2.Document doc) { try { Namespace nsOfx = Namespace.getNamespace("ofx", "http://www.openfuxml.org"); Namespace nsWiki = Namespace.getNamespace("wiki", "http://www.openfuxml.org/wiki"); XPath xpath = XPath.newInstance("//wiki:template"); xpath.addNamespace(nsOfx); xpath.addNamespace(nsWiki); Element result = exchangeParagraphByTemplate(doc.getRootElement(),xpath); result.detach(); doc.setRootElement(result); } catch (JDOMException e) {logger.error("",e);} return doc; }
public Document toXml() { if (this.createTime == null){ this.createTime = new Date().getTime() / 1000; } this.document = new Document(); this.root = new Element("xml"); this.document.setRootElement(root); this.root.addContent(new Element("ToUserName").setContent(new CDATA(this.toUserName))); this.root.addContent(new Element("FromUserName").setContent(new CDATA(this.fromUserName))); this.root.addContent(new Element("CreateTime").setText(this.createTime + "")); this.root.addContent(new Element("MsgType").setContent(new CDATA(this.msgType))); return this.document; }
public static ContentPayload getMetadataPayload(TransferredResource transferredResource) { try { Element root = new Element("metadata"); org.jdom2.Document doc = new org.jdom2.Document(); Element child = new Element("field"); child.setAttribute("name", "title"); child.addContent(transferredResource.getName()); root.addContent(child); doc.setRootElement(root); XMLOutputter outter = new XMLOutputter(); outter.setFormat(Format.getPrettyFormat()); outter.outputString(doc); return new StringContentPayload(outter.outputString(doc)); } catch (IllegalDataException e) { LOGGER.debug("Error generating TransferredResource metadata file {}", e.getMessage()); return new StringContentPayload(""); } }
static public void passTwo() throws IOException { org.jdom2.Document tdoc; try { SAXBuilder builder = new SAXBuilder(); tdoc = builder.build(trans1); org.jdom2.Document ndoc = new org.jdom2.Document(); Element nroot = new Element("ndoc"); ndoc.setRootElement(nroot); transform2(tdoc.getRootElement(), nroot); XMLOutputter fmt = new XMLOutputter(Format.getPrettyFormat()); Writer pw = new FileWriter(trans2); fmt.output(ndoc, pw); pw = new PrintWriter(System.out); fmt.output(ndoc, pw); } catch (JDOMException e) { throw new IOException(e.getMessage()); } }
static public void passOne() throws IOException { org.jdom2.Document orgDoc; try { SAXBuilder builder = new SAXBuilder(); orgDoc = builder.build(orgXml); org.jdom2.Document tdoc = new org.jdom2.Document(); Element root = new Element("tdoc"); tdoc.setRootElement(root); transform(orgDoc.getRootElement(), root); /* XMLOutputter fmt = new XMLOutputter(Format.getPrettyFormat()); Writer pw = new FileWriter("C:/docs/bufr/wmo/Code-FlagTables-11-2007.trans.xml"); fmt.output(tdoc, pw); pw = new PrintWriter(System.out); fmt.output(tdoc, pw); // */ } catch (JDOMException e) { throw new IOException(e.getMessage()); } }
public Document getDocument () throws SQLException, HibernateException { Document doc = new Document (); doc.setDocType (new DocType ("minigl", "http://jpos.org/dtd/minigl.dtd")); Element root = new Element ("minigl"); root.addContent ( new Comment ( "jPOS MiniGL export $" ) ); root.addContent (new Element ("create-schema")); addUsers (root); addCurrencies (root); addCharts (root); addJournals (root); addTransactions (root); doc.setRootElement (root); return doc; }