Example usage for javax.servlet.jsp JspWriter write

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

Introduction

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

Prototype

public void write(int c) throws IOException 

Source Link

Document

Writes a single character.

Usage

From source file:kr.co.skysoft.framework.taglib.JSR303JSValidateTag.java

public int doEndTag() throws JspException {
    try {/*from  www  .j a  v a 2s  .c o  m*/
        List<ValidationMetaData> rules = new ArrayList<ValidationMetaData>();
        if (commandName != null) {
            rules.addAll(getValidationMetaDataForCommand());
            this.addValidVOs(rules);

        }
        String bodyString = null;
        if (bodyContent != null) {
            // body can be a JSON object, specifying date formats, or other extra configuration info
            bodyString = FileCopyUtils.copyToString(bodyContent.getReader());
            bodyString = bodyString.trim().replaceAll("\\s{2,}", " ");
        }

        JspWriter out = pageContext.getOut();
        out.write("<script type=\"text/javascript\" id=\"");
        out.write(commandName + "JSR303JSValidator");
        out.write("\">");
        generator.generateJavaScript(out, commandName, true, bodyString, rules, new MessageSourceAccessor(
                getRequestContext().getWebApplicationContext(), getRequestContext().getLocale()));
        out.write("</script>");
        return EVAL_PAGE;
    } catch (IOException e) {
        throw new JspException("Could not write validation rules", e);
    }
}

From source file:kr.co.skysoft.framework.taglib.JSR303JSCodebaseTag.java

public int doEndTag() throws JspException {
    try {//from w  ww  . ja  va2  s  .com
        JspWriter out = pageContext.getOut();
        if (includeScriptTags) {
            out.write("<script type=\"text/javascript\">\n");
        }
        if (globalErrorsId != null) {
            out.write("var tlGlobalErrorsId = '" + globalErrorsId + "';\n");
        }
        if (fieldErrorsIdSuffix != null) {
            out.write("var tlFieldErrorIdSuffix = '" + fieldErrorsIdSuffix + "';\n");
        }
        copy(getCodebaseReader(), out);
        if (includeScriptTags) {
            out.write("\n</script>");
        }
        return EVAL_PAGE;
    } catch (IOException e) {
        throw new JspException("Could not write validation codebase", e);
    }
}

From source file:org.springmodules.validation.valang.javascript.taglib.ValangCodebaseTag.java

public int doEndTag() throws JspException {
    try {/* www . j  ava 2  s  . com*/
        JspWriter out = pageContext.getOut();
        if (includeScriptTags) {
            out.write("<script type=\"text/javascript\">\n");
        }
        copy(ValangJavaScriptTranslator.getCodebaseReader(), out);

        if (globalErrorsId != null) {
            out.write("ValangValidator.prototype.globalErrorsId = '" + globalErrorsId + "';\n");
        }
        if (fieldErrorIdSuffix != null) {
            out.write("ValangValidator.prototype.fieldErrorIdSuffix = '" + fieldErrorIdSuffix + "';\n");
        }
        if (logId != null) {
            out.write("ValangValidator.Logger.logId = '" + logId + "';\n");
        }
        if (includeScriptTags) {
            out.write("\n</script>");
        }
        return EVAL_PAGE;
    } catch (IOException e) {
        throw new JspException("Could not write validation codebase", e);
    }
}

From source file:com.redhat.rhn.frontend.configuration.tags.ConfigFileTag.java

/**
 * {@inheritDoc}/* w  ww  .j a v a 2  s . c  o m*/
 */
@Override
public int doEndTag() throws JspException {
    StringBuilder result = new StringBuilder();
    if (nolink || id == null) {
        result.append(writeIcon());
        result.append(StringEscapeUtils.escapeXml(path));
    } else {
        String url;
        if (revisionId != null) {
            url = makeConfigFileRevisionUrl(id, revisionId);
        } else {
            url = makeConfigFileUrl(id);
        }

        result.append("<a href=\"" + url + "\">");
        result.append(writeIcon());
        result.append(StringEscapeUtils.escapeXml(path) + "</a>");
    }
    JspWriter writer = pageContext.getOut();
    try {
        writer.write(result.toString());
    } catch (IOException e) {
        throw new JspException(e);
    }
    return BodyTagSupport.SKIP_BODY;
}

From source file:info.magnolia.cms.taglibs.util.ConvertNewLineTag.java

/**
 * @see javax.servlet.jsp.tagext.Tag#doEndTag()
 *///from  ww  w .j av  a  2s.c o m
public int doEndTag() throws JspException {
    String bodyText = bodyContent.getString();

    if (StringUtils.isNotEmpty(bodyText)) {
        StringTokenizer bodyTk = new StringTokenizer(bodyText, "\n", false); //$NON-NLS-1$
        JspWriter out = pageContext.getOut();

        try {
            if (this.para) {
                // wrap text in p
                while (bodyTk.hasMoreTokens()) {
                    out.write("<p>"); //$NON-NLS-1$
                    out.write(StringUtils.replaceChars(bodyTk.nextToken(), (char) 63, '\''));
                    out.write("</p>"); //$NON-NLS-1$
                }
            } else {
                // add newlines
                while (bodyTk.hasMoreTokens()) {
                    out.write(StringUtils.replaceChars(bodyTk.nextToken(), (char) 63, '\''));
                    if (bodyTk.hasMoreTokens()) {
                        out.write("<br/>"); //$NON-NLS-1$
                    }
                }
            }
        } catch (IOException e) {
            throw new JspTagException(e.getMessage());
        }
    }
    return EVAL_PAGE;
}

From source file:com.acc.storefront.renderer.CMSLinkComponentRenderer.java

