List of usage examples for org.jdom2.filter Filters fpassthrough
Filter fpassthrough
To view the source code for org.jdom2.filter Filters fpassthrough.
Click Source Link
From source file:org.apache.marmotta.ldclient.provider.xml.mapping.XPathValueMapper.java
License:Apache License
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())); }//from ww w. ja v a 2 s . com } this.compiled = XPathFactory.instance().compile(xpath, Filters.fpassthrough(), null, xnamespaces); }
From source file:org.apache.marmotta.ldclient.provider.xml.mapping.XPathValueMapper.java
License:Apache License
protected XPathValueMapper(String xpath, Collection<Namespace> namespaces) { this.xpath = xpath; this.compiled = XPathFactory.instance().compile(xpath, Filters.fpassthrough(), null, namespaces); }
From source file:org.mycore.frontend.xeditor.MCRBinding.java
License:Open Source License
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 RuntimeException( "XPath MUST only bind either element, attribute or document nodes: " + xPath); LOGGER.debug("Bind to " + xPath + " selected " + boundNodes.size() + " node(s)"); if (boundNodes.isEmpty() && buildIfNotExists) { MCRNodeBuilder builder = new MCRNodeBuilder(variables); Object built = builder.buildNode(xPath, initialValue, (Parent) (parent.getBoundNode())); LOGGER.debug("Bind to " + xPath + " generated node " + MCRXPathBuilder.buildXPath(built)); boundNodes.add(built);/*from w w w. j a v a 2s . co m*/ trackNodeCreated(builder.getFirstNodeBuilt()); } }
From source file:org.mycore.urn.events.MCRURNEventHandler.java
License:Open Source License
/** * Handles object created events. This method updates the urn store. * The urn is retrieved from object metadata with an XPath expression which can be configured by properties * MCR.Persistence.URN.XPath.{type} or as a default MCR.Persistence.URN.XPath * * @param evt/*from w w w . j av a 2s . co m*/ * the event that occurred * @param obj * the MCRObject that caused the event */ @Override protected final void handleObjectCreated(MCREvent evt, MCRObject obj) { try { MCRBaseContent content = new MCRBaseContent(obj); Document doc = content.asXML(); String type = obj.getId().getTypeId(); MCRConfiguration conf = MCRConfiguration.instance(); String xPathString = conf.getString("MCR.Persistence.URN.XPath." + type, conf.getString("MCR.Persistence.URN.XPath", "")); if (!xPathString.isEmpty()) { String urn = null; XPathExpression<Object> xpath = XPathFactory.instance().compile(xPathString, Filters.fpassthrough(), null, MCRConstants.getStandardNamespaces()); Object o = xpath.evaluateFirst(doc); if (o instanceof Attribute) { urn = ((Attribute) o).getValue(); } //element or text node else if (o instanceof Content) { urn = ((Content) o).getValue(); } if (urn != null) { if (MCRURNManager.getURNforDocument(obj.getId().toString()) == null) { MCRURNManager.assignURN(urn, obj.getId().toString()); } else { if (!MCRURNManager.getURNforDocument(obj.getId().toString()).equals(urn)) { LOGGER.warn("URN in metadata " + urn + "isn't equals with registered URN " + MCRURNManager.getURNforDocument(obj.getId().toString()) + ", please check!"); } } } else { if (MCRURNManager.hasURNAssigned(obj.getId().toString())) { MCRURNManager.removeURNByObjectID(obj.getId().toString()); } } } } catch (Exception ex) { LOGGER.error("Could not store / update the urn for object with id " + obj.getId().toString() + " into the database", ex); } }
From source file:org.xflatdb.xflat.convert.converters.JAXBPojoConverter.java
License:Apache License
private XPathExpression<Object> makeIdSelector(Class<?> clazz) { IdAccessor accessor = IdAccessor.forClass(clazz); if (!accessor.hasId()) { return null; }//from ww w . j a v a2 s . co m Namespace ns = null; StringBuilder ret = new StringBuilder(clazz.getSimpleName()); XmlAttribute attribute = (XmlAttribute) accessor.getIdPropertyAnnotation(XmlAttribute.class); if (attribute != null) { ret.append("/@"); if (attribute.namespace() != null) { ns = Namespace.getNamespace("id", attribute.namespace()); ret.append(ns.getPrefix()).append(":"); } if (attribute.name() != null) { ret.append(attribute.name()); } else { ret.append(accessor.getIdPropertyName()); } } else { ret.append("/"); XmlElement element = (XmlElement) accessor.getIdPropertyAnnotation(XmlElement.class); if (element != null) { if (element.namespace() != null) { ns = Namespace.getNamespace("id", attribute.namespace()); ret.append(ns.getPrefix()).append(":"); } if (element.name() != null) { ret.append(element.name()); } else { ret.append(accessor.getIdPropertyName()); } } else { ret.append(accessor.getIdPropertyName()); } } if (ns == null) { return XPathFactory.instance().compile(ret.toString()); } return XPathFactory.instance().compile(ret.toString(), Filters.fpassthrough(), null, ns); }
From source file:org.xflatdb.xflat.db.IdAccessor.java
License:Apache License
private static XPathExpression<Object> getAlternateId(Id idPropertyAnnotation) { if (idPropertyAnnotation == null) return null; String expression = idPropertyAnnotation.value(); if (expression == null || "".equals(expression)) { return null; }/*w w w .jav a2 s. c o m*/ List<Namespace> namespaces = null; if (idPropertyAnnotation.namespaces() != null && idPropertyAnnotation.namespaces().length > 0) { for (String ns : idPropertyAnnotation.namespaces()) { if (!ns.startsWith("xmlns:")) { continue; } int eqIndex = ns.indexOf("="); if (eqIndex < 0 || eqIndex >= ns.length() - 1) { continue; } String prefix = ns.substring(6, eqIndex); String url = ns.substring(eqIndex + 1); if (url.startsWith("\"") || url.startsWith("'")) url = url.substring(1); if (url.endsWith("\"") || url.endsWith("'")) url = url.substring(0, url.length() - 1); if ("".equals(prefix) || "".equals(url)) continue; if (namespaces == null) namespaces = new ArrayList<>(); namespaces.add(Namespace.getNamespace(prefix, url)); } } //compile it return XPathFactory.instance().compile(expression, Filters.fpassthrough(), null, namespaces == null ? Collections.EMPTY_LIST : namespaces); }