Example usage for javax.servlet.jsp PageContext getOut

List of usage examples for javax.servlet.jsp PageContext getOut

Introduction

In this page you can find the example usage for javax.servlet.jsp PageContext getOut.

Prototype

abstract public JspWriter getOut();

Source Link

Document

The current value of the out object (a JspWriter).

Usage

From source file:de.micromata.genome.gwiki.page.impl.i18n.GWikiMessageTag.java

@SuppressWarnings("unchecked")
public static void renderPatchDom(PageContext pageContext) throws JspException {
    Object l = pageContext.getAttribute(GWIKI_MESSAGE_ATTR);
    if ((l instanceof List) == false) {
        return;//from ww w .  j  a  v a2s  .c  o m
    }
    List<GWikiMessageTag> tags = (ArrayList<GWikiMessageTag>) l;
    if (tags.isEmpty() == true) {
        return;
    }
    StringBuilder sb = new StringBuilder();
    sb.append("<script type=\"text/javascript\">gwikiPatchI18NElements([");
    boolean first = true;
    for (GWikiMessageTag tag : tags) {
        if (first == false) {
            sb.append(", ");
        } else {
            first = false;
        }
        sb.append("{ id: '" + tag.getTagId() + "', i18nKey: '" + tag.getKeyAttrValue() + "'}");
    }
    sb.append("]);</script>");

    try {
        pageContext.getOut().write(sb.toString());
    } catch (IOException e) {
        throw new JspException(e);
    }

}

From source file:dk.netarkivet.common.webinterface.HTMLUtils.java

/**
 * Prints the header information for the webpages in the GUI. This includes the navigation menu, and links for
 * changing the language.//from   w  w w .  j  av  a  2  s.  com
 *
 * @param title An internationalised title of the page.
 * @param context The context of the web page request.
 * @param refreshInSeconds auto-refresh time in seconds
 * @throws IOException if an error occurs during writing to output.
 */
public static void generateHeader(String title, long refreshInSeconds, PageContext context) throws IOException {
    ArgumentNotValid.checkNotNull(title, "title");
    ArgumentNotValid.checkNotNull(context, "context");

    JspWriter out = context.getOut();
    String url = ((HttpServletRequest) context.getRequest()).getRequestURL().toString();
    Locale locale = context.getResponse().getLocale();
    title = escapeHtmlValues(title);
    log.debug("Loaded URL '" + url + "' with title '" + title + "'");
    out.print(WEBPAGE_HEADER_TEMPLATE_TOP);
    if (refreshInSeconds > 0) {
        out.print(WEBPAGE_HEADER_AUTOREFRESH.replace(TITLE_PLACEHOLDER, Long.toString(refreshInSeconds)));
    }
    out.print(WEBPAGE_HEADER_TEMPLATE_BOTTOM.replace(TITLE_PLACEHOLDER, title).replace(JS_PLACEHOLDER, ""));
    // Start the two column / one row table which fills the page
    out.print("<table id =\"main_table\"><tr>\n");
    // fill in data in the left column
    generateNavigationTree(out, url, locale);
    // The right column contains the active form content for this page
    out.print("<td valign = \"top\" >\n");
    // Language links
    generateLanguageLinks(out);
}

From source file:dk.netarkivet.common.webinterface.HTMLUtils.java

/**
 * Prints the header information for the webpages in the GUI. This includes the navigation menu, and links for
 * changing the language./*from w  w  w .j a v a  2  s .  c o  m*/
 *
 * @param title An internationalised title of the page.
 * @param context The context of the web page request.
 * @param jsToInclude path(s) to external .js files to include in header.
 * @throws IOException if an error occurs during writing to output.
 */
public static void generateHeader(String title, PageContext context, String... jsToInclude) throws IOException {
    ArgumentNotValid.checkNotNull(title, "title");
    ArgumentNotValid.checkNotNull(context, "context");

    JspWriter out = context.getOut();
    String url = ((HttpServletRequest) context.getRequest()).getRequestURL().toString();
    Locale locale = context.getResponse().getLocale();
    title = escapeHtmlValues(title);
    log.debug("Loaded URL '" + url + "' with title '" + title + "'");
    out.print(WEBPAGE_HEADER_TEMPLATE_TOP);

    String includeJs = "";
    if (jsToInclude != null && jsToInclude.length > 0) {
        for (String js : jsToInclude) {
            includeJs += "<script type=\"text/javascript\" src=\"" + js + "\"></script>\n";
        }
    }

    out.print(WEBPAGE_HEADER_TEMPLATE_BOTTOM.replace(TITLE_PLACEHOLDER, title).replace(JS_PLACEHOLDER,
            includeJs));
    // Start the two column / one row table which fills the page
    out.print("<table id =\"main_table\"><tr>\n");
    // fill in data in the left column
    generateNavigationTree(out, url, locale);
    // The right column contains the active form content for this page
    out.print("<td valign = \"top\" >\n");
    // Language links
    generateLanguageLinks(out);
}

