public void validate(Element element, ConfigElementImplementationRegistry registry) throws Exception { XPathFactory xPathFactory = XPathFactory.instance(); List<String> tasks = ConfigUtil.allTasks(registry); for (String task : tasks) { List<Element> taskNodes = xPathFactory.compile("//" + task, Filters.element()).evaluate(element); for (Element taskNode : taskNodes) { List<Element> list = xPathFactory.compile("oncancel", Filters.element()).evaluate(taskNode); if (list.size() > 1) { throw new Exception("Task [" + task + "] should not contain more than 1 oncancel task"); } } } } }
/** * Create a XPathExpression<Object> instance from this factory. * * @param expression * The XPath expression. * @return an XPathExpression<Object> instance. * @throws NullPointerException * if the query or filter is null * @throws IllegalArgumentException * if there is any reason that the XPath query cannot be compiled. */ public XPathExpression<Object> compile(String expression) { return compile(expression, Filters.fpassthrough(), null, EMPTYNS); }
/** * update the disks in the domain XML. It is assumed that the the size of the volumes is the same as the number of * disk elements and that the order is the same. */ public static void updateDisks(Document domainXml, List<StorageVol> volumes) throws LibvirtException { XPathFactory xpf = XPathFactory.instance(); XPathExpression<Element> diskExpr = xpf.compile(XPATH_DISK, Filters.element()); XPathExpression<Attribute> fileExpr = xpf.compile(XPATH_DISK_FILE, Filters.attribute()); List<Element> disks = diskExpr.evaluate(domainXml); Iterator<StorageVol> cloneDiskIter = volumes.iterator(); for (Element disk : disks) { Attribute file = fileExpr.evaluateFirst(disk); StorageVol cloneDisk = cloneDiskIter.next(); file.setValue(cloneDisk.getPath()); } }
@Autowired public HolidayEndpoint(HumanResourceService humanResourceService){ this.humanResourceService = humanResourceService; Namespace namespace = Namespace.getNamespace("hr", NAMESPACE_URI); XPathFactory xPathFactory = XPathFactory.instance(); startDateExpression =xPathFactory.compile("//hr:StartDate", Filters.element(), null,namespace); endDateExpression = xPathFactory.compile("//hr:EndDate", Filters.element(), null,namespace); nameExpression = xPathFactory.compile( "concat(//hr:FirstName,' ',//hr:LastName)", Filters.fstring(), null,namespace); }
pnt.getContent(Filters.text()); // CDATA return getPositionPath(content, sibs, "text()", buffer); pnt.getContent(Filters.comment()); return getPositionPath(content, sibs, "comment()", buffer); pnt.getContent(Filters.processinginstruction()); return getPositionPath(content, sibs, "processing-instruction()", buffer);
/** * Select all attributes matching a given expression within the given object. * * @param root * The object from which the expression is to begin its application. * @param expression * The XPath expression to be evaluated. * @return A {@link List} of {@link Attribute} objects representing all XML element attributes that match the * given XPath expression. * @throws JDOMException * If any errors occur during the analysis. */ private List<Attribute> selectAttributeInternal(final Object root, final String expression) throws JDOMException { return XPathFactory.instance().compile(expression, Filters.attribute()).evaluate(root); }
public Optional<String> extractText(Document d, String xpath) { XPathExpression<Text> expression = XPathFactory.instance().compile( xpath, Filters.text()); return getText(expression.evaluate(d)); }
public static void removeChangeTracking(Element element) { for (Iterator<ProcessingInstruction> iter = element.getDescendants(Filters.processinginstruction()) .iterator(); iter.hasNext();) { if (iter.next().getTarget().startsWith(PREFIX)) { iter.remove(); } } }
/** Get the disks connected to the domain. */ public static List<Disk> getDisks(Connect connect, Document domainXml) { try { List<Disk> ret = new ArrayList<>(); XPathFactory xpf = XPathFactory.instance(); XPathExpression<Element> diskExpr = xpf.compile(XPATH_DISK, Filters.element()); XPathExpression<Attribute> typeExpr = xpf.compile(XPATH_DISK_TYPE, Filters.attribute()); XPathExpression<Attribute> fileExpr = xpf.compile(XPATH_DISK_FILE, Filters.attribute()); XPathExpression<Attribute> devExpr = xpf.compile(XPATH_DISK_DEV, Filters.attribute()); List<Element> disks = diskExpr.evaluate(domainXml); for (Element disk : disks) { Attribute type = typeExpr.evaluateFirst(disk); Attribute file = fileExpr.evaluateFirst(disk); Attribute dev = devExpr.evaluateFirst(disk); StorageVol volume = LibvirtUtil.findVolume(connect, file.getValue()); ret.add(new Disk(dev.getValue(), file.getValue(), volume, type.getValue())); } return ret; } catch (LibvirtException e) { throw new LibvirtRuntimeException(e); } }
private void filterLang(org.jdom2.Document j2Doc) { XPathFactory xpfac = XPathFactory.instance(); XPathExpression<Attribute> xp = xpfac.compile("//*/@lang", Filters.attribute()); for (Attribute att : xp.evaluate(j2Doc)) { if(!att.getValue().equals(lang)) { att.getParent().detach(); } } }
public MCRJDOMContent transform(MCRContent source) throws IOException { try { Element root = source.asXML().getRootElement().clone(); for (Text text : root.getDescendants(Filters.text())) { text.setText(MCRXMLFunctions.normalizeUnicode(text.getText())); } return new MCRJDOMContent(root); } catch (JDOMException | SAXException ex) { throw new IOException(ex); } } }
public MCRChangeData findLastChange(Document doc) { String typePrefix = PREFIX + counter + "-"; for (ProcessingInstruction instruction : doc.getDescendants(Filters.processinginstruction())) { String target = instruction.getTarget(); if (target.startsWith(typePrefix)) { return new MCRChangeData(instruction, typePrefix); } } throw new MCRException("Lost processing instruction for undo, not found: " + typePrefix); }
XPathFactory xPathFactory = XPathFactory.instance(); for (String attributeName : encryptedAttributes) { XPathExpression<Element> xpathExpression = xPathFactory.compile(String.format("//*[@%s]", attributeName), Filters.element()); List<Element> encryptedPasswordElements = xpathExpression.evaluate(document); for (Element element : encryptedPasswordElements) { XPathExpression<Element> xpathExpression = xPathFactory.compile(String.format("//%s", nodeName), Filters.element()); List<Element> encryptedNode = xpathExpression.evaluate(document); for (Element element : encryptedNode) {
private XPathExpression createXpathExpression() { XPathFactory xpfac = XPathFactory.instance(); XPathExpression xp = null; if (namespaces.isEmpty()) { xp = xpfac.compile(xpath, Filters.fpassthrough()); } else { xp = xpfac.compile(xpath, Filters.fpassthrough(), new LinkedHashMap<String, Object>(), namespaces.toArray(new Namespace[namespaces.size()])); } return xp; }
private void filterLang(org.jdom2.Document j2Doc) { XPathFactory xpfac = XPathFactory.instance(); XPathExpression<Attribute> xp = xpfac.compile("//*/@classifier", Filters.attribute()); for (Attribute att : xp.evaluate(j2Doc)) { boolean remove = true; for(String classifier : classifiers) { if(att.getValue().equals(classifier)) { remove = false; } } if(remove){att.getParent().detach();} } } }
protected XPathExpression<Element> build() { // Namespace ns = Namespace.getNamespace("ofx", "http://www.openfuxml.org"); XPathExpression<Element> xpe= xpFactory.compile("//*[@include]", Filters.element()); return xpe; }
protected XPathValueMapper(String xpath, Map<String,String> namespaces) { this.xpath = xpath; Set<Namespace> xnamespaces = new HashSet<Namespace>(); if(namespaces != null) { for(Map.Entry<String,String> ns : namespaces.entrySet()) { xnamespaces.add(Namespace.getNamespace(ns.getKey(), ns.getValue())); } } this.compiled = XPathFactory.instance().compile(xpath, Filters.fpassthrough(),null,xnamespaces); }
XPathExpression<Attribute> hintPath = XPathFactory.instance().compile("password/@hint", Filters.attribute()); Attribute hintAttr = hintPath.evaluateFirst(u); String hint = hintAttr == null ? null : hintAttr.getValue();
private static List<String> getOrcidsFromDocument(Document document) { XPathExpression<Element> orchidXpath = XPathFactory.instance() .compile(SEARCH_ORCID_XPATH, Filters.element(), null, ORCID_SEARCH_NAMESPACE, ORCID_COMMON_NAMESPACE); return orchidXpath .evaluate(document) .stream() .map(Element::getTextTrim) .collect(Collectors.toList()); }
protected XPathValueMapper(String xpath, Map<String,String> namespaces) { this.xpath = xpath; Set<Namespace> xnamespaces = new HashSet<Namespace>(); if(namespaces != null) { for(Map.Entry<String,String> ns : namespaces.entrySet()) { xnamespaces.add(Namespace.getNamespace(ns.getKey(), ns.getValue())); } } this.compiled = XPathFactory.instance().compile(xpath, Filters.fpassthrough(),null,xnamespaces); }