Example usage for javax.servlet.jsp JspWriter print

List of usage examples for javax.servlet.jsp JspWriter print

Introduction

In this page you can find the example usage for javax.servlet.jsp JspWriter print.

Prototype


abstract public void print(Object obj) throws IOException;

Source Link

Document

Print an object.

Usage

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 ww w .j  a  v a  2 s . c  om*/
 *
 * @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./*from   www.jav  a2  s. c o 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:info.magnolia.cms.taglibs.util.Date.java

/**
 * @see javax.servlet.jsp.tagext.Tag#doStartTag()
 *//* w  w  w.ja va 2 s.  c  om*/
public int doStartTag() {
    if (this.actpage) {
        this.contentNode = Resource.getCurrentActivePage((HttpServletRequest) pageContext.getRequest());
    } else {
        this.contentNode = Resource.getLocalContentNode((HttpServletRequest) pageContext.getRequest());
        if (this.contentNode == null) {
            this.contentNode = Resource.getGlobalContentNode((HttpServletRequest) pageContext.getRequest());
        }
    }
    String printDate = getDateString();
    JspWriter out = pageContext.getOut();
    try {
        out.print(printDate);
    } catch (Exception e) {
        log.error(e.getMessage());
    }
    return EVAL_PAGE;
}

From source file:org.apache.hadoop.hdfs.server.datanode.DatanodeJspHelper.java

static void generateFileChunksForTail(JspWriter out, HttpServletRequest req, Configuration conf)
        throws IOException, InterruptedException {
    String referrer = null;// w  w w. ja  v  a2  s.  co  m
    boolean noLink = false;
    try {
        referrer = new URL(req.getParameter("referrer")).toString();
    } catch (IOException e) {
        referrer = null;
        noLink = true;
    }

    final String filename = JspHelper
            .validatePath(StringEscapeUtils.unescapeHtml(req.getParameter("filename")));
    if (filename == null) {
        out.print("Invalid input (file name absent)");
        return;
    }
    String tokenString = req.getParameter(JspHelper.DELEGATION_PARAMETER_NAME);
    UserGroupInformation ugi = JspHelper.getUGI(req, conf);

    String namenodeInfoPortStr = req.getParameter("namenodeInfoPort");
    String nnAddr = StringEscapeUtils.escapeHtml(req.getParameter(JspHelper.NAMENODE_ADDRESS));
    int namenodeInfoPort = -1;
    if (namenodeInfoPortStr != null)
        namenodeInfoPort = Integer.parseInt(namenodeInfoPortStr);

    final int chunkSizeToView = JspHelper.string2ChunkSizeToView(req.getParameter("chunkSizeToView"),
            getDefaultChunkSize(conf));

    if (!noLink) {
        out.print("<h3>Tail of File: ");
        JspHelper.printPathWithLinks(filename, out, namenodeInfoPort, tokenString, nnAddr);
        out.print("</h3><hr>");
        out.print("<a href=\"" + referrer + "\">Go Back to File View</a><hr>");
    } else {
        out.print("<h3>" + filename + "</h3>");
    }
    out.print("<b>Chunk size to view (in bytes, up to file's DFS block size): </b>");
    out.print("<input type=\"text\" name=\"chunkSizeToView\" value=" + chunkSizeToView
            + " size=10 maxlength=10>");
    out.print("&nbsp;&nbsp;<input type=\"submit\" name=\"submit\" value=\"Refresh\"><hr>");
    out.print("<input type=\"hidden\" name=\"filename\" value=\"" + filename + "\">");
    out.print("<input type=\"hidden\" name=\"namenodeInfoPort\" value=\"" + namenodeInfoPort + "\">");
    out.print("<input type=\"hidden\" name=\"" + JspHelper.NAMENODE_ADDRESS + "\" value=\"" + nnAddr + "\">");
    if (!noLink)
        out.print("<input type=\"hidden\" name=\"referrer\" value=\"" + referrer + "\">");

    // fetch the block from the datanode that has the last block for this file
    final DFSClient dfs = getDFSClient(ugi, nnAddr, conf);
    List<LocatedBlock> blocks = dfs.getNamenode().getBlockLocations(filename, 0, Long.MAX_VALUE)
            .getLocatedBlocks();
    if (blocks == null || blocks.size() == 0) {
        out.print("No datanodes contain blocks of file " + filename);
        dfs.close();
        return;
    }
    LocatedBlock lastBlk = blocks.get(blocks.size() - 1);
    String poolId = lastBlk.getBlock().getBlockPoolId();
    long blockSize = lastBlk.getBlock().getNumBytes();
    long blockId = lastBlk.getBlock().getBlockId();
    Token<BlockTokenIdentifier> accessToken = lastBlk.getBlockToken();
    long genStamp = lastBlk.getBlock().getGenerationStamp();
    DatanodeInfo chosenNode;
    try {
        chosenNode = JspHelper.bestNode(lastBlk, conf);
    } catch (IOException e) {
        out.print(e.toString());
        dfs.close();
        return;
    }
    InetSocketAddress addr = NetUtils.createSocketAddr(chosenNode.getXferAddr());
    // view the last chunkSizeToView bytes while Tailing
    final long startOffset = blockSize >= chunkSizeToView ? blockSize - chunkSizeToView : 0;

    out.print("<textarea cols=\"100\" rows=\"25\" wrap=\"virtual\" style=\"width:100%\" READONLY>");
    JspHelper.streamBlockInAscii(addr, poolId, blockId, accessToken, genStamp, blockSize, startOffset,
            chunkSizeToView, out, conf, dfs.getConf(), dfs, getSaslDataTransferClient(req));
    out.print("</textarea>");
    dfs.close();
}

