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:com.camel.framework.tag.StaticTag.java

@Override
public int doStartTag() throws JspException {
    this.pageContext.getServletConfig();
    // jspJspWriter
    JspWriter out = this.pageContext.getOut();

    // environmentConfig.xml?????value
    String resourcesUrl = null;//from  w ww. j  ava 2s .  c om
    if (null != ConfigParamMap.getConfigParamMap()) {
        ConfigParamMap.getValue(IEnvironmentConfigBasic.RESOURCES_URL);
    }

    // ?null??URL
    if (null == resourcesUrl) {
        HttpServletRequest request = (HttpServletRequest) this.pageContext.getRequest();
        resourcesUrl = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
                + request.getContextPath();
    }

    if (StringUtils.isNotBlank(resourcesUrl)) {
        try {
            // ?resourcesUrl?????
            out.print(resourcesUrl);
        } catch (IOException e) {
            logger.error("Could not print out value '" + resourcesUrl, e);
        }
    } else {
        logger.error("resourcesUrl is null,so static tag is invalid");
    }

    return SKIP_BODY;
}

From source file:org.codelabor.system.web.taglib.CurrentIndexTag.java

@Override
public void doTag() throws JspException, IOException {
    logger.debug("doTag");

    parent = (PaginationTag) getParent();
    JspWriter out = getJspContext().getOut();

    // first page number of previous
    logger.debug("firstPageNoOnCurrentIndex: {}", parent.getFirstPageNoOnCurrentIndex());
    StringBuilder sb = new StringBuilder();
    for (int i = parent.getFirstPageNoOnCurrentIndex(); (i <= parent.getLastPageNoOnCurrentIndex())
            && (i <= parent.getLastPageNo()); i++) {
        logger.debug("pageNo: {}", i);
        sb.setLength(0);//from ww w  . j a v a  2s. c om
        sb.trimToSize();
        if (i == parent.getCurrentPageNo()) {
            sb.append("<span>").append(i).append("</span>");
        } else {
            sb.append(this.generateAnchorTagForCurrentIndex(parent.getQueryString(), i,
                    parent.getMaxRowPerPage()));
        }
        sb.append(System.getProperty("line.separator"));
        out.print(sb.toString());
    }
    logger.debug("lastPageNoOnCurrentIndex: {}", parent.getLastPageNoOnCurrentIndex());
}

From source file:edu.wustl.common.util.tag.AutoCompleteTag.java

/**
 * A call back function, which gets executed by JSP runtime when opening tag
 * for this custom tag is encountered./*w ww .  ja  v  a 2s.com*/
 * @exception JspException jsp exception.
 * @return integer value to skip body.
 */
public int doStartTag() throws JspException {

    try {
        JspWriter out = pageContext.getOut();
        String autocompleteHTMLStr = null;
        if (staticField.equalsIgnoreCase(TRUE)) {
            autocompleteHTMLStr = getAutocompleteHTML();
        } else {
            autocompleteHTMLStr = getAutocompleteHTMLForDynamicProperty();
        }

        clearTagVariables();

        out.print(autocompleteHTMLStr);
    } catch (IOException ioe) {
        LOGGER.debug(ioe.getMessage(), ioe);
        throw new JspTagException("Error:IOException while writing to the user");
    }

    return SKIP_BODY;
}

From source file:com.xhsoft.framework.common.page.PageTag.java

/**
 * <p>Description: ?</p>/*from   ww  w . j  av  a2 s. com*/
 * @param pageNo 
 * @param request
 * @return void
 * @author wenzhi
 * @version 1.0
 * @exception JspException
 */
private void printOutFront(int pageNo, HttpServletRequest request) throws JspException {

    try {
        String first = "";
        String prev = "";
        JspWriter out = pageContext.getOut();
        String outString = "";
        if (pageNo == 1) {
            outString = "" + " " + first + "&nbsp;&nbsp;" + " " + prev + "&nbsp;&nbsp;";
        } else {
            Integer prePage = new Integer(pageNo == 1 ? pageNo : pageNo - 1);
            outString = "" + "<a href=\"javascript:setPage('" + 1 + "','" + targets + "');\">" + first
                    + "&nbsp;</a>&nbsp;" + "<a href=\"javascript:setPage('" + prePage + "','" + targets
                    + "');\">" + prev + "&nbsp;</a>&nbsp;";
        }
        out.print(outString);
    } catch (Exception e) {
        throw new JspException(e);
    }

}

