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.redhat.rhn.frontend.taglibs.UnpagedListDisplayTag.java

/** {@inheritDoc} */
public int doStartTag() throws JspException {
    rowCnt = 0;/*from   w  ww  .  j  a v  a 2 s  .  c o m*/
    JspWriter out = null;

    try {
        out = pageContext.getOut();
        setupPageList();

        // Now that we have setup the proper tag state we
        // need to return if this is an export render.
        if (isExport()) {
            return SKIP_PAGE;
        }

        String sortedColumn = getSortedColumn();
        if (sortedColumn != null) {
            doSort(sortedColumn);
        }

        out.print("<div class=\"spacewalk-list\">");
        out.print("<div class=\"panel panel-default\">");

        renderPanelHeading(out);

        /* If the type is list, we must set the width explicitly. Otherwise,
         * it shouldn't matter
         */
        if (getType().equals("list")) {
            out.print("<table class=\"table table-striped\"");
        } else if (getType().equals("treeview")) {
            out.print("<table class=\"table table-striped\" id=\"channel-list\"");
        } else {
            out.print("<table class=\"" + getType() + "\"");
        }

        /*if (isTransparent()) {
        out.print(" style=\"border-bottom: 1px solid #ffffff;\" ");
        }*/

        out.println(">");
        out.println("<thead>");
        out.println("<tr>");

        if (getIterator() != null && getIterator().hasNext()) {
            // Push a new BodyContent writer onto the stack so that
            // we can buffer the body data.
            bodyContent = pageContext.pushBody();
            return EVAL_BODY_INCLUDE;
        }
        return SKIP_BODY;
    } catch (IOException ioe) {
        throw new JspException("IO error writing to JSP file:", ioe);
    }
}

From source file:org.seasar.struts.taglib.S2FormTag.java

/**
 * Render the beginning of this form.//from  w w w  .  j  a  va 2 s .c o m
 *
 * @exception JspException if a JSP exception has occurred
 */
public int doStartTag() throws JspException {

    // Look up the form bean name, scope, and type if necessary
    this.lookup();

    // Create an appropriate "form" element based on our parameters
    StringBuffer results = new StringBuffer();

    results.append(this.renderFormStartElement());
    results.append(this.renderToken());

    JspWriter writer = pageContext.getOut();
    try {
        writer.print(results.toString());
    } catch (IOException e) {
        throw new JspException(e);
    }

    // Store this tag itself as a page attribute
    pageContext.setAttribute(Constants.FORM_KEY, this, PageContext.REQUEST_SCOPE);

    this.initFormBean();

    return (EVAL_BODY_INCLUDE);

}

From source file:org.seasar.struts.taglib.S2FormTag.java

/**
 * Render the end of this form./*from   ww  w. jav  a  2s . co  m*/
 *
 * @exception JspException if a JSP exception has occurred
 */
public int doEndTag() throws JspException {

    // Remove the page scope attributes we created
    pageContext.removeAttribute(BEAN_KEY, PageContext.REQUEST_SCOPE);
    pageContext.removeAttribute(FORM_KEY, PageContext.REQUEST_SCOPE);

    // Render a tag representing the end of our current form
    StringBuilder results = new StringBuilder("</form>");

    // Render JavaScript to set the input focus if required
    if (this.focus != null) {
        results.append(this.renderFocusJavascript());
    }

    // Print this value to our output writer
    JspWriter writer = pageContext.getOut();
    try {
        writer.print(results.toString());
    } catch (IOException e) {
        throw new JspException(e.toString(), e);
    }

    // Continue processing this page
    return (EVAL_PAGE);

}

From source file:org.apache.struts.taglib.html.JavascriptValidatorTag.java

/**
 * Render the JavaScript for to perform validations based on the form
 * name.//from   w  w w. j ava 2  s . c o  m
 *
 * @throws JspException if a JSP exception has occurred
 */
public int doStartTag() throws JspException {
    JspWriter writer = pageContext.getOut();

    try {
        writer.print(this.renderJavascript());
    } catch (IOException e) {
        throw new JspException(e.getMessage());
    }

    return EVAL_BODY_TAG;
}

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

/**
 * <p>Description:?</p>//w  ww. j av a 2 s . co m
 * @param pageNo   
 * @param request 
 * @param totalPages 
 * @return void
 * @author wenzhi
 * @version 1.0
 * @exception JspException
 */
private void printOutBack(int pageNo, int totalPages, HttpServletRequest request) throws JspException {
    try {
        Integer nextPage = new Integer(pageNo == totalPages ? totalPages : pageNo + 1);
        String next = "";
        String last = "";
        JspWriter out = pageContext.getOut();
        String outString = "";

        if (pageNo == totalPages || totalPages == 0 || totalPages == 1) {
            outString = " "

                    + next + "&nbsp;&nbsp;" + " " + last + "&nbsp;&nbsp;";
        } else {
            outString = " " + "<a href=\"javascript:setPage('" + nextPage + "','" + targets + "');\">" + next
                    + "&nbsp;</a>&nbsp;" + "<a href=\"javascript:setPage('" + totalPages + "','" + targets
                    + "');\">" + last + "&nbsp;</a>&nbsp;";
        }

        out.print(outString);
    } catch (Exception e) {
        throw new JspException(e);
    }
}

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

