List of usage examples for org.dom4j DocumentHelper createDocument
public static Document createDocument(Element rootElement)
From source file:Main2.java
License:Open Source License
public static void main(String[] args) throws IOException { boolean printTokens = false; boolean showTree = false; boolean produceXml = false; boolean produceSource = false; for (int i = 2; i < args.length; i++) { if (args[i].length() == 2) { switch (args[i].charAt(1)) { case 't': printTokens = true;//w ww. ja v a 2 s . co m break; case 'v': showTree = true; break; case 'x': produceXml = true; break; case 's': produceSource = true; break; } } } ASTWindow window = showTree ? new ASTWindow("AST") : null; Document doc = null; if (produceXml) { doc = DocumentHelper.createDocument(DocumentHelper.createElement("asp")); } try { File f = new File(args[0]); File base = new File(args[1]); if (printTokens) { AspStreamSelector selector = new AspStreamSelector(f, base); printApsTokens(selector); if (!(showTree || produceXml)) { return; } } AspParser asp = new AspParser(base, new File("out")); asp.setGenerateCode(produceSource); Map vbTokens = null; Map jsTokens = null; Map tokens = null; List astList = asp.parseFile(f, true); for (Iterator it = astList.iterator(); it.hasNext();) { Object[] val = (Object[]) it.next(); boolean isVb = ((Boolean) val[0]).booleanValue(); if (showTree) { if (isVb) { window.addAST("Original VB", createRoot("VB ASP", (AST) val[1])); if (val.length > 2) { window.addAST("VB Generated", createRoot("VB", (AST) val[2])); } } else { window.addAST("ASP JS", createRoot("JS", (AST) val[1])); window.addAST("JS Generated", createRoot("JS", (AST) val[2])); } } if (produceXml) { String rootName; if (isVb) { rootName = "vb"; if (vbTokens == null) { vbTokens = new HashMap(); putTokens(new VbsTree(), vbTokens); } tokens = vbTokens; } else { rootName = "js"; if (jsTokens == null) { jsTokens = new HashMap(); putTokens(new JsTree(), jsTokens); } tokens = jsTokens; } Element nodeEl = doc.getRootElement().addElement(rootName); Element orig = nodeEl.addElement("original"); new XmlTestBuilder(orig, tokens).visit((AST) val[1]); Element trans = nodeEl.addElement("translated"); new XmlTestBuilder(trans, tokens).visit((AST) val[2]); } } if (produceXml) { OutputFormat of = OutputFormat.createPrettyPrint(); of.setEncoding("ISO-8859-7"); XMLWriter xwriter = new XMLWriter(new FileWriter("asp.xml"), of); xwriter.write(doc); xwriter.close(); } if (showTree && window.hasAST()) { window.pack(); window.setVisible(true); window.setExtendedState(Frame.MAXIMIZED_BOTH); } } catch (Exception ex) { ex.printStackTrace(System.out); System.err.println("Error"); } }
From source file:com.haulmont.cuba.restapi.XMLConverter2.java
License:Apache License
protected String paramElementContentAsString(Element paramEl) { Element nestedEl = paramEl.element("instance"); if (nestedEl == null) { nestedEl = paramEl.element("instances"); }/*from ww w . ja va 2 s. c om*/ if (nestedEl == null) { return paramEl.getText(); } else { Document doc = DocumentHelper.createDocument(nestedEl.createCopy()); return doc.asXML(); } }
From source file:com.ibm.cognos.API.java
License:Open Source License
public API() { Element reportElement = DocumentHelper.createElement("report"); // In dom4j 1.6.1, can no longer add xmlns with addAttribute reportElement.addNamespace("", "http://developer.cognos.com/schemas/report/8.0/"); reportElement.addAttribute("expressionLocale", "en-us"); oDocument = DocumentHelper.createDocument(reportElement); }
From source file:com.ibm.cognos.ReportObject.java
License:Open Source License
public Document getPackages(CRNConnect connection, String sPath) { Document oDom = null;/* w ww . j a v a2 s . c o m*/ Element packagesElement; try { com.cognos.developer.schemas.bibus._3.BaseClass oBase[]; oBase = connection.getCMService() .query(new SearchPathMultipleObject(sPath), new PropEnum[] { PropEnum.defaultName, PropEnum.source, PropEnum.dispatcherPath, PropEnum.searchPath }, new Sort[] {}, new QueryOptions()); packagesElement = DocumentHelper.createElement("packages"); oDom = DocumentHelper.createDocument(packagesElement); for (int i = 0; i < oBase.length; i++) { if (oBase[i].getClass().getName().toString() .equals("com.cognos.developer.schemas.bibus._3._package")) { Element oElement = DocumentHelper.createElement("package"); String oBaseName = oBase[i].getDefaultName().getValue(); String oBaseSearchPath = oBase[i].getSearchPath().getValue(); oElement.addElement("name").setText(oBaseName); oElement.addElement("searchPath").setText(oBaseSearchPath); oDom.getRootElement().add(oElement); } } } catch (Exception e) { e.printStackTrace(); } return oDom; }
From source file:com.liferay.portal.xml.SAXReaderImpl.java
License:Open Source License
public Document createDocument(Element rootElement) { ElementImpl rootElementImpl = (ElementImpl) rootElement; return new DocumentImpl(DocumentHelper.createDocument(rootElementImpl.getWrappedElement())); }
From source file:com.nokia.ant.Database.java
License:Open Source License
public Document createDOM() throws Exception { //log("Building Ant project database", Project.MSG_DEBUG); Element root = DocumentHelper.createElement("antDatabase"); Document outDoc = DocumentHelper.createDocument(root); ArrayList antFiles = getAntFiles(getProject(), homeFilesOnly); Iterator antFilesIter = antFiles.iterator(); while (antFilesIter.hasNext()) { String antFile = (String) antFilesIter.next(); readSignals(root, antFile);//from w ww . j a v a 2 s. c o m } antFilesIter = antFiles.iterator(); while (antFilesIter.hasNext()) { String antFile = (String) antFilesIter.next(); parseAntFile(root, antFile); } buildTaskDefs(root); return outDoc; }
From source file:com.pureinfo.srm.config.affirm.domain.AffirmMgrImpl.java
License:Open Source License
public void store() throws PureException { if (!isLoaded()) return;/* ww w . j av a 2 s. com*/ synchronized (this) { Element root = DocumentHelper.createElement(ELEMENT_AFFIRMS); m_affirm.toXMLElement(root); String sFileName = ClassResourceUtil.mapFullPath(DATA_FILENAME, true); try { new XMLWriter(new FileOutputStream(sFileName), OutputFormat.createPrettyPrint()) .write(DocumentHelper.createDocument(root)); } catch (Exception ex) { throw new PureException(PureException.UNKNOWN, "", ex); } } }
From source file:com.pureinfo.srm.config.notice.domain.NoticeMgrImpl.java
License:Open Source License
public void store() throws PureException { if (!isLoaded()) return;//from w ww . ja va 2 s .c om synchronized (this) { Element root = DocumentHelper.createElement(ELEMENT_NOTICES); for (Iterator iter = m_notices.values().iterator(); iter.hasNext();) { Notice notice = (Notice) iter.next(); notice.toXMLElement(root.addElement(ELEMENT_NOTICE)); } String sFileName = ClassResourceUtil.mapFullPath(DATA_FILENAME, true); try { new XMLWriter(new FileOutputStream(sFileName), OutputFormat.createPrettyPrint()) .write(DocumentHelper.createDocument(root)); } catch (Exception ex) { throw new PureException(PureException.UNKNOWN, "", ex); } } }
From source file:cz.fi.muni.xkremser.editor.server.fedora.utils.FoxmlUtils.java
License:Open Source License
public static org.dom4j.Document createRelsExtSkeleton(String uuid, String model, Policy policy) { Namespace rdfNs = Namespaces.rdf; Namespace krameriusNs = Namespaces.kramerius; org.dom4j.Element rootElement = DocumentHelper.createElement(new QName("RDF", rdfNs)); rootElement.add(rdfNs);//www .jav a2s .co m rootElement.add(krameriusNs); org.dom4j.Document doc = DocumentHelper.createDocument(rootElement); org.dom4j.Element description = rootElement.addElement(new QName("Description", rdfNs)); description.addAttribute(new QName("about", rdfNs), "info:fedora/".concat(Constants.FEDORA_UUID_PREFIX + uuid)); org.dom4j.Element hasModel = description.addElement(new QName("hasModel", Namespaces.fedora_model)); hasModel.addAttribute(new QName("resource", rdfNs), "info:fedora/model:".concat(model)); org.dom4j.Element itemId = description.addElement(new QName("itemID", Namespaces.oai)); itemId.addText(Constants.FEDORA_UUID_PREFIX + uuid); org.dom4j.Element krameriusPolicy = description.addElement(new QName("policy", krameriusNs)); krameriusPolicy.addText("policy:".concat(policy.toString().toLowerCase())); return doc; }
From source file:cz.fi.muni.xkremser.editor.server.newObject.FoxmlBuilder.java
License:Open Source License
private void createDocumentAndRootElement() { rootElement = DocumentHelper.createElement(new QName("digitalObject", Namespaces.foxml)); document = DocumentHelper.createDocument(rootElement); document.getRootElement().add(Namespaces.foxml); document.getRootElement().add(Namespaces.xsi); document.getRootElement().addAttribute(new QName("schemaLocation", Namespaces.xsi), "info:fedora/fedora-system:def/foxml# http://www.fedora.info/definitions/1/0/foxml1-1.xsd"); rootElement.addAttribute("VERSION", "1.1"); rootElement.addAttribute("PID", pid); }