List of usage examples for org.apache.commons.jxpath ClassFunctions ClassFunctions
public ClassFunctions(Class functionClass, String namespace)
From source file:com.technofovea.hl2parse.JxPathUtil.java
/** * Adds custom functions onto a context which correspond to * static methods on this class, such as {@link #startswith(java.lang.String, java.lang.String)} * @param context The context to alter.//from w w w. j a v a2 s . co m */ public static void addFunctions(JXPathContext context) { context.setFunctions(new ClassFunctions(JxPathUtil.class, "custom")); }
From source file:com.htm.query.jxpath.JXpathQueryEvaluator.java
public JXpathQueryEvaluator(Object evalContext) { this.setContext(evalContext); this.log = Utilities.getLogger(this.getClass()); /*//from w ww .j a va2 s .c o m * Enable lenient mode to prevent that there exceptions are thrown when * xpath does not map to an existing property - instead null is returned */ this.jXpathContext.setLenient(true); /* Add our user defined XPath functions */ this.jXpathContext.setFunctions(new ClassFunctions(XPathFunctions.class, FUNCTIONS_PREFIX)); }
From source file:de.tudarmstadt.ukp.dkpro.core.tokit.TokenMergerTest.java
@SuppressWarnings("unchecked") public static List<Object> pick(Collection<?> aContext, String aPath) { List<Object> result = new ArrayList<Object>(); for (Object a : aContext) { JXPathContext ctx = JXPathContext.newContext(a); ctx.setFunctions(new ClassFunctions(JXPathCasFunctions.class, "cas")); result.addAll(ctx.selectNodes(aPath)); }//from ww w. j a va 2 s . c om return result; }
From source file:org.apache.cocoon.components.modules.input.JXPathHelperConfiguration.java
/** * Register all extension functions listed in the configuration * through <code><function name="fully.qualified.Class" * prefix="prefix"/></code> in the given FunctionLibrary. * * @param conf a <code>Configuration</code> value *//*from w w w.j a va2s . c o m*/ private void getFunctions(Configuration conf) { Configuration[] children = conf.getChildren("function"); int i = children.length; while (i-- > 0) { String clazzName = children[i].getAttribute("name", null); String prefix = children[i].getAttribute("prefix", null); if (clazzName != null && prefix != null) { try { Class clazz = Class.forName(clazzName); this.library.addFunctions(new ClassFunctions(clazz, prefix)); } catch (ClassNotFoundException cnf) { // ignore } } } }
From source file:org.chiba.xml.xforms.xpath.test.ChibaExtensionFunctionsTest.java
/** * Sets up the test./* w w w .java 2 s . com*/ * * @throws Exception in any error occurred during setup. */ protected void setUp() throws Exception { Config.getInstance(getClass().getResource("ChibaExtensionFunctionsTestConfig.xml").getPath()); this.chibaBean = new ChibaBean(); this.chibaBean.setXMLContainer(getClass().getResourceAsStream("ChibaExtensionFunctionsTest.xml")); this.chibaBean.init(); this.context = this.chibaBean.getContainer().getDefaultModel().getDefaultInstance().getInstanceContext(); this.context.setFunctions(new ClassFunctions(ChibaExtensionFunctions.class, "chiba")); }
From source file:org.commonjava.maven.galley.maven.parse.JXPathUtils.java
public static JXPathContext newContext(final Node node) { final JXPathContext ctx = JXPathContext.newContext(node); ctx.setLenient(true);//from w ww . j a v a 2s. c o m ctx.setFunctions(new ClassFunctions(ResolveFunctions.class, "ext")); return ctx; }
From source file:org.eclipse.e4.emf.internal.xpath.JXPathContextImpl.java
/** * Create a new context/*w w w.j a v a 2 s.com*/ * * @param contextBean * the context bean (=root of the xpath expression) */ JXPathContextImpl(Object contextBean) { this.context = JXPathContext.newContext(contextBean); this.context.setFunctions(new ClassFunctions(EMFFunctions.class, "ecore")); }
From source file:org.openvpms.archetype.function.factory.ArchetypeFunctionsFactory.java
/** * Creates a new {@code Functions} for a class. * * @param namespace the function namespace * @param functionClass the function class * @return the functions/* w w w. ja va 2 s.c o m*/ */ protected Functions create(String namespace, Class functionClass) { return new ClassFunctions(functionClass, namespace); }
From source file:org.openvpms.component.system.common.jxpath.JXPathHelper.java
/** * Adds functions for the specified class name and namespace. * * @param className the class name//from w ww.j a v a 2 s .c om * @param namespace the namespace */ private void addFunctions(String className, String namespace) { try { ClassLoader loader = Thread.currentThread().getContextClassLoader(); Class clazz = loader.loadClass(className); functions.addFunctions(new ClassFunctions(clazz, namespace)); } catch (Exception exception) { throw new JXPathHelperException(JXPathHelperException.ErrorCode.InvalidClassSpecified, new Object[] { className }, exception); } }
From source file:org.openvpms.component.system.service.jxpath.JXPathTestCase.java
/** * Test the JXPath expressions for retrieving an object with an id * from a collection//from www .j a v a 2 s . c o m */ @Test public void testJXPathSearchCollectionForMatchingUid() { List<Party> list = new ArrayList<Party>(); Party person = createPerson("MR", "Jim", "Alateras"); person.setId(1); list.add(person); person = createPerson("MS", "Bernadette", "Feeney"); person.setId(2); list.add(person); person = createPerson("MS", "Grace", "Alateras"); person.setId(3); list.add(person); JXPathContext ctx = JXPathHelper.newContext(list); // NOTE: Using a extension function to do the work. assertTrue(ctx.getValue( "org.openvpms.component.system.service.jxpath.TestFunctions.findObjectWithUid(., 1)") != null); assertTrue(ctx.getValue( "org.openvpms.component.system.service.jxpath.TestFunctions.findObjectWithUid(., 3)") != null); assertTrue(ctx.getValue( "org.openvpms.component.system.service.jxpath.TestFunctions.findObjectWithUid(., 4)") == null); assertTrue(ctx.getValue( "org.openvpms.component.system.service.jxpath.TestFunctions.findObjectWithUid(., 0)") == null); // execute the same test using function namespaces FunctionLibrary lib = new FunctionLibrary(); lib.addFunctions(new ClassFunctions(TestFunctions.class, "collfunc")); ctx.setFunctions(lib); assertTrue(ctx.getValue("collfunc:findObjectWithUid(., 1)") != null); assertTrue(ctx.getValue("collfunc:findObjectWithUid(., 3)") != null); assertTrue(ctx.getValue("collfunc:findObjectWithUid(., 4)") == null); assertTrue(ctx.getValue("collfunc:findObjectWithUid(., 0)") == null); assertTrue(ctx.getValue("collfunc:findObjectWithUid(., 1)/name") != null); }