From source file:net.swas.explorer.httpprofile.DOProfile.java

/**
 * This function generates tree based on specified parent.
 * @param parent parent node of application profile
 * @param out out is JspWriter object, for writing on JSP page
 * @throws Exception//  ww w.j a  v a 2 s  .  com
 */
public void generateTree(String parent, JspWriter out) throws Exception

{
    String sql_qry = "select count(*) as total from pairs";
    PreparedStatement pstmt = (PreparedStatement) cdb.prepareQuery(sql_qry);
    ResultSet rs = cdb.executeQuery(pstmt);
    rs.next();

    ArrayList<String> child = this.getChilds(parent, out);
    for (String string : child) {

        if (this.getChilds(string, out).size() == 0) {

            out.print("<li><a href=\"resourceDescription.jsp?node=" + string + "\">" + string + "</a>" + string
                    + "</li>\n");
            System.out.println("<li><a href=\"resourceDescription.jsp?node=" + string + "\">" + string + "</a>"
                    + string + "</li>\n");

        } else {

            out.print("<li id=\"key3\" class=\"folder\">" + string + "\n");
            out.print("<ul>\n");
            generateTree(string, out);
            out.print("</ul>\n");

        }

    }

}

From source file:org.hyperic.hq.ui.taglib.HelpTag.java

public int doStartTag() throws JspException {
    JspWriter output = pageContext.getOut();
    String helpURL = HELP_BASE_URL;
    String helpUrlFromProFile = null;

    if (context) {
        ServletContext servletContext = pageContext.getServletContext();
        if (servletContext != null) {
            helpUrlFromProFile = (String) servletContext.getAttribute("helpBaseURL");
            log.debug("helpUrlFromPropertyFile=" + helpUrlFromProFile);
        }/*  w w  w.j a va  2s.  c  om*/
        if (!StringUtils.isEmpty(helpUrlFromProFile)) {
            helpURL = helpUrlFromProFile;
        }

        /* ignore context for now   
         *   String helpContext = (String) pageContext.getRequest().getAttribute(Constants.PAGE_TITLE_KEY);
                      
              if ( helpContext != null)
        helpURL = helpURL + "/?key=ui-" + helpContext;
        */
    }
    //helpURL+=key;      

    try {
        output.print(helpURL);
    } catch (IOException e) {
        throw new JspException(e);
    }

    return SKIP_BODY;
}

From source file:info.magnolia.templating.jsp.taglib.SimpleNavigationTag.java

/**
 * Draws page children as an unordered list.
 * //w w  w.ja  va  2s.  c o  m
 * @param page current page
 * @param activePage active page
 * @param out jsp writer
 * @throws IOException jspwriter exception
 * @throws RepositoryException any exception thrown during repository reading
 */
