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:org.shredzone.cilla.plugin.social.renderer.SocialFragmentRenderer.java

@Fragment(name = "social")
public void socialFragment(Page page, JspWriter out) throws IOException {
    for (SocialLink link : socialHandlerManager.fetchLinksToPage(page)) {
        String escapedTitle = escape(link.getTitle());

        out.append("<a href=\"").append(escape(link.getUrl())).append("\"");
        out.append(" title=\"").append(escapedTitle).append("\" rel=\"nofollow\">");
        out.append("<img src=\"").append(escape(link.getIconUrl())).append("\"");
        out.append(" alt=\"").append(escapedTitle).append("\" />");
        out.append("</a>");
    }/*from   w  w w  . ja  v a2 s  .com*/
}

From source file:com.jredrain.tag.PagerTag.java

private void wrapLink(JspWriter out, String href, int curr, String title) throws IOException {
    out.append("<li><a href=\"").append(href).append(idParameterName).append("=").append("" + curr).append("&")
            .append(sizeParameterName).append("=").append("" + size).append("\">").append(title)
            .append("</a></li>");
}

From source file:com.jredrain.tag.PagerTag.java

private void wrapSpan(JspWriter out, String title, int status) throws IOException {
    if (status == 1) {
        out.append("<li class='active'>");
    } else if (status == -1) {
        out.append("<li class='disabled'>");
    } else {// w  ww.j  av  a2  s .  c om
        out.append("<li>");
    }
    out.append("<a href='javascript:void(0);'>");
    out.append(title);
    out.append("</a></li>");
}

From source file:com.cognifide.slice.cq.taglib.AnchorTag.java

/** {@inheritDoc} */
@Override/* ww  w .  j a  v a2 s.  c  o m*/
public int doStartTag() throws JspTagException {
    if (isRender()) {
        try {
            String link = this.href;

            if (externalise) {
                final LinkBuilderImpl linkBuilder = new LinkBuilderImpl();
                linkBuilder.setPath(link);
                linkBuilder.setSelectorString(selector);
                linkBuilder.setExtension(extension);

                final LinkExternalizer linkExternalizer = new LinkExternalizerImpl(null);
                link = linkExternalizer.externalizeLink(linkBuilder.toLink()).toString();
            }

            JspWriter out = getJspWriter();
            out.append("<a");
            apppendAttributeIfNotBlank(out, "href", link);
            apppendAttributeIfNotBlank(out, "id", id);
            apppendAttributeIfNotBlank(out, "class", clazz);
            apppendAttributeIfNotBlank(out, "title", title);
            apppendAttributeIfNotBlank(out, "target", target);
            apppendAttributeIfNotBlank(out, "name", name);
            apppendAttributeIfNotBlank(out, "rel", rel);
            apppendAttributeIfNotBlank(out, "onclick", onclick);
            out.append(">");
        } catch (IOException e) {
            // should never occur
            logger.error("unexpected exception occured", e);
        }
    }
    return EVAL_BODY_INCLUDE;
}

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

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

    Pair<String, Integer> p = periodUntilNow(getSince());
    String msg = getMessageSource().getMessage(p.getKey(), new Object[] { p.getValue() }, p.getKey(),
            getRequestContext().getLocale());

    try {/*from  ww  w  .  j  a v  a2 s .com*/
        jspWriter.append(msg);
    } catch (IOException e) {
        e.printStackTrace();
    }

    return SKIP_BODY;
}

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

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

    String value = getExpression();
    if (StringUtils.isBlank(value)) {
        return SKIP_BODY;
    }/*  w ww  .j  a v a  2s  . c om*/

    Class<T> clazz = getEnumClass();
    if (clazz == null) {
        return SKIP_BODY;
    }

    try {
        LocalizedEnum<?> val = LocalizedEnum.parseString(value, getMessageSource(), clazz);
        jspWriter.append(val.getLabel());
    } catch (IOException ex) {
        throw new JspException(ex);
    }

    return SKIP_BODY;
}

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

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

    String path = getRequestContext().getPathToServlet();

    int page = getPage().getNumber() + 1;
    int numberOfPages = getPage().getTotalPages();

    List<HtmlTag> items = new ArrayList<HtmlTag>();
    for (Integer p = 1; p <= numberOfPages; p++) {
        HtmlTag a = a(p.toString()).href(path + "?page.page=" + p);

        if (page == p) {
            items.add(li(a).cssClass("active"));
        } else {/*from  w w w.j ava2 s .  c  o  m*/
            items.add(li(a));
        }
    }

    HtmlTag pagination = div(ul(tags(items))).cssClass("pagination pagination-centered");

    try {
        jspWriter.append(pagination.build());
    } catch (IOException e) {
        e.printStackTrace();
    }

    return SKIP_BODY;
}