From source file:net.duckling.ddl.web.tag.ResourceNameTag.java

@Override
public int doEndTag() throws JspException {
    JspWriter j = pageContext.getOut();
    try {//from   w  w w .ja  v  a2s.c  o m
        j.print(getTagConext());
    } catch (IOException e) {
        LOG.error("", e);
    }
    return super.doEndTag();
}

From source file:org.apache.pluto.driver.tags.PortletModeAnchorTag.java

/**
 * Method invoked when the start tag is encountered.
 * @throws JspException  if an error occurs.
 *//*from ww w  .  j  a v a  2 s. c o  m*/
public int doStartTag() throws JspException {

    // Ensure that the modeAnchor tag resides within a portlet tag.
    PortletTag parentTag = (PortletTag) TagSupport.findAncestorWithClass(this, PortletTag.class);
    if (parentTag == null) {
        throw new JspException("Portlet window controls may only reside " + "within a pluto:portlet tag.");
    }

    portletId = parentTag.getPortletId();
    // Evaluate portlet ID attribute.
    evaluatePortletId();

    // Retrieve the portlet window config for the evaluated portlet ID.
    ServletContext servletContext = pageContext.getServletContext();
    DriverConfiguration driverConfig = (DriverConfiguration) servletContext
            .getAttribute(AttributeKeys.DRIVER_CONFIG);

    if (isPortletModeAllowed(driverConfig, portletMode)) {
        // Retrieve the portal environment.
        PortalRequestContext portalEnv = PortalRequestContext
                .getContext((HttpServletRequest) pageContext.getRequest());

        PortalURL portalUrl = portalEnv.createPortalURL();
        portalUrl.setPortletMode(evaluatedPortletId, new PortletMode(portletMode));

        // Build a string buffer containing the anchor tag
        StringBuffer tag = new StringBuffer();
        //            tag.append("<a class=\"" + ToolTips.CSS_CLASS_NAME + "\" href=\"" + portalUrl.toString() + "\">");
        //            tag.append("<span class=\"" + portletMode + "\"></span>");
        //            tag.append("<span class=\"" + ToolTips.CSS_CLASS_NAME + "\">");
        //            tag.append(ToolTips.forMode(new PortletMode(portletMode)));
        //            tag.append("</span></a>");
        tag.append("<a title=\"");
        tag.append(ToolTips.forMode(new PortletMode(portletMode)));
        tag.append("\" ");
        tag.append("href=\"" + portalUrl.toString() + "\">");
        tag.append("<span class=\"" + portletMode + "\"></span>");
        tag.append("</a>");
        // Print the mode anchor tag.
        try {
            JspWriter out = pageContext.getOut();
            out.print(tag.toString());
        } catch (IOException ex) {
            throw new JspException(ex);
        }
    }

    // Continue to evaluate the tag body.
    return EVAL_BODY_INCLUDE;
}

