List of usage examples for org.dom4j DocumentHelper createXPath
public static XPath createXPath(String xpathExpression) throws InvalidXPathException
createXPath
parses an XPath expression and creates a new XPath XPath
instance using the singleton DocumentFactory .
From source file:net.form105.rm.server.ant.container.InboundConfiguration.java
License:Apache License
public void readXml(Node xmlNode) { List<Node> nodes; XPath xPath;//from w w w . j a va2s . c om inboundType = xmlNode.valueOf("@type"); xPath = DocumentHelper.createXPath("//inbound/parameters/parameter"); nodes = (List<Node>) xPath.selectNodes(xmlNode); for (Node node : nodes) { logger.info(node); paramMap.addParameter(new ConfigParameter(node.valueOf("@key"), node.valueOf("@value"))); } xPath = DocumentHelper.createXPath("//inbound/validators/validator"); nodes = (List<Node>) xPath.selectNodes(xmlNode); for (Node node : nodes) { IInboundValidator validator = (IInboundValidator) Agent.getComponentById(node.getText()); validatorList.add(validator); } xPath = DocumentHelper.createXPath("//inbound/listeners/listener"); nodes = (List<Node>) xPath.selectNodes(xmlNode); for (Node node : nodes) { IInboundListener inboundListener = (IInboundListener) Agent.getComponentById(node.getText()); listenerList.add(inboundListener); } xPath = DocumentHelper.createXPath("//inbound/executor"); logger.info(xPath.selectSingleNode(xmlNode).getText()); command = (AbstractCallbackCommand) Agent.getComponentById(xPath.selectSingleNode(xmlNode).getText()); }
From source file:net.nikr.eve.jeveasset.io.local.update.Update.java
License:Open Source License
void setVersion(final File xml, final int newVersion) throws DocumentException { SAXReader xmlReader = new SAXReader(); Document doc = xmlReader.read(xml); XPath xpathSelector = DocumentHelper.createXPath("/settings"); List<?> results = xpathSelector.selectNodes(doc); for (Iterator<?> iter = results.iterator(); iter.hasNext();) { Element element = (Element) iter.next(); Attribute attr = element.attribute("version"); if (attr == null) { element.add(new DefaultAttribute("version", String.valueOf(newVersion))); } else {/*from w w w .j a v a 2 s .c o m*/ attr.setText(String.valueOf(newVersion)); } } try { FileOutputStream fos = new FileOutputStream(xml); OutputFormat outformat = OutputFormat.createPrettyPrint(); outformat.setEncoding("UTF-16"); XMLWriter writer = new XMLWriter(fos, outformat); writer.write(doc); writer.flush(); } catch (IOException ioe) { LOG.error("Failed to update the serttings.xml version number", ioe); throw new RuntimeException(ioe); } }
From source file:net.nikr.eve.jeveasset.io.local.update.updates.Update1To2.java
License:Open Source License
private void convertModes(final Document doc) { XPath xpathSelector = DocumentHelper.createXPath("/settings/filters/filter/row"); List<?> results = xpathSelector.selectNodes(doc); for (Iterator<?> iter = results.iterator(); iter.hasNext();) { Element elem = (Element) iter.next(); Attribute attr = elem.attribute("mode"); String currentValue = attr.getText(); attr.setText(convertMode(currentValue)); }/*w w w.ja v a 2 s .com*/ }
From source file:net.nikr.eve.jeveasset.io.local.update.updates.Update1To2.java
License:Open Source License
private void convertDefaultPriceModes(final Document doc) { XPath xpathSelector = DocumentHelper.createXPath("/settings/marketstat"); List<?> results = xpathSelector.selectNodes(doc); for (Iterator<?> iter = results.iterator(); iter.hasNext();) { Element elem = (Element) iter.next(); Attribute attr = elem.attribute("defaultprice"); if (attr != null) { //May not exist (in early versions) String currentValue = attr.getText(); attr.setText(convertDefaultPriceMode(currentValue)); }//from www . j av a 2 s .c o m } }
From source file:net.nikr.eve.jeveasset.io.local.update.updates.Update1To2.java
License:Open Source License
private void convertTableSettings(final Document doc) { XPath xpathSelector = DocumentHelper.createXPath("/settings/columns/column"); List<?> results = xpathSelector.selectNodes(doc); List<String> tableColumnNames = new ArrayList<String>(); List<String> tableColumnVisible = new ArrayList<String>(); for (Iterator<?> iter = results.iterator(); iter.hasNext();) { Element element = (Element) iter.next(); Attribute name = element.attribute("name"); Attribute visible = element.attribute("visible"); tableColumnNames.add(name.getText()); if (visible.getText().equals("true")) { tableColumnVisible.add(name.getText()); }/*w w w . j a v a 2s .co m*/ } String mode = convertFlag(doc); writeTableSettings(doc, mode, tableColumnNames, tableColumnVisible); }
From source file:net.nikr.eve.jeveasset.io.local.update.updates.Update1To2.java
License:Open Source License
private String convertFlag(final Document doc) { XPath flagSelector = DocumentHelper.createXPath("/settings/flags/flag"); List<?> flagResults = flagSelector.selectNodes(doc); boolean text = false; boolean window = false; for (Iterator<?> iter = flagResults.iterator(); iter.hasNext();) { Element element = (Element) iter.next(); Attribute key = element.attribute("key"); Attribute visible = element.attribute("enabled"); if (key.getText().equals("FLAG_AUTO_RESIZE_COLUMNS_TEXT")) { text = visible.getText().equals("true"); element.detach();/*from w w w .j a va2 s .co m*/ } if (key.getText().equals("FLAG_AUTO_RESIZE_COLUMNS_WINDOW")) { window = visible.getText().equals("true"); element.detach(); } } if (text) { return "TEXT"; } if (window) { return "WINDOW"; } return "NONE"; }
From source file:net.sf.jguard.ext.authentication.manager.XmlAuthenticationManager.java
License:Open Source License
private Element getElement(String xpath) { XPath xp2 = DocumentHelper.createXPath(xpath); Map<String, String> uris = new HashMap<String, String>(); uris.put(STRING_NAMESPACE_PREFIX, HTTP_JGUARD_SOURCEFORGE_NET_XSD_J_GUARD_USERS_PRINCIPALS_2_0_0_XSD); xp2.setNamespaceURIs(uris);//www. j a v a2s . c om return (Element) xp2.selectSingleNode(root); }
From source file:net.sf.jguard.ext.authorization.manager.XmlAuthorizationManager.java
License:Open Source License
private Element getElement(String xpath) { XPath xp2 = DocumentHelper.createXPath(xpath); Map<String, String> uris = new HashMap<String, String>(); uris.put(STRING_NAMESPACE_PREFIX, HTTP_JGUARD_SOURCEFORGE_NET_XSD_J_GUARD_PRINCIPALS_PERMISSIONS_2_0_0); xp2.setNamespaceURIs(uris);//w w w . j av a2 s .c o m return (Element) xp2.selectSingleNode(root); }
From source file:net.sf.jguard.ext.authorization.manager.XmlAuthorizationManager.java
License:Open Source License
private List getElements(String xpath) { XPath xp2 = DocumentHelper.createXPath(xpath); Map<String, String> uris = new HashMap<String, String>(); uris.put(STRING_NAMESPACE_PREFIX, HTTP_JGUARD_SOURCEFORGE_NET_XSD_J_GUARD_PRINCIPALS_PERMISSIONS_2_0_0); xp2.setNamespaceURIs(uris);// w w w. j ava 2s .c om return xp2.selectNodes(root); }
From source file:org.alfresco.web.bean.wcm.FilePickerBean.java
License:Open Source License
/** * Run a configured search represented by the given node reference, against * the web project the XForm is currently within * //from w w w.ja va2s . c o m * @param configuredQueryNodRef * NodeRef of the configured query with which to run the search * * @return content nodes returned by the search */ private List<AVMNodeDescriptor> runConfiguredSearch(NodeRef configSearchNodeRef) { // get the store id used to run the configured search query WebProject webProject = this.getAvmBrowseBean().getWebProject(); String storeID = webProject.getStoreId(); // extract the content of configured search node to XML document ContentReader contentReader = getContentService().getReader(configSearchNodeRef, ContentModel.PROP_CONTENT); InputStream queryInpStream = contentReader.getContentInputStream(); SAXReader reader = new SAXReader(); Document queryDoc = null; try { queryDoc = reader.read(queryInpStream); } catch (DocumentException de) { // ignore exception and return null return null; } // extract search query from configured search XML document String query = null; XPath queryXPath = DocumentHelper.createXPath(CONFIGURED_SEARCH_QUERY_XPATH); List xpathResult = queryXPath.selectNodes(queryDoc); if ((xpathResult != null) && (xpathResult.size() != 0)) { // get the text from the query element Element queryElement = (Element) xpathResult.get(0); String queryElemText = queryElement.getText(); // now extract the actual search query string from the CDATA section // within that text int cdataStartDelimIndex = queryElemText.indexOf(CDATA_START_DELIM); int cdataEndDelimIndex = queryElemText.indexOf(CDATA_END_DELIM); // if the CDATA start delimiter is found in the query element text // && there is text between the CDATA start and end delimiters then // extract // the query string from the CDATA section if ((cdataStartDelimIndex > -1) && ((cdataStartDelimIndex + CDATA_START_DELIM.length()) < cdataEndDelimIndex)) { query = queryElemText.substring(cdataStartDelimIndex + CDATA_START_DELIM.length(), cdataEndDelimIndex); } else { // otherwise just use the text as is query = queryElemText; } } // perform the search against the repository // if query was extracted from the configured search successfully // (extracted query non-null) List<AVMNodeDescriptor> resultNodeDescriptors = null; if ((query != null) && (query.length() != 0)) { ResultSet results = null; try { results = this.getSearchService().query(new StoreRef(StoreRef.PROTOCOL_AVM, storeID), SearchService.LANGUAGE_LUCENE, query); if (results.length() != 0) { resultNodeDescriptors = new ArrayList<AVMNodeDescriptor>(); for (int i = 0; i < results.length(); i++) { ResultSetRow row = results.getRow(i); NodeRef resultNodeRef = row.getNodeRef(); Node resultNode = new Node(resultNodeRef); // only add content type nodes to the search result // as we don't want the user to navigate down into folders // in the search results if (getDictionaryService().isSubClass(resultNode.getType(), ContentModel.TYPE_CONTENT)) { Pair<Integer, String> pair = AVMNodeConverter.ToAVMVersionPath(resultNodeRef); Integer version = pair.getFirst(); String path = pair.getSecond(); resultNodeDescriptors.add(getAvmService().lookup(version, path)); } } } } catch (Throwable err) { throw new AlfrescoRuntimeException("Failed to execute search: " + query, err); } finally { if (results != null) { results.close(); } } } return resultNodeDescriptors; }