Example usage for javax.servlet.jsp.el VariableResolver VariableResolver

List of usage examples for javax.servlet.jsp.el VariableResolver VariableResolver

Introduction

In this page you can find the example usage for javax.servlet.jsp.el VariableResolver VariableResolver.

Prototype

VariableResolver

Source Link

Usage

From source file:com.agilejava.docbkx.maven.ExpressionEvaluatorTest.java

/**
 * DOCUMENT ME!/*from   ww w  . j ava  2s .  c om*/
 *
 * @throws ELException DOCUMENT ME!
 */
public void testEvaluator() throws ELException {
    ExpressionEvaluator evaluator = new ExpressionEvaluatorImpl();
    final Map foo = new HashMap();
    foo.put("bar", "whatever");

    Object result = evaluator.evaluate("${foo.bar}", Object.class, new VariableResolver() {
        public Object resolveVariable(String name) throws ELException {
            System.out.println(name);

            return foo;
        }
    }, new FunctionMapper() {
        public Method resolveFunction(String arg0, String arg1) {
            // TODO Auto-generated method stub
            return null;
        }
    });

    System.out.println(result);
}

From source file:freemarker.ext.jsp._FreeMarkerPageContext2.java

/**
 * Returns a variable resolver that will resolve variables by searching through
 * the page scope, request scope, session scope and application scope for an
 * attribute with a matching name./*www . j a v  a2 s.  c  o m*/
 */
public VariableResolver getVariableResolver() {
    final PageContext ctx = this;

    return new VariableResolver() {
        public Object resolveVariable(String name) throws ELException {
            return ctx.findAttribute(name);
        }
    };
}

From source file:de.micromata.genome.gwiki.page.gspt.StandAlonePageContext.java

public StandAlonePageContext(JspWriter jspWriter, ServletContext servletContext, HttpServletRequest request,
        HttpServletResponse response) {//from  w w w.  j  av  a2 s  .  c om
    this.writer = jspWriter;
    this.request = request;
    this.response = response;
    this.servletCtx = servletContext != null ? servletContext : new ServletContextMock();
    initScopes();
    this.resolver = new VariableResolver() {
        public Object resolveVariable(String key) throws ELException {
            return findAttribute(key);
        }
    };
}

From source file:freemarker.ext.jsp._FreeMarkerPageContext21.java

/**
 * Returns a variable resolver that will resolve variables by searching through
 * the page scope, request scope, session scope and application scope for an
 * attribute with a matching name.//from  w  w w.j  av  a  2s .co  m
 */
@Override
public VariableResolver getVariableResolver() {
    final PageContext ctx = this;

    return new VariableResolver() {
        public Object resolveVariable(String name) throws ELException {
            return ctx.findAttribute(name);
        }
    };
}

From source file:de.micromata.genome.gwiki.page.gspt.ServletStandalonePageContext.java

@Override
public void initialize(Servlet servlet, ServletRequest request, ServletResponse response, String errorPageURL,
        boolean needsSession, int bufferSize, boolean autoFlush)
        throws IOException, IllegalStateException, IllegalArgumentException {

    this.request = (HttpServletRequest) request;
    this.response = (HttpServletResponse) response;
    this.servlet = (HttpServlet) servlet;
    PrintWriterPatched pout = new PrintWriterPatched(response.getOutputStream());
    GspJspWriter gsptWriter = new GspJspWriter(pout);
    this.writer = gsptWriter;
    this.servletCtx = this.servlet.getServletContext();
    this.session = this.request.getSession(false);

    this.resolver = new VariableResolver() {

        public Object resolveVariable(String key) throws ELException {
            return findAttribute(key);
        }//from w ww  .j  av  a2 s . c  o m

    };
}

From source file:com.streamsets.datacollector.el.ELEvaluator.java

@Override
@SuppressWarnings("unchecked")
public <T> T evaluate(final ELVars vars, String expression, Class<T> returnType) throws ELEvalException {
    VariableResolver variableResolver = new VariableResolver() {

        @Override/*  w w  w .j ava 2s  . co  m*/
        public Object resolveVariable(String name) throws ELException {
            Object value = constants.get(name);
            if (!vars.hasVariable(name)) {
                if (value == null && !constants.containsKey(name)) {
                    throw new ELException(Utils.format("Constants/Variable '{}' cannot be resolved", name));
                }
            } else {
                value = vars.getVariable(name);
            }
            return value;
        }
    };
    try {
        return (T) EVALUATOR.evaluate(expression, returnType, variableResolver, functionMapper);
    } catch (ELException e) {
        LOG.debug("Error valuating EL '{}': {}", expression, e.toString(), e);
        Throwable t = e;
        if (e.getRootCause() != null) {
            t = e.getRootCause();
        }
        throw new ELEvalException(CommonError.CMN_0104, expression, t.toString(), e);
    }
}

From source file:com.agilejava.docbkx.maven.AbstractTransformerMojo.java

/**
 * Creates an XML Processing handler for the built-in docbkx <code>&lt;?eval?&gt;</code> PI. This PI resolves maven
 * properties and basic math formula.// w w  w  . ja  v a  2  s.  c  o m
 *
 * @param resolver The initial resolver to use.
 * @param reader   The source XML reader.
 * @return The XML PI filter.
 */
private PreprocessingFilter createPIHandler(EntityResolver resolver, XMLReader reader) {
    PreprocessingFilter filter = new PreprocessingFilter(reader);
    ProcessingInstructionHandler resolvingHandler = new ExpressionHandler(new VariableResolver() {

        public Object resolveVariable(String name) throws ELException {
            if ("date".equals(name)) {
                return DateFormat.getDateInstance(DateFormat.LONG).format(new Date());
            } else if ("project".equals(name)) {
                return getMavenProject();
            } else {
                return getMavenProject().getProperties().get(name);
            }
        }

    }, getLog());
    filter.setHandlers(Arrays.asList(new Object[] { resolvingHandler }));
    filter.setEntityResolver(resolver);
    return filter;
}

From source file:org.codehaus.groovy.grails.web.pages.ext.jsp.GroovyPagesPageContext.java

@Override
public VariableResolver getVariableResolver() {
    final PageContext ctx = this;
    return new VariableResolver() {
        public Object resolveVariable(String name) throws ELException {
            return ctx.findAttribute(name);
        }// www. j a  v a  2s .co m
    };
}

From source file:org.netbeans.jmiimpl.omg.uml.foundation.core.TaggedValueImpl.java

private void append(StringBuffer sb, Collection contents) {
    for (Iterator it = contents.iterator(); it.hasNext();) {
        Object o = it.next();/*  w  w w. j  av a2 s .  c o  m*/
        try {
            VariableResolver vr = new VariableResolver() {
                public Object resolveVariable(String string) {
                    Object result = null;
                    if (string.equals("model")) {
                        result = getModelElement().refOutermostPackage();
                    } else if (string.equals("parent")) {
                        result = getModelElement();
                    }
                    return result;
                }
            };
            String result = (String) ev.evaluate(o.toString(), String.class, vr, null);
            if (result.length() > 0) {
                if (sb.length() > 0) {
                    sb.append(" ");
                }
                sb.append(result);
            }
        } catch (ELException e) {
            throw new RuntimeException(e);
        }
    }
}