From source file:org.webcurator.ui.common.taglib.HarvestResultChain.java

public void doIt(int ix) throws JspException, IOException {
    JspWriter writer = pageContext.getOut();

    HarvestResult result = chain.get(ix);

    writer.println("<wct:HarvestResult>");
    writer.print("<wct:Creator>");
    writer.print(/*from   w  w  w .  j a v  a2s  .co m*/
            StringEscapeUtils.escapeXml(result.getCreatedBy().getUsername()) + " " + ix + "/" + chain.size());
    writer.println("</wct:Creator>");

    writer.print("<wct:CreationDate>");
    writer.print(dateFormatter.format(result.getCreationDate()));
    writer.println("</wct:CreationDate>");

    writer.print("<wct:ProvenanceNote>");
    writer.print(StringEscapeUtils.escapeXml(result.getProvenanceNote()));
    writer.println("</wct:ProvenanceNote>");

    if (!result.getModificationNotes().isEmpty()) {
        writer.println("<wct:ModificationNotes>");
        for (String note : result.getModificationNotes()) {
            writer.print("<wct:ModificationNote>");
            writer.print(StringEscapeUtils.escapeXml(note));
            writer.println("</wct:ModificationNote>");
        }
        writer.println("</wct:ModificationNotes>");
    }

    if ((ix + 1) < chain.size()) {
        writer.println("<wct:DerivedFrom>");
        doIt(ix + 1);
        writer.println("</wct:DerivedFrom>");
    }

    writer.println("</wct:HarvestResult>");
}

From source file:org.apache.pluto.driver.tags.PortletWindowStateAnchorTag.java

/**
 * Method invoked when the start tag is encountered.
 * @throws JspException  if an error occurs.
 *//*from   ww  w . j  av  a 2s  .  c o  m*/
public int doStartTag() throws JspException {

    // Ensure that the modeAnchor tag resides within a portlet tag.
    PortletTag parentTag = (PortletTag) TagSupport.findAncestorWithClass(this, PortletTag.class);
    if (parentTag == null) {
        throw new JspException("Portlet window controls may only reside " + "within a pluto:portlet tag.");
    }

    portletId = parentTag.getPortletId();
    // Evaluate portlet ID attribute.
    evaluatePortletId();

    // Retrieve the portlet window config for the evaluated portlet ID.
    ServletContext servletContext = pageContext.getServletContext();
    DriverConfiguration driverConfig = (DriverConfiguration) servletContext
            .getAttribute(AttributeKeys.DRIVER_CONFIG);

    if (isWindowStateAllowed(driverConfig, state)) {
        // Retrieve the portal environment.
        PortalRequestContext portalEnv = PortalRequestContext
                .getContext((HttpServletRequest) pageContext.getRequest());

        PortalURL portalUrl = portalEnv.createPortalURL();
        portalUrl.setWindowState(evaluatedPortletId, new WindowState(state));

        // Build a string buffer containing the anchor tag
        StringBuffer tag = new StringBuffer();
        //            tag.append("<a class=\"" + ToolTips.CSS_CLASS_NAME + "\" href=\"" + portalUrl.toString() + "\">");
        //            tag.append("<span class=\"" + state + "\"></span>");
        //            tag.append("<span class=\"" + ToolTips.CSS_CLASS_NAME + "\">");
        //            tag.append(ToolTips.forWindowState(new WindowState(state)));
        //            tag.append("</span></a>");
        tag.append("<a title=\"");
        tag.append(ToolTips.forWindowState(new WindowState(state)));
        tag.append("\" ");
        tag.append("href=\"" + portalUrl.toString() + "\">");
        tag.append("<img border=\"0\" src=\"" + icon + "\" />");
        tag.append("</a>");

        // Print the mode anchor tag.
        try {
            JspWriter out = pageContext.getOut();
            out.print(tag.toString());
        } catch (IOException ex) {
            throw new JspException(ex);
        }
    }

    // Continue to evaluate the tag body.
    return EVAL_BODY_INCLUDE;
}

