.getValue( "manifest//instrumentation/@android:name", String.class );
/** * @param ns namespaces * @param xpathString xpath to search on * @param doc xml to search * @return the (single) value matching the xpath in the xml supplied */ public static String getSingleXPathValue( NamespaceSupport ns, String xpathString, Document doc) { String id = null; JXPathContext context = initialiseContext(ns, doc); try { Object ob = context.getValue(xpathString); id = (String) ob; } catch (RuntimeException e) { throw new RuntimeException("Error reading xpath " + xpathString, e); } return id; }
public Object get(Object object, String xpath, Class target) throws IllegalArgumentException { JXPathContext context = JXPathContext.newContext(object); context.setLenient(true); Object value = context.getValue(xpath); return value; }
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); } }
@SuppressWarnings({"unchecked"}) protected Comparable<Comparable<?>> getTokenValue(JXPathContext jxcontext, String token) { // assume all values are comparable return (Comparable<Comparable<?>>) jxcontext.getValue(token); }
@SuppressWarnings({"unchecked"}) protected Comparable<Comparable<?>> getTokenValue(JXPathContext jxcontext, String token) { // assume all values are comparable return (Comparable<Comparable<?>>) jxcontext.getValue(token); }
private String getNonMandatoryData( JXPathContext ctx, String ctxFieldName ) { String value = null; try { value = (String)ctx.getValue( ctxFieldName ); if ( value != null && value.length() == 0 ) { value = null; } } catch ( JXPathException ex ) { value = null; } return value; }
@Override public Object value() { return JXPathContext.newContext(target).getValue(path); } }
public class Employee { public String getFirstName(){ ... } } Employee emp = new Employee(); JXPathContext context = JXPathContext.newContext(emp); String fName = (String)context.getValue("firstName");
/** execute an xpath query, using thiis object as the root of an object graph * * @param xpath query to execute * @return object found, or null */ public final Object findXPathValue(String xpath) { return this.accessJXPathContext().getValue(xpath); } /** execute an expath query, using this object as the root of an object graph
JXPathContext context = JXPathContext.newContext(purchase); OrderType orderDetail = (OrderType) context.getValue("orderDetail"); // equivalent to purchase.getOrderDetail() for(Iterator iter = context.iterate("/orderDetail/items"); iter.hasNext()){ Item i = (Item) iter.next(); //... } // Assumes that OrderType has a items property // List<Item> getItems()
/** * apply jxpath to object * * @param jxpath * @param child * @return child if jxpath null, else apply jxpath */ private Object extractFeature(String jxpath, Object child) { return jxpath != null ? JXPathContext.newContext(child) .getValue(jxpath) : child; }
public static Object query(Object obj, String path){ try{ JXPathContext jxpc = JXPathContext.newContext(obj); return jxpc.getValue(path); } catch(NullPointerException e){ return null; } catch(JXPathNotFoundException e){ return null; } }
private String getMandatoryData( JXPathContext ctx, String ctxFieldName ) { String value = (String)ctx.getValue( ctxFieldName ); if ( value != null && value.length() == 0 ) { throw new JXPathException( "Mandatory field " + ctxFieldName + " not provided, uncompliant UPNP device !!" ); } return value; }
public static Object getNode(Object rootConfigNode, String path) { try { return JXPathContext.newContext(rootConfigNode).getValue(path); } catch (JXPathNotFoundException e) { return null; } }
/** * Gets value of object using xpath expression. * * @param object source object * @param index xpath expression * @return obtained value */ public static Object getXPathIndexedValue(Object object, String index) { JXPathContext context = JXPathContext.newContext(object); context.setLenient(true); return context.getValue(index); }
/** * Gets value of object using xpath expression. * * @param object source object * @param index xpath expression * @return obtained value */ public static Object getXPathIndexedValue(Object object, String index) { JXPathContext context = JXPathContext.newContext(object); context.setLenient(true); return context.getValue(index); }
@SuppressWarnings("unchecked") @Override public boolean apply(Object input) { JXPathContext jxpath = JXPathContext.newContext(input); // We should allow non-existing path, and let predicate handle it. jxpath.setLenient(true); Object value = jxpath.getValue(xpath); return predicate.apply(value); }
public String evalInheritanceConstraint(Conf conf, String inheritConstraint) { try { JXPathContext jxpc = JXPathContext.newContext(conf); return (String)jxpc.getValue(inheritConstraint); } catch (Exception e) { throw new ConfException("Error evaluating configuration inheritance uniqueness constraint expression: \"" + inheritConstraint + "\" on conf defined at " + conf.getLocation(), e); } }