From source file:dk.netarkivet.archive.webinterface.BatchGUI.java

/**
 * Method for creating the batchjob overview page. Creates both the heading and the table for the batchjobs defined
 * in settings.//  www .  j a va 2  s  .co  m
 *
 * @param context The context of the page. Contains the locale for the language package.
 * @throws ArgumentNotValid If the PageContext is null.
 * @throws IOException If it is not possible to write to the JspWriter.
 */
public static void getBatchOverviewPage(PageContext context) throws ArgumentNotValid, IOException {
    ArgumentNotValid.checkNotNull(context, "PageContext context");
    JspWriter out = context.getOut();

    // retrieve the jobs etc.
    String[] jobs = Settings.getAll(CommonSettings.BATCHJOBS_CLASS);
    Locale locale = context.getResponse().getLocale();

    if (jobs.length == 0) {
        out.print("<h3>" + I18N.getString(locale, "batchpage;No.batchjobs.defined.in.settings", new Object[] {})
                + "</h3>");
        return;
    }

    // add header for batchjob selection table
    out.print("<table class=\"selection_table\" cols=\"4\">\n");
    out.print("  <tr>\n");
    out.print("    <th>" + I18N.getString(locale, "batchpage;Batchjob", new Object[] {}) + "</th>\n");
    out.print("    <th>" + I18N.getString(locale, "batchpage;Last.run", new Object[] {}) + "</th>\n");
    out.print("    <th>" + I18N.getString(locale, "batchpage;Output.file", new Object[] {}) + "</th>\n");
    out.print("    <th>" + I18N.getString(locale, "batchpage;Error.file", new Object[] {}) + "</th>\n");
    out.print("  </tr>\n");

    for (int i = 0; i < jobs.length; i++) {
        out.print("  <tr Class=\"" + HTMLUtils.getRowClass(i) + "\">\n");
        out.print(getOverviewTableEntry(jobs[i], locale));
        out.print("  </tr>\n");
    }

    out.print("</table>\n");
}

From source file:de.u808.simpleinquest.web.tags.VersionInfoTag.java

@Override
public void doTag() throws JspException, IOException {
    PageContext pageContext = (PageContext) getJspContext();
    JspWriter out = pageContext.getOut();
    try {//from w  w w.  ja v a  2s. c om
        String appServerHome = pageContext.getServletContext().getRealPath("/");

        File manifestFile = new File(appServerHome, "META-INF/MANIFEST.MF");

        Manifest mf = new Manifest();
        mf.read(new FileInputStream(manifestFile));

        Attributes atts = mf.getMainAttributes();

        out.println("<span id=\"version\"> (Revision " + atts.getValue("Implementation-Version") + " Build "
                + atts.getValue("Implementation-Build") + " Built-By " + atts.getValue("Built-By")
                + ")</span>");
    } catch (Exception e) {
        log.error("Tag error", e);
    }
}

From source file:de.u808.simpleinquest.web.tags.MimeIconTag.java

@Override
public void doTag() throws JspException, IOException {
    if (this.mimeIconRegistry == null) {
        this.initMimeIconRegistry();
    }//from  w  ww .jav a 2 s .  c o  m
    PageContext pageContext = (PageContext) getJspContext();
    JspWriter out = pageContext.getOut();
    try {
        if (StringUtils.isNotEmpty(filename)) {
            String iconURI = mimeIconRegistry.getMimeIcon(filename);
            out.println("<img src=\"" + iconURI + "\" alt=\"Letzte Seite\"/>");
        }
    } catch (Exception e) {
        log.error("Tag error", e);
    }
}

From source file:de.u808.simpleinquest.web.tags.HitsNavigationTag.java

