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"); } } } } }
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) {
protected XPathExpression<Element> build() { // Namespace ns = Namespace.getNamespace("ofx", "http://www.openfuxml.org"); XPathExpression<Element> xpe= xpFactory.compile("//*[@include]", Filters.element()); return xpe; }
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()); }
private XPathExpression<Element> buildXPath(String xPath) throws JDOMException { return XPathFactory.instance().compile(xPath, Filters.element(), null, MCRConstants.MODS_NAMESPACE, MCRConstants.XLINK_NAMESPACE); }
protected List<Element> evaluateForElements(String xpath) { XPathFactory f = XPathFactory.instance(); XPathExpression<Element> expr = f.compile(xpath, Filters.element(), new HashMap<String, Object>(), namespaces); return expr.evaluate(internalDoc); }
@Override public Stream<String> resolve(MCRDNBURN identifier) throws MCRIdentifierUnresolvableException { Document pidefDocument = MCRDNBPIDefProvider.get(identifier); XPathExpression<Element> compile = XPathFactory.instance().compile( ".//pidef:resolving_information/pidef:url_info/pidef:url", Filters.element(), null, MCRConstants.PIDEF_NAMESPACE); return compile.evaluate(pidefDocument).stream().map(Element::getTextTrim); }
@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); }
@Override public void removeIdentifier(MCRPersistentIdentifier identifier, MCRBase obj, String additional) { String xpath = getProperties().get("Xpath"); Document xml = obj.createXML(); XPathFactory xPathFactory = XPathFactory.instance(); XPathExpression<Element> xp = xPathFactory.compile(xpath, Filters.element()); List<Element> elements = xp.evaluate(xml); elements.stream() .filter(element -> element.getTextTrim().equals(identifier.asString())) .forEach(Element::detach); }
MCRIdentifierType(String typeID, String xPath) { this.typeID = typeID; this.xPath = xPath; this.xPathExpr = XPathFactory.instance().compile(xPath, Filters.element(), null, MCRConstants.getStandardNamespaces()); }
/** * Helper method to lookup child elements by XPath. * * @param xPath XPath expression relative to the element wrapped by this merger. * @return a list of elements matching the given XPath */ protected List<Element> getNodes(String xPath) { XPathExpression<Element> xPathExpr = XPathFactory.instance().compile(xPath, Filters.element(), null, NS); return xPathExpr.evaluate(element); } }
public static Date getDNBRegisterDate(String identifier) throws MCRIdentifierUnresolvableException, ParseException { Document document = MCRDNBPIDefProvider.get(identifier); XPathExpression<Element> xp = XPathFactory.instance().compile( ".//pidef:created[contains(../pidef:identifier, '" + identifier + "')]", Filters.element(), null, MCRConstants.PIDEF_NAMESPACE); Element element = xp.evaluateFirst(document); if (element == null) { return null; } return new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSXXX", Locale.GERMAN).parse(element.getText()); }
public static Document setDomainName(Document domainXml, String name) { XPathFactory xpf = XPathFactory.instance(); XPathExpression<Element> nameExpr = xpf.compile("/domain/name", Filters.element()); Element nameElement = nameExpr.evaluateFirst(domainXml); nameElement.setText(name); return domainXml; }
private static Element getHostGenre(Element mods) { XPathExpression<Element> expr = XPathFactory.instance().compile("mods:relatedItem[@type='host']/mods:genre", Filters.element(), null, MCRConstants.getStandardNamespaces()); return expr.evaluateFirst(mods); } }
Element getRelatedItemIfExists(Element parent) { XPathExpression<Element> xPath = XPathFactory.instance().compile(xPathOfRelatedItem, Filters.element(), null, MCRConstants.getStandardNamespaces()); Element fixedParent = xPath.evaluateFirst(parent); return fixedParent != null ? fixedParent : parent; } }
public static Info getReportInfo(Document jdomDocument) { XPathExpression<Element> xpath = XPathFactory.instance().compile("/report/info", Filters.element()); Element eInfo = xpath.evaluateFirst(jdomDocument); eInfo = JDomUtil.setNameSpaceRecursive(eInfo, AhtUtilsNsPrefixMapper.nsReport); Info info = JDomUtil.toJaxb(eInfo, Info.class); return info; } }
public static void removeFilesystemsWithTarget(Document domainXml, String targetDir) { XPathFactory xpf = XPathFactory.instance(); XPathExpression<Element> fsExpr = xpf.compile(String.format("/domain/devices/filesystem[@type='mount']/target[@dir='%s']", targetDir), Filters.element()); List<Element> tfs = fsExpr.evaluate(domainXml); for (Element e : tfs) { e.getParentElement().getParentElement().removeContent(e.getParentElement()); } }
MCREnricher(String configID) { xPath2FindNestedObjects = XPathFactory.instance().compile(XPATH_HOST_SERIES, Filters.element(), null, MCRConstants.getStandardNamespaces()); dsConfig = MCRConfiguration.instance().getString("MCR.MODS.EnrichmentResolver.DataSources." + configID); idPool = new MCRIdentifierPool(); prepareDataSourceCalls(dsConfig); }
/** remove elements that need to be unique per clone. */ public static Document prepareForCloning(Document domainXml) { XPathFactory xpf = XPathFactory.instance(); // remove uuid so it will be generated domainXml.getRootElement().removeChild("uuid"); // remove mac address, so it will be generated XPathExpression<Element> macExpr = xpf.compile("/domain/devices/interface/mac", Filters.element()); for (Element mac : macExpr.evaluate(domainXml)) { mac.getParentElement().removeChild("mac"); } return domainXml; } }
private void changeToTestDOI(Document metadata) { XPathExpression<Element> compile = XPathFactory.instance().compile( "//datacite:identifier[@identifierType='DOI']", Filters.element(), null, Namespace.getNamespace("datacite", metadata.getRootElement().getNamespace().getURI())); Element element = compile.evaluateFirst(metadata); MCRDigitalObjectIdentifier doi = new MCRDOIParser() .parse(element.getText()) .orElseThrow(() -> new MCRException("Datacite Document contains invalid DOI!")); String testDOI = doi.toTestPrefix().asString(); element.setText(testDOI); }