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:org.napile.asm.io.xml.out.AbstractAsmXmlWriter.java
License:Apache License
private void visitCode(@NotNull Element temp, @Nullable CodeInfo code) { if (code == null) return;/* w w w.j a v a 2 s . co m*/ Element parent = temp.addElement("code"); parent.addAttribute("max-locals", String.valueOf(code.maxLocals)); if (!code.instructions.isEmpty()) { Element instructions = parent.addElement("instructions"); int i = 0; for (Instruction instruction : code.instructions) { Element e = instruction.accept(this, instructions); if (hasOption(AsmWriterOption.INSTRUCTION_INDEX_IN_COMMENT)) e.addComment(String.valueOf(i++)); } } if (!code.tryCatchBlockNodes.isEmpty()) ifNotEmptyAdd(code.tryCatchBlockNodes, "try-catch-block", parent.addElement("try-catch-blocks")); }
From source file:org.nuxeo.ecm.platform.layout.service.LayoutAutomaticGeneration.java
License:Open Source License
public static Document generateLayoutOutput(SchemaManager sm, String schemaName, boolean generateLabels) { String layoutName = String.format("%s", schemaName); Document document = DocumentFactory.getInstance().createDocument(); document.setName(layoutName);/*from w w w . j av a 2 s . co m*/ Element component = document.addElement("component"); component.addAttribute("name", String.format("myproject.%s.generatedContrib", layoutName)); Element extension = component.addElement("extension"); extension.addAttribute("target", "org.nuxeo.ecm.platform.forms.layout.WebLayoutManager"); extension.addAttribute("point", "layouts"); Element layout = extension.addElement("layout"); layout.addAttribute("name", layoutName); Element rows = layout.addElement("rows"); Schema schema = sm.getSchema(schemaName); String schemaPrefix = schema.getNamespace().prefix; List<Field> fields = new ArrayList<Field>(); fields.addAll(schema.getFields()); Collections.sort(fields, new Comparator<Field>() { public int compare(Field f1, Field f2) { return f1.getName().getLocalName().compareTo(f2.getName().getLocalName()); } }); for (Field field : fields) { // add row element Element row = rows.addElement("row"); Element rowWidget = row.addElement("widget"); String fieldName = field.getName().getLocalName(); rowWidget.setText(fieldName); // add widget element boolean widgetResolved = false; if (field.getType().isSimpleType()) { boolean needsInputStyleClass = false; boolean needsDateFormat = false; Type fieldType = field.getType(); String widgetType = null; if (fieldType == StringType.INSTANCE) { widgetType = "text"; needsInputStyleClass = true; } else if (fieldType == LongType.INSTANCE || fieldType == IntegerType.INSTANCE || fieldType == DoubleType.INSTANCE) { widgetType = "int"; needsInputStyleClass = true; } else if (fieldType == DateType.INSTANCE) { widgetType = "datetime"; needsDateFormat = true; } else { break; } widgetResolved = true; Element widget = layout.addElement("widget"); widget.addAttribute("name", fieldName); widget.addAttribute("type", widgetType); if (generateLabels) { Element labels = widget.addElement("labels"); Element label = labels.addElement("label"); label.addAttribute("mode", BuiltinModes.ANY); label.setText(String.format("label.widget.%s.%s", layoutName, fieldName)); } Element fieldsElement = widget.addElement("fields"); Element fieldElement = fieldsElement.addElement("field"); if (schemaPrefix != null) { fieldElement.setText(field.getName().getPrefixedName()); } else { fieldElement.addAttribute("schema", schemaName); fieldElement.setText(fieldName); } // FIXME: this condition is always true. What's the point? if (needsDateFormat || needsInputStyleClass) { Element properties = widget.addElement("properties"); if (needsDateFormat) { properties.addAttribute("mode", BuiltinModes.ANY); String defaultDatePattern = "#{nxu:basicDateFormater()}"; Element patternProp = properties.addElement("property"); patternProp.addAttribute("name", "pattern"); patternProp.setText(defaultDatePattern); Element formatProp = properties.addElement("property"); formatProp.addAttribute("name", "format"); formatProp.setText(defaultDatePattern); } if (needsInputStyleClass) { properties.addAttribute("mode", BuiltinModes.EDIT); String defaultStyleClass = "dataInputText"; Element styleClassProp = properties.addElement("property"); styleClassProp.addAttribute("name", "styleClass"); styleClassProp.setText(defaultStyleClass); } } } if (!widgetResolved) { // widget needs to be done by hand for now layout.addComment(String.format("TODO: %s", fieldName)); } } return document; }
From source file:org.opencms.setup.xml.v8.CmsXmlAddSolrSearch.java
License:Open Source License
/** * @see org.opencms.setup.xml.CmsXmlUpdateAction#executeUpdate(org.dom4j.Document, java.lang.String, boolean) *//*w w w .j a v a2 s . c o m*/ @SuppressWarnings("unchecked") @Override public boolean executeUpdate(Document doc, String xpath, boolean forReal) { Element node = (Element) doc.selectSingleNode("/opencms/search"); if (node.selectSingleNode("solr") == null) { String solrComment = " To enable Solr in OpenCms you must create a solr/ home\n" + " directory in the WEB-INF folder of your OpenCms application.\n" + " Copy the solr/ folder from the OpenCms standard distribution\n" + " as a starting point for your configuration. "; try { Element solrElement = createElementFromXml("<solr enabled=\"false\"></solr>"); solrElement.addComment(solrComment); node.elements().add(0, solrElement); } catch (DocumentException e) { System.out.println("Could not add solr node"); return false; } } else { String solrComment = "\n" + " During the update Solr will be disabled in the WEB-INF/config/opencms-search.xml.\n" + " To update Solr you must update the 'schema.xml and' the 'solrconfig.xml' manually.\n" + " The new default configuration files are located in the solr-update/ directory in\n" + " the WEB-INF folder of your application. If you are using the default configuration\n" + " from the distribution, it is sufficient to copy the new configuration files to the\n" + " WEB-INF/solr folder. Else if you have customized the Solr configuration you might\n" + " want to merge the 'schema.xml' and the 'solrconfig.xml' first. When you are done\n" + " set the attribute enabled to 'true' again.\n"; Element solrElement = (Element) node.selectSingleNode("solr"); Attribute a = solrElement.attribute("enabled"); if (a != null) { a.setValue("false"); } solrElement.addComment(solrComment); } try { tryToAddMissingElement(doc, "//index[name='Solr Offline']", "//indexes", "<index class=\"org.opencms.search.solr.CmsSolrIndex\">\n" + " <name>Solr Offline</name>\n" + " <rebuild>offline</rebuild>\n" + " <project>Offline</project>\n" + " <locale>all</locale>\n" + " <configuration>solr_fields</configuration>\n" + " <sources>\n" + " <source>solr_source</source>\n" + " </sources>\n" + " <param name=\"search.solr.postProcessor\">org.opencms.search.solr.CmsSolrLinkProcessor</param>\n" + " </index>"); tryToAddMissingElement(doc, "//index[name='Solr Online']", "//indexes", "<index class=\"org.opencms.search.solr.CmsSolrIndex\">\n" + " <name>Solr Online</name>\n" + " <rebuild>auto</rebuild>\n" + " <project>Online</project>\n" + " <locale>all</locale>\n" + " <configuration>solr_fields</configuration>\n" + " <sources>\n" + " <source>solr_source</source>\n" + " </sources>\n" + " <param name=\"search.solr.postProcessor\">org.opencms.search.solr.CmsSolrLinkProcessor</param>\n" + " </index>"); Element solrSource = (Element) (doc.selectSingleNode("//indexsource[name='solr_source']")); // will be added again in next step if (solrSource != null) { solrSource.detach(); } tryToAddMissingElement(doc, "//indexsource[name='solr_source']", "//indexsources", "<indexsource>\n" + " <name>solr_source</name>\n" + " <indexer class=\"org.opencms.search.CmsVfsIndexer\" />\n" + " <resources>\n" + " <resource>/</resource>\n" + " </resources>\n" + " <documenttypes-indexed>\n" + " <name>xmlcontent-solr</name>\n" + " <name>containerpage-solr</name>\n" + " <name>xmlpage</name>\n" + " <name>text</name>\n" + " <name>jsp</name>\n" + " <name>pdf</name>\n" + " <name>rtf</name>\n" + " <name>html</name>\n" + " <name>image</name>\n" + " <name>generic</name>\n" + " <name>msoffice-ole2</name>\n" + " <name>msoffice-ooxml</name>\n" + " <name>openoffice</name>\n" + " </documenttypes-indexed>\n" + " </indexsource>"); tryToAddMissingElement(doc, "//fieldconfiguration[name='solr_fields']", "//fieldconfigurations", "<fieldconfiguration class=\"org.opencms.search.solr.CmsSolrFieldConfiguration\">\n" + " <name>solr_fields</name>\n" + " <description>The Solr search index field configuration.</description>\n" + " <fields />\n" + " </fieldconfiguration>"); tryToAddMissingElement(doc, "//documenttype[name='xmlcontent-solr']", "//documenttypes", "<documenttype>\n" + " <name>xmlcontent-solr</name>\n" + " <class>org.opencms.search.solr.CmsSolrDocumentXmlContent</class>\n" + " <mimetypes>\n" + " <mimetype>text/html</mimetype>\n" + " </mimetypes>\n" + " <resourcetypes>\n" + " <resourcetype>xmlcontent-solr</resourcetype>\n" + " </resourcetypes>\n" + " </documenttype>"); tryToAddMissingElement(doc, "//documenttype[name='containerpage-solr']", "//documenttypes", "<documenttype>\n" + " <name>containerpage-solr</name>\n" + " <class>org.opencms.search.solr.CmsSolrDocumentContainerPage</class>\n" + " <mimetypes>\n" + " <mimetype>text/html</mimetype>\n" + " </mimetypes>\n" + " <resourcetypes>\n" + " <resourcetype>containerpage-solr</resourcetype>\n" + " </resourcetypes>\n" + " </documenttype>"); } catch (DocumentException e) { e.printStackTrace(); } return true; }
From source file:org.opencms.xml.types.CmsXmlDynamicCategoryValue.java
License:Open Source License
/** * @see org.opencms.xml.types.I_CmsXmlSchemaType#generateXml(org.opencms.file.CmsObject, org.opencms.xml.I_CmsXmlDocument, org.dom4j.Element, java.util.Locale) *//* ww w. j a v a2 s. com*/ @Override public Element generateXml(CmsObject cms, I_CmsXmlDocument document, Element root, Locale locale) { Element element = root.addElement(getName()); element.addComment("Categories are read dynamically"); return element; }
From source file:org.pentaho.commons.connection.DataUtilities.java
License:Open Source License
/** * Get an XML representation of the resultset * //ww w . j av a 2s .co m * @return String containing XML which represents the data (eg for use with xquery) */ public static String getXMLString(IPentahoResultSet resultSet) { String xmlResultString = null; Document document = DOMDocumentFactory.getInstance().createDocument(); org.dom4j.Element resultSetNode = document.addElement("result-set"); //$NON-NLS-1$ Object[] colHeaders = resultSet.getMetaData().getColumnHeaders()[0]; String metaDataStr = ""; //$NON-NLS-1$ Object[] firstDataRow = resultSet.getDataRow(0); for (int i = 0; i < firstDataRow.length; i++) { metaDataStr += firstDataRow[i].getClass().getName() + (i == firstDataRow.length - 1 ? "" : ","); //$NON-NLS-1$//$NON-NLS-2$ } resultSetNode.addComment(metaDataStr); int rowCount = resultSet.getRowCount(); for (int i = 0; i < rowCount; i++) { Object[] row = resultSet.getDataRow(i); org.dom4j.Element rowNode = resultSetNode.addElement("row"); //$NON-NLS-1$ for (int j = 0; j < row.length; j++) { String column = colHeaders[j].toString(); String value = row[j] != null ? row[j].toString() : ""; //$NON-NLS-1$ if (row[j] instanceof Timestamp || row[j] instanceof Date) { value = String.valueOf(((Timestamp) row[j]).getTime()); } org.dom4j.Element dataNode = rowNode.addElement(column); dataNode.setText(value); } } OutputFormat format = OutputFormat.createPrettyPrint(); ByteArrayOutputStream outStream = new ByteArrayOutputStream(); try { XMLWriter writer = new XMLWriter(outStream, format); writer.write(document); xmlResultString = outStream.toString(); } catch (Exception e) { // try to return the xml unformatted xmlResultString = document.asXML(); } return xmlResultString; }
From source file:org.sipfoundry.sipxconfig.admin.dialplan.config.RulesXmlFile.java
License:Contributor Agreement License
protected void addRuleNameComment(Element hostMatch, IDialingRule rule) { String nameText = rule.getName(); if (!StringUtils.isBlank(nameText)) { hostMatch.addComment(nameText); }/*from w ww .jav a 2s .c om*/ }
From source file:org.talend.core.ui.documentation.generation.ExternalNodeComponentHandler.java
License:Open Source License
@Override public void generateComponentInfo() { for (INode externalNode : this.componentsList) { Element componentElement = generateComponentDetailsInfo(true, externalNode, this.externalNodeElement, this.picFilePathMap, this.sourceConnectionMap, this.targetConnectionMap, this.repositoryDBIdAndNameMap); String componentName = externalNode.getUniqueName(); IComponentDocumentation componentDocumentation = externalNode.getExternalNode() .getComponentDocumentation(componentName, HTMLDocUtils.getTmpFolder() /* checkExternalPathIsExists(tempFolderPath) */); // Checks if generating html file for external node failed, generating the same information as internal node // instead. if (componentDocumentation == null) { Element parametersElement = componentElement.addElement("parameters"); //$NON-NLS-1$ List elementParameterList = externalNode.getElementParameters(); // generateElementParamInfo(parametersElement, elementParameterList); // see 3328, document for scd is generated similar to internal node generateComponentSchemaInfo(externalNode, componentElement); generateComponentElementParamInfo(parametersElement, elementParameterList); } else {/*w w w. jav a2s .c o m*/ URL fileURL = componentDocumentation.getHTMLFile(); if (fileURL != null) { this.externalNodeHTMLMap.put(componentName, fileURL); } } componentElement.addComment(componentName); } }
From source file:org.unitime.banner.ant.MergeXml.java
License:Apache License
private void merge(Element target, Element source) { for (Iterator i = source.attributeIterator(); i.hasNext();) { Attribute attribute = (Attribute) i.next(); target.addAttribute(attribute.getName(), attribute.getValue()); }/*ww w.j a v a2 s .c o m*/ for (Iterator i = source.nodeIterator(); i.hasNext();) { Node node = (Node) i.next(); if (node instanceof Element) { Element element = (Element) node; if ("property".equals(element.getName())) { String name = element.attributeValue("name", "noname"); Element targetProperty = null; for (Iterator j = target.elementIterator("property"); j.hasNext();) { Element property = (Element) j.next(); if (name.equals(property.attributeValue("name"))) { targetProperty = property; break; } } if (targetProperty != null) { target.remove(targetProperty); } if (element.getText() != null && element.getText().trim().length() > 0) { target.addElement("property").addAttribute("name", name).setText(element.getText()); } } else { if (target.elements(element.getName()).size() == 1 && source.elements(element.getName()).size() == 1) merge(target.element(element.getName()), element); else merge(target.addElement(element.getName()), element); } } else if (node instanceof Comment) { Comment comment = (Comment) node; target.addComment(comment.getText()); } else if (node instanceof CDATA) { CDATA data = (CDATA) node; target.add((CDATA) data.clone()); } else if (node instanceof Text) { Text text = (Text) node; if (text.getText() != null && text.getText().trim().length() > 0) target.addText(text.getText()); } else if (node instanceof Namespace) { } else { log("Unknown node " + node); } } }
From source file:packet_readers.lineage2.listeners.L2AcquireSkillListener.java
License:Open Source License
@Override public void closeImpl() throws IOException { if (_skillTree.isEmpty()) return;/*from w w w . j ava 2 s . c o m*/ Document document = DocumentHelper.createDocument(); Element listElement = document.addElement("list"); for (IntObjectMap.Entry<Map<L2AcquireType, Set<L2SkillLearn>>> entry : _skillTree.entrySet()) { Element classIdElement = listElement.addElement("class_id"); classIdElement.addAttribute("id", String.valueOf(entry.getKey())); for (Map.Entry<L2AcquireType, Set<L2SkillLearn>> sEntry : entry.getValue().entrySet()) { Element acquireTypeElement = classIdElement.addElement("type"); acquireTypeElement.addAttribute("id", sEntry.getKey().name()); for (L2SkillLearn val : sEntry.getValue()) { Element skillElement = acquireTypeElement.addElement("skill"); skillElement.addAttribute("id", String.valueOf(val.getId())); skillElement.addAttribute("level", String.valueOf(val.getLevel())); skillElement.addAttribute("min-level", String.valueOf(val.getMinLevel())); skillElement.addAttribute("cost", String.valueOf(val.getCost())); skillElement.addComment(SkillNameHolder.getInstance().name(val.getId(), val.getLevel())); for (L2ItemWithCount item : val.getNeedItems()) { Element needItemElement = skillElement.addElement("need_item"); needItemElement.addAttribute("id", String.valueOf(item.getItemId())); needItemElement.addAttribute("count", String.valueOf(item.getCount())); //needItemElement.addComment(ItemNameHolder.getInstance().name(item.getItemId())); } for (L2SkillInfo skill : val.getNeedSkills()) { Element needSkillElement = skillElement.addElement("need_skill"); needSkillElement.addAttribute("id", String.valueOf(skill.getId())); needSkillElement.addAttribute("level", String.valueOf(skill.getLevel())); //needSkillElement.addComment(SkillNameHolder.getInstance().name(skill.getId(), skill.getLevel())); } } } } OutputFormat format = OutputFormat.createPrettyPrint(); format.setIndent("\t"); format.setExpandEmptyElements(false); XMLWriter writer = new XMLWriter(new FileWriter(getLogFile("./skilltree/ ", "xml")), format); writer.write(document); writer.close(); }
From source file:packet_readers.lineage2.listeners.L2MoveNpcListener.java
License:Open Source License
@Override public void closeImpl() throws IOException { Document document = DocumentHelper.createDocument(); Element listElement = document.addElement("list"); for (L2NpcInfo info : _world.valuesNpc()) { if (info.getMoveLocs().isEmpty()) continue; Element npcElement = listElement.addElement("npc"); npcElement.addAttribute("id", String.valueOf(info.getNpcId())); npcElement.addComment(NpcNameHolder.getInstance().name(info.getNpcId())); for (L2Loc loc : info.getMoveLocs()) { Element element = npcElement.addElement("loc"); element.addAttribute("x", String.valueOf(loc.getX())); element.addAttribute("y", String.valueOf(loc.getY())); element.addAttribute("z", String.valueOf(loc.getZ())); }/*from w w w .j a va2 s . c o m*/ } if (listElement.elements().isEmpty()) return; OutputFormat format = OutputFormat.createPrettyPrint(); format.setIndent("\t"); XMLWriter writer = new XMLWriter(new FileWriter(getLogFile("./move_locs ", "xml")), format); writer.write(document); writer.close(); }