public void doTag() throws JspException {
    PageContext pageContext = (PageContext) getJspContext();
    JspWriter out = pageContext.getOut();
    try {/*from   w w w  .j ava2s  . c  o m*/
        boolean isFirstPage = search.getPageIndex() == 0;
        boolean isLastPage = search.getPageIndex() == search.getPageCount() - 1;
        if (!isFirstPage) {
            out.println("<a href=\"search.htm?searchString=" + search.getSearchString() + "&pageIndex=0\"> ");
        }
        out.println("<img src=\"/SimpleInquest/img/start.gif\" alt=\"Erste Seite\"/>");
        if (!isFirstPage) {
            out.println("</a>");
            out.println("<a href=\"search.htm?searchString=" + search.getSearchString() + "&pageIndex="
                    + (search.getPageIndex() - 1) + "\"> ");
        }
        out.println("<img src=\"/SimpleInquest/img/left.gif\" alt=\"Vorherige Seite\"/>");
        if (!isFirstPage) {
            out.println("</a>");
        }
        for (int i = 0; i < search.getPageCount(); i++) {
            if (i != search.getPageIndex()) {
                out.println("<a href=\"search.htm?searchString=" + search.getSearchString() + "&pageIndex=" + i
                        + "\"> " + (i + 1) + "</a>");
            } else {
                out.print(i + 1);
            }
        }
        if (!isLastPage) {
            out.println("<a href=\"search.htm?searchString=" + search.getSearchString() + "&pageIndex="
                    + (search.getPageIndex() + 1) + "\"> ");
        }
        out.println("<img src=\"/SimpleInquest/img/right.gif\" alt=\"Folgende Seite\"/>");
        if (!isLastPage) {
            out.println("</a>");
            out.println("<a href=\"search.htm?searchString=" + search.getSearchString() + "&pageIndex="
                    + (search.getPageCount() - 1) + "\"> ");
        }
        out.println("<img src=\"/SimpleInquest/img/end.gif\" alt=\"Letzte Seite\"/>");
        if (!isLastPage) {
            out.println("</a>");
        }
    } catch (Exception e) {
        log.error("Tag error", e);
    }

}

From source file:com.feilong.taglib.util.TagUtils.java

/**
 * Write the specified text as the response to the writer associated with this page. <strong>WARNING</strong> - If you are writing body
 * content from the <code>doAfterBody()</code> method of a custom tag class that implements <code>BodyTag</code>, you should be calling
 * <code>writePrevious()</code> instead.
 *
 * @param pageContext/*from ww  w. ja  v a 2 s . c  o  m*/
 *            The PageContext object for this page
 * @param text
 *            The text to be written
 * @throws UncheckedIOException
 *             the unchecked io exception
 */
public void write(PageContext pageContext, String text) throws UncheckedIOException {
    JspWriter writer = pageContext.getOut();
    try {
        writer.print(text);
    } catch (IOException e) {
        throw new UncheckedIOException(e);
    }
}

From source file:com.feilong.taglib.util.TagUtils.java

/**
 * Write the specified text as the response to the writer associated with the body content for the tag within which we are currently
 * nested./* w  w  w.j a v  a  2s .  c om*/
 *
 * @param pageContext
 *            The PageContext object for this page
 * @param text
 *            The text to be written
 * @throws UncheckedIOException
 *             the unchecked io exception
 */
public void writePrevious(PageContext pageContext, String text) throws UncheckedIOException {
    JspWriter writer = pageContext.getOut();
    if (writer instanceof BodyContent) {
        writer = ((BodyContent) writer).getEnclosingWriter();
    }
    try {
        writer.print(text);
    } catch (IOException e) {
        throw new UncheckedIOException(e);
    }
}

From source file:i2p.bote.web.PeerInfoTag.java

@Override
public void doTag() {
    PageContext pageContext = (PageContext) getJspContext();
    JspWriter out = pageContext.getOut();

    try {//from w  ww.  j a va2 s. c  om
        // Print DHT peer info
        DhtPeerStats dhtStats = I2PBote.getInstance().getDhtStats();
        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 (List<String> row : dhtStats.getData()) {
                out.println("<tr>");
                for (String cellData : row)
                    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>" + (peer.getBanReason() == null ? "" : peer.getBanReason()) + "</td>");
                out.println("</tr>");
            }

            out.println("</table>");
        }
    } catch (IOException e) {
        log.error("Can't write output to HTML page", e);
    }
}