From source file:com.jredrain.tag.PagerTag.java

@Override
public void doTag() throws JspException, IOException {
    JspWriter out = getJspContext().getOut();

    if (StringUtils.isEmpty(idParameterName)) {
        idParameterName = "pageNo";
    }/*from w  ww .jav a  2s.c o  m*/
    if (StringUtils.isEmpty(sizeParameterName)) {
        sizeParameterName = "pageSize";
    }

    if (!href.endsWith("?") && !href.endsWith("&")) {
        if (href.indexOf("?") == -1) {
            href = href + "?";
        } else {
            href = href + "&";
        }
    }

    int pageTotal = 0;
    if ((total % size) == 0) {
        pageTotal = total / size;
    } else {
        pageTotal = (total / size) + 1;
    }

    if (id <= 0) {
        id = 1;
    } else if (id > pageTotal) {
        id = pageTotal;
    }

    //?
    if (getTotal() <= 0) {
        super.doTag();
        return;
    }
    out.append("<ul class='pagination fr mr20'>");
    // 
    if (id == 1) {
        wrapSpan(out, "", -1);
    } else {
        wrapLink(out, href, 1, "");
    }

    // 
    if (id == 1) {
        wrapSpan(out, "", -1);
    } else {
        wrapLink(out, href, id - 1, "");
    }

    int offsetNum = 5;
    int startId;
    if (id < offsetNum * 2 + 1) {
        startId = 1;
    } else {
        startId = id - offsetNum;
    }

    int endId = id + offsetNum;
    if (endId > pageTotal) {
        endId = pageTotal;
    }

    for (int i = startId; i <= endId; i++) {
        if (i == id) {
            wrapSpan(out, String.valueOf(i), 1);
        } else {
            wrapLink(out, href, i, String.valueOf(i));
        }
    }

    // 
    if (id == pageTotal) {
        wrapSpan(out, "", -1);
    } else {
        wrapLink(out, href, id + 1, "");
    }

    // 
    if (id == pageTotal) {
        wrapSpan(out, "", -1);
    } else {
        wrapLink(out, href, pageTotal, "");
    }
    out.append("</ul>");
    super.doTag();
}

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

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

    Account account = userService.findBySlug(getUser());
    if (account == null) {
        return SKIP_BODY;
    }//w  w  w  .ja v  a 2 s  .  c  om

    String gravatarImageURL = new Gravatar().setSize(getSize()).setHttps(true)
            .setRating(Rating.PARENTAL_GUIDANCE_SUGGESTED).setStandardDefaultImage(DefaultImage.MYSTERY_MAN)
            .getUrl(account.getEmailAddress());

    try {
        StringBuilder sb = new StringBuilder();

        if (showGravatarLink()) {
            sb.append("\n<a href=\"http://gravatar.com/emails/\">");
        }

        sb.append("\n<img ").append("height=\"").append(getSize()).append("\" ").append("width=\"")
                .append(getSize()).append("\" ").append("src=\"").append(gravatarImageURL).append("\" />");

        if (showGravatarLink()) {
            sb.append("\n</a>");
        }

        if (showUsername()) {
            sb.append("\n<br/>");
            sb.append("\n" + account.getDisplayName());
        }

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

    return SKIP_BODY;
}

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

@Override
protected int writeTagContent(JspWriter jspWriter, String contextPath) throws JspException {
    LocalizedField<?> value = (LocalizedField<?>) getBoundValue();
    Locale userLocale = getRequestContext().getLocale();

    List<HtmlTag> tags = new ArrayList<HtmlTag>();

    List<String> errorMessages = new ArrayList<String>();
    errorMessages.addAll(Arrays.asList(getBindStatus().getErrorMessages()));

    String cssClass = errorMessages.size() == 0 ? "control-group" : "control-group error";

    for (Locale loc : LocalizedField.locales(userLocale)) {
        String errorMsg = errorMessage(loc, errorMessages);

        tags.add(div(label(labelMessage(loc)).forId(getName(loc)).cssClass("control-label"),
                div(textArea(getValue(value, loc)).cssClass("input-xlarge").rows(getRows()).cols(getCols())
                        .id(getName(loc)).name(getName(loc)), span(errorMsg).cssClass("help-inline"))
                                .cssClass("controls")).cssClass(cssClass));
    }//from  w  w w. ja  va 2 s  . co  m

    try {
        jspWriter.append(snippet(tags(tags)).toString());
    } catch (IOException e) {
        e.printStackTrace();
    }

    return SKIP_BODY;
}