/** * 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; } }
/** * 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; }
/** * 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; }
new ServletRequestAndContext(request, servletContext); context = factory.newContext(parentContext, handle); context.setVariables( new KeywordVariables(Constants.REQUEST_SCOPE, handle)); request.setAttribute(Constants.JXPATH_CONTEXT, context);
private JXPathContext getContext(ObjectModel objectModel) { // This could be made more efficient by caching the // JXPathContext within the Context object. JXPathContext jxobjectModel = JXPathContext.newContext(objectModel.get(ObjectModel.CONTEXTBEAN)); jxobjectModel.setVariables(new VariableAdapter(objectModel)); jxobjectModel.setLenient(this.lenient); jxobjectModel.setNamespaceContextPointer(new NamespacesTablePointer((NamespacesTable)objectModel.get(ObjectModel.NAMESPACE))); return jxobjectModel; }
xpathContext.setVariables(vars); xpathContext.setIdentityManager(this);
xpathContext.setVariables(vars); xpathContext.setIdentityManager(this);
vars.addDeprecatedVariable("session"); vars.addDeprecatedVariable("parameters"); jxpc.setVariables(vars);