Search in sources :

Example 1 with PageContext

use of javax.servlet.jsp.PageContext in project tomcat by apache.

the class ScopedAttributeELResolver method setValue.

@Override
public void setValue(ELContext context, Object base, Object property, Object value) {
    Objects.requireNonNull(context);
    if (base == null) {
        context.setPropertyResolved(base, property);
        if (property != null) {
            String key = property.toString();
            PageContext page = (PageContext) context.getContext(JspContext.class);
            int scope = page.getAttributesScope(key);
            if (scope != 0) {
                page.setAttribute(key, value, scope);
            } else {
                page.setAttribute(key, value);
            }
        }
    }
}
Also used : JspContext(javax.servlet.jsp.JspContext) PageContext(javax.servlet.jsp.PageContext)

Example 2 with PageContext

use of javax.servlet.jsp.PageContext in project tomcat by apache.

the class ScopedAttributeELResolver method getValue.

@Override
public Object getValue(ELContext context, Object base, Object property) {
    Objects.requireNonNull(context);
    Object result = null;
    if (base == null) {
        context.setPropertyResolved(base, property);
        if (property != null) {
            String key = property.toString();
            PageContext page = (PageContext) context.getContext(JspContext.class);
            result = page.findAttribute(key);
            if (result == null) {
                boolean resolveClass = true;
                // Performance short-cut available when running on Tomcat
                if (AST_IDENTIFIER_KEY != null) {
                    // Tomcat will set this key to Boolean.TRUE if the
                    // identifier is a stand-alone identifier (i.e.
                    // identifier) rather than part of an AstValue (i.e.
                    // identifier.something). Imports do not need to be
                    // checked if this is a stand-alone identifier
                    Boolean value = (Boolean) context.getContext(AST_IDENTIFIER_KEY);
                    if (value != null && value.booleanValue()) {
                        resolveClass = false;
                    }
                }
                // This might be the name of an imported class
                ImportHandler importHandler = context.getImportHandler();
                if (importHandler != null) {
                    Class<?> clazz = null;
                    if (resolveClass) {
                        clazz = importHandler.resolveClass(key);
                    }
                    if (clazz != null) {
                        result = new ELClass(clazz);
                    }
                    if (result == null) {
                        // This might be the name of an imported static field
                        clazz = importHandler.resolveStatic(key);
                        if (clazz != null) {
                            try {
                                result = clazz.getField(key).get(null);
                            } catch (IllegalArgumentException | IllegalAccessException | NoSuchFieldException | SecurityException e) {
                            // Most (all?) of these should have been
                            // prevented by the checks when the import
                            // was defined.
                            }
                        }
                    }
                }
            }
        }
    }
    return result;
}
Also used : JspContext(javax.servlet.jsp.JspContext) ImportHandler(javax.el.ImportHandler) ELClass(javax.el.ELClass) PageContext(javax.servlet.jsp.PageContext)

Example 3 with PageContext

use of javax.servlet.jsp.PageContext in project opennms by OpenNMS.

the class EvaluationTest method createTestContext.

// -------------------------------------
// Test data
// -------------------------------------
/**
 * Creates and returns the test PageContext that will be used for
 * the tests.
 */