@Override
public void renderComponent(final PageContext pageContext, final CMSLinkComponentModel component)
        throws ServletException, IOException {
    try {//  www  .  ja  va  2 s.co m
        final String url = getUrl(component);
        final String encodedUrl = UrlSupport.resolveUrl(url, null, pageContext);

        final JspWriter out = pageContext.getOut();

        if (encodedUrl == null || encodedUrl.isEmpty()) {
            // <span class="empty-nav-item">${component.linkName}</span>
            out.write("<span class=\"empty-nav-item\">");
            out.write(component.getLinkName());
            out.write("</span>");
        } else {
            // <a href="${encodedUrl}" ${component.styleAttributes} title="${component.linkName}" ${component.target == null || component.target == 'SAMEWINDOW' ? '' : 'target="_blank"'}>${component.linkName}</a>

            out.write("<a href=\"");
            out.write(encodedUrl);
            out.write("\" ");

            // Write additional attributes onto the link
            if (component.getStyleAttributes() != null) {
                out.write(component.getStyleAttributes());
            }

            out.write(" title=\"");
            out.write(component.getLinkName());
            out.write("\" ");

            if (component.getTarget() != null && !LinkTargets.SAMEWINDOW.equals(component.getTarget())) {
                out.write(" target=\"_blank\"");
            }
            out.write(">");
            out.write(component.getLinkName());
            out.write("</a>");
        }
    } catch (final JspException ignore) {
        // ignore
    }
}

From source file:de.hybris.platform.yacceleratorstorefront.renderer.CMSLinkComponentRenderer.java

@Override
public void renderComponent(final PageContext pageContext, final CMSLinkComponentModel component)
        throws ServletException, IOException {
    try {/*from  w ww  . j  a va2  s .c  om*/
        final String url = getUrl(component);
        final String encodedUrl = UrlSupport.resolveUrl(url, null, pageContext);

        final JspWriter out = pageContext.getOut();

        if (encodedUrl == null || encodedUrl.isEmpty()) {
            // <span class="empty-nav-item">${component.linkName}</span>
            out.write("<span class=\"empty-nav-item\">");
            out.write(component.getLinkName());
            out.write("</span>");
        } else {
            // <a href="${encodedUrl}" ${component.styleAttributes}
            // title="${component.linkName}" ${component.target == null || component.target ==
            // 'SAMEWINDOW' ? '' : 'target="_blank"'}>${component.linkName}</a>

            out.write("<a href=\"");
            out.write(encodedUrl);
            out.write("\" ");

            // Write additional attributes onto the link
            if (component.getStyleAttributes() != null) {
                out.write(component.getStyleAttributes());
            }

            out.write(" title=\"");
            out.write(component.getLinkName());
            out.write("\" ");

            if (component.getTarget() != null && !LinkTargets.SAMEWINDOW.equals(component.getTarget())) {
                out.write(" target=\"_blank\"");
            }
            out.write(">");
            out.write(component.getLinkName());
            out.write("</a>");
        }
    } catch (final JspException ignore) {
        // ignore
    }
}

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

/**
 * @see javax.servlet.jsp.tagext.Tag#doEndTag()
 *///  w  ww.j  ava 2 s  .  c  o m
@Override
public int doEndTag() throws JspException {
    String bodyText = bodyContent.getString();

    if (StringUtils.isNotEmpty(bodyText)) {
        StringTokenizer bodyTk = new StringTokenizer(bodyText, "\n", false);
        JspWriter out = pageContext.getOut();

        try {
            if (this.para) {
                // wrap text in p
                while (bodyTk.hasMoreTokens()) {
                    out.write("<p>");
                    out.write(StringUtils.replaceChars(bodyTk.nextToken(), (char) 63, '\''));
                    out.write("</p>");
                }
            } else {
                // add newlines
                while (bodyTk.hasMoreTokens()) {
                    out.write(StringUtils.replaceChars(bodyTk.nextToken(), (char) 63, '\''));
                    if (bodyTk.hasMoreTokens()) {
                        out.write("<br/>");
                    }
                }
            }
        } catch (IOException e) {
            throw new JspTagException(e.getMessage());
        }
    }
    return EVAL_PAGE;
}

From source file:com.dianping.lion.web.tag.StrutsTagSupport.java

public int doEndTag() throws JspException {
    evaluateParams();//from   w ww.j av  a 2  s .co m
    JspWriter writer = pageContext.getOut();
    try {
        if (bodyContent != null && StringUtils.isNotBlank(bodyContent.getString())) {
            writer.write(bodyContent.getString().trim());
        }
        if (templatePath != null) {
            renderTemplateContent();
        }
    } catch (Exception e) {
        throw new RuntimeException("Render customized strutsTag[" + getClass() + "] failed.", e);
    }
    return EVAL_PAGE;
}

From source file:com.redhat.rhn.frontend.taglibs.RequiredFieldTag.java

/**
 * {@inheritDoc}/*from w  w w  .  java 2s  .c om*/
 */
public int doEndTag() throws JspException {
    JspWriter writer = pageContext.getOut();
    //<span class="required-form-field">*</span>
    HtmlTag span = new HtmlTag("span");
    span.setAttribute("class", REQUIRED_FIELD_CSS);
    span.addBody("*");
    try {
        writer.write(span.render());
        if (!StringUtils.isBlank(key)) {
            LocalizationService ls = LocalizationService.getInstance();
            String msg = ls.getMessage(key);
            if (msg.endsWith(":")) {
                writer.write(":");
            }
        }

    } catch (IOException e) {
        throw new JspException(e);
    }
    return SKIP_BODY;
}