List of usage examples for org.dom4j Namespace Namespace
public Namespace(String prefix, String uri)
From source file:eml.studio.server.oozie.workflow.WFGraph.java
License:Open Source License
/** * Transform the Graph into an workflow xml definition * @param jobname the job name of Oozie job, can't be null * @return workflow xml/* ww w .ja v a 2 s. c om*/ */ public String toWorkflow(String jobname) { Namespace xmlns = new Namespace("", "uri:oozie:workflow:0.4"); // root namespace uri QName qName = QName.get("workflow-app", xmlns); // your root element's name Element workflow = DocumentHelper.createElement(qName); Document xmldoc = DocumentHelper.createDocument(workflow); // Create workflow root workflow.addAttribute("xmlns", "uri:oozie:workflow:0.4"); // <workflow-app name='xxx'></workflow-app> if (jobname == null || "".equals(jobname)) workflow.addAttribute("name", "Not specified"); else workflow.addAttribute("name", jobname); Queue<NodeDef> que = new LinkedList<NodeDef>(); que.add(start); while (!que.isEmpty()) { NodeDef cur = que.remove(); cur.append2XML(workflow); for (NodeDef toNode : cur.getOutNodes()) { toNode.delInNode(cur); if (toNode.getInDegree() == 0) que.add(toNode); } } // Set XML document format OutputFormat outputFormat = OutputFormat.createPrettyPrint(); // Set XML encoding, use the specified encoding to save the XML document to the string, it can be specified GBK or ISO8859-1 outputFormat.setEncoding("UTF-8"); outputFormat.setSuppressDeclaration(true); // Whether generate xml header outputFormat.setIndent(true); // Whether set indentation outputFormat.setIndent(" "); // Implement indentation with four spaces outputFormat.setNewlines(true); // Set whether to wrap try { // stringWriter is used to save xml document StringWriter stringWriter = new StringWriter(); // xmlWriter is used to write XML document to string(tool) XMLWriter xmlWriter = new XMLWriter(stringWriter, outputFormat); // Write the created XML document into the string xmlWriter.write(xmldoc); xmlWriter.close(); System.out.println(stringWriter.toString().trim()); // Print the string, that is, the XML document return stringWriter.toString().trim(); } catch (Exception ex) { ex.printStackTrace(); } return null; }
From source file:eml.studio.server.oozie.workflow.WFGraph.java
License:Open Source License
public static void main(String args[]) { Namespace rootNs = new Namespace("", "uri:oozie:workflow:0.4"); // root namespace uri QName rootQName = QName.get("workflow-app", rootNs); // your root element's name Element workflow = DocumentHelper.createElement(rootQName); Document doc = DocumentHelper.createDocument(workflow); workflow.addAttribute("name", "test"); Element test = workflow.addElement("test"); test.addText("hello"); OutputFormat outputFormat = OutputFormat.createPrettyPrint(); outputFormat.setEncoding("UTF-8"); outputFormat.setIndent(true);//from w w w .ja va 2 s. c o m outputFormat.setIndent(" "); outputFormat.setNewlines(true); try { StringWriter stringWriter = new StringWriter(); XMLWriter xmlWriter = new XMLWriter(stringWriter); xmlWriter.write(doc); xmlWriter.close(); System.out.println(doc.asXML()); System.out.println(stringWriter.toString().trim()); } catch (Exception ex) { ex.printStackTrace(); } }
From source file:eu.planets_project.pp.plato.services.characterisation.xcl.Comparator.java
License:Open Source License
/** * Generates a PCR for all <param>mappedProperties</param> and their metrics. * Note: All possible metrics are included. * /*from w w w. jav a2 s . co m*/ * @param mappedProperties * @return */ private String generateConfig(Set<XCLObjectProperty> mappedProperties) { Document doc = DocumentHelper.createDocument(); Element root = doc.addElement("pcRequest"); Namespace xsi = new Namespace("xsi", "http://www.w3.org/2001/XMLSchema-instance"); root.add(xsi); root.addAttribute(xsi.getPrefix() + ":schemaLocation", "http://www.planets-project.eu/xcl/schemas/xcl data/pp5/schemas/pcr/pcr.xsd"); Namespace xcl = new Namespace("", "http://www.planets-project.eu/xcl/schemas/xcl"); root.add(xcl); Element compSet = root.addElement("compSet", xcl.getURI()); compSet.addElement("source").addAttribute("name", "samplerecord"); compSet.addElement("target").addAttribute("name", "experimentresult"); /* Element root = doc.addElement("plans"); Namespace xsi = new Namespace("xsi", "http://www.w3.org/2001/XMLSchema-instance"); root.add(xsi); root.addAttribute(xsi.getPrefix()+":noNamespaceSchemaLocation", "http://www.ifs.tuwien.ac.at/dp/plato/schemas/plato-1.9.xsd"); */ for (XCLObjectProperty objectProperty : mappedProperties) { Element prop = compSet.addElement("property").addAttribute("id", objectProperty.getPropertyId()) .addAttribute("name", objectProperty.getName()); for (Metric metric : objectProperty.getMetrics()) { prop.addElement("metric").addAttribute("id", metric.getMetricId()).addAttribute("name", metric.getName()); } } return doc.asXML(); }
From source file:eu.planets_project.pp.plato.xml.ProjectExporter.java
License:Open Source License
public Document createProjectDoc() { Document doc = DocumentHelper.createDocument(); Element root = doc.addElement("plans"); root.add(xsi);/* ww w .j a v a 2 s .c om*/ root.add(platoNS); root.addAttribute(xsi.getPrefix() + ":schemaLocation", "http://www.planets-project.eu/plato plato-3.0.xsd"); root.add(excutablePlanNS); root.add(new Namespace("fits", "http://hul.harvard.edu/ois/xml/ns/fits/fits_output")); // set version of corresponding schema root.addAttribute("version", "3.0.0"); return doc; }
From source file:eu.planets_project.pp.plato.xml.ProjectExporter.java
License:Open Source License
public String exportTreeToFreemind(TreeNode treeRoot) { Document doc = DocumentHelper.createDocument(); Element root = doc.addElement("map"); Namespace xsi = new Namespace("xsi", "http://www.w3.org/2001/XMLSchema-instance"); root.add(xsi);//www. j a v a 2 s.c o m root.addAttribute("version", "0.8.1"); root.addComment( "To view this file, download free mind mapping software FreeMind from http://freemind.sourceforge.net"); addSubTreeFreemind(root, treeRoot); String xml = doc.asXML(); //PlatoLogger.getLogger(ProjectExporter.class).debug(arg0) return xml; }
From source file:eu.scape_project.planning.criteria.bean.CriteriaHierarchyHelperBean.java
License:Apache License
/** * A function which exports all current criteria into a freemind xml string. * Used to ease creation of criteria-hierarchies (manual this is a hard * job)./*from w w w .j a v a 2 s .c o m*/ * * @return the criteria as XML string */ private String exportAllCriteriaToFreeMindXml() { Document doc = DocumentHelper.createDocument(); doc.setXMLEncoding("UTF-8"); Element root = doc.addElement("map"); Namespace xsi = new Namespace("xsi", "http://www.w3.org/2001/XMLSchema-instance"); root.add(xsi); root.addAttribute("version", "0.8.1"); root.addComment( "To view this file, download free mind mapping software FreeMind from http://freemind.sourceforge.net"); Element baseNode = root.addElement("node"); baseNode.addAttribute("TEXT", "allCriteria"); Collection<Measure> allCriteria = criteriaManager.getAllMeasures(); ArrayList<Measure> allCriteriaSortable = new ArrayList<Measure>(allCriteria); Collections.sort(allCriteriaSortable); allCriteria = allCriteriaSortable; // each criterion should be added as simple node for (Measure measure : allCriteria) { // construct node text String nodeText = measure.getAttribute().getName() + "#" + measure.getName() + "|" + measure.getUri(); // add node Element node = baseNode.addElement("node"); node.addAttribute("TEXT", nodeText); } String xml = doc.asXML(); return xml; }
From source file:eu.scape_project.planning.criteria.xml.CriteriaHierarchyExporter.java
License:Apache License
/** * Method responsible for exporting a CriteriaHierarchy-TreeNode to freemind-xml format. * /* www .j a v a2s .com*/ * @param criteriaTreeNode CriteriaHierarchy-Treenode to export * @return freemind-xml String. */ private String exportToFreemindXml(CriteriaTreeNode criteriaTreeNode) { Document doc = DocumentHelper.createDocument(); doc.setXMLEncoding("UTF-8"); Element root = doc.addElement("map"); Namespace xsi = new Namespace("xsi", "http://www.w3.org/2001/XMLSchema-instance"); root.add(xsi); root.addAttribute("version", "0.8.1"); root.addComment( "To view this file, download free mind mapping software FreeMind from http://freemind.sourceforge.net"); addSubTreeFreemind(root, criteriaTreeNode); String xml = doc.asXML(); return xml; }
From source file:eu.scape_project.planning.xml.ProjectExporter.java
License:Apache License
/** * Creates a dom4j document template to add plans. * // w w w . j av a 2 s . co m * @return the dom4j document */ public Document createProjectDoc() { Document doc = DocumentHelper.createDocument(); Element root = doc.addElement("plans"); root.add(XSI_NAMESPACE); root.add(PLATO_NAMESPACE); root.addAttribute(XSI_NAMESPACE.getPrefix() + ":schemaLocation", PlanXMLConstants.PLATO_NS + " " + PlanXMLConstants.PLATO_SCHEMA); root.add(new Namespace("fits", "http://hul.harvard.edu/ois/xml/ns/fits/fits_output")); // set version of corresponding schema root.addAttribute("version", PlanXMLConstants.PLATO_SCHEMA_VERSION); return doc; }
From source file:eu.scape_project.planning.xml.ProjectExporter.java
License:Apache License
public String exportTreeToFreemind(TreeNode treeRoot) { Document doc = DocumentHelper.createDocument(); Element root = doc.addElement("map"); Namespace xsi = new Namespace("xsi", "http://www.w3.org/2001/XMLSchema-instance"); root.add(xsi);//from w w w. ja v a 2 s . c o m root.addAttribute("version", "0.8.1"); root.addComment( "To view this file, download free mind mapping software FreeMind from http://freemind.sourceforge.net"); addSubTreeFreemind(root, treeRoot); String xml = doc.asXML(); // PlatoLogger.getLogger(ProjectExporter.class).debug(arg0) return xml; }
From source file:ie.cmrc.smtx.sws.exceptions.SWSExceptionReport.java
License:Apache License
public Document getXML() { if (!this.isEmpty()) { Namespace sws = new Namespace("sws", swsURI); Namespace xml = new Namespace("xml", xmlURI); //Namespace xsi = new Namespace("xsi", xsiURI); QName exReportQN = new QName("ExceptionReport", sws); Element exceptionReport = DocumentHelper.createElement(exReportQN); exceptionReport.add(xml);//from ww w . ja v a 2 s . c o m exceptionReport.add(sws); //exceptionReport.add(xsi); //QName schemaLocQN = new QName ("schemaLocation", xsi); //exceptionReport.addAttribute(schemaLocQN, this.xsiSchameLocation); //Language if (this.language != null) { if (!this.language.trim().equals("")) { QName langQN = new QName("lang", xml); exceptionReport.addAttribute(langQN, this.language.trim()); } } //Version exceptionReport.addAttribute("version", this.version); QName exceptionQN = new QName("Exception", sws); for (SWSException e : this.exceptions) { if (e != null) { Element exception = exceptionReport.addElement(exceptionQN).addAttribute("code", e.getCode()); if (e.getLocator() != null) { if (!e.getLocator().trim().equals("")) { exception.addAttribute("locator", e.getLocator().trim()); } } if (e.getMessage() != null) { QName messageQN = new QName("Message", sws); exception.addElement(messageQN).addText(e.getMessage()); } } } Document exceptionReportDoc = DocumentHelper.createDocument(exceptionReport); return exceptionReportDoc; } else { //Raise Empty exceptionReport exception return null; } }