/**
 * <p>Description:?</p>/*from   w w w  .  java  2s  .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=\"" + link + "qm.pn=" + 1 + "\">" + first + "&nbsp;</a>|" + "<a href=\""
                    + link + "qm.pn=" + prePage + "\">" + prev + "&nbsp;</a>|";
        }
        out.print(outString);
    } catch (Exception e) {
        throw new JspException(e);
    }

}

From source file:org.apache.struts.faces.taglib.JavascriptValidatorTag.java

/**
 * Render the JavaScript for to perform validations based on the form name.
 *
 * @exception JspException if a JSP exception has occurred
 *///from   w ww  .  ja v a 2s.  co m
public int doStartTag() throws JspException {
    StringBuffer results = new StringBuffer();

    ModuleConfig config = RequestUtils.getModuleConfig(pageContext);
    ValidatorResources resources = (ValidatorResources) pageContext
            .getAttribute(ValidatorPlugIn.VALIDATOR_KEY + config.getPrefix(), PageContext.APPLICATION_SCOPE);

    Locale locale = RequestUtils.retrieveUserLocale(this.pageContext, null);

    Form form = resources.get(locale, formName);
    if (form != null) {
        if ("true".equalsIgnoreCase(dynamicJavascript)) {
            MessageResources messages = (MessageResources) pageContext.getAttribute(bundle + config.getPrefix(),
                    PageContext.APPLICATION_SCOPE);

            List lActions = new ArrayList();
            List lActionMethods = new ArrayList();

            // Get List of actions for this Form
            for (Iterator i = form.getFields().iterator(); i.hasNext();) {
                Field field = (Field) i.next();

                for (Iterator x = field.getDependencies().iterator(); x.hasNext();) {
                    Object o = x.next();

                    if (o != null && !lActionMethods.contains(o)) {
                        lActionMethods.add(o);
                    }
                }

            }

            // Create list of ValidatorActions based on lActionMethods
            for (Iterator i = lActionMethods.iterator(); i.hasNext();) {
                String depends = (String) i.next();
                ValidatorAction va = resources.getValidatorAction(depends);

                // throw nicer NPE for easier debugging
                if (va == null) {
                    throw new NullPointerException(
                            "Depends string \"" + depends + "\" was not found in validator-rules.xml.");
                }

                String javascript = va.getJavascript();
                if (javascript != null && javascript.length() > 0) {
                    lActions.add(va);
                } else {
                    i.remove();
                }
            }

            Collections.sort(lActions, new Comparator() {
                public int compare(Object o1, Object o2) {
                    ValidatorAction va1 = (ValidatorAction) o1;
                    ValidatorAction va2 = (ValidatorAction) o2;

                    if ((va1.getDepends() == null || va1.getDepends().length() == 0)
                            && (va2.getDepends() == null || va2.getDepends().length() == 0)) {
                        return 0;
                    } else if ((va1.getDepends() != null && va1.getDepends().length() > 0)
                            && (va2.getDepends() == null || va2.getDepends().length() == 0)) {
                        return 1;
                    } else if ((va1.getDepends() == null || va1.getDepends().length() == 0)
                            && (va2.getDepends() != null && va2.getDepends().length() > 0)) {
                        return -1;
                    } else {
                        return va1.getDependencies().size() - va2.getDependencies().size();
                    }
                }
            });

            String methods = null;
            for (Iterator i = lActions.iterator(); i.hasNext();) {
                ValidatorAction va = (ValidatorAction) i.next();

                if (methods == null) {
                    methods = va.getMethod() + "(form)";
                } else {
                    methods += " && " + va.getMethod() + "(form)";
                }
            }

            results.append(getJavascriptBegin(methods));

            for (Iterator i = lActions.iterator(); i.hasNext();) {
                ValidatorAction va = (ValidatorAction) i.next();
                String jscriptVar = null;
                String functionName = null;

                if (va.getJsFunctionName() != null && va.getJsFunctionName().length() > 0) {
                    functionName = va.getJsFunctionName();
                } else {
                    functionName = va.getName();
                }

                if (isStruts11()) {
                    results.append("    function " + functionName + " () { \n");
                } else {
                    results.append("    function " + formName + "_" + functionName + " () { \n");
                }
                for (Iterator x = form.getFields().iterator(); x.hasNext();) {
                    Field field = (Field) x.next();

                    // Skip indexed fields for now until there is a good way to handle 
                    // error messages (and the length of the list (could retrieve from scope?))
                    if (field.isIndexed() || field.getPage() != page || !field.isDependency(va.getName())) {

                        continue;
                    }

                    String message = Resources.getMessage(messages, locale, va, field);

                    message = (message != null) ? message : "";

                    jscriptVar = this.getNextVar(jscriptVar);

                    results.append("     this." + jscriptVar + " = new Array(\"" + getFormClientId() + ":"
                            + field.getKey() + "\", \"" + message + "\", ");

                    results.append("new Function (\"varName\", \"");

                    Map vars = field.getVars();
                    // Loop through the field's variables.
                    Iterator varsIterator = vars.keySet().iterator();
                    while (varsIterator.hasNext()) {
                        String varName = (String) varsIterator.next();
                        Var var = (Var) vars.get(varName);
                        String varValue = var.getValue();
                        String jsType = var.getJsType();

                        // skip requiredif variables field, fieldIndexed, fieldTest, fieldValue
                        if (varName.startsWith("field")) {
                            continue;
                        }

                        if (Var.JSTYPE_INT.equalsIgnoreCase(jsType)) {
                            results.append("this." + varName + "="
                                    + ValidatorUtil.replace(varValue, "\\", "\\\\") + "; ");
                        } else if (Var.JSTYPE_REGEXP.equalsIgnoreCase(jsType)) {
                            results.append("this." + varName + "=/"
                                    + ValidatorUtil.replace(varValue, "\\", "\\\\") + "/; ");
                        } else if (Var.JSTYPE_STRING.equalsIgnoreCase(jsType)) {
                            results.append("this." + varName + "='"
                                    + ValidatorUtil.replace(varValue, "\\", "\\\\") + "'; ");
                            // So everyone using the latest format doesn't need to change their xml files immediately.
                        } else if ("mask".equalsIgnoreCase(varName)) {
                            results.append("this." + varName + "=/"
                                    + ValidatorUtil.replace(varValue, "\\", "\\\\") + "/; ");
                        } else {
                            results.append("this." + varName + "='"
                                    + ValidatorUtil.replace(varValue, "\\", "\\\\") + "'; ");
                        }
                    }

                    results.append(" return this[varName];\"));\n");
                }
                results.append("    } \n\n");
            }
        } else if ("true".equalsIgnoreCase(staticJavascript)) {
            results.append(this.getStartElement());
            if ("true".equalsIgnoreCase(htmlComment)) {
                results.append(htmlBeginComment);
            }
        }
    }

    if ("true".equalsIgnoreCase(staticJavascript)) {
        results.append(getJavascriptStaticMethods(resources));
    }

    if (form != null
            && ("true".equalsIgnoreCase(dynamicJavascript) || "true".equalsIgnoreCase(staticJavascript))) {

        results.append(getJavascriptEnd());
    }

    JspWriter writer = pageContext.getOut();
    try {
        writer.print(results.toString());
    } catch (IOException e) {
        throw new JspException(e.getMessage());
    }

    return (EVAL_BODY_TAG);

}

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