private void drawChildren(Content page, Content activePage, JspWriter out)
        throws IOException, RepositoryException {

    Collection<Content> children = new ArrayList<Content>(page.getChildren(ItemType.CONTENT));

    if (children.size() == 0) {
        return;
    }

    out.print("<ul class=\"level");
    out.print(page.getLevel());
    if (style != null && page.getLevel() == startLevel) {
        out.print(" ");
        out.print(style);
    }
    out.print("\">");

    Iterator<Content> iter = children.iterator();
    // loop through all children and discard those we don't want to display
    while (iter.hasNext()) {
        final Content child = iter.next();

        if (expandAll.equalsIgnoreCase(EXPAND_NONE) || expandAll.equalsIgnoreCase(EXPAND_SHOW)) {
            if (child.getNodeData(StringUtils.defaultString(this.hideInNav, DEFAULT_HIDEINNAV_NODEDATA))
                    .getBoolean()) {
                iter.remove();
                continue;
            }
            // use a filter
            if (filter != null) {
                if (!filter.accept(child)) {
                    iter.remove();
                    continue;
                }
            }
        } else {
            if (child.getNodeData(StringUtils.defaultString(this.hideInNav, DEFAULT_HIDEINNAV_NODEDATA))
                    .getBoolean()) {
                iter.remove();
                continue;
            }
        }
    }

    boolean isFirst = true;
    Iterator<Content> visibleIt = children.iterator();
    while (visibleIt.hasNext()) {
        Content child = visibleIt.next();
        List<String> cssClasses = new ArrayList<String>(4);

        NodeData nodeData = I18nContentSupportFactory.getI18nSupport().getNodeData(child,
                NODEDATA_NAVIGATIONTITLE);
        String title = null;
        if (nodeData != null) {
            title = nodeData.getString(StringUtils.EMPTY);
        }

        // if nav title is not set, the main title is taken
        if (StringUtils.isEmpty(title)) {
            title = child.getTitle();
        }

        // if main title is not set, the name of the page is taken
        if (StringUtils.isEmpty(title)) {
            title = child.getName();
        }

        boolean showChildren = false;
        boolean self = false;

        if (!expandAll.equalsIgnoreCase(EXPAND_NONE)) {
            showChildren = true;
        }

        if (activePage.getHandle().equals(child.getHandle())) {
            // self
            showChildren = true;
            self = true;
            cssClasses.add(CSS_LI_ACTIVE);
        } else if (!showChildren) {
            showChildren = child.getLevel() <= activePage.getAncestors().size() && StringUtils
                    .equals(activePage.getAncestor(child.getLevel()).getHandle(), child.getHandle());
        }

        if (!showChildren) {
            showChildren = child
                    .getNodeData(StringUtils.defaultString(this.openMenu, DEFAULT_OPENMENU_NODEDATA))
                    .getBoolean();
        }

        if (endLevel > 0) {
            showChildren &= child.getLevel() < endLevel;
        }

        cssClasses.add(hasVisibleChildren(child) ? showChildren ? CSS_LI_OPEN : CSS_LI_CLOSED : CSS_LI_LEAF);

        if (child.getLevel() < activePage.getLevel()
                && activePage.getAncestor(child.getLevel()).getHandle().equals(child.getHandle())) {
            cssClasses.add(CSS_LI_TRAIL);
        }

        if (StringUtils.isNotEmpty(classProperty) && child.hasNodeData(classProperty)) {
            cssClasses.add(child.getNodeData(classProperty).getString(StringUtils.EMPTY));
        }

        if (markFirstAndLastElement && isFirst) {
            cssClasses.add(CSS_LI_FIRST);
            isFirst = false;
        }

        if (markFirstAndLastElement && !visibleIt.hasNext()) {
            cssClasses.add(CSS_LI_LAST);
        }

        StringBuffer css = new StringBuffer(cssClasses.size() * 10);
        Iterator<String> iterator = cssClasses.iterator();
        while (iterator.hasNext()) {
            css.append(iterator.next());
            if (iterator.hasNext()) {
                css.append(" ");
            }
        }

        out.print("<li class=\"");
        out.print(css.toString());
        out.print("\">");

        if (self) {
            out.println("<strong>");
        }

        String accesskey = null;
        if (child.getNodeData(NODEDATA_ACCESSKEY) != null) {
            accesskey = child.getNodeData(NODEDATA_ACCESSKEY).getString(StringUtils.EMPTY);
        }

        out.print("<a href=\"");
        out.print(((HttpServletRequest) this.pageContext.getRequest()).getContextPath());
        out.print(I18nContentSupportFactory.getI18nSupport().toI18NURI(child.getHandle()));
        out.print(".html\"");

        if (StringUtils.isNotEmpty(accesskey)) {
            out.print(" accesskey=\"");
            out.print(accesskey);
            out.print("\"");
        }

        if (nofollow != null && child.getNodeData(this.nofollow).getBoolean()) {
            out.print(" rel=\"nofollow\"");
        }

        out.print(">");

        if (StringUtils.isNotEmpty(this.wrapperElement)) {
            out.print("<" + this.wrapperElement + ">");
        }

        out.print(StringEscapeUtils.escapeHtml(title));

        if (StringUtils.isNotEmpty(this.wrapperElement)) {
            out.print("</" + this.wrapperElement + ">");
        }

        out.print(" </a>");

        if (self) {
            out.println("</strong>");
        }

        if (showChildren) {
            drawChildren(child, activePage, out);
        }
        out.print("</li>");
    }

    out.print("</ul>");
}

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

