Package org.apache.commons.jxpath

Examples of org.apache.commons.jxpath.JXPathContext


    }


    public Object evaluate(Exchange exchange) {
        try {
            JXPathContext context = JXPathContext.newContext(exchange);
            Object result = getJXPathExpression().getValue(context, type);
            assertResultType(exchange, result);
            return result;
        } catch (JXPathException e) {
            throw new ExpressionEvaluationException(this, exchange, e);
View Full Code Here


            result.add(root);
            return result;
        }
        else
        {
            JXPathContext context = createContext(root, key);
            List result = context.selectNodes(key);
            return (result != null) ? result : Collections.EMPTY_LIST;
        }
    }
View Full Code Here

     * @param key the key to be queried
     * @return the new context
     */
    protected JXPathContext createContext(ConfigurationNode root, String key)
    {
        JXPathContext context = JXPathContext.newContext(root);
        context.setLenient(true);
        return context;
    }
View Full Code Here

        catch(NoSuchMethodError ex)
        {
            return;
        }
        Node root = ((Document) result.getNode()).getDocumentElement();
        JXPathContext ctx = JXPathContext.newContext(root);

        assertEquals("Wrong name of root element", "database", root.getNodeName());
        assertEquals("Wrong number of children of root", 1, ctx.selectNodes(
                "/*").size());
        assertEquals("Wrong number of tables", 2, ctx.selectNodes(
                "/tables/table").size());
        assertEquals("Wrong name of first table", "users", ctx
                .getValue("/tables/table[1]/name"));
        assertEquals("Wrong number of fields in first table", 5, ctx
                .selectNodes("/tables/table[1]/fields/field").size());
        assertEquals("Wrong attribute value", "system", ctx
                .getValue("/tables/table[1]/@tableType"));
    }
View Full Code Here

  private static void list(Prevayler prevayler, String xpathExp) {
    System.out.println("Executing XPath expression...");

    ProjectManagementSystem pms =
        (ProjectManagementSystem) prevayler.prevalentSystem();
    JXPathContext context = JXPathContext.newContext(pms);
    Iterator i = context.iterate(xpathExp);

    while (i.hasNext()) {

      Object obj = (Object) i.next();
      System.out.println(obj.toString());
View Full Code Here

            int index = Integer.parseInt(fieldName);
            while (((List) obj).size() <= index) ((List) obj).add(null);
            ((List) obj).set(index, parseValue(fieldValue, String.class)); //List of Strings
        }
        else if (fieldName.indexOf('.') != -1) { //Set it by JXPath, valid only for strings
            JXPathContext ctx = JXPathContext.newContext(obj);
            ctx.setValue(fieldName.replace('.', '/'), parseValue(fieldValue, String.class));
        }
        else {
            // Find a Field
            Field field = getField(obj, fieldName);
            if (field != null) {
View Full Code Here

            int index = Integer.parseInt(fieldName);
            while (((List) obj).size() <= index) ((List) obj).add(null);
            ((List) obj).set(index, fieldValue); //List of Strings
        }
        else if (fieldName.indexOf('.') != -1) { //Set it by JXPath, valid only for strings
            JXPathContext ctx = JXPathContext.newContext(obj);
            ctx.setValue(fieldName.replace('.', '/'), fieldValue);
        }
        else {
            // Find a Field
            Field field = getField(obj, fieldName);
            if (field != null) {
View Full Code Here

                        } catch (Exception e) {
                            log.error("Error in component lifecycle ", e);
                        }
                    }
                    setTheInstance(object);
                    JXPathContext ctx = JXPathContext.newContext(object);
                    for (Iterator it = componentConfiguredProperties.keySet().iterator(); it.hasNext();) {
                        String propertyName = (String) it.next();
                        List propertyValue = (List) componentConfiguredProperties.get(propertyName);
                        try {
                            setObjectProperty(object, propertyName, propertyValue, ctx);
View Full Code Here

        if (value == null && parent.getFormaterTagDynamicAttributesInterpreter() != null) {
            value = parent.getFormaterTagDynamicAttributesInterpreter().getValueForParameter(name);
        }
        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())
View Full Code Here

            Object propertyName = getParameter("property");
            if (componentName != null) {
                Object component = CDIBeanLocator.getBeanByNameOrType((String) componentName);
                array = component;
                if (propertyName != null) {
                    JXPathContext ctx = JXPathContext.newContext(component);
                    try {
                        array = ctx.getValue((String) propertyName);
                    } catch (Exception e) {
                        log.debug("Error:", e);
                    }
                }
            }
View Full Code Here

TOP

Related Classes of org.apache.commons.jxpath.JXPathContext

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.