/**
 * <p>Description:?</p>/*  w  w w  .  j  a  v  a2 s  .co  m*/
 * @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:com.xhsoft.framework.common.page.WebappPageTag.java

/**
 * <p>Description:?</p>/*from w w w  . jav a 2s.c  o m*/
 * @param  pageNo   
 * @param totalPages 
 * @param request 
 * @return void
 * @author wenzhi
 * @version 1.0
 * @exception JspException
 */
private void printOutBack(int pageNo, int totalPages, HttpServletRequest request) throws JspException {
    try {
        Integer nextPage = new Integer(pageNo == totalPages ? totalPages : pageNo + 1);
        String next = "";
        String last = "?";
        JspWriter out = pageContext.getOut();
        String outString = "";

        if (pageNo == totalPages || totalPages == 0 || totalPages == 1) {
            outString = " "

                    + next + "&nbsp;|&nbsp;" + " " + last + "&nbsp;|&nbsp;";
        } else {
            outString = " " + "<a href=\"" + link + "qm.pn=" + nextPage + "\">" + next + "&nbsp;</a>|"
                    + "<a href=\"" + link + "qm.pn=" + totalPages + "\">" + last + "&nbsp;</a>|&nbsp;&nbsp;";
        }
        out.print(outString);
    } catch (Exception e) {
        throw new JspException(e);
    }
}

From source file:com.adobe.acs.commons.wcm.tags.PlaceholderTag.java

/**
 * {@inheritDoc}/*from  w w w. java2s .  co  m*/
 */
@Override
public int doEndTag() throws JspException {
    SlingHttpServletRequest request = TagUtil.getRequest(pageContext);
    Component component = WCMUtils.getComponent(request.getResource());
    if (componentHelper.isEditMode(request)) {
        JspWriter writer = pageContext.getOut();
        String placeholder;

        String bodyContentString = bodyContent != null ? bodyContent.getString() : null;
        if (StringUtils.isNotBlank(bodyContentString)) {
            // use the body content as the default placeholder
            placeholder = Placeholder.getDefaultPlaceholder(request, component, bodyContentString,
                    getDdClass());
        } else {
            String classicUIPlaceholder = componentHelper.generateClassicUIPlaceholder(getAllClassNames(),
                    null);
            placeholder = Placeholder.getDefaultPlaceholder(request, component, classicUIPlaceholder,
                    getDdClass());
        }

        try {
            writer.print(placeholder);
        } catch (IOException e) {
            throw new JspException(e);
        }

    }
    reset();
    return EVAL_PAGE;
}