List of usage examples for org.dom4j Node getName
String getName();
getName
returns the name of this node.
From source file:org.jbpm.graph.def.SuperState.java
License:Open Source License
public Map getNodesMap() { if ((nodesMap == null) && (nodes != null)) { nodesMap = new HashMap(); Iterator iter = nodes.iterator(); while (iter.hasNext()) { Node node = (Node) iter.next(); nodesMap.put(node.getName(), node); }/* ww w . j av a 2 s . c o m*/ } return nodesMap; }
From source file:org.jbpm.jpdl.xml.JpdlXmlWriter.java
License:Open Source License
private void writeNode(Element element, org.jbpm.graph.def.Node node) { addAttribute(element, "name", node.getName()); writeTransitions(element, node);/*from w ww. j av a 2 s . co m*/ writeEvents(element, node); }
From source file:org.jivesoftware.openfire.pubsub.PubSubModule.java
License:Open Source License
public Iterator<DiscoItem> getItems(String name, String node, JID senderJID) { // Check if the service is disabled. Info is not available when disabled. if (!isServiceEnabled()) { return null; }// www . j a va 2 s.c o m List<DiscoItem> answer = new ArrayList<DiscoItem>(); String serviceDomain = getServiceDomain(); if (name == null && node == null) { // Answer all first level nodes for (Node pubNode : rootCollectionNode.getNodes()) { if (canDiscoverNode(pubNode)) { final DiscoItem item = new DiscoItem(new JID(serviceDomain), pubNode.getName(), pubNode.getNodeID(), null); answer.add(item); } } } else if (name == null) { Node pubNode = getNode(node); if (pubNode != null && canDiscoverNode(pubNode)) { if (pubNode.isCollectionNode()) { // Answer all nested nodes as items for (Node nestedNode : pubNode.getNodes()) { if (canDiscoverNode(nestedNode)) { final DiscoItem item = new DiscoItem(new JID(serviceDomain), nestedNode.getName(), nestedNode.getNodeID(), null); answer.add(item); } } } else { // This is a leaf node so answer the published items which exist on the service for (PublishedItem publishedItem : pubNode.getPublishedItems()) { answer.add(new DiscoItem(new JID(serviceDomain), publishedItem.getID(), null, null)); } } } else { // Answer null to indicate that specified item was not found return null; } } return answer.iterator(); }
From source file:org.opencms.importexport.CmsImportVersion2.java
License:Open Source License
/** * Merges a single page.<p>/*from ww w.ja v a2s. com*/ * * @param resourcename the resource name of the page * @throws CmsImportExportException if something goes wrong * @throws CmsXmlException if the page file could not be unmarshalled */ private void mergePageFile(String resourcename) throws CmsXmlException, CmsImportExportException { try { if (LOG.isDebugEnabled()) { LOG.debug(Messages.get().getBundle().key(Messages.LOG_IMPORTEXPORT_START_MERGING_1, resourcename)); } // in OpenCms versions <5 node names have not been case sensitive. thus, nodes are read both in upper // and lower case letters, or have to be tested for equality ignoring upper/lower case... // get the header file CmsFile pagefile = m_cms.readFile(resourcename, CmsResourceFilter.ALL); Document contentXml = CmsXmlUtils.unmarshalHelper(pagefile.getContents(), null); // get the <masterTemplate> node to check the content. this node contains the name of the template file. String masterTemplateNodeName = "//masterTemplate"; Node masterTemplateNode = contentXml.selectSingleNode(masterTemplateNodeName); if (masterTemplateNode == null) { masterTemplateNode = contentXml.selectSingleNode(masterTemplateNodeName.toLowerCase()); } if (masterTemplateNode == null) { masterTemplateNode = contentXml.selectSingleNode(masterTemplateNodeName.toUpperCase()); } // there is only one <masterTemplate> allowed String mastertemplate = null; if (masterTemplateNode != null) { // get the name of the mastertemplate mastertemplate = masterTemplateNode.getText().trim(); } // get the <ELEMENTDEF> nodes to check the content. // this node contains the information for the body element. String elementDefNodeName = "//ELEMENTDEF"; Node bodyNode = contentXml.selectSingleNode(elementDefNodeName); if (bodyNode == null) { bodyNode = contentXml.selectSingleNode(elementDefNodeName.toLowerCase()); } // there is only one <ELEMENTDEF> allowed if (bodyNode != null) { String bodyclass = null; String bodyname = null; Map bodyparams = null; List nodes = ((Element) bodyNode).elements(); for (int i = 0, n = nodes.size(); i < n; i++) { Node node = (Node) nodes.get(i); if ("CLASS".equalsIgnoreCase(node.getName())) { bodyclass = node.getText().trim(); } else if ("TEMPLATE".equalsIgnoreCase(node.getName())) { bodyname = node.getText().trim(); if (!bodyname.startsWith("/")) { bodyname = CmsResource.getFolderPath(resourcename) + bodyname; } } else if ("PARAMETER".equalsIgnoreCase(node.getName())) { Element paramElement = (Element) node; if (bodyparams == null) { bodyparams = new HashMap(); } bodyparams.put((paramElement.attribute("name")).getText(), paramElement.getTextTrim()); } } if ((mastertemplate == null) || (bodyname == null)) { CmsMessageContainer message = Messages.get().container( Messages.ERR_IMPORTEXPORT_ERROR_CANNOT_MERGE_PAGE_FILE_3, resourcename, mastertemplate, bodyname); if (LOG.isDebugEnabled()) { LOG.debug(message.key()); } throw new CmsImportExportException(message); } // lock the resource, so that it can be manipulated m_cms.lockResource(resourcename); // get all properties List properties = m_cms.readPropertyObjects(resourcename, false); // now get the content of the bodyfile and insert it into the control file CmsFile bodyfile = m_cms.readFile(bodyname, CmsResourceFilter.IGNORE_EXPIRATION); //get the encoding String encoding = CmsProperty.get(CmsPropertyDefinition.PROPERTY_CONTENT_ENCODING, properties) .getValue(); if (encoding == null) { encoding = OpenCms.getSystemInfo().getDefaultEncoding(); } if (m_convertToXmlPage) { if (LOG.isDebugEnabled()) { LOG.debug(Messages.get().getBundle() .key(Messages.LOG_IMPORTEXPORT_START_CONVERTING_TO_XML_0)); } CmsXmlPage xmlPage = CmsXmlPageConverter.convertToXmlPage(m_cms, bodyfile.getContents(), getLocale(resourcename, properties), encoding); if (LOG.isDebugEnabled()) { LOG.debug( Messages.get().getBundle().key(Messages.LOG_IMPORTEXPORT_END_CONVERTING_TO_XML_0)); } if (xmlPage != null) { pagefile.setContents(xmlPage.marshal()); // set the type to xml page pagefile.setType(CmsResourceTypeXmlPage.getStaticTypeId()); } } // add the template and other required properties CmsProperty newProperty = new CmsProperty(CmsPropertyDefinition.PROPERTY_TEMPLATE, mastertemplate, null); // property lists must not contain equal properties properties.remove(newProperty); properties.add(newProperty); // if set, add the bodyclass as property if (CmsStringUtil.isNotEmpty(bodyclass)) { newProperty = new CmsProperty(CmsPropertyDefinition.PROPERTY_TEMPLATE, mastertemplate, null); newProperty.setAutoCreatePropertyDefinition(true); properties.remove(newProperty); properties.add(newProperty); } // if set, add bodyparams as properties if (bodyparams != null) { for (Iterator p = bodyparams.entrySet().iterator(); p.hasNext();) { Map.Entry entry = (Map.Entry) p.next(); String key = (String) entry.getKey(); String value = (String) entry.getValue(); newProperty = new CmsProperty(key, value, null); newProperty.setAutoCreatePropertyDefinition(true); properties.remove(newProperty); properties.add(newProperty); } } if (LOG.isDebugEnabled()) { LOG.debug(Messages.get().getBundle().key(Messages.LOG_IMPORTEXPORT_START_IMPORTING_XML_PAGE_0)); } // now import the resource m_cms.importResource(resourcename, pagefile, pagefile.getContents(), properties); // finally delete the old body file, it is not needed anymore m_cms.lockResource(bodyname); m_cms.deleteResource(bodyname, CmsResource.DELETE_PRESERVE_SIBLINGS); if (LOG.isDebugEnabled()) { LOG.debug(Messages.get().getBundle().key(Messages.LOG_IMPORTEXPORT_END_IMPORTING_XML_PAGE_0)); } m_report.println(org.opencms.report.Messages.get().container(org.opencms.report.Messages.RPT_OK_0), I_CmsReport.FORMAT_OK); } else { // there are more than one template nodes in this control file // convert the resource into a plain text file // lock the resource, so that it can be manipulated m_cms.lockResource(resourcename); // set the type to plain pagefile.setType(CmsResourceTypePlain.getStaticTypeId()); // write all changes m_cms.writeFile(pagefile); // done, unlock the resource m_cms.unlockResource(resourcename); if (LOG.isDebugEnabled()) { LOG.debug(Messages.get().getBundle() .key(Messages.LOG_IMPORTEXPORT_CANNOT_CONVERT_XML_STRUCTURE_1, resourcename)); } m_report.println(Messages.get().container(Messages.RPT_NOT_CONVERTED_0), I_CmsReport.FORMAT_OK); } if (LOG.isDebugEnabled()) { LOG.debug(Messages.get().getBundle().key(Messages.LOG_IMPORTEXPORT_END_MERGING_1, resourcename)); } } catch (CmsXmlException e) { throw e; } catch (CmsException e) { m_report.println(e); CmsMessageContainer message = Messages.get() .container(Messages.ERR_IMPORTEXPORT_ERROR_MERGING_PAGE_FILE_1, resourcename); if (LOG.isDebugEnabled()) { LOG.debug(message.key(), e); } throw new CmsImportExportException(message, e); } }
From source file:org.opencms.importexport.CmsXmlPageConverter.java
License:Open Source License
/** * Converts the contents of a page into an xml page.<p> * /*from w w w . j av a2s . c o m*/ * @param cms the cms object * @param content the content used with xml templates * @param locale the locale of the body element(s) * @param encoding the encoding to the xml page * @return the xml page content or null if conversion failed * @throws CmsImportExportException if the body content or the XMLTEMPLATE element were not found * @throws CmsXmlException if there is an error reading xml contents from the byte array into a document */ public static CmsXmlPage convertToXmlPage(CmsObject cms, byte[] content, Locale locale, String encoding) throws CmsImportExportException, CmsXmlException { CmsXmlPage xmlPage = null; Document page = CmsXmlUtils.unmarshalHelper(content, null); Element xmltemplate = page.getRootElement(); if ((xmltemplate == null) || !"XMLTEMPLATE".equals(xmltemplate.getName())) { throw new CmsImportExportException(Messages.get().container(Messages.ERR_NOT_FOUND_ELEM_XMLTEMPLATE_0)); } // get all edittemplate nodes Iterator i = xmltemplate.elementIterator("edittemplate"); boolean useEditTemplates = true; if (!i.hasNext()) { // no edittemplate nodes found, get the template nodes i = xmltemplate.elementIterator("TEMPLATE"); useEditTemplates = false; } // now create the XML page xmlPage = new CmsXmlPage(locale, encoding); while (i.hasNext()) { Element currentTemplate = (Element) i.next(); String bodyName = currentTemplate.attributeValue("name"); if (CmsStringUtil.isEmpty(bodyName)) { // no template name found, use the parameter body name bodyName = "body"; } String bodyContent = null; if (useEditTemplates) { // no content manipulation needed for edittemplates bodyContent = currentTemplate.getText(); } else { // parse content for TEMPLATEs StringBuffer contentBuffer = new StringBuffer(); for (Iterator k = currentTemplate.nodeIterator(); k.hasNext();) { Node n = (Node) k.next(); if (n.getNodeType() == Node.CDATA_SECTION_NODE) { contentBuffer.append(n.getText()); continue; } else if (n.getNodeType() == Node.ELEMENT_NODE) { if ("LINK".equals(n.getName())) { contentBuffer.append(OpenCms.getSystemInfo().getOpenCmsContext()); contentBuffer.append(n.getText()); continue; } } } bodyContent = contentBuffer.toString(); } if (bodyContent == null) { throw new CmsImportExportException(Messages.get().container(Messages.ERR_BODY_CONTENT_NOT_FOUND_0)); } bodyContent = CmsStringUtil.substitute(bodyContent, CmsStringUtil.MACRO_OPENCMS_CONTEXT, OpenCms.getSystemInfo().getOpenCmsContext()); if (CmsStringUtil.isNotEmptyOrWhitespaceOnly(bodyContent)) { xmlPage.addValue(bodyName, locale); xmlPage.setStringValue(cms, bodyName, locale, bodyContent); } } return xmlPage; }
From source file:org.opencms.xml.content.CmsXmlContent.java
License:Open Source License
/** * Adds a new XML content value for the given element name and locale at the given index position * to this XML content document.<p> * /*from w w w. j av a2 s.c om*/ * @param cms the current users OpenCms context * @param path the path to the XML content value element * @param locale the locale where to add the new value * @param index the index where to add the value (relative to all other values of this type) * * @return the created XML content value * * @throws CmsIllegalArgumentException if the given path is invalid * @throws CmsRuntimeException if the element identified by the path already occurred {@link I_CmsXmlSchemaType#getMaxOccurs()} * or the given <code>index</code> is invalid (too high). */ public I_CmsXmlContentValue addValue(CmsObject cms, String path, Locale locale, int index) throws CmsIllegalArgumentException, CmsRuntimeException { // get the schema type of the requested path I_CmsXmlSchemaType type = m_contentDefinition.getSchemaType(path); if (type == null) { throw new CmsIllegalArgumentException( Messages.get().container(Messages.ERR_XMLCONTENT_UNKNOWN_ELEM_PATH_SCHEMA_1, path)); } Element parentElement; String elementName; CmsXmlContentDefinition contentDefinition; if (CmsXmlUtils.isDeepXpath(path)) { // this is a nested content definition, so the parent element must be in the bookmarks String parentPath = CmsXmlUtils.createXpath(CmsXmlUtils.removeLastXpathElement(path), 1); Object o = getBookmark(parentPath, locale); if (o == null) { throw new CmsIllegalArgumentException( Messages.get().container(Messages.ERR_XMLCONTENT_UNKNOWN_ELEM_PATH_1, path)); } CmsXmlNestedContentDefinition parentValue = (CmsXmlNestedContentDefinition) o; parentElement = parentValue.getElement(); elementName = CmsXmlUtils.getLastXpathElement(path); contentDefinition = parentValue.getNestedContentDefinition(); } else { // the parent element is the locale element parentElement = getLocaleNode(locale); elementName = CmsXmlUtils.removeXpathIndex(path); contentDefinition = m_contentDefinition; } // read the XML siblings from the parent node List<Element> siblings = CmsXmlGenericWrapper.elements(parentElement, elementName); int insertIndex; if (contentDefinition.getChoiceMaxOccurs() > 0) { // for a choice sequence we do not check the index position, we rather do a full XML validation afterwards insertIndex = index; } else if (siblings.size() > 0) { // we want to add an element to a sequence, and there are elements already of the same type if (siblings.size() >= type.getMaxOccurs()) { // must not allow adding an element if max occurs would be violated throw new CmsRuntimeException(Messages.get().container(Messages.ERR_XMLCONTENT_ELEM_MAXOCCURS_2, elementName, new Integer(type.getMaxOccurs()))); } if (index > siblings.size()) { // index position behind last element of the list throw new CmsRuntimeException( Messages.get().container(Messages.ERR_XMLCONTENT_ADD_ELEM_INVALID_IDX_3, new Integer(index), new Integer(siblings.size()))); } // check for offset required to append beyond last position int offset = (index == siblings.size()) ? 1 : 0; // get the element from the parent at the selected position Element sibling = siblings.get(index - offset); // check position of the node in the parent node content insertIndex = sibling.getParent().content().indexOf(sibling) + offset; } else { // we want to add an element to a sequence, but there are no elements of the same type yet if (index > 0) { // since the element does not occur, index must be 0 throw new CmsRuntimeException(Messages.get().container( Messages.ERR_XMLCONTENT_ADD_ELEM_INVALID_IDX_2, new Integer(index), elementName)); } // check where in the type sequence the type should appear int typeIndex = contentDefinition.getTypeSequence().indexOf(type); if (typeIndex == 0) { // this is the first type, so we just add at the very first position insertIndex = 0; } else { // create a list of all element names that should occur before the selected type List<String> previousTypeNames = new ArrayList<String>(); for (int i = 0; i < typeIndex; i++) { I_CmsXmlSchemaType t = contentDefinition.getTypeSequence().get(i); previousTypeNames.add(t.getName()); } // iterate all elements of the parent node Iterator<Node> i = CmsXmlGenericWrapper.content(parentElement).iterator(); int pos = 0; while (i.hasNext()) { Node node = i.next(); if (node instanceof Element) { if (!previousTypeNames.contains(node.getName())) { // the element name is NOT in the list of names that occurs before the selected type, // so it must be an element that occurs AFTER the type break; } } pos++; } insertIndex = pos; } } I_CmsXmlContentValue newValue; if (contentDefinition.getChoiceMaxOccurs() > 0) { // for a choice we do a full XML validation try { // append the new element at the calculated position newValue = addValue(cms, parentElement, type, locale, insertIndex); // validate the XML structure to see if the index position was valid CmsXmlUtils.validateXmlStructure(m_document, m_encoding, new CmsXmlEntityResolver(cms)); } catch (Exception e) { throw new CmsRuntimeException( Messages.get().container(Messages.ERR_XMLCONTENT_ADD_ELEM_INVALID_IDX_CHOICE_3, new Integer(insertIndex), elementName, parentElement.getUniquePath())); } } else { // just append the new element at the calculated position newValue = addValue(cms, parentElement, type, locale, insertIndex); } // re-initialize this XML content initDocument(m_document, m_encoding, m_contentDefinition); // return the value instance that was stored in the bookmarks // just returning "newValue" isn't enough since this instance is NOT stored in the bookmarks return getBookmark(getBookmarkName(newValue.getPath(), locale)); }
From source file:org.pdfsam.console.business.pdf.handlers.ConcatCmdExecutor.java
License:Open Source License
/** * Reads the input xml file and return a File[] of input files * /*from w w w . ja v a 2 s .c om*/ * @param inputFile * XML input file * @return PdfFile[] of files */ private PdfFile[] parseXmlFile(File inputFile) throws ConcatException { List fileList = new ArrayList(); String parentPath = null; try { LOG.debug("Parsing xml file " + inputFile.getAbsolutePath()); SAXReader reader = new SAXReader(); org.dom4j.Document document = reader.read(inputFile); List nodes = document.selectNodes("/filelist/*"); parentPath = inputFile.getParent(); for (Iterator iter = nodes.iterator(); iter.hasNext();) { Node domNode = (Node) iter.next(); String nodeName = domNode.getName(); if (FILESET_NODE.equals(nodeName)) { // found a fileset node fileList.addAll(getFileNodesFromFileset(domNode, parentPath)); } else if (FILE_NODE.equals(nodeName)) { fileList.add(getPdfFileFromNode(domNode, null)); } else { LOG.warn("Node type not supported: " + nodeName); } } } catch (Exception e) { throw new ConcatException(ConcatException.ERR_READING_CSV_OR_XML, new String[] { inputFile.getAbsolutePath() }, e); } return (PdfFile[]) fileList.toArray(new PdfFile[0]); }
From source file:org.pentaho.cdf.context.autoinclude.DashboardMatchRule.java
License:Open Source License
/** * // w ww . ja va 2s . c o m * @param cdaMatcher matcher for a cda file recognized by the cda regex * @param ruleNode <include> or <exclude> node */ public DashboardMatchRule(Matcher cdaMatcher, Node ruleNode) { this.mode = parseMode(ruleNode.getName()); this.regex = replaceTokens(cdaMatcher, ruleNode.getText()); }
From source file:org.pentaho.commons.connection.memory.MemoryResultSet.java
License:Open Source License
public static MemoryResultSet createFromActionSequenceInputsNode(Node rootNode) { List colHeaders = rootNode.selectNodes("columns/*"); //$NON-NLS-1$ Object[][] columnHeaders = new String[1][colHeaders.size()]; String[] columnTypes = new String[colHeaders.size()]; for (int i = 0; i < colHeaders.size(); i++) { Node theNode = (Node) colHeaders.get(i); columnHeaders[0][i] = theNode.getName(); columnTypes[i] = getNodeText("@type", theNode); //$NON-NLS-1$ }//from w w w. ja v a 2 s . c o m MemoryMetaData metaData = new MemoryMetaData(columnHeaders, null); metaData.setColumnTypes(columnTypes); MemoryResultSet result = new MemoryResultSet(metaData); List rowNodes = rootNode.selectNodes("default-value/row"); //$NON-NLS-1$ for (int r = 0; r < rowNodes.size(); r++) { Node theNode = (Node) rowNodes.get(r); Object[] theRow = new Object[columnHeaders[0].length]; for (int c = 0; c < columnHeaders[0].length; c++) { theRow[c] = getNodeText(columnHeaders[0][c].toString(), theNode); } result.addRow(theRow); } return result; }
From source file:org.pentaho.di.ui.trans.steps.getxmldata.GetXMLDataDialog.java
License:Open Source License
private void ChildNode(Node node, String realXPath, String realXPathCleaned) { Element ce = (Element) node; // List child for (int j = 0; j < ce.nodeCount(); j++) { Node cnode = ce.node(j); if (!Const.isEmpty(cnode.getName())) { Element cce = (Element) cnode; if (cce.nodeCount() > 1) { if (Const.getOccurenceString(cnode.asXML(), "/>") <= 1) { // We do not have child nodes ... setNodeField(cnode, realXPathCleaned); } else { // let's get child nodes ChildNode(cnode, realXPath, realXPathCleaned); }/* w ww .java 2 s . c om*/ } else { setNodeField(cnode, realXPathCleaned); } } } }