Example usage for org.apache.commons.jxpath.servlet JXPathServletContexts getSessionContext

List of usage examples for org.apache.commons.jxpath.servlet JXPathServletContexts getSessionContext

Introduction

In this page you can find the example usage for org.apache.commons.jxpath.servlet JXPathServletContexts getSessionContext.

Prototype

public static JXPathContext getSessionContext(HttpSession session, ServletContext servletContext) 

Source Link

Document

Returns a JXPathContext bound to the "session" scope.

Usage

From source file:com.netspective.sparx.console.form.InspectObject.java

public void execute(Writer writer, DialogContext dc) throws IOException, DialogExecuteException {
    JXPathContext jxPathContext = null;//from  ww w.j  av  a  2 s  . com

    DialogFieldStates fieldStates = dc.getFieldStates();
    String contextValue = fieldStates.getState("context").getValue().getTextValue();
    String jxPathExprValue = fieldStates.getState("jxpath-expr").getValue().getTextValue();
    String action = fieldStates.getState("action").getValue().getTextValue();

    if (contextValue.equalsIgnoreCase("Project"))
        jxPathContext = JXPathContext.newContext(dc.getProject());
    else if (contextValue.equalsIgnoreCase("Servlet"))
        jxPathContext = JXPathContext.newContext(dc.getServlet());
    else if (contextValue.equalsIgnoreCase("Application"))
        jxPathContext = JXPathServletContexts
                .getApplicationContext(dc.getServlet().getServletConfig().getServletContext());
    else if (contextValue.equalsIgnoreCase("Request"))
        jxPathContext = JXPathServletContexts.getRequestContext(dc.getRequest(),
                dc.getServlet().getServletConfig().getServletContext());
    else if (contextValue.equalsIgnoreCase("Session"))
        jxPathContext = JXPathServletContexts.getSessionContext(dc.getHttpRequest().getSession(),
                dc.getServlet().getServletConfig().getServletContext());

    Object jxPathValue = null;
    if (action.equalsIgnoreCase("getValue"))
        jxPathValue = jxPathContext.getValue(jxPathExprValue);
    else
        jxPathValue = jxPathContext.iterate(jxPathExprValue);

    if (jxPathValue != null) {
        Map vars = new HashMap();
        vars.put("jxPathValue", jxPathValue);
        vars.put("jxPathExpr", jxPathExprValue);
        inspectJxPathValueTemplate.process(writer, dc, vars);
    } else
        writer.write("JXPath expression '" + jxPathExprValue + "' evaluated to NULL.");
}