List of usage examples for org.apache.commons.jxpath JXPathContext setLenient
public synchronized void setLenient(boolean lenient)
From source file:org.firesoa.common.jxpath.JXPathTestCase.java
protected void assertXPathPointerLenient(JXPathContext ctx, String xpath, String expected) { ctx.setLenient(true); Pointer pointer = ctx.getPointer(xpath); String actual = pointer.toString(); assertEquals("Evaluating pointer <" + xpath + ">", expected, actual); }
From source file:org.firesoa.common.jxpath.JXPathTestCase.java
protected void assertXPathValueType(JXPathContext ctx, String xpath, Class clazz) { ctx.setLenient(false); Object actual = ctx.getValue(xpath); assertTrue("Evaluating <" + xpath + "> = " + actual.getClass(), clazz.isAssignableFrom(actual.getClass())); }
From source file:org.firesoa.common.jxpath.JXPathTestCase.java
protected void assertXPathNodeType(JXPathContext ctx, String xpath, Class clazz) { ctx.setLenient(false); Pointer actual = ctx.getPointer(xpath); assertTrue("Evaluating <" + xpath + "> = " + actual.getNode().getClass(), clazz.isAssignableFrom(actual.getNode().getClass())); }
From source file:org.geotools.util.XmlXpathUtilites.java
private static JXPathContext initialiseContext(NamespaceSupport ns, Document doc) { JXPathContext context = JXPathContext.newContext(doc); addNamespaces(ns, context);/*from w w w . j a v a 2 s . co m*/ context.setLenient(true); return context; }
From source file:org.geotools.xml.impl.jxpath.JXPathStreamingParserHandler.java
protected boolean stream(ElementHandler handler) { //create an xpath context from the root element // TODO: cache the context, should work just the same // JXPathIntrospector.registerDynamicClass(ElementHandlerImpl.class, // ElementHandlerPropertyHandler.class); JXPathIntrospector.registerDynamicClass(NodeImpl.class, NodePropertyHandler.class); // ElementHandler rootHandler = // ((DocumentHandler) handlers.firstElement()).getDocumentElementHandler(); Node root = ((DocumentHandler) handlers.firstElement()).getParseNode(); JXPathContext jxpContext = JXPathContextFactory.newInstance().newContext(null, root); jxpContext.setLenient(true); Iterator itr = jxpContext.iterate(xpath); for (; itr.hasNext();) { Object obj = itr.next();/* w w w . jav a2 s . c o m*/ if (handler.getParseNode().equals(obj)) { return true; } } return false; }
From source file:org.jboss.dashboard.ui.taglib.formatter.FragmentTag.java
public Object getParam(String name) { FormatterTag parent = (FormatterTag) getParent(); Object value = parent.getFragmentParams().get(name); if (value == null && parent.getFormaterTagDynamicAttributesInterpreter() != null) { value = parent.getFormaterTagDynamicAttributesInterpreter().getValueForParameter(name); }//w w w. ja va 2 s . c o m if (value == null && name.indexOf('/') != -1) try { log.debug("Attempt JXPath detection of param..."); JXPathContext ctx = JXPathContext.newContext(parent.getFragmentParams()); ctx.setLenient(false); value = ctx.getValue(name); if (value == null && parent.getFormaterTagDynamicAttributesInterpreter() != null) { String firstName = name.substring(0, name.indexOf('/')); Object firstValue = parent.getFormaterTagDynamicAttributesInterpreter() .getValueForParameter(firstName); if (firstValue != null) { ctx = JXPathContext.newContext(firstValue); ctx.setLenient(false); value = ctx.getValue(name.substring(name.indexOf('/') + 1)); } } } catch (Exception e) { if (log.isDebugEnabled()) log.warn("Error getting attribute " + value + " in params."); } return value; }
From source file:org.lilyproject.runtime.conf.test.InheritanceTest.java
public void testInheritance2() throws Exception { ConfImpl parent = loadConf("inherit2_parent.xml"); // Child 1//w ww . j av a 2 s .co m { ConfImpl child = loadConf("inherit2_child1.xml"); child.inherit(parent); JXPathContext context = JXPathContext.newContext(child); assertEquals(3, context.getValue("count(*)", Integer.class)); assertEquals("val1", context.getValue("@attr1")); assertEquals("val2 - altered", context.getValue("@attr2")); assertEquals("ee", context.getValue("c/e")); context.setLenient(true); assertEquals(null, context.getValue("c/d")); } }
From source file:org.mule.module.xml.filters.JXPathFilter.java
/** * Initializes the JXPathContext based on any relevant properties set for the * filter./*from w w w . j ava2s . c o m*/ * * @param context the JXPathContext to initialize */ protected void initialise(JXPathContext context) { if (namespaces != null) { if (logger.isDebugEnabled()) { logger.debug("Initializing JXPathContext with namespaces: " + namespaces); } for (Map.Entry<String, String> entry : namespaces.entrySet()) { context.registerNamespace(entry.getKey(), entry.getValue()); } } Map.Entry entry; if (contextProperties != null) { if (logger.isDebugEnabled()) { logger.debug("Initializing JXPathContext with properties: " + contextProperties); } for (Iterator iterator = contextProperties.entrySet().iterator(); iterator.hasNext();) { entry = (Map.Entry) iterator.next(); context.setValue(entry.getKey().toString(), entry.getValue()); } } if (factory != null) { context.setFactory(factory); } context.setLenient(lenient); }
From source file:org.onecmdb.core.utils.xpath.commands.CreateCommand.java
@Override public void transfer(OutputStream out) { this.context.put("create", true); JXPathContext xPathContext = getXPathContext(); xPathContext.setLenient(true); Object o = xPathContext.getValue(getPath()); if (o != null) { throw new IllegalArgumentException("Path '" + getPath() + "' exists."); }/*from w ww . ja va 2s .com*/ setupTX(); Pointer p = xPathContext.createPath(getPath()); JXPathContext relContext = getRelativeContext(p); for (String outputAttribute : getInputAttributeNameAsArray()) { /* Iterator<Pointer> outputAttrPointersIter = context.iteratePointers(outputAttribute); while(outputAttrPointersIter.hasNext()) { Pointer vPointer = outputAttrPointersIter.next(); Object values = getValues(outputAttribute); //NodePointer nP = (NodePointer)vPointer; //nP.getImmediateValuePointer().setValue(values); vPointer.setValue(values); } */ Object values = getValues(outputAttribute); relContext.setValue(outputAttribute, values); } processTX(); }
From source file:org.onehippo.forge.content.pojo.model.ContentNode.java
/** * Creates and returns a {@link JXPathContext} instance used by default. * @return a {@link JXPathContext} instance used by default *//*from w w w.java 2 s.c o m*/ private JXPathContext createJXPathContext() { JXPathContext jxpathCtx = JXPathContext.newContext(this); jxpathCtx.setLenient(true); return jxpathCtx; }