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); while (itr.hasNext()) { Object obj = itr.next(); if (handler.getParseNode().equals(obj)) { return true; } } return false; } }
/** * Creates a new JXPathContext with the specified object as the root node. * @param contextBean Object * @return JXPathContext */ public static JXPathContext newContext(Object contextBean) { return getContextFactory().newContext(null, contextBean); }
/** * Acquires a context factory and caches it. * @return JXPathContextFactory */ private static JXPathContextFactory getContextFactory () { if (contextFactory == null) { contextFactory = JXPathContextFactory.newInstance(); } return contextFactory; }
if (factoryImplName == null) { factoryImplName = findFactory(FACTORY_NAME_PROPERTY, DEFAULT_FACTORY_CLASS);
/** * Creates a new JXPathContext with the specified bean as the root node and * the specified parent context. Variables defined in a parent context can * be referenced in XPaths passed to the child context. * @param parentContext parent context * @param contextBean Object * @return JXPathContext */ public static JXPathContext newContext( JXPathContext parentContext, Object contextBean) { return getContextFactory().newContext(parentContext, contextBean); }
JXPathContext context(Object object) { JXPathContext context = JXPathContextFactory.newInstance().newContext(null, object); context.setLenient(true); return context; } }
/** * Returns a JXPathContext bound to the "application" scope. Caches that * context within the servlet context itself. * @param servletContext operative * @return JXPathContext */ public static JXPathContext getApplicationContext( ServletContext servletContext) { JXPathContext context = (JXPathContext) servletContext.getAttribute( Constants.JXPATH_CONTEXT); if (context == null) { context = factory.newContext(null, servletContext); context.setVariables( new KeywordVariables( Constants.APPLICATION_SCOPE, servletContext)); servletContext.setAttribute(Constants.JXPATH_CONTEXT, context); } return context; } }
JXPathContext context( Object object ) { JXPathContext context = JXPathContextFactory.newInstance().newContext( null, object ); context.setLenient( true ); return context; }
/** * Returns a JXPathContext bound to the "session" scope. Caches that context * within the session itself. * @param session as described * @param servletContext operative * @return JXPathContext */ public static JXPathContext getSessionContext(HttpSession session, ServletContext servletContext) { JXPathContext context = (JXPathContext) session.getAttribute(Constants.JXPATH_CONTEXT); if (context == null) { JXPathContext parentContext = getApplicationContext(servletContext); HttpSessionAndServletContext handle = new HttpSessionAndServletContext(session, servletContext); context = factory.newContext(parentContext, handle); context.setVariables( new KeywordVariables(Constants.SESSION_SCOPE, handle)); session.setAttribute(Constants.JXPATH_CONTEXT, context); } return context; }
JXPathContext context(Object object) { JXPathContext context = JXPathContextFactory.newInstance().newContext(null, object); context.setLenient(true); return context; } }
/** * Returns a JXPathContext bound to the "page" scope. Caches that context * within the PageContext itself. * @param pageContext as described * @return JXPathContext */ public static JXPathContext getPageContext(PageContext pageContext) { JXPathContext context = (JXPathContext) pageContext.getAttribute(Constants.JXPATH_CONTEXT); if (context == null) { JXPathContext parentContext = getRequestContext( pageContext.getRequest(), pageContext.getServletContext()); context = factory.newContext(parentContext, pageContext); context.setVariables( new KeywordVariables( Constants.PAGE_SCOPE, new PageScopeContext(pageContext))); pageContext.setAttribute(Constants.JXPATH_CONTEXT, context); } return context; }
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(); if (handler.getParseNode().equals(obj)) { return true; } } return false; } }
context = factory.newContext(parentContext, handle); context.setVariables( new KeywordVariables(Constants.REQUEST_SCOPE, handle));
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(); if (handler.getParseNode().equals(obj)) { return true; } } return false; }
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(); if (handler.getParseNode().equals(obj)) { return true; } } return false; } }