Examples of JXPathContext


Examples of org.apache.commons.jxpath.JXPathContext

    /**
     * Returns a JXPathContext bound to the "page" scope. Caches that context
     * within the PageContext itself.
     */
    public static JXPathContext getPageContext(PageContext pageContext) {
        JXPathContext context =
            (JXPathContext) pageContext.getAttribute(Constants.JXPATH_CONTEXT);
        if (context == null) {
            JXPathIntrospector.registerDynamicClass(
                pageContext.getClass(),
                PageContextHandler.class);
            JXPathContext parentContext =
                getRequestContext(
                    pageContext.getRequest(),
                    pageContext.getServletContext());
            context = factory.newContext(parentContext, pageContext);
            context.setVariables(
View Full Code Here

Examples of org.apache.commons.jxpath.JXPathContext

     */
    public static JXPathContext getRequestContext(
        ServletRequest request,
        ServletContext servletContext)
    {
        JXPathContext context =
            (JXPathContext) request.getAttribute(Constants.JXPATH_CONTEXT);
        if (context == null) {
            JXPathContext parentContext = null;
            if (request instanceof HttpServletRequest) {
                HttpSession session =
                    ((HttpServletRequest) request).getSession(false);
                if (session != null) {
                    parentContext = getSessionContext(session, servletContext);
View Full Code Here

Examples of org.apache.commons.jxpath.JXPathContext

     */
    public static JXPathContext getSessionContext(
        HttpSession session,
        ServletContext servletContext)
    {
        JXPathContext context =
            (JXPathContext) session.getAttribute(Constants.JXPATH_CONTEXT);
        if (context == null) {
            JXPathIntrospector.registerDynamicClass(
                session.getClass(),
                HttpSessionHandler.class);
            JXPathContext parentContext = getApplicationContext(servletContext);
            context = factory.newContext(parentContext, session);
            context.setVariables(
                new KeywordVariables(Constants.SESSION_SCOPE, session));
            session.setAttribute(Constants.JXPATH_CONTEXT, context);
        }
View Full Code Here

Examples of org.apache.commons.jxpath.JXPathContext

     * context within the servlet context itself.
     */
    public static JXPathContext getApplicationContext(
            ServletContext servletContext)
    {
        JXPathContext context =
            (JXPathContext) servletContext.getAttribute(
                Constants.JXPATH_CONTEXT);
        if (context == null) {
            JXPathIntrospector.registerDynamicClass(
                servletContext.getClass(),
                ServletContextHandler.class);
            context = factory.newContext(null, servletContext);
            context.setVariables(
                new KeywordVariables(
                    Constants.APPLICATION_SCOPE,
                    servletContext));
            servletContext.setAttribute(Constants.JXPATH_CONTEXT, context);
        }
View Full Code Here

Examples of org.apache.commons.jxpath.JXPathContext

    }

    protected abstract AbstractFactory getAbstractFactory();

    protected JXPathContext createContext() {
        JXPathContext context =
            JXPathContext.newContext(createDocumentContainer());
        context.setFactory(getAbstractFactory());
        return context;
    }
View Full Code Here

Examples of org.apache.commons.jxpath.JXPathContext

        }
        return -1;
    }

    public void testIteratePropertyArrayWithHasNext() {
        JXPathContext context = JXPathContext.newContext(createContextBean());
        Iterator it = context.iteratePointers("/integers");
        List actual = new ArrayList();
        while (it.hasNext()) {
            actual.add(((Pointer) it.next()).asPath());
        }
        assertEquals(
View Full Code Here

Examples of org.apache.commons.jxpath.JXPathContext

                "/integers[4]"),
            actual);
    }

    public void testIteratePropertyArrayWithoutHasNext() {
        JXPathContext context = JXPathContext.newContext(createContextBean());
        Iterator it = context.iteratePointers("/integers");
        List actual = new ArrayList();
        for (int i = 0; i < 4; i++) {
            actual.add(it.next().toString());
        }
        assertEquals(
View Full Code Here

Examples of org.apache.commons.jxpath.JXPathContext

                "/integers[4]"),
            actual);
    }

    public void testIterateAndSet() {
        JXPathContext context = JXPathContext.newContext(createContextBean());

        Iterator it = context.iteratePointers("beans/int");
        int i = 5;
        while (it.hasNext()) {
            NodePointer pointer = (NodePointer) it.next();
            pointer.setValue(new Integer(i++));
        }

        it = context.iteratePointers("beans/int");
        List actual = new ArrayList();
        while (it.hasNext()) {
            actual.add(((Pointer) it.next()).getValue());
        }
        assertEquals(
View Full Code Here

Examples of org.apache.commons.jxpath.JXPathContext

    /**
     * Test contributed by Kate Dvortsova
     */
    public void testIteratePointerSetValue() {
        JXPathContext context = JXPathContext.newContext(createContextBean());

        assertXPathValue(context, "/beans[1]/name", "Name 1");
        assertXPathValue(context, "/beans[2]/name", "Name 2");

        // Test setting via context
        context.setValue("/beans[2]/name", "Name 2 set");
        assertXPathValue(context, "/beans[2]/name", "Name 2 set");

        // Restore original value
        context.setValue("/beans[2]/name", "Name 2");
        assertXPathValue(context, "/beans[2]/name", "Name 2");

        int iterCount = 0;
        Iterator iter = context.iteratePointers("/beans/name");
        while (iter.hasNext()) {
            iterCount++;
            Pointer pointer = (Pointer) iter.next();
            String s = (String) pointer.getValue();
            s = s + "suffix";
            pointer.setValue(s);
            assertEquals("pointer.getValue", s, pointer.getValue());
            // fails right here, the value isn't getting set in the bean.
            assertEquals(
                "context.getValue",
                s,
                context.getValue(pointer.asPath()));
        }
        assertEquals("Iteration count", 2, iterCount);

        assertXPathValue(context, "/beans[1]/name", "Name 1suffix");
        assertXPathValue(context, "/beans[2]/name", "Name 2suffix");
View Full Code Here

Examples of org.apache.commons.jxpath.JXPathContext

            null,
            context.getValue("nestedBean"));
    }
   
    public void testRelativeContextRelativePath() {
        JXPathContext relative =
            context.getRelativeContext(context.getPointer("nestedBean"));
       
        assertXPathValueAndPointer(relative,
            "int",
            new Integer(1),
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.