List of usage examples for org.dom4j XPath selectNodes
List<Node> selectNodes(Object context);
selectNodes
performs this XPath expression on the given Node or List of Node s instances appending all the results together into a single list. From source file:com.panet.imeta.trans.steps.getxmldata.GetXMLData.java
License:Open Source License
@SuppressWarnings("unchecked") private boolean applyXPath() { try {// w ww.j a v a 2s .c om XPath xpath = data.document.createXPath(data.PathValue); if (meta.isNamespaceAware()) { xpath = data.document.createXPath(addNSPrefix(data.PathValue, data.PathValue)); xpath.setNamespaceURIs(data.NAMESPACE); } // get nodes list data.an = (List<AbstractNode>) xpath.selectNodes(data.document); data.nodesize = data.an.size(); data.nodenr = 0; } catch (Exception e) { log.logError(toString(), Messages.getString("GetXMLData.Log.ErrorApplyXPath", e.getMessage())); return false; } return true; }
From source file:com.pureinfo.dolphinview.component.model.ViewComponent.java
License:Open Source License
/** * Set formatter: <resource-script-block(ScriptBlock)> <br> *///from www . java 2 s.c o m private Set getResources(Element _element) throws PureException { XPath elementPath = _element.createXPath(PATH_RESOURCE); List elementList = elementPath.selectNodes(_element); Set ids = new HashSet(); for (Iterator iter = elementList.iterator(); iter.hasNext();) { Element element = (Element) iter.next(); String sId = XMLUtil.getRequiredAttributeValue(element, ATTRIBUTE_ID); ScriptBlock sb = ScriptReader.readBlock(sId); ids.add(sb); } return ids; }
From source file:com.surenpi.autotest.suite.parser.XmlSuiteParser.java
License:Apache License
/** * ?page?//from w w w .j a v a 2 s. c o m * @param document * @param suite */ private void pagesParse(Document document, Suite suite) { List<SuitePage> pageList = new ArrayList<SuitePage>(); suite.setPageList(pageList); String pagePackage = suite.getPagePackage(); if (!StringUtils.isBlank(pagePackage)) { pagePackage = (pagePackage.trim() + "."); } XPath xpath = new DefaultXPath("/ns:suite/ns:page"); xpath.setNamespaceContext(simpleNamespaceContext); @SuppressWarnings("unchecked") List<Element> pageNodes = xpath.selectNodes(document); if (pageNodes == null || pageNodes.size() == 0) { throw new RuntimeException("Can not found page config."); } for (Element pageEle : pageNodes) { String pageCls = pageEle.attributeValue("class"); xpath = new DefaultXPath("ns:actions"); xpath.setNamespaceContext(simpleNamespaceContext); Element actionsEle = (Element) xpath.selectSingleNode(pageEle); if (actionsEle == null) { throw new RuntimeException("Can not found actions config."); } String disable = actionsEle.attributeValue("disable", "false"); if (Boolean.parseBoolean(disable)) { continue; } String beforeSleep = actionsEle.attributeValue("beforeSleep", "0"); String afterSleep = actionsEle.attributeValue("afterSleep", "0"); String repeat = actionsEle.attributeValue("repeat", "1"); List<SuiteAction> actionList = new ArrayList<SuiteAction>(); SuitePage suitePage = new SuitePage(String.format("%s%s", pagePackage, pageCls)); suitePage.setActionList(actionList); suitePage.setRepeat(Integer.parseInt(repeat)); pageList.add(suitePage); parse(actionList, actionsEle, beforeSleep, afterSleep); } }
From source file:com.webtide.jetty.load.generator.jenkins.AlpnBootVersions.java
License:Open Source License
private AlpnBootVersions() { Map<String, String> map = new HashMap<>(); try {/*from w w w . j av a 2 s .c o m*/ try (InputStream inputStream = this.getClass().getResourceAsStream("/jetty/jetty-project.pom")) { SAXReader reader = new SAXReader(); Document document = reader.read(inputStream); Map<String, String> namespaceMap = new HashMap<>(); namespaceMap.put("mvn", "http://maven.apache.org/POM/4.0.0"); XPath xpath = document.createXPath("//mvn:profiles/mvn:profile"); xpath.setNamespaceURIs(namespaceMap); List<DefaultElement> nodes = xpath.selectNodes(document); for (DefaultElement o : nodes) { if (StringUtils.startsWith((String) o.element("id").getData(), "8u")) { // olamy well a bit fragile way to parse if more than one property... //"//mvn:properties/mvn:alpn.version" // o.selectSingleNode( "//properties/alpn.version" ); Node version = o.element("properties").element("alpn.version"); //"//mvn:activation/mvn:property/mvn:value" //o.selectSingleNode( "//activation/property/value" ); Node javaVersion = o.element("activation").element("property").element("value"); map.put(javaVersion.getStringValue(), version.getStringValue()); } } } } catch (Exception e) { throw new RuntimeException(e.getMessage(), e); } jdkVersionAlpnBootVersion = Collections.unmodifiableMap(map); }
From source file:cz.fi.muni.xkremser.editor.server.newObject.MonographBuilder.java
License:Open Source License
private void updateDcDoc(Document dcDoc, String pid, String signature, String sysno, DigitalObjectModel model) { Element dcRootEl = dcDoc.getRootElement(); Attribute schemaLoc = dcRootEl.attribute("schemaLocation"); dcRootEl.remove(schemaLoc);//from w w w. j av a 2 s.co m Namespace xsi = DocumentHelper.createNamespace("xsi2", FedoraNamespaces.SCHEMA_NAMESPACE_URI); dcRootEl.add(xsi); dcRootEl.addAttribute(new QName("schemaLocation", xsi), "http://www.openarchives.org/OAI/2.0/oai_dc/ http://www.openarchives.org/OAI/2.0/oai_dc.xsd"); XPath typeXpath = Dom4jUtils.createXPath("/oai_dc:dc/dc:identifier"); List<? extends Node> nodes = typeXpath.selectNodes(dcDoc); for (Node node : nodes) { node.detach(); } Element idUuid = dcRootEl.addElement("dc:identifier"); idUuid.addText(pid); for (Node node : nodes) { if (node.getText() != null && !"".equals(node.getText().trim()) && !node.getText().contains(Constants.FEDORA_UUID_PREFIX)) { Element temp = dcRootEl.addElement("dc:identifier"); temp.addText(node.getText()); } } if (signature != null) { Element idSignature = dcRootEl.addElement("dc:identifier"); idSignature.addText("signature:" + signature); } if (sysno != null) { Element idSysno = dcRootEl.addElement("dc:identifier"); idSysno.addText("sysno:" + sysno); } removeDcTypeElements(dcDoc); Element typeEl = dcRootEl.addElement("dc:type"); typeEl.addText("model:" + model.toString()); Element rightsEl = dcRootEl.addElement("dc:rights"); rightsEl.addText("policy:" + Policy.PUBLIC.toString().toLowerCase()); updateDcLanguages(dcDoc); }
From source file:cz.fi.muni.xkremser.editor.server.newObject.MonographBuilder.java
License:Open Source License
private void removeDcTypeElements(Document doc) { XPath typeXpath = Dom4jUtils.createXPath("/oai_dc:dc/dc:type"); List<? extends Node> nodes = typeXpath.selectNodes(doc); for (Node node : nodes) { node.detach();/*from www. j a v a 2s .co m*/ } }
From source file:cz.fi.muni.xkremser.editor.server.newObject.MonographBuilder.java
License:Open Source License
private void updateLanguages(Document doc, XPath xpath) { List<? extends Node> nodes = xpath.selectNodes(doc); for (Node languageNode : nodes) { Element languageEl = (Element) languageNode; String originalLang = languageEl.getTextTrim(); languageEl.clearContent();//from ww w. j a v a 2 s . c om languageEl.addText(transformLanguage(originalLang)); } }
From source file:cz.fi.muni.xkremser.editor.server.newObject.PeriodicalBuilder.java
License:Open Source License
private void updateDcDoc(Document dcDoc, String pid, String signature, String sysno, DigitalObjectModel model) { Element dcRootEl = dcDoc.getRootElement(); Attribute schemaLoc = dcRootEl.attribute("schemaLocation"); dcRootEl.remove(schemaLoc);/*from www . j a v a2 s .c om*/ Namespace xsi = DocumentHelper.createNamespace("xsi2", FedoraNamespaces.SCHEMA_NAMESPACE_URI); dcRootEl.add(xsi); dcRootEl.addAttribute(new QName("schemaLocation", xsi), "http://www.openarchives.org/OAI/2.0/oai_dc/ http://www.openarchives.org/OAI/2.0/oai_dc.xsd"); XPath typeXpath = Dom4jUtils.createXPath("/oai_dc:dc/dc:identifier"); List<? extends Node> nodes = typeXpath.selectNodes(dcDoc); for (Node node : nodes) { node.detach(); } Element idUuid = dcRootEl.addElement("dc:identifier"); idUuid.addText(pid); for (Node node : nodes) { if (node.getText() != null && !"".equals(node.getText().trim()) && !node.getText().contains(Constants.FEDORA_UUID_PREFIX)) { Element temp = dcRootEl.addElement("dc:identifier"); temp.addText(node.getText()); } } if (signature != null) { Element idSignature = dcRootEl.addElement("dc:identifier"); idSignature.addText("signature:" + signature); } if (sysno != null) { Element idSysno = dcRootEl.addElement("dc:identifier"); idSysno.addText("sysno:" + sysno); } removeDcTypeElements(dcDoc); Element typeEl = dcRootEl.addElement("dc:type"); typeEl.addText("model:" + model.getValue()); Element rightsEl = dcRootEl.addElement("dc:rights"); rightsEl.addText("policy:" + Policy.PUBLIC.toString().toLowerCase()); updateDcLanguages(dcDoc); }
From source file:cz.mzk.editor.server.newObject.MonographBuilder.java
License:Open Source License
@SuppressWarnings("unchecked") private void updateDcDoc(Document dcDoc, String pid, String signature, String sysno, DigitalObjectModel model) { Element dcRootEl = dcDoc.getRootElement(); Attribute schemaLoc = dcRootEl.attribute("schemaLocation"); dcRootEl.remove(schemaLoc);// w w w.j av a 2 s . c o m Namespace xsi = DocumentHelper.createNamespace("xsi2", FedoraNamespaces.SCHEMA_NAMESPACE_URI); dcRootEl.add(xsi); dcRootEl.addAttribute(new QName("schemaLocation", xsi), "http://www.openarchives.org/OAI/2.0/oai_dc/ http://www.openarchives.org/OAI/2.0/oai_dc.xsd"); XPath typeXpath = Dom4jUtils.createXPath("/oai_dc:dc/dc:identifier"); List<? extends Node> nodes = typeXpath.selectNodes(dcDoc); for (Node node : nodes) { node.detach(); } Element idUuid = dcRootEl.addElement("dc:identifier"); idUuid.addText(pid); for (Node node : nodes) { if (node.getText() != null && !"".equals(node.getText().trim()) && !node.getText().contains(Constants.FEDORA_UUID_PREFIX)) { Element temp = dcRootEl.addElement("dc:identifier"); temp.addText(node.getText()); } } if (signature != null) { Element idSignature = dcRootEl.addElement("dc:identifier"); idSignature.addText("signature:" + signature); } if (sysno != null) { Element idSysno = dcRootEl.addElement("dc:identifier"); idSysno.addText("sysno:" + sysno); } removeDcTypeElements(dcDoc); Element typeEl = dcRootEl.addElement("dc:type"); typeEl.addText("model:" + model.getValue()); Element rightsEl = dcRootEl.addElement("dc:rights"); rightsEl.addText("policy:" + getPolicy().toString().toLowerCase()); updateDcLanguages(dcDoc); }
From source file:cz.mzk.editor.server.newObject.MonographBuilder.java
License:Open Source License
@SuppressWarnings("unchecked") private void removeDcTypeElements(Document doc) { XPath typeXpath = Dom4jUtils.createXPath("/oai_dc:dc/dc:type"); List<? extends Node> nodes = typeXpath.selectNodes(doc); for (Node node : nodes) { node.detach();//from w w w . j av a 2 s . com } }