/**
 * Print HTML formatted state for missing files on a given replica in a given locale.
 *
 * @param out The writer to write state to.
 * @param replica The replica to write state for.
 * @param locale The locale to write state in.
 * @throws IOException On IO trouble writing state to the writer.
 *//*from  w w w.j av  a2  s  . c  o  m*/
public static void printMissingFileStateForReplica(JspWriter out, Replica replica, Locale locale)
        throws IOException {
    ArgumentNotValid.checkNotNull(out, "JspWriter out");
    ArgumentNotValid.checkNotNull(replica, "Replica replica");
    ArgumentNotValid.checkNotNull(locale, "Locale locale");
    ActiveBitPreservation activeBitPreservation = ActiveBitPreservationFactory.getInstance();

    //element id's
    final String replicaName = replica.getName();
    final String numberId = replicaName + "_number";
    final String missingId = replicaName + "_missing";
    final String updatedId = replicaName + "_updated";
    //Header
    out.println(I18N.getString(locale, "filestatus.for") + "&nbsp;<b>" + HTMLUtils.escapeHtmlValues(replicaName)
            + "</b>");
    out.println("<br/>");

    // Number of files, and number of files missing
    out.println(I18N.getString(locale, "number.of.files") + "&nbsp;<span id=\"" + numberId + "\">"
            + HTMLUtils.localiseLong(activeBitPreservation.getNumberOfFiles(replica), locale) + "</span>");
    out.println("<br/>");
    long numberOfMissingFiles = activeBitPreservation.getNumberOfMissingFiles(replica);
    out.println(I18N.getString(locale, "missing.files") + "&nbsp;<span id=\"" + missingId + "\">"
            + HTMLUtils.localiseLong(numberOfMissingFiles, locale) + "</span>");

    if (numberOfMissingFiles > 0) {
        out.print("&nbsp;<a href=\"" + Constants.FILESTATUS_MISSING_PAGE + "?"
                + (Constants.BITARCHIVE_NAME_PARAM + "=" + HTMLUtils.encodeAndEscapeHTML(replicaName))
                + " \">");
        out.print(I18N.getString(locale, "show.missing.files"));
        out.print("</a>");
    }
    out.println("<br/>");
    Date lastMissingFilesupdate = activeBitPreservation.getDateForMissingFiles(replica);
    if (lastMissingFilesupdate == null) {
        lastMissingFilesupdate = new Date(0);
    }
    out.println("<span id=\"" + updatedId + "\">"
            + I18N.getString(locale, "last.update.at.0", lastMissingFilesupdate) + "</span>");
    out.println("<br/>");

    out.println("<a href=\"" + Constants.FILESTATUS_UPDATE_PAGE + "?" + Constants.UPDATE_TYPE_PARAM + "="
            + Constants.FIND_MISSING_FILES_OPTION + "&amp;"
            + (Constants.BITARCHIVE_NAME_PARAM + "=" + HTMLUtils.encodeAndEscapeHTML(replicaName)) + "\">"
            + I18N.getString(locale, "update.filestatus.for.0", replica.getId()) + "</a>");
    out.println("<br/><br/>");
}

From source file:info.magnolia.templating.jsp.taglib.Breadcrumb.java

