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

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

Introduction

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

Prototype

public static JXPathContext getApplicationContext(ServletContext servletContext) 

Source Link

Document

Returns a JXPathContext bound to the "application" 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  .ja  va  2 s .  c  o m

    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.");
}