Search in sources :

Example 16 with PageContext

use of javax.servlet.jsp.PageContext in project Openfire by igniterealtime.

the class FlashMessageTag method doTag.

@Override
public void doTag() throws IOException {
    final PageContext pageContext = (PageContext) getJspContext();
    final JspWriter jspWriter = pageContext.getOut();
    final HttpSession session = pageContext.getSession();
    for (final String flash : new String[] { SUCCESS_MESSAGE_KEY, WARNING_MESSAGE_KEY, ERROR_MESSAGE_KEY }) {
        final Object flashValue = session.getAttribute(flash);
        if (flashValue != null) {
            jspWriter.append(String.format("<div class='%s'>%s</div>", flash, flashValue));
            session.setAttribute(flash, null);
        }
    }
}
Also used : HttpSession(javax.servlet.http.HttpSession) PageContext(javax.servlet.jsp.PageContext) JspWriter(javax.servlet.jsp.JspWriter)

Example 17 with PageContext

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

the class ImplicitObjectELResolver method getValue.

@Override
public Object getValue(ELContext context, Object base, Object property) {
    Objects.requireNonNull(context);
    if (base == null && property != null) {
        int idx = Arrays.binarySearch(SCOPE_NAMES, property.toString());
        if (idx >= 0) {
            PageContext page = (PageContext) context.getContext(JspContext.class);
            context.setPropertyResolved(base, property);
            switch(idx) {
                case APPLICATIONSCOPE:
                    return ScopeManager.get(page).getApplicationScope();
                case COOKIE:
                    return ScopeManager.get(page).getCookie();
                case HEADER:
                    return ScopeManager.get(page).getHeader();
                case HEADERVALUES:
                    return ScopeManager.get(page).getHeaderValues();
                case INITPARAM:
                    return ScopeManager.get(page).getInitParam();
                case PAGECONTEXT:
                    return ScopeManager.get(page).getPageContext();
                case PAGESCOPE:
                    return ScopeManager.get(page).getPageScope();
                case PARAM:
                    return ScopeManager.get(page).getParam();
                case PARAM_VALUES:
                    return ScopeManager.get(page).getParamValues();
                case REQUEST_SCOPE:
                    return ScopeManager.get(page).getRequestScope();
                case SESSION_SCOPE:
                    return ScopeManager.get(page).getSessionScope();
            }
        }
    }
    return null;
}
Also used : JspContext(javax.servlet.jsp.JspContext) PageContext(javax.servlet.jsp.PageContext)

Example 18 with PageContext

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

the class ScopedAttributeELResolver method getFeatureDescriptors.

@Override
public Iterator<FeatureDescriptor> getFeatureDescriptors(ELContext context, Object base) {
    PageContext ctxt = (PageContext) context.getContext(JspContext.class);
    List<FeatureDescriptor> list = new ArrayList<>();
    Enumeration<String> e;
    Object value;
    String name;
    e = ctxt.getAttributeNamesInScope(PageContext.PAGE_SCOPE);
    while (e.hasMoreElements()) {
        name = e.nextElement();
        value = ctxt.getAttribute(name, PageContext.PAGE_SCOPE);
        FeatureDescriptor descriptor = new FeatureDescriptor();
        descriptor.setName(name);
        descriptor.setDisplayName(name);
        descriptor.setExpert(false);
        descriptor.setHidden(false);
        descriptor.setPreferred(true);
        descriptor.setShortDescription("page scoped attribute");
        descriptor.setValue("type", value.getClass());
        descriptor.setValue("resolvableAtDesignTime", Boolean.FALSE);
        list.add(descriptor);
    }
    e = ctxt.getAttributeNamesInScope(PageContext.REQUEST_SCOPE);
    while (e.hasMoreElements()) {
        name = e.nextElement();
        value = ctxt.getAttribute(name, PageContext.REQUEST_SCOPE);
        FeatureDescriptor descriptor = new FeatureDescriptor();
        descriptor.setName(name);
        descriptor.setDisplayName(name);
        descriptor.setExpert(false);
        descriptor.setHidden(false);
        descriptor.setPreferred(true);
        descriptor.setShortDescription("request scope attribute");
        descriptor.setValue("type", value.getClass());
        descriptor.setValue("resolvableAtDesignTime", Boolean.FALSE);
        list.add(descriptor);
    }
    if (ctxt.getSession() != null) {
        e = ctxt.getAttributeNamesInScope(PageContext.SESSION_SCOPE);
        while (e.hasMoreElements()) {
            name = e.nextElement();
            value = ctxt.getAttribute(name, PageContext.SESSION_SCOPE);
            FeatureDescriptor descriptor = new FeatureDescriptor();
            descriptor.setName(name);
            descriptor.setDisplayName(name);
            descriptor.setExpert(false);
            descriptor.setHidden(false);
            descriptor.setPreferred(true);
            descriptor.setShortDescription("session scoped attribute");
            descriptor.setValue("type", value.getClass());
            descriptor.setValue("resolvableAtDesignTime", Boolean.FALSE);
            list.add(descriptor);
        }
    }
    e = ctxt.getAttributeNamesInScope(PageContext.APPLICATION_SCOPE);
    while (e.hasMoreElements()) {
        name = e.nextElement();
        value = ctxt.getAttribute(name, PageContext.APPLICATION_SCOPE);
        FeatureDescriptor descriptor = new FeatureDescriptor();
        descriptor.setName(name);
        descriptor.setDisplayName(name);
        descriptor.setExpert(false);
        descriptor.setHidden(false);
        descriptor.setPreferred(true);
        descriptor.setShortDescription("application scoped attribute");
        descriptor.setValue("type", value.getClass());
        descriptor.setValue("resolvableAtDesignTime", Boolean.FALSE);
        list.add(descriptor);
    }
    return list.iterator();
}
Also used : JspContext(javax.servlet.jsp.JspContext) FeatureDescriptor(java.beans.FeatureDescriptor) ArrayList(java.util.ArrayList) PageContext(javax.servlet.jsp.PageContext)

Example 19 with PageContext

use of javax.servlet.jsp.PageContext in project jodd by oblac.

the class DebugTag method doTag.

@Override
public void doTag() throws JspException, IOException {
    PageContext pageContext = (PageContext) getJspContext();
    JspWriter out = getJspContext().getOut();
    out.println(ServletUtil.debug(pageContext));
}
Also used : PageContext(javax.servlet.jsp.PageContext) JspWriter(javax.servlet.jsp.JspWriter)

Example 20 with PageContext

use of javax.servlet.jsp.PageContext in project spring-framework by spring-projects.

the class MessageTagTests method messageTagWithNullCode.

@Test
public void messageTagWithNullCode() throws JspException {
    PageContext pc = createPageContext();
    final StringBuffer message = new StringBuffer();
    MessageTag tag = new MessageTag() {

        @Override
        protected void writeMessage(String msg) {
            message.append(msg);
        }
    };
    tag.setPageContext(pc);
    tag.setCode(null);
    assertTrue("Correct doStartTag return value", tag.doStartTag() == Tag.EVAL_BODY_INCLUDE);
    assertEquals("Correct doEndTag return value", Tag.EVAL_PAGE, tag.doEndTag());
    assertEquals("Correct message", "null", message.toString());
}
Also used : PageContext(javax.servlet.jsp.PageContext) Test(org.junit.Test)

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