From source file:jp.terasoluna.fw.web.struts.taglib.ChangeStyleClassTag.java

/**
 * ^O]Jn?\bh?B/*from  w ww  .  ja v  a 2 s . c o  m*/
 * G?[L?oX^CV?[gNX?X?B
 *
 * @return ???w
 * @throws JspException JSPO
 */
@Override
public int doStartTag() throws JspException {
    HttpServletRequest req = (HttpServletRequest) pageContext.getRequest();
    if (req == null) {
        return SKIP_BODY;
    }
    String result = chooseClass(req, this.name, this.defaultValue, this.errorValue);
    try {
        JspWriter out = pageContext.getOut();
        out.print(result);
    } catch (IOException e) {
        log.error("Output failed.");
        throw new JspTagException(e.toString());
    }
    return EVAL_BODY_INCLUDE;
}

From source file:ams.fwk.customtag.AmsDownloadTag.java

/**
 * @return int/*ww w  . ja  va 2s .com*/
 * @throws JspException
 */
public int doEndTag() throws JspException {
    String context = getContextPath(pageContext);
    try {
        List uploads = getUploads();
        JspWriter out = pageContext.getOut();
        out.print(listOpen);

        for (Iterator all = uploads.iterator(); all.hasNext();) {
            Map each = (Map) all.next();
            if ("IMG".equals(typeId)) {
                String temp = StringUtils.replace(imgTag, "$context$", context);

                temp = StringUtils.replace(temp, "$programId$", (String) each.get("PROGRAM_ID"));
                temp = StringUtils.replace(temp, "$fileSeqNo$", fileSeqNo);
                temp = StringUtils.replace(temp, "$fileId$", (String) each.get("FILE_ID"));

                out.print(temp);

            } else if ("URL".equals(typeId)) {
                String temp = StringUtils.replace(urlTag, "$context$", context);
                temp = StringUtils.replace(temp, "$programId$", (String) each.get("PROGRAM_ID"));
                temp = StringUtils.replace(temp, "$fileSeqNo$", fileSeqNo);
                temp = StringUtils.replace(temp, "$fileId$", (String) each.get("FILE_ID"));

                out.print(temp);
            } else {
                //                   ("N/A".equals(typeId) || typeId.equals(each.get("TYPE_ID"))) {
                String temp = "";
                if ("N".equals(deleteOption)) {
                    temp = StringUtils.replace(listItem, "$deleteImgTag$", "");
                } else {
                    temp = StringUtils.replace(listItem, "$deleteImgTag$", deleteImgTag);
                }
                temp = StringUtils.replace(temp, "$context$", context);
                temp = StringUtils.replace(temp, "$programId$", (String) each.get("PROGRAM_ID"));
                temp = StringUtils.replace(temp, "$fileSeqNo$", fileSeqNo);
                temp = StringUtils.replace(temp, "$fileId$", (String) each.get("FILE_ID"));
                temp = StringUtils.replace(temp, "$filename$", (String) each.get("FILE_NAME"));
                temp = StringUtils.replace(temp, "$filesize$", nexcore.framework.core.util.StringUtils
                        .formatNumber(((BigDecimal) each.get("FILE_SIZE")).toString(), "FINT"));
                out.print(temp);
            }
        }
        out.print(listClose);

        return EVAL_PAGE;
    } catch (IOException e) {
        e.printStackTrace();
        throw new JspException(e);
    } finally {
        typeId = "N/A";
    }
}