Search in sources :

Example 26 with PageContext

use of javax.servlet.jsp.PageContext in project Sylvanas by ceruleannn.

the class ImplicitObjectELResolver method getValue.

@Override
public Object getValue(ELContext context, Object base, Object property) throws NullPointerException, PropertyNotFoundException, ELException {
    if (context == null) {
        throw new NullPointerException();
    }
    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(true);
            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 27 with PageContext

use of javax.servlet.jsp.PageContext in project Sylvanas by ceruleannn.

the class ScopedAttributeELResolver method getValue.

@Override
public Object getValue(ELContext context, Object base, Object property) throws NullPointerException, PropertyNotFoundException, ELException {
    if (context == null) {
        throw new NullPointerException();
    }
    if (base == null) {
        context.setPropertyResolved(true);
        if (property != null) {
            String key = property.toString();
            PageContext page = (PageContext) context.getContext(JspContext.class);
            return page.findAttribute(key);
        }
    }
    return null;
}
Also used : JspContext(javax.servlet.jsp.JspContext) PageContext(javax.servlet.jsp.PageContext)

Example 28 with PageContext

use of javax.servlet.jsp.PageContext in project Sylvanas by ceruleannn.

the class ScopedAttributeELResolver method setValue.

@Override
public void setValue(ELContext context, Object base, Object property, Object value) throws NullPointerException, PropertyNotFoundException, PropertyNotWritableException, ELException {
    if (context == null) {
        throw new NullPointerException();
    }
    if (base == null) {
        context.setPropertyResolved(true);
        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 29 with PageContext

use of javax.servlet.jsp.PageContext in project i2p.i2p-bote by i2p.

the class PeerInfoTag method doTag.

@Override
public void doTag() {
    PageContext pageContext = (PageContext) getJspContext();
    JspWriter out = pageContext.getOut();
    try {
        // Print DHT peer info
        DhtPeerStats dhtStats = I2PBote.getInstance().getDhtStats(new WebappPeerStatsRenderer());
        if (dhtStats == null)
            return;
        int numDhtPeers = dhtStats.getData().size();
        // Get a sorted list of relay peers
        RelayPeer[] relayPeers = I2PBote.getInstance().getRelayPeers().toArray(new RelayPeer[0]);
        Arrays.sort(relayPeers, new Comparator<RelayPeer>() {

            @Override
            public int compare(RelayPeer peer1, RelayPeer peer2) {
                return peer2.getReachability() - peer1.getReachability();
            }
        });
        // Print charts
        out.println("<div class=\"network-charts\">");
        out.println("<div class=\"chart\">");
        out.println("<img src=\"displayChart?filename=" + createDhtChart(dhtStats) + "\"/>");
        out.println("<div class=\"chart-text\">" + numDhtPeers + "</div>");
        out.println("</div>");
        out.println("<div class=\"chart\">");
        out.println("<img src=\"displayChart?filename=" + createRelayChart(relayPeers) + "\"/>");
        out.println("<div class=\"chart-text\">" + relayPeers.length + "</div>");
        out.println("</div>");
        out.println("</div>");
        out.println("<br>");
        out.println("<span class=\"subheading\">" + _t("Kademlia Peers:") + " " + numDhtPeers + "</span>");
        if (numDhtPeers > 0) {
            out.println("<table");
            // header
            out.println("<tr>");
            for (String columnHeader : dhtStats.getHeader()) out.println("<th>" + columnHeader + "</th>");
            out.println("</tr>");
            // data
            for (DhtPeerStatsRow row : dhtStats.getData()) {
                out.println("<tr>");
                for (String cellData : row.toStrings()) out.println("<td class=\"ellipsis\">" + cellData + "</td>");
                out.println("</tr>");
            }
            out.println("</table>");
        }
        out.println("<br/>");
        // Print relay peer info
        out.println("<span class=\"subheading\">" + _t("Relay Peers:") + " " + relayPeers.length + "</span>");
        if (relayPeers.length > 0) {
            out.println("<table");
            out.println("<tr>");
            out.println("<th>" + _t("Peer") + "</th>");
            out.println("<th>" + _t("I2P Destination") + "</th>");
            out.println("<th>" + _t("Reachability %") + "</th>");
            out.println("</tr>");
            int i = 1;
            for (RelayPeer peer : relayPeers) {
                out.println("<tr>");
                out.println("<td>" + i + "</td>");
                out.println("<td class=\"ellipsis\">" + Util.toBase32(peer) + "</td>");
                int reachability = peer.getReachability();
                out.println("<td>" + (reachability == 0 ? _t("Untested") : reachability) + "</td>");
                out.println("</tr>");
                i++;
            }
            out.println("</table>");
        }
        out.println("<br/>");
        // List banned peers
        Collection<BannedPeer> bannedPeers = I2PBote.getInstance().getBannedPeers();
        out.println("<span class=\"subheading\">" + _t("Banned Peers:") + " " + bannedPeers.size() + "</span>");
        if (bannedPeers.size() > 0) {
            out.println("<table>");
            out.println("<tr>");
            out.println("<th>" + _t("Peer") + "</th>");
            out.println("<th>" + _t("Destination Hash") + "</th>");
            out.println("<th>" + _t("Ban Reason") + "</th>");
            out.println("</tr>");
            int peerIndex = 1;
            for (BannedPeer peer : bannedPeers) {
                out.println("<tr>");
                out.println("<td>" + peerIndex++ + "</td>");
                out.println("<td class=\"ellipsis\">" + Util.toBase32(peer.getDestination()) + "</td>");
                out.println("<td>" + getBanReason(peer) + "</td>");
                out.println("</tr>");
            }
            out.println("</table>");
        }
    } catch (IOException e) {
        log.error("Can't write output to HTML page", e);
    }
}
Also used : DhtPeerStatsRow(i2p.bote.network.DhtPeerStatsRow) RelayPeer(i2p.bote.network.RelayPeer) IOException(java.io.IOException) JspWriter(javax.servlet.jsp.JspWriter) BannedPeer(i2p.bote.network.BannedPeer) DhtPeerStats(i2p.bote.network.DhtPeerStats) PageContext(javax.servlet.jsp.PageContext)

Example 30 with PageContext

use of javax.servlet.jsp.PageContext in project i2p.i2p-bote by i2p.

the class QuoteTag method doTag.

@Override
public void doTag() {
    PageContext pageContext = (PageContext) getJspContext();
    JspWriter out = pageContext.getOut();
    try {
        StringBuilder quotation = new StringBuilder();
        String[] lines = text.split("\r?\n|\r");
        for (String line : lines) quotation = quotation.append("&gt; ").append(line).append("\n");
        out.println(quotation);
    } catch (IOException e) {
        log.error("Can't write output to HTML page", e);
    }
}
Also used : PageContext(javax.servlet.jsp.PageContext) IOException(java.io.IOException) JspWriter(javax.servlet.jsp.JspWriter)

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