/** * 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); }
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; }
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); }
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); }
protected XPathValueMapper(String xpath, Collection<Namespace> namespaces) { this.xpath = xpath; this.compiled = XPathFactory.instance().compile(xpath, Filters.fpassthrough(),null,namespaces); }
protected XPathValueMapper(String xpath, Collection<Namespace> namespaces) { this.xpath = xpath; this.compiled = XPathFactory.instance().compile(xpath, Filters.fpassthrough(),null,namespaces); }
MCRCleaningRule(String xPathExprNodesToInspect, String xPathExprRelevancyTest) { this.xPathExprNodesToInspect = xPathExprNodesToInspect; this.xPathNodesToInspect = XPathFactory.instance().compile(xPathExprNodesToInspect, Filters.fpassthrough(), null, MCRConstants.getStandardNamespaces()); this.xPathRelevancyTest = XPathFactory.instance().compile(xPathExprRelevancyTest, Filters.fpassthrough(), null, MCRConstants.getStandardNamespaces()); }
private void bind(String xPath, boolean buildIfNotExists, String initialValue) throws JaxenException { this.xPath = xPath; Map<String, Object> variables = buildXPathVariables(); XPathExpression<Object> xPathExpr = XPathFactory.instance().compile(xPath, Filters.fpassthrough(), variables, MCRConstants.getStandardNamespaces()); boundNodes.addAll(xPathExpr.evaluate(parent.getBoundNodes())); for (Object boundNode : boundNodes) { if (!(boundNode instanceof Element || boundNode instanceof Attribute || boundNode instanceof Document)) { throw new TypeNotPresentException( "XPath MUST only bind either element, attribute or document nodes: " + xPath, null); } } LOGGER.debug("Bind to {} selected {} node(s)", xPath, boundNodes.size()); if (boundNodes.isEmpty() && buildIfNotExists) { MCRNodeBuilder builder = new MCRNodeBuilder(variables); Object built = builder.buildNode(xPath, initialValue, (Parent) (parent.getBoundNode())); LOGGER.debug("Bind to {} generated node {}", xPath, MCRXPathBuilder.buildXPath(built)); boundNodes.add(built); trackNodeCreated(builder.getFirstNodeBuilt()); } }