List of usage examples for org.dom4j Element addComment
Element addComment(String comment);
Comment
node with the given text to this element. 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. * /* w ww . ja v a 2 s .c o 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.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);// w w w. ja v a2 s .c om 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:jt56.comm.code.util.WolfXmlUtil.java
License:Open Source License
private void getAddStrutsElemant(String filePath, String nodexPath) throws Exception { Document document = getPath(filePath, "utf-8"); Element element = document.getRootElement(); Element nextElement = element.element("package"); Element newElement = nextElement.addElement("action"); newElement.addComment(""); newElement.addAttribute("name", "test"); newElement.addAttribute("class", ""); newElement.addAttribute("method", ""); newElement.addText("hello"); }
From source file:lost.tok.html.Menu.java
License:Open Source License
/** Returns the html's div element of the menu */ public Element getMenuDiv() { //Element div = DocumentHelper.createElement("div"); Element script = DocumentHelper.createElement("script"); //$NON-NLS-1$ script.addAttribute("type", "text/javascript"); //$NON-NLS-1$ //$NON-NLS-2$ script.addComment(getDTreeCode()); return script; }
From source file:net.unicon.academus.apps.briefcase.migrate.BriefcaseMigrator.java
License:Open Source License
public static void main(String[] args) { System.out.println("Starting Briefcase portlet migration of data from Academus 1.5 " + " to Academus 1.6"); if (args.length == 2) { try {//from w w w . j a v a 2s. c om DataSource ds = new SimpleDataSource(); SAXReader reader = new SAXReader(); // replace the old urls with the new classpaths System.out.println("Updating the resource urls."); updateUrl(ds); updateSharedResourceUrls(ds); // replace the OWNER access type. System.out.println("Updating the accessTypes."); updateAccessType(ds); // set the uni_sequence table for the RdbmsAccessBroker Counter // and the FSA_Kernel_Sequencer updateSequencers(ds); // read the old config file // and correct the classpaths for all the access brokers. Document oldDoc = reader.read(args[0]); DOMDocumentFactory dFac = new DOMDocumentFactory(); // Get all access brokers List brokers = oldDoc.selectNodes("//access-broker"); Element broker = null; // Change access brokers to point to alchemist instead of academus for (int i = 0; i < brokers.size(); i++) { broker = (Element) brokers.get(i); String implValue = broker.attributeValue("impl").replaceFirst("academus", "alchemist"); broker.addAttribute("impl", implValue); } // Get the Access Broker under the personal Drive, and make sure it's a JIT broker Element targetsJitAccessBroker = (Element) ((Element) oldDoc.selectNodes( "/briefcase/drive[@handle='personal']/access-broker[@impl='net.unicon.alchemist.access.jit.JitAccessBroker']") .get(0)).detach(); // Only enter this code if the personal drive section was successful selected if (targetsJitAccessBroker != null) { // Create new permissions element, mirroring targets element Element permissionsJitAccessBroker = (Element) targetsJitAccessBroker.clone(); // Change handles targetsJitAccessBroker.addAttribute("handle", "personal-resourses-t"); permissionsJitAccessBroker.addAttribute("handle", "personal-resourses-p"); // Create new permissions access-broker Element permAccessBroker = dFac.createElement(new QName("access-broker"), 2); permAccessBroker.addAttribute("handle", "personal-jit"); permAccessBroker.addAttribute("impl", PermissionsAccessBroker.class.getName()); // Create new access element and add it to permAccessBroker Element permAccess = dFac.createElement(new QName("access"), 1); permAccess.addAttribute("impl", BriefcaseAccessType.class.getName()); permAccessBroker.add(permAccess); // Create targets and permissions elements and add to the new permissions access-broker Element targets = permAccessBroker.addElement("targets"); targets.add(targetsJitAccessBroker); Element permissions = permAccessBroker.addElement("permissions"); permissions.add(permissionsJitAccessBroker); // Add new permissions access broker to the drive Element curDrive = (Element) oldDoc.selectNodes("/briefcase/drive[@handle='personal']").get(0); curDrive.add(permAccessBroker); // // Change targets internals // List targetsAccess = targets.selectNodes("access-broker/jit-rule/behavior/access"); for (int i = 0; i < targetsAccess.size(); i++) { // Add impl attribute with value of fully-qualified class name ((Element) targetsAccess.get(i)).addAttribute("impl", DummyAccessType.class.getName()); // Get all child type elements and remove them List types = ((Element) targetsAccess.get(i)).elements(); for (int j = 0; j < types.size(); j++) { ((Element) types.get(j)).detach(); } // Add a single dummy element Element eType = dFac.createElement(new QName("type"), 2); eType.addAttribute("value", "GRANT"); eType.addAttribute("handle", "DUMMY"); ((Element) targetsAccess.get(i)).add(eType); } // Add internal access broker's access element Element targetsIAccessBroker = (Element) (targets.selectNodes("access-broker/access-broker") .get(0)); Element targetsIAccess = dFac.createElement(new QName("access"), 1); targetsIAccess.addAttribute("impl", DummyAccessType.class.getName()); targetsIAccessBroker.add(targetsIAccess); // // Change permissions internals // List permissionsAccess = permissions.selectNodes("access-broker/jit-rule/behavior/access"); for (int i = 0; i < permissionsAccess.size(); i++) { // Add impl attribute with value of fully-qualified class name ((Element) permissionsAccess.get(i)).addAttribute("impl", BriefcaseAccessType.class.getName()); // Get all child type elements and replace them List types = ((Element) permissionsAccess.get(i)).elements(); for (int j = 0; j < types.size(); j++) { Attribute value = ((Element) types.get(j)).attribute("value"); String text = value.getValue(); value.setValue("GRANT"); if (text.equals("0")) { BriefcaseAccessType[] aTypes = BriefcaseAccessType.getInstances(); ((Element) types.get(j)).addAttribute("handle", aTypes[0].getName()); for (int k = 1; k < aTypes.length; k++) { Element eType = dFac.createElement(new QName("type"), 2); eType.addAttribute("value", "GRANT"); eType.addAttribute("handle", aTypes[k].getName()); ((Element) permissionsAccess.get(i)).add(eType); } } else { ((Element) types.get(j)).addAttribute("handle", BriefcaseAccessType.getAccessType(Integer.parseInt(text)).getName()); } } } // Change other elements in the permissions section List permissionsBehavior = permissions.selectNodes("access-broker/jit-rule/behavior"); for (int i = 0; i < permissionsBehavior.size(); i++) { Element trigger = (Element) ((Element) permissionsBehavior.get(i)).elements("trigger") .get(0); Element target = (Element) ((Element) permissionsBehavior.get(i)).elements("target").get(0); Element creator = (Element) ((Element) permissionsBehavior.get(i)).elements("creator") .get(0); // Insert trigger text into target target.addAttribute("type", "GROUP"); target.addText(trigger.getText()); // Remove current creator element creator.detach(); // Add new current creator element Element eCreator = dFac.createElement(new QName("creator"), 1); eCreator.addAttribute("impl", DummyCreator.class.getName()); ((Element) permissionsBehavior.get(i)).add(eCreator); } // Change internal access broker's name Element permissionsIAccessBroker = (Element) (permissions .selectNodes("access-broker/access-broker").get(0)); permissionsIAccessBroker.addAttribute("handle", "personal-resources-p-i"); // Add internal access broker's access element Element permissionsIAccess = dFac.createElement(new QName("access"), 1); permissionsIAccess.addAttribute("impl", BriefcaseAccessType.class.getName()); permissionsIAccessBroker.add(permissionsIAccess); } List access = oldDoc.selectNodes("/briefcase/drive[@handle!='personal']//access"); for (int i = 0; i < access.size(); i++) { // Add impl attribute with value of fully-qualified class name ((Element) access.get(i)).addAttribute("impl", BriefcaseAccessType.class.getName()); List types = ((Element) access.get(i)).elements(); for (int j = 0; j < types.size(); j++) { Attribute value = ((Element) types.get(j)).attribute("value"); String text = value.getValue(); value.setValue("GRANT"); if (text.equals("0")) { BriefcaseAccessType[] aTypes = BriefcaseAccessType.getInstances(); ((Element) types.get(j)).addAttribute("handle", aTypes[0].getName()); for (int k = 1; k < aTypes.length; k++) { Element eType = dFac.createElement(new QName("type"), 2); eType.addAttribute("value", "GRANT"); eType.addAttribute("handle", aTypes[k].getName()); ((Element) access.get(i)).add(eType); } } else { ((Element) types.get(j)).addAttribute("handle", BriefcaseAccessType.getAccessType(Integer.parseInt(text)).getName()); } } } // add impl attribute to specify the UserDirectory impl to user-attribute element List userAttr = oldDoc.selectNodes("//user-attribute"); for (int i = 0; i < userAttr.size(); i++) { ((Element) userAttr.get(i)).addAttribute("impl", "net.unicon.academus.apps.briefcase.UserAttributeDirectory"); } //replace the resource factory urls List entries = oldDoc .selectNodes("/briefcase/drive[@handle!='personal']//access-broker/entry[@target!='']"); for (int i = 0; i < entries.size(); i++) { ((Element) entries.get(i)).addAttribute("target", ((Element) entries.get(i)) .attributeValue("target").replaceAll("academus.resource.factory", "demetrius.fac")); } // add access element to specify the AccessType to the RdbmsAccessBroker brokers = oldDoc.selectNodes("/briefcase/drive[@handle!='personal']//access-broker[@impl='" + RdbmsAccessBroker.class.getName() + "']"); for (int i = 0; i < brokers.size(); i++) { broker = (Element) brokers.get(i); Element eType = dFac.createElement(new QName("access"), 1); eType.addAttribute("impl", BriefcaseAccessType.class.getName()); broker.add(eType); } // add the civis address book information. Element drive = (Element) oldDoc.selectSingleNode("briefcase"); drive.addComment("Civis implementation to be used to resolve usernames and group paths" + " to academus users and groups. This should not require" + " modification, as it utilized the Academus framework for gathering this" + " information."); Element civis = dFac.createElement("civis"); civis.addAttribute("id", "addressBook"); civis.addAttribute("impl", "net.unicon.civis.fac.academus.AcademusCivisFactory"); Element restrictor = dFac.createElement("restrictor"); restrictor.addAttribute("impl", "net.unicon.civis.grouprestrictor.AcademusGroupRestrictor"); civis.add(restrictor); drive.add(civis); File f = new File(args[1]); PrintWriter pw = new PrintWriter(new FileOutputStream(f)); pw.write(oldDoc.asXML()); pw.flush(); pw.close(); System.out.println( "Done. Enjoy !! \n Remember to the use the migrated config file with the 1.6 deploy."); } catch (Exception e) { e.printStackTrace(); } } else { usage(); } }
From source file:nl.tue.gale.common.XPPEntityReader.java
License:Open Source License
protected Document parseDocument() throws DocumentException, IOException, XmlPullParserException { DocumentFactory df = getDocumentFactory(); Document document = df.createDocument(); Element parent = null; XmlPullParser pp = getXPPParser();/*from w w w .ja v a 2 s . com*/ pp.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, true); pp.setFeature(XmlPullParser.FEATURE_PROCESS_DOCDECL, false); defineEntities(pp); while (true) { int type = pp.nextToken(); switch (type) { case XmlPullParser.PROCESSING_INSTRUCTION: { String text = pp.getText(); int loc = text.indexOf(" "); if (loc >= 0) { String target = text.substring(0, loc); String txt = text.substring(loc + 1); document.addProcessingInstruction(target, txt); } else { document.addProcessingInstruction(text, ""); } break; } case XmlPullParser.COMMENT: { if (parent != null) { parent.addComment(pp.getText()); } else { document.addComment(pp.getText()); } break; } case XmlPullParser.CDSECT: { if (parent != null) { parent.addCDATA(pp.getText()); } else { String msg = "Cannot have text content outside of the " + "root document"; throw new DocumentException(msg); } break; } case XmlPullParser.ENTITY_REF: if (parent != null) { if (pp.getName().equals("gt")) { parent.addText(">"); } else if (pp.getName().equals("lt")) { parent.addText("<"); } else if (pp.getName().equals("amp")) { parent.addText("&"); } else if (pp.getName().equals("quot")) { parent.addText("\""); } else parent.addEntity(pp.getName(), "&" + pp.getName() + ";"); } break; case XmlPullParser.END_DOCUMENT: return document; case XmlPullParser.START_TAG: { QName qname = (pp.getPrefix() == null) ? df.createQName(pp.getName(), pp.getNamespace()) : df.createQName(pp.getName(), pp.getPrefix(), pp.getNamespace()); Element newElement = df.createElement(qname); int nsStart = pp.getNamespaceCount(pp.getDepth() - 1); int nsEnd = pp.getNamespaceCount(pp.getDepth()); for (int i = nsStart; i < nsEnd; i++) { if (pp.getNamespacePrefix(i) != null) { newElement.addNamespace(pp.getNamespacePrefix(i), pp.getNamespaceUri(i)); } } for (int i = 0; i < pp.getAttributeCount(); i++) { QName qa = (pp.getAttributePrefix(i) == null) ? df.createQName(pp.getAttributeName(i)) : df.createQName(pp.getAttributeName(i), pp.getAttributePrefix(i), pp.getAttributeNamespace(i)); newElement.addAttribute(qa, pp.getAttributeValue(i)); } if (parent != null) { parent.add(newElement); } else { document.add(newElement); } parent = newElement; break; } case XmlPullParser.END_TAG: { if (parent != null) { parent = parent.getParent(); } break; } case XmlPullParser.TEXT: { String text = pp.getText(); if (parent != null) { parent.addText(text); } else { String msg = "Cannot have text content outside of the " + "root document"; throw new DocumentException(msg); } break; } default: break; } } }
From source file:org.apache.openmeetings.servlet.outputhandler.LangExport.java
License:Apache License
public Document createDocument(List<Fieldlanguagesvalues> flvList, List<Fieldlanguagesvalues> untranslatedList) throws Exception { Document document = createDocument(); Element root = createRoot(document); for (Fieldlanguagesvalues flv : flvList) { Element eTemp = root.addElement("string") .addAttribute("id", flv.getFieldvalues().getFieldvalues_id().toString()) .addAttribute("name", flv.getFieldvalues().getName()); Element value = eTemp.addElement("value"); value.addText(flv.getValue());/*from www. j ava 2 s . co m*/ } //untranslated if (untranslatedList.size() > 0) { root.addComment("Untranslated strings"); for (Fieldlanguagesvalues flv : untranslatedList) { Element eTemp = root.addElement("string") .addAttribute("id", flv.getFieldvalues().getFieldvalues_id().toString()) .addAttribute("name", flv.getFieldvalues().getName()); Element value = eTemp.addElement("value"); value.addText(flv.getValue()); } } return document; }
From source file:org.apache.openmeetings.web.admin.labels.LangPanel.java
License:Apache License
public static Document createDocument(List<Fieldlanguagesvalues> flvList, List<Fieldlanguagesvalues> untranslatedList) throws Exception { Document document = LangExport.createDocument(); Element root = LangExport.createRoot(document); for (Fieldlanguagesvalues flv : flvList) { Element eTemp = root.addElement("string") .addAttribute("id", flv.getFieldvalues().getFieldvalues_id().toString()) .addAttribute("name", flv.getFieldvalues().getName()); Element value = eTemp.addElement("value"); value.addText(flv.getValue());// ww w . ja v a 2s .c o m } //untranslated if (untranslatedList.size() > 0) { root.addComment("Untranslated strings"); for (Fieldlanguagesvalues flv : untranslatedList) { Element eTemp = root.addElement("string") .addAttribute("id", flv.getFieldvalues().getFieldvalues_id().toString()) .addAttribute("name", flv.getFieldvalues().getName()); Element value = eTemp.addElement("value"); value.addText(flv.getValue()); } } return document; }
From source file:org.jboss.as.ee.deployment.spi.DeploymentMetaData.java
License:Open Source License
public Document getDocument() { Document document = DocumentHelper.createDocument(); Element root = document.addElement("jboss-deployment-plan"); root.addElement("deployment-name").addText(deploymentName); root.addComment("Note, deployment-entry elements are not used by the DeploymentManager"); root.addComment("The DeploymentManager relies on the the entry naming convention"); Iterator it = entryList.iterator(); while (it.hasNext()) { Entry entry = (Entry) it.next(); Element element = root.addElement("deployment-entry"); element.addElement("archive-name").addText(entry.archiveName); element.addElement("descriptor-name").addText(entry.descriptorName); }//from w w w . j a va 2s . co m return document; }
From source file:org.jboss.deployment.spi.DeploymentMetaData.java
License:Open Source License
public Document getDocument() { Document document = DocumentHelper.createDocument(); Element root = document.addElement("jboss-deployment-plan"); root.addElement("deployment-name").addText(deploymentName); root.addComment("Note, deployment-entry elements are not used by the DeploymentManager"); root.addComment("The DeploymentManager relies on the the entry nameing convention"); Iterator it = entryList.iterator(); while (it.hasNext()) { Entry entry = (Entry) it.next(); Element element = root.addElement("deployment-entry"); element.addElement("archive-name").addText(entry.archiveName); element.addElement("descriptor-name").addText(entry.descriptorName); }/*from w w w .j a v a 2 s . c om*/ return document; }