static PageContext createTestContext() {
    PageContext ret = new PageContextImpl();
    // Create some basic values for lookups
    ret.setAttribute("val1a", "page-scoped1", PageContext.PAGE_SCOPE);
    ret.setAttribute("val1b", "request-scoped1", PageContext.REQUEST_SCOPE);
    ret.setAttribute("val1c", "session-scoped1", PageContext.SESSION_SCOPE);
    ret.setAttribute("val1d", "app-scoped1", PageContext.APPLICATION_SCOPE);
    // Create a bean
    {
        Bean1 b1 = new Bean1();
        b1.setBoolean1(true);
        b1.setByte1((byte) 12);
        b1.setShort1((short) -124);
        b1.setChar1('b');
        b1.setInt1(4);
        b1.setLong1(222423);
        b1.setFloat1((float) 12.4);
        b1.setDouble1(89.224);
        b1.setString1("hello");
        b1.setStringArray1(new String[] { "string1", "string2", "string3", "string4" });
        {
            List l = new ArrayList();
            l.add(new Integer(14));
            l.add("another value");
            l.add(b1.getStringArray1());
            b1.setList1(l);
        }
        {
            Map m = new HashMap();
            m.put("key1", "value1");
            m.put(new Integer(14), "value2");
            m.put(new Long(14), "value3");
            m.put("recurse", b1);
            b1.setMap1(m);
        }
        ret.setAttribute("bean1a", b1);
        Bean1 b2 = new Bean1();
        b2.setInt2(new Integer(-224));
        b2.setString2("bean2's string");
        b1.setBean1(b2);
        Bean1 b3 = new Bean1();
        b3.setDouble1(1422.332);
        b3.setString2("bean3's string");
        b2.setBean2(b3);
    }
    // Create the public/private beans
    {
        ret.setAttribute("pbean1", Factory.createBean1());
        ret.setAttribute("pbean2", Factory.createBean2());
        ret.setAttribute("pbean3", Factory.createBean3());
        ret.setAttribute("pbean4", Factory.createBean4());
        ret.setAttribute("pbean5", Factory.createBean5());
        ret.setAttribute("pbean6", Factory.createBean6());
        ret.setAttribute("pbean7", Factory.createBean7());
    }
    // Create the empty tests
    {
        Map m = new HashMap();
        m.put("emptyArray", new Object[0]);
        m.put("nonemptyArray", new Object[] { "abc" });
        m.put("emptyList", new ArrayList());
        {
            List l = new ArrayList();
            l.add("hello");
            m.put("nonemptyList", l);
        }
        m.put("emptyMap", new HashMap());
        {
            Map m2 = new HashMap();
            m2.put("a", "a");
            m.put("nonemptyMap", m2);
        }
        m.put("emptySet", new HashSet());
        {
            Set s = new HashSet();
            s.add("hello");
            m.put("nonemptySet", s);
        }
        ret.setAttribute("emptyTests", m);
    }
    return ret;
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) PageContext(javax.servlet.jsp.PageContext) ArrayList(java.util.ArrayList) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map) HashSet(java.util.HashSet)

Example 4 with PageContext

use of javax.servlet.jsp.PageContext in project JessMA by ldcsaa.

the class Error method doTag.

/**
 * 输出标签内容
 */
@Override
public void doTag() throws JspException, IOException {
    PageContext context = (PageContext) getJspContext();
    List<String> list = new ArrayList<String>();
    fillErrorList(context, list);
    if (list.isEmpty())
        return;
    Element e = Element.fromString(element);
    String html = e.write(this, list);
    getJspContext().getOut().print(html);
}
Also used : ArrayList(java.util.ArrayList) PageContext(javax.servlet.jsp.PageContext)

Example 5 with PageContext

use of javax.servlet.jsp.PageContext in project JessMA by ldcsaa.

the class Message method doTag.

/**
 * 输出标签内容
 */
@Override
public void doTag() throws JspException, IOException {
    PageContext context = (PageContext) getJspContext();
    Locale __locale = null;
    if (GeneralHelper.isStrEmpty(locale))
        __locale = (Locale) context.findAttribute(Action.Constant.I18N_ATTR_LOCALE);
    else
        __locale = GeneralHelper.getAvailableLocale(locale);
    if (__locale == null)
        __locale = context.getRequest().getLocale();
    if (GeneralHelper.isStrEmpty(res)) {
        res = (String) getJspContext().getAttribute(Action.Constant.APP_ATTR_DEFAULT_APP_BUNDLE, PageContext.APPLICATION_SCOPE);
        if (res == null)
            res = Action.Constant.DEFAULT_APP_BUNDLE;
    }
    Object[] p = null;
    if (params == null)
        p = new Object[] { p0, p1, p2, p3, p4, p5, p6, p7, p8, p9 };
    else
        p = GeneralHelper.object2Array(params);
    String msg = GeneralHelper.getResourceMessage(__locale, res, key, p);
    if (escape)
        msg = GeneralHelper.escapeXML(msg);
    getJspContext().getOut().print(msg);
}
Also used : Locale(java.util.Locale) PageContext(javax.servlet.jsp.PageContext)

Aggregations

PageContext (javax.servlet.jsp.PageContext)36 JspContext (javax.servlet.jsp.JspContext)12 JspWriter (javax.servlet.jsp.JspWriter)10 IOException (java.io.IOException)6 HttpServletRequest (javax.servlet.http.HttpServletRequest)6 ArrayList (java.util.ArrayList)5 JspException (javax.servlet.jsp.JspException)5 FeatureDescriptor (java.beans.FeatureDescriptor)3 Test (org.junit.Test)2 BannedPeer (i2p.bote.network.BannedPeer)1 DhtPeerStats (i2p.bote.network.DhtPeerStats)1 DhtPeerStatsRow (i2p.bote.network.DhtPeerStatsRow)1 RelayPeer (i2p.bote.network.RelayPeer)1 PrintWriter (java.io.PrintWriter)1 Collection (java.util.Collection)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Locale (java.util.Locale)1 Map (java.util.Map)1