private static void addNamespaces(NamespaceSupport ns, JXPathContext context) { Enumeration<String> prefixes = ns.getPrefixes(); while (prefixes.hasMoreElements()) { String prefix = prefixes.nextElement(); String uri = ns.getURI(prefix); context.registerNamespace(prefix, uri); } }
public Object get(Object object, String xpath, Class target) { JXPathContext context = JXPathContext.newContext(object); Enumeration declaredPrefixes = namespaces.getDeclaredPrefixes(); while (declaredPrefixes.hasMoreElements()) { String prefix = (String) declaredPrefixes.nextElement(); String uri = namespaces.getURI(prefix); context.registerNamespace(prefix, uri); } Iterator it = context.iteratePointers(xpath); List results = new ArrayList<Object>(); while (it.hasNext()) { Pointer pointer = (Pointer) it.next(); if (pointer instanceof AttributeNodePointer) { results.add(((AttributeNodePointer) pointer).getImmediateAttribute()); } else { results.add(pointer.getValue()); } } if (results.size() == 0) { throw new IllegalArgumentException("x-path gives no results."); } else if (results.size() == 1) { return results.get(0); } else { return results; } }
public void set(Object object, String xpath, Object value, Class target) throws IllegalAttributeException { if (object instanceof FeatureType) { throw new IllegalAttributeException(null, "feature type is immutable"); } JXPathContext context = JXPathContext.newContext(object); Enumeration declaredPrefixes = namespaces.getDeclaredPrefixes(); while (declaredPrefixes.hasMoreElements()) { String prefix = (String) declaredPrefixes.nextElement(); String uri = namespaces.getURI(prefix); context.registerNamespace(prefix, uri); } context.setValue(xpath, value); assert value == context.getValue(xpath); } }
private void applyNSDeclarations(JXPathContext jxpc) { if (this.commonAtts.nsDeclarations != null) { Iterator keysIter = this.commonAtts.nsDeclarations.keySet().iterator(); while (keysIter.hasNext()) { String nsuri = (String) keysIter.next(); String pfx = (String) this.commonAtts.nsDeclarations.get(nsuri); jxpc.registerNamespace(pfx, nsuri); } } }
private JXPathContext getBwMeta(Attachment<?> metadataAttachment) throws Exception { try (InputStream bwmetaStream = getPartStream(metadataAttachment)) { DocumentBuilder db = dbf.newDocumentBuilder(); Document document = db.parse(bwmetaStream); Element root = document.getDocumentElement(); String namespace = root.getNamespaceURI(); JXPathContext context = JXPathContext.newContext(document); context.registerNamespace(DEFAULT_NAMESPACE_PREFIX, namespace); return context; } }
private static void addNamespaces(NamespaceSupport ns, JXPathContext context) { Enumeration<String> prefixes = ns.getPrefixes(); while (prefixes.hasMoreElements()) { String prefix = prefixes.nextElement(); String uri = ns.getURI(prefix); context.registerNamespace(prefix, uri); } }
protected void addNamespacesToContext(NamespaceManager manager, JXPathContext context) { for (Map.Entry<String, String> entry : manager.getNamespaces().entrySet()) { try { context.registerNamespace(entry.getKey(), entry.getValue()); } catch (Exception e) { throw new ExpressionRuntimeException(XmlMessages.failedToRegisterNamespace(entry.getKey(), entry.getValue())); } } }
public Object get(Object object, String xpath, Class target) { JXPathContext context = JXPathContext.newContext(object); Enumeration declaredPrefixes = namespaces.getDeclaredPrefixes(); while (declaredPrefixes.hasMoreElements()) { String prefix = (String) declaredPrefixes.nextElement(); String uri = namespaces.getURI(prefix); context.registerNamespace(prefix, uri); } Iterator it = context.iterate(xpath); List results = new ArrayList<Object>(); while(it.hasNext()) { results.add(it.next()); } if (results.size()==0) { throw new IllegalArgumentException("x-path gives no results."); } else if (results.size()==1) { return results.get(0); } else { return results; } }
context.registerNamespace(entry.getKey(), entry.getValue());
public Object get(Object object, String xpath, Class target) { JXPathContext context = JXPathContext.newContext(object); Enumeration declaredPrefixes = namespaces.getDeclaredPrefixes(); while (declaredPrefixes.hasMoreElements()) { String prefix = (String) declaredPrefixes.nextElement(); String uri = namespaces.getURI(prefix); context.registerNamespace(prefix, uri); } Iterator it = context.iteratePointers(xpath); List results = new ArrayList<Object>(); while (it.hasNext()) { Pointer pointer = (Pointer) it.next(); if (pointer instanceof AttributeNodePointer) { results.add(((AttributeNodePointer) pointer).getImmediateAttribute()); } else { results.add(pointer.getValue()); } } if (results.size() == 0) { throw new IllegalArgumentException("x-path gives no results."); } else if (results.size() == 1) { return results.get(0); } else { return results; } }
/** * Actually add global functions and packages as well as those * listed in the configuration object. * * @param setup The JXPathHelperConfiguration. * @param context a <code>JXPathContext</code> value. * @param conf a <code>Configuration</code> value holding local. * packages and functions. */ private static void setup(JXPathHelperConfiguration setup, JXPathContext context, Configuration conf) throws ConfigurationException { // Create local config (if necessary) JXPathHelperConfiguration local = conf == null ? setup : new JXPathHelperConfiguration(setup, conf); // Setup context with local config context.setLenient(setup.isLenient()); context.setFunctions(local.getLibrary()); if (local.getNamespaces() != null) { for (Iterator i = local.getNamespaces().entrySet().iterator(); i.hasNext();) { final Map.Entry entry = (Map.Entry) i.next(); context.registerNamespace((String) entry.getKey(), (String) entry.getValue()); } } }
public void set(Object object, String xpath, Object value, Class target) throws IllegalAttributeException { if (object instanceof FeatureType) { throw new IllegalAttributeException(null, "feature type is immutable"); } JXPathContext context = JXPathContext.newContext(object); Enumeration declaredPrefixes = namespaces.getDeclaredPrefixes(); while (declaredPrefixes.hasMoreElements()) { String prefix = (String) declaredPrefixes.nextElement(); String uri = namespaces.getURI(prefix); context.registerNamespace(prefix, uri); } context.setValue(xpath, value); assert value == context.getValue(xpath); } }
public void set(Object object, String xpath, Object value, Class target) throws IllegalAttributeException { if (object instanceof FeatureType) { throw new IllegalAttributeException("feature type is immutable"); } JXPathContext context = JXPathContext.newContext(object); Enumeration declaredPrefixes = namespaces.getDeclaredPrefixes(); while (declaredPrefixes.hasMoreElements()) { String prefix = (String) declaredPrefixes.nextElement(); String uri = namespaces.getURI(prefix); context.registerNamespace(prefix, uri); } context.setValue(xpath, value); assert value == context.getValue(xpath); } }
context.registerNamespace(DEFAULT_NAMESPACE_PREFIX, namespace); Iterator<Pointer> iterator = context.iteratePointers(contentLocationXPath);
context.registerNamespace(DEFAULT_NAMESPACE_PREFIX, namespace); if (paths != null) {
String uri = namespace.getUri(); if(null != uri && null != prefix){ messageContext.registerNamespace(prefix, uri);
String uri = namespace.getUri(); if(null != uri && null != prefix){ messageContext.registerNamespace(prefix, uri);