Example usage for org.apache.commons.jxpath JXPathContext newContext

List of usage examples for org.apache.commons.jxpath JXPathContext newContext

Introduction

In this page you can find the example usage for org.apache.commons.jxpath JXPathContext newContext.

Prototype

public static JXPathContext newContext(Object contextBean) 

Source Link

Document

Creates a new JXPathContext with the specified object as the root node.

Usage

From source file:org.toobsframework.pres.util.ParameterUtil.java

public static void mapDoItParameters(IRequest request, Parameter[] paramMap, Map paramsIn, Map paramsOut,
        boolean useJXPathContext) {
    JXPathContext context = null;//  ww  w .j  a  va  2 s.co  m
    if (useJXPathContext)
        context = JXPathContext.newContext(paramsIn);

    for (int j = 0; j < paramMap.length; j++) {
        Parameter thisParam = paramMap[j];
        Object value = null;
        if (thisParam.getIsStatic()) {
            String[] valueAry = new String[1];
            valueAry[0] = resolveParam(request, thisParam.getPath(), paramsIn)[0];
            value = valueAry;
        } else {
            value = context.getValue(resolveParam(request, thisParam.getPath(), paramsIn)[0]);
            if (value != null && value.getClass().isArray() && ((Object[]) value).length == 1) {
                value = ((Object[]) value)[0];
            } else if (value == null && thisParam.getDefault() != null) {
                value = thisParam.getDefault();
            }
        }
        paramsOut.put(resolveParam(request, thisParam.getName(), paramsIn)[0], value);
    }
}

From source file:org.xchain.framework.jxpath.JXPathContextTest.java

@Test
public void testRelativeContext() throws Exception {
    Node root = new Node("root");
    Node child = new Node("child");
    root.getChild().add(child);//from  w  w w  . j a v a  2s .com

    JXPathContext rootContext = JXPathContext.newContext(root);

    JXPathContext childContext = rootContext.getRelativeContext(rootContext.getPointer("/child"));

    String rootName = (String) childContext.getValue("/name");
    assertEquals("The root node has the wrong name.", "root", rootName);

    String childName = (String) childContext.getValue("name");
    assertEquals("The context node has the wrong name.", "child", childName);
}

From source file:org.xchain.framework.jxpath.JXPathContextTest.java

@Test
public void testBindMethodIgnore() throws Exception {
    JXPathContext context = JXPathContext.newContext(new Object());
    context.getVariables().declareVariable("sub-foo", new SubFoo());
    context.getVariables().declareVariable("bar", new SubBar());

    // This will throw a JXPathException, due to an ambiguous method lookup, unless 
    // GenericsWisePackageFunctions is used.
    String result = (String) context.getValue("take($sub-foo, $bar)", String.class);
    assertEquals("SubFoo", result);
}

From source file:org.xchain.framework.lifecycle.ExecutionTraceTest.java

@Before
public void setUp() throws Exception {
    context = JXPathContext.newContext(new Object());
    catalog = CatalogFactory.getInstance().getCatalog(CATALOG_URI);
}

From source file:org.xchain.framework.quartz.CommandJob.java

/**
 * <p>Creates a JXPathContext for a JobExecutionContext.</p>
 * @param jobContext the job execution context for which the jxpath context will be created.
 * @return the JXPathContext created for the job execution context.
 *///from  ww  w  .j  av a  2s  .c om
private JXPathContext createJXPathContext(JobExecutionContext jobContext) {
    JXPathContext commandContext = JXPathContext.newContext(new HashMap());
    ((QNameVariables) commandContext.getVariables())
            .declareVariable(new QName(Constants.LIFECYCLE_URI, Constants.JOB_EXECUTION_CONTEXT), jobContext);
    return commandContext;
}

From source file:org.xchain.framework.sax.TestXChainStylesheetDecl.java

@Before
public void setUp() throws Exception {
    context = JXPathContext.newContext(new Object());
    context.getVariables().declareVariable("result", Boolean.FALSE);
    catalog = CatalogFactory.getInstance().getCatalog(CATALOG_URI);
}

From source file:org.xchain.framework.security.TestIdentityFunctions.java

@Before
public void setUp() throws Exception {
    threadContext = new ThreadContext();
    ThreadLifecycle.getInstance().startThread(threadContext);
    context = JXPathContext.newContext(new Object());
    catalog = CatalogFactory.getInstance().getCatalog(CATALOG_URI);
}

From source file:org.xchain.framework.servlet.CatalogServlet.java

/**
 * Build a new JXPathContext and populate it with the given request and response.
 * /* www  .j  av a 2s. c om*/
 * @param request The incoming HttpServletRequest.
 * @param response The outgoing HttpServletResponse.
 * 
 * @return A JXPath which contains the servlet request and response.
        
 */
protected JXPathContext jXPathContext(HttpServletRequest request, HttpServletResponse response) {
    JXPathContext context = JXPathContext.newContext(new HashMap());

    ((QNameVariables) context.getVariables()).declareVariable(new QName(Constants.URI, Constants.CONTEXT),
            getServletConfig().getServletContext());
    ((QNameVariables) context.getVariables()).declareVariable(new QName(Constants.URI, Constants.REQUEST),
            request);
    ((QNameVariables) context.getVariables()).declareVariable(new QName(Constants.URI, Constants.RESPONSE),
            response);

    return context;
}

From source file:org.xchain.javassist.CommandEngineeringTest.java

@Test
public void testExtendingExecute() throws Exception {
    Command command = getExtendingCommand("org.xchain.javassist.SimpleCommand");

    // create a context.
    JXPathContext context = JXPathContext.newContext(new Object());

    // execute the command
    command.execute(context);/*ww  w .  j av a 2s  .  c o m*/

    // assert that the namespace was defined while the command executed.
    assertEquals("The namespace returned was not correct.", (Object) "http://www.xchain.org/test",
            context.getValue("$namespace"));

    // assert that the namespace is no longer defined on the context.
    assertEquals("The namespace was still defined on the context.", (String) null,
            context.getNamespaceURI("test"));
}

From source file:org.xchain.javassist.CommandEngineeringTest.java

@Test
public void testWrappingExecute() throws Exception {
    Command command = getWrappingCommand("org.xchain.javassist.SimpleCommand");

    // create a context.
    JXPathContext context = JXPathContext.newContext(new Object());

    // execute the command
    command.execute(context);//w  w  w. ja  va2  s  .  com

    // assert that the namespace was defined while the command executed.
    assertEquals("The namespace returned was not correct.", (Object) "http://www.xchain.org/test",
            context.getValue("$namespace"));

    // assert that the namespace is no longer defined on the context.
    assertEquals("The namespace was still defined on the context.", (String) null,
            context.getNamespaceURI("test"));
}