Example usage for javax.servlet.jsp JspWriter append

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

Introduction

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

Prototype

public Writer append(CharSequence csq) throws IOException 

Source Link

Document

Appends the specified character sequence to this writer.

Usage

From source file:com.trenako.web.tags.ActivityTags.java

@Override
protected int writeTagContent(JspWriter jspWriter, String contextPath) throws JspException {

    StringBuilder sb = new StringBuilder();

    Account user = users().findBySlug(activity().getActor());

    String slug = user == null ? activity().getActor() : user.getSlug();
    String displayName = user == null ? activity().getActor() : user.getDisplayName();
    sb.append("\n<a href=\"").append(contextPath).append("/users/").append(slug).append("\">")
            .append(displayName).append("</a>");

    LocalizedEnum<ActivityVerb> verb = LocalizedEnum.parseString(activity().getVerb(), messageSource(),
            ActivityVerb.class);
    sb.append(" ").append(verb.getLabel()).append(" ");

    String objectName = activity().getObject().getDisplayName();
    String objectUrl = activity().getObject().getUrl();

    sb.append("\n<a href=\"").append(contextPath).append(objectUrl).append("\">").append(objectName)
            .append("</a>");

    if (activity().getContext() != null) {
        String contextMsg = "activitycontext." + activity().getContext().getContextType() + ".label";
        String contextLabel = messageSource().getMessage(contextMsg, null, contextMsg,
                getRequestContext().getLocale());

        sb.append(" ").append(contextLabel);
    }/*  www. j  ava  2s.  co  m*/

    Pair<String, Integer> p = periodUntilNow(activity().getRecorded());
    String periodText = messageSource().getMessage(p.getKey(), new Object[] { p.getValue() }, p.getKey(),
            getRequestContext().getLocale());

    sb.append("\n<br/><strong>").append(periodText).append("</strong>");

    try {
        jspWriter.append(sb.toString());
    } catch (IOException e) {
        throw new JspException(e);
    }

    return SKIP_BODY;
}

From source file:org.jahia.taglibs.template.CaptchaTag.java

@Override
public int doEndTag() throws JspException {
    JspWriter out = pageContext.getOut();

    try {//from www . jav  a  2  s . c  o m
        URLGenerator urlGen = (URLGenerator) pageContext.findAttribute("url");
        StringBuilder url = new StringBuilder();
        String formId = (String) pageContext.findAttribute("currentFormId");
        url.append(urlGen.getContext()).append(urlGen.getCaptcha()).append("?token=##formtoken(").append(formId)
                .append(")##");

        if (StringUtils.isNotEmpty(var)) {
            pageContext.setAttribute(var, url);
        }
        if (display) {
            out.append("<img id=\"jahia-captcha-").append(formId).append("\" alt=\"captcha\" src=\"")
                    .append(url).append("\" />");
        }
        if (displayReloadLink) {
            out.append("&nbsp;").append(
                    "<a href=\"#reload-captcha\" onclick=\"var captcha=document.getElementById('jahia-captcha-")
                    .append(formId)
                    .append("'); var captchaUrl=captcha.src; if (captchaUrl.indexOf('&amp;tst=') != -1){"
                            + "captchaUrl=captchaUrl.substring(0,captchaUrl.indexOf('&amp;tst='));}"
                            + "captchaUrl=captchaUrl+'&amp;tst='+new Date().getTime();"
                            + " captcha.src=captchaUrl; return false;\"><img src=\"")
                    .append(urlGen.getContext()).append("/icons/refresh.png\" alt=\"refresh\"/></a>");
        }

        pageContext.setAttribute("hasCaptcha", true, PageContext.REQUEST_SCOPE);
    } catch (IOException e) {
        throw new JspException(e);
    }

    return EVAL_PAGE;
}