List of usage examples for org.dom4j Element add
void add(Namespace namespace);
Namespace
to this element. 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); root.addAttribute("version", "0.8.1"); root.addComment(/*from www. jav a 2 s . c o m*/ "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 www . j av a2s . c om * * @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 a2 s. co m*/ * @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.PreservationActionPlanGenerator.java
License:Apache License
/** * Generates a preservation action plan as dom4j document. * /*from ww w . j a v a 2s. c om*/ * @return the preservation action plan * @throws PlanningException * if an error occurred during generation */ public Document generatePreservationActionPlanDocument(CollectionProfile collectionProfile, ExecutablePlanDefinition executablePlanDefinition, Plan plan) throws PlanningException { Document doc = createPapDoc(); Element preservationActionPlan = doc.getRootElement(); // Preservation action plan try { addPreservationActionPlanData(collectionProfile, preservationActionPlan); addPreservationActionPlanT2flow(executablePlanDefinition.getT2flowExecutablePlan(), preservationActionPlan); QLDGenerator qldGen = new QLDGenerator(); qldGen.generateQLD(plan); Element qualityLevelDescription = preservationActionPlan.addElement("qualityLevelDescription"); Element root = qldGen.getQldNode().getRootElement(); Element schema = qualityLevelDescription.addElement("schema", "http://purl.oclc.org/dsdl/schematron"); schema.addAttribute("xmlns", "http://purl.oclc.org/dsdl/schematron"); schema.add(root.element("pattern").detach()); } catch (ParserException e) { throw new PlanningException("Error parsing collection profile", e); } catch (TavernaParserException e) { throw new PlanningException("Error parsing executable plan", e); } return doc; }
From source file:eu.scape_project.planning.xml.PreservationActionPlanGenerator.java
License:Apache License
/** * Creates a document for the preservation action plan. * //from w ww . ja v a 2 s .c o m * @return the document */ private Document createPapDoc() { Document doc = DocumentHelper.createDocument(); Element root = doc.addElement(new QName("preservationActionPlan", platoNS)); root.add(xsi); root.add(platoNS); root.addAttribute(xsi.getPrefix() + ":schemaLocation", PlanXMLConstants.PLATO_NS + " " + PlanXMLConstants.PAP_SCHEMA); // Set version of corresponding schema root.addAttribute("version", "1.0"); return doc; }
From source file:eu.scape_project.planning.xml.PreservationActionPlanGenerator.java
License:Apache License
/** * Adds an executable plan t2flow to the parent. * //from w ww . j a v a2 s.co m * @param t2flow * the t2flow to add * @param parent * the parent element of the element to create * @return the newly created element or null if none was created * @throws TavernaParserException * if the workflow could not be parsed * @throws StorageException * if the data could not be loaded */ private Element addPreservationActionPlanT2flow(DigitalObject t2flow, Element parent) throws TavernaParserException, StorageException { Element executablePlan = null; if (t2flow != null && t2flow.isDataExistent()) { executablePlan = parent.addElement("executablePlan").addAttribute("type", "t2flow"); if (!addDigitalObjectData) { // Add only DigitalObject ID, it can be replaced later executablePlan.setText(String.valueOf(t2flow.getId())); } else { DigitalObject t2flowObject = t2flow; try { if (t2flowObject.getData().getData() == null || t2flowObject.getData().getData().length == 0) { t2flowObject = digitalObjectManager.getCopyOfDataFilledDigitalObject(t2flowObject); } T2FlowParser parser = T2FlowParser .createParser(new ByteArrayInputStream(t2flowObject.getData().getData())); Document doc = parser.getDoc(); executablePlan.add(doc.getRootElement()); } finally { t2flowObject = null; } } } return executablePlan; }
From source file:eu.scape_project.planning.xml.ProjectExporter.java
License:Apache License
/** * Creates a dom4j document template to add plans. * //from www . ja v a 2 s . c o 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
/** * Creates a template document.// w w w . j a v a 2 s .com * * @return the dom4j-document */ public Document createTemplateDoc() { Document doc = DocumentHelper.createDocument(); Element root = doc.addElement("templates"); root.add(XSI_NAMESPACE); 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); root.addAttribute("version", "0.8.1"); root.addComment(/* w w w . j a v a2 s. co m*/ "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.xml.ProjectExporter.java
License:Apache License
/** * Adds a preservation action plan element to the provided parent if the * preservation action plan is defined.//from ww w . ja va2s .c o m * * @param preservationActionPlan * the preservation action plan to add * @param parent * the parent element * @param addDigitalObjectData * true if the data should be written, false otherwise * @return the newly created element or null * @throws PlanningException * if an error occurred during creation */ private Element addPreservationActionPlan(DigitalObject preservationActionPlan, Element parent, boolean addDigitalObjectData) throws PlanningException { Element preservationActionPlanElement = null; if (preservationActionPlan != null) { if (preservationActionPlan != null && preservationActionPlan.isDataExistent()) { if (!addDigitalObjectData) { preservationActionPlanElement = parent.addElement("preservationActionPlan"); preservationActionPlanElement.setText(String.valueOf(preservationActionPlan.getId())); } else { Document doc; try { doc = DocumentHelper.parseText( new String(preservationActionPlan.getData().getData(), PlanXMLConstants.ENCODING)); if (doc.getRootElement().hasContent()) { preservationActionPlanElement = doc.getRootElement(); parent.add(preservationActionPlanElement); } } catch (UnsupportedEncodingException e) { log.error("Error parsing preservation action plan {}.", e.getMessage()); throw new PlanningException("Error parsing preservation action plan.", e); } catch (DocumentException e) { log.error("Error parsing preservation action plan {}.", e.getMessage()); throw new PlanningException("Error parsing preservation action plan.", e); } } } } return preservationActionPlanElement; }