Java Code Examples for org.jdom2.xpath.XPathFactory#compile()
The following examples show how to use
org.jdom2.xpath.XPathFactory#compile() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MCRPIXPathMetadataService.java From mycore with GNU General Public License v3.0 | 6 votes |
@Override public Optional<MCRPersistentIdentifier> getIdentifier(MCRBase obj, String additional) throws MCRPersistentIdentifierException { String xpath = getProperties().get("Xpath"); Document xml = obj.createXML(); XPathFactory xpfac = XPathFactory.instance(); XPathExpression<Element> xp = xpfac .compile(xpath, Filters.element(), null, MCRConstants.getStandardNamespaces()); List<Element> evaluate = xp.evaluate(xml); if (evaluate.size() > 1) { throw new MCRPersistentIdentifierException( "Got " + evaluate.size() + " matches for " + obj.getId() + " with xpath " + xpath + ""); } if (evaluate.size() == 0) { return Optional.empty(); } Element identifierElement = evaluate.listIterator().next(); String identifierString = identifierElement.getTextNormalize(); Optional<MCRPersistentIdentifier> parsedIdentifierOptional = MCRPIManager.getInstance() .getParserForType(getProperties().get("Type")).parse(identifierString); return parsedIdentifierOptional.map(MCRPersistentIdentifier.class::cast); }
Example 2
Source File: MCRPIXPathMetadataService.java From mycore with GNU General Public License v3.0 | 5 votes |
@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); }
Example 3
Source File: XPathExtractor.java From web-data-extractor with Apache License 2.0 | 5 votes |
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; }
Example 4
Source File: JDomParser.java From tutorials with MIT License | 5 votes |
public Element getNodeById(String id) { try { SAXBuilder builder = new SAXBuilder(); Document document = (Document) builder.build(file); String filter = "//*[@tutId='" + id + "']"; XPathFactory xFactory = XPathFactory.instance(); XPathExpression<Element> expr = xFactory.compile(filter, Filters.element()); List<Element> node = expr.evaluate(document); return node.get(0); } catch (JDOMException | IOException e) { e.printStackTrace(); return null; } }
Example 5
Source File: MCRPIXPathPredicate.java From mycore with GNU General Public License v3.0 | 4 votes |
public MCRPIXPathPredicate(String propertyPrefix) { super(propertyPrefix); final String xPath = requireProperty("XPath"); XPathFactory factory = XPathFactory.instance(); expr = factory.compile(xPath, Filters.fpassthrough(), null, MCRConstants.getStandardNamespaces()); }
Example 6
Source File: HolidayEndpoint.java From spring-boot-samples with Apache License 2.0 | 4 votes |
@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); }