@Override
public int doStartTag() throws JspException {
    HttpServletRequest request = (HttpServletRequest) pageContext.getRequest();
    int endLevel = 0;

    try {// w w  w  .j a v  a 2 s  .  c om
        Node node = MgnlContext.getJCRSession(MgnlContext.getAggregationState().getRepository())
                .getNode(MgnlContext.getAggregationState().getHandle());
        endLevel = node.getDepth();

        if (this.excludeCurrent) {
            endLevel--;
        }
        int addedcount = 0;

        JspWriter out = pageContext.getOut();
        for (int j = this.startLevel; j <= endLevel; j++) {
            Node ancestor = (Node) node.getAncestor(j);

            if (StringUtils.isNotEmpty(hideProperty) && ancestor.getProperty(hideProperty).getBoolean()) {
                continue;
            }

            String title = null;

            if (StringUtils.isNotEmpty(titleProperty)) {
                title = ancestor.getProperty(titleProperty).getString();
            }

            if (StringUtils.isEmpty(title)) {
                title = ancestor.getName();
            }

            if (StringUtils.isNotEmpty(title)) {
                if (addedcount != 0) {
                    out.print(StringUtils.defaultString(this.delimiter, " &gt; "));
                }
                if (this.link && !(endLevel == j && nolinkCurrent)) {
                    out.print("<a href=\"");
                    out.print(request.getContextPath());
                    out.print(ancestor.getPath());
                    out.print(".");
                    out.print(ServerConfiguration.getInstance().getDefaultExtension());
                    if (node.getPath().equals(ancestor.getPath())) {
                        out.print("\" class=\"");
                        out.print(activeCss);
                    }

                    out.print("\">");

                }
                out.print(title);
                if (this.link && !(endLevel == j && nolinkCurrent)) {
                    out.print("</a>");
                }
                addedcount++;
            }
        }
    } catch (RepositoryException e) {
        log.debug("Exception caught: " + e.getMessage(), e);
    } catch (IOException e) {
        throw new NestableRuntimeException(e);
    }

    return super.doStartTag();
}

From source file:dk.netarkivet.harvester.datamodel.IngestDomainList.java

/**
 * Adds all new domains from a newline-separated file of domain names. The
 * file is assumed to be in the UTF-8 format. For large files, a line is
 * printed to the log, and to the out variable (if not set to null), every
 * PRINT_INTERVAL lines./*from ww  w. j a  v a 2 s .c  o  m*/
 * 
 * @param domainList
 *            the file containing the domain names.
 * @param out
 *            a stream to which output can be sent. May be null.
 * @param theLocale
 *            the given Locale
 */
public void updateDomainInfo(File domainList, JspWriter out, Locale theLocale) {
    ArgumentNotValid.checkNotNull(domainList, "File domainList");
    ArgumentNotValid.checkNotNull(theLocale, "Locale theLocale");
    Domain myDomain;
    String domainName;
    BufferedReader in = null;
    int countDomains = 0;
    boolean print = (out != null);
    try {
        in = new BufferedReader(new InputStreamReader(new FileInputStream(domainList), "UTF-8"));

        while ((domainName = in.readLine()) != null) {
            try {
                countDomains++;
                if ((countDomains % PRINT_INTERVAL) == 0) {
                    Date d = new Date();
                    String msg = "Domain #" + countDomains + ": " + domainName + " added at " + d;
                    log.info(msg);
                    if (print) {
                        out.print(I18N.getString(theLocale, "domain.number.0.1.added.at.2", countDomains,
                                domainName, d));
                        out.print("<br/>");
                        out.flush();
                    }
                }

                if (DomainUtils.isValidDomainName(domainName)) {
                    if (!dao.exists(domainName)) {
                        myDomain = Domain.getDefaultDomain(domainName);
                        dao.create(myDomain);
                    }
                } else {
                    log.debug("domain '" + domainName + "' is not a valid domain Name");
                    if (print) {
                        out.print(I18N.getString(theLocale, "errormsg;domain.0.is.not.a.valid" + ".domainname",
                                domainName));
                        out.print("<br/>");
                        out.flush();
                    }
                }
            } catch (Exception e) {
                log.debug("Could not create domain '" + domainName + "'", e);
                if (print) {
                    out.print(
                            I18N.getString(theLocale, "errormsg;unable.to.create" + ".domain.0.due.to.error.1",
                                    domainName, e.getMessage()));
                    out.print("<br/>\n");
                    out.flush();
                }
            }
        }
    } catch (FileNotFoundException fnf) {
        String msg = "File '" + domainList.getAbsolutePath() + "' not found";
        log.debug(msg);
        throw new IOFailure(msg, fnf);
    } catch (IOException io) {
        String msg = " Can't read the domain-file '" + domainList.getAbsolutePath() + "'.";
        log.debug(msg);
        throw new IOFailure(msg, io);
    } finally {
        try {
            if (in != null) {
                in.close();
            }
        } catch (IOException e) {
            throw new IOFailure("Problem closing input stream", e);
        }
    }
}