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:org.jasig.schedassist.web.VisibleScheduleTag.java

/**
 * Render a single {@link AvailableBlock} with {@link AvailableStatus#ATTENDING}.
 * //www.  ja v  a 2s  .  c  om
 * @param writer
 * @param event
 * @throws IOException
 */
protected void renderAttendingBlock(final ServletContext servletContext, final JspWriter writer,
        final AvailableBlock event) throws IOException {
    SimpleDateFormat stpFormat = new SimpleDateFormat("yyyyMMdd-HHmm");
    SimpleDateFormat idFormat = CommonDateOperations.getDateTimeFormat();
    SimpleDateFormat timeFormat = new SimpleDateFormat("h:mm a");
    String startTimeFormatted = stpFormat.format(event.getStartTime());
    String endTimeFormatted = stpFormat.format(event.getEndTime());
    String cancelTitle = getMessageSource().getMessage("cancel.my.appointment", null, null);
    writer.write("<li id=\"" + idFormat.format(event.getStartTime()) + "\" class=\"attending\" title=\""
            + cancelTitle + "\">");
    if (!previewMode) {
        writer.write("<a href=\"cancel.html?startTime=" + startTimeFormatted + "&endTime=" + endTimeFormatted
                + "\">");
    }
    writer.write("<img src=\"" + getSilkIconPrefix(servletContext) + "calendar_delete.png\" alt=\"\"/>&nbsp;");
    writer.write("<span id=\"" + idFormat.format(event.getStartTime()) + "-text\">");
    writer.write(timeFormat.format(event.getStartTime()));
    writer.write(" - ");
    writer.write(timeFormat.format(event.getEndTime()));
    writer.write("</span>");
    if (!previewMode) {
        writer.write("</a>");
    }
    writer.write("</li>");
}

From source file:com.concursive.connect.web.taglibs.ULPagedListControlHandler.java

/**
 * Description of the Method/* w w  w.  ja v a  2 s. c  o m*/
 *
 * @return Description of the Returned Value
 */
public int doEndTag() {
    try {
        PortletRequest renderRequest = (PortletRequest) pageContext.getRequest()
                .getAttribute(org.apache.pluto.tags.Constants.PORTLET_REQUEST);
        RenderResponse renderResponse = (RenderResponse) pageContext.getRequest()
                .getAttribute(org.apache.pluto.tags.Constants.PORTLET_RESPONSE);
        PagedListInfo pagedListInfo = null;

        // Check the request first
        pagedListInfo = (PagedListInfo) pageContext.getRequest().getAttribute(object);

        // Check the portlet next
        if (pagedListInfo == null) {
            if (renderRequest != null) {
                pagedListInfo = (PagedListInfo) renderRequest.getAttribute(object);
                if (pagedListInfo == null) {
                    pagedListInfo = (PagedListInfo) renderRequest.getPortletSession().getAttribute(object);
                }
            }
        }

        // Check the session last
        if (pagedListInfo == null) {
            pagedListInfo = (PagedListInfo) pageContext.getSession().getAttribute(object);
        }

        // Display the control
        if (pagedListInfo != null) {
            String ctx = ((HttpServletRequest) pageContext.getRequest()).getContextPath();
            boolean useCtx = true;
            if (url != null && url.startsWith(ctx)) {
                useCtx = false;
            }

            pagedListInfo.setShowForm(showForm);
            pagedListInfo.setResetList(resetList);
            pagedListInfo.setEnableJScript(enableJScript);
            JspWriter out = this.pageContext.getOut();
            String prevClass = pagedListInfo.getHasPreviousPageLink() ? CLASS_PREVIOUS_ENABLED
                    : CLASS_PREVIOUS_DISABLED;
            String nextClass = pagedListInfo.getHasNextPageLink() ? CLASS_NEXT_ENABLED : CLASS_NEXT_DISABLED;

            if (enableJScript) {
                out.write("<SCRIPT LANGUAGE=\"JavaScript\" TYPE=\"text/javascript\" SRC=\"" + ctx
                        + "/javascript/pageListInfo.js\"></SCRIPT>");
            }
            if (pagedListInfo.getMaxRecords() > 0 || pagedListInfo.getNumberOfPages() > 1) {
                out.write("<div class=\"pagination\">");
            }
            if (pagedListInfo.getMaxRecords() > 0) {
                out.write("<em>" + pagedListInfo.getMaxRecords() + " result"
                        + (pagedListInfo.getMaxRecords() == 1 ? "" : "s") + " found</em>");
            }
            if (pagedListInfo.getNumberOfPages() > 1) {
                out.write("<ol class=\"" + CLASS_PAGINATE + "\">");
                if (url != null) {
                    int prevPage = 1;
                    if (pagedListInfo.getCurrentPageNumber() != 1) {
                        prevPage = pagedListInfo.getCurrentPageNumber() - 1;
                        String prevLink = (useCtx ? ctx : "") + url + ((prevPage != 1) ? "/" + prevPage : "");
                        out.write("<li class=\"" + prevClass + "\"><a href=\"" + getCompleteLink(prevLink)
                                + "\">&lt; Previous</a></li>");
                    } else {
                        out.write("<li class=\"" + prevClass + "\"><a>&lt; Previous</a></li>");
                    }
                } else {
                    String previousPageLink = pagedListInfo.getPreviousPageLink("&lt; Previous",
                            "&lt; Previous", null, renderResponse);
                    if (!previousPageLink.contains("<a")) {
                        previousPageLink = "<a>" + previousPageLink + "</a>";
                    }
                    out.write("<li class=\"" + prevClass + "\">" + previousPageLink + "</li>");
                }
                //@TODO make number of links shown available to customize for cases where pagination needs to be larger or smaller
                int PRIOR_LIMIT = 3; //this might be useful to be dynamic
                int AFTER_LIMIT = 3;
                int padPrior = 0;
                int padAfter = 0;
                int currentPage = pagedListInfo.getCurrentPageNumber();
                int lastPage = pagedListInfo.getNumberOfPages();
                int pageStart = currentPage - PRIOR_LIMIT;
                int pageEnd = currentPage + AFTER_LIMIT;
                // Make Sure pageStart and pageEnd fall within legal ranges and calculate any padding
                if (pageStart < 1) {
                    padAfter += 0 - pageStart;
                    pageStart = 1;
                }
                if (pageEnd > lastPage) {
                    padPrior += pageEnd - lastPage;
                    pageEnd = lastPage;
                }
                // Check to see if prior or after can get extra padding
                if (padAfter > 0 && pageEnd != lastPage) {
                    pageEnd += padAfter;
                    if (pageEnd > lastPage)
                        pageEnd = lastPage;
                }
                if (padPrior > 0 && pageStart != 1) {
                    pageStart -= padPrior;
                    if (pageStart < 1)
                        pageStart = 1;
                }

                if (pageStart != 1) {
                    // Show 1st 2 @TODO make dynamic
                    for (int i = 1; i < 3; i++) {
                        if (pageStart == i)
                            break; // don't print link twice
                        String link = null;
                        if (url != null) {
                            link = (useCtx ? ctx : "") + url + ((i != 1) ? "/" + i : "");
                        } else {
                            link = pagedListInfo.getLinkForPage(i, renderResponse);
                        }
                        out.write("<li class=\"page\"><a href=\"" + getCompleteLink(link) + "\">" + i
                                + "</a></li>");
                    }
                    if (pageStart > 3) { // only show ... if there was a break in the counting
                        out.write("<li>...</li>");
                    }
                }

                for (int i = pageStart; i != pageEnd + 1; i++) {
                    if (i == pagedListInfo.getCurrentPageNumber()) {
                        out.write("<li class=\"" + CLASS_ACTIVE + "\"><a>" + i + "</a></li>");
                    } else {
                        String link = null;
                        if (url != null) {
                            link = (useCtx ? ctx : "") + url + ((i != 1) ? "/" + i : "");
                        } else {
                            link = pagedListInfo.getLinkForPage(i, renderResponse);
                        }
                        out.write("<li class=\"page\"><a href=\"" + getCompleteLink(link) + "\">" + i
                                + "</a></li>");
                    }
                }

                if (pageEnd != lastPage) {
                    if (pageEnd < lastPage - 2) {
                        out.write("<li>...</li>");
                    }
                    // Show last 2 @TODO make dynamic
                    for (int i = lastPage - 1; i <= lastPage; i++) {
                        if (pageEnd == i)
                            continue; // don't print link twice
                        String link = null;
                        if (url != null) {
                            link = (useCtx ? ctx : "") + url + ((i != 1) ? "/" + i : "");
                        } else {
                            link = pagedListInfo.getLinkForPage(i, renderResponse);
                        }
                        out.write("<li class=\"page\"><a href=\"" + getCompleteLink(link) + "\">" + i
                                + "</a></li>");
                    }
                }

                if (url != null) {
                    int nextPage = 1;
                    if (pagedListInfo.getCurrentPageNumber() != pagedListInfo.getNumberOfPages()) {
                        nextPage = pagedListInfo.getCurrentPageNumber() + 1;
                        String nextLink = (useCtx ? ctx : "") + url + "/" + nextPage;
                        out.write("<li class=\"" + nextClass + "\"><a href=\"" + getCompleteLink(nextLink)
                                + "\">Next &gt;</a></li>");
                    } else {
                        out.write("<li class=\"" + nextClass + "\"><a>Next &gt;</a></li>");
                    }
                } else {
                    String nextPageLink = pagedListInfo.getNextPageLink("Next &gt;", "Next &gt;", null,
                            renderResponse);
                    if (!nextPageLink.contains("<a")) {
                        nextPageLink = "<a>" + nextPageLink + "</a>";
                    }
                    out.write("<li class=\"" + nextClass + "\">" + nextPageLink + "</li>");
                }
                out.write("</ol>");
            }
            if (pagedListInfo.getMaxRecords() > 0 || pagedListInfo.getNumberOfPages() > 1) {
                out.write("</div>");
            }
        } else {
            LOG.error("Control not found in request: " + object);
        }
    } catch (IOException e) {
        LOG.error("doEndTag error", e);
    }
    return EVAL_PAGE;
}

From source file:com.truthbean.core.web.kindeditor.FileUpload.java

@Override
public void service(final HttpServletRequest request, final HttpServletResponse response)
        throws IOException, ServletException {

    final PageContext pageContext;
    HttpSession session = null;//  ww  w .  j ava 2 s.  c  om
    final ServletContext application;
    final ServletConfig config;
    JspWriter out = null;
    final Object page = this;
    JspWriter _jspx_out = null;
    PageContext _jspx_page_context = null;

    try {
        response.setContentType("text/html; charset=UTF-8");
        pageContext = _jspxFactory.getPageContext(this, request, response, null, true, 8192, true);
        _jspx_page_context = pageContext;
        application = pageContext.getServletContext();
        config = pageContext.getServletConfig();
        session = pageContext.getSession();
        out = pageContext.getOut();
        _jspx_out = out;

        out.write("\r\n");
        out.write("\r\n");
        out.write("\r\n");
        out.write("\r\n");
        out.write("\r\n");
        out.write("\r\n");
        out.write("\r\n");

        /**
         * KindEditor JSP
         *
         * JSP???? ??
         *
         */
        // ?
        String savePath = pageContext.getServletContext().getRealPath("/") + "resource/";

        String savePath$ = savePath;

        // ?URL
        String saveUrl = request.getContextPath() + "/resource/";

        // ???
        HashMap<String, String> extMap = new HashMap<>();
        extMap.put("image", "gif,jpg,jpeg,png,bmp");
        extMap.put("flash", "swf,flv");
        extMap.put("media", "swf,flv,mp3,wav,wma,wmv,mid,avi,mpg,asf,rm,rmvb");
        extMap.put("file", "doc,docx,xls,xlsx,ppt,htm,html,txt,zip,rar,gz,bz2");

        // ?
        long maxSize = 10 * 1024 * 1024 * 1024L;

        response.setContentType("text/html; charset=UTF-8");

        if (!ServletFileUpload.isMultipartContent(request)) {
            out.println(getError(""));
            return;
        }
        // 
        File uploadDir = new File(savePath);
        if (!uploadDir.isDirectory()) {
            out.println(getError("?"));
            return;
        }
        // ??
        if (!uploadDir.canWrite()) {
            out.println(getError("??"));
            return;
        }

        String dirName = request.getParameter("dir");
        if (dirName == null) {
            dirName = "image";
        }
        if (!extMap.containsKey(dirName)) {
            out.println(getError("???"));
            return;
        }
        // 
        savePath += dirName + "/";
        saveUrl += dirName + "/";
        File saveDirFile = new File(savePath);
        if (!saveDirFile.exists()) {
            saveDirFile.mkdirs();
        }
        SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
        String ymd = sdf.format(new Date());
        savePath += ymd + "/";
        saveUrl += ymd + "/";
        File dirFile = new File(savePath);
        if (!dirFile.exists()) {
            dirFile.mkdirs();
        }

        FileItemFactory factory = new DiskFileItemFactory();
        ServletFileUpload upload = new ServletFileUpload(factory);
        upload.setHeaderEncoding("UTF-8");
        List items = upload.parseRequest(request);
        Iterator itr = items.iterator();
        while (itr.hasNext()) {
            FileItem item = (FileItem) itr.next();
            String fileName = item.getName();
            if (!item.isFormField()) {
                // ?
                if (item.getSize() > maxSize) {
                    out.println(getError("??"));
                    return;
                }
                // ??
                String fileExt = fileName.substring(fileName.lastIndexOf(".") + 1).toLowerCase();
                if (!Arrays.asList(extMap.get(dirName).split(",")).contains(fileExt)) {
                    out.println(getError("??????\n??"
                            + extMap.get(dirName) + "?"));
                    return;
                }

                SimpleDateFormat df = new SimpleDateFormat("yyyyMMddHHmmss");
                String newFileName = df.format(new Date()) + "_" + new Random().nextInt(1000) + "." + fileExt;
                try {
                    File uploadedFile = new File(savePath, newFileName);
                    item.write(uploadedFile);
                } catch (Exception e) {
                    out.println(getError(""));
                    return;
                }

                JSONObject obj = new JSONObject();
                obj.put("error", 0);
                obj.put("url", saveUrl + newFileName);

                request.getSession().setAttribute("fileName", savePath$ + fileName);
                request.getSession().setAttribute("filePath", savePath + newFileName);
                request.getSession().setAttribute("fileUrl", saveUrl + newFileName);

                out.println(obj.toJSONString());
            }
        }

        out.write('\r');
        out.write('\n');
    } catch (IOException | FileUploadException t) {
        if (!(t instanceof javax.servlet.jsp.SkipPageException)) {
            out = _jspx_out;
            if (out != null && out.getBufferSize() != 0) {
                if (response.isCommitted()) {
                    out.flush();
                } else {
                    out.clearBuffer();
                }
            }
            if (_jspx_page_context != null) {
                _jspx_page_context.handlePageException(t);
            } else {
                throw new ServletException(t);
            }
        }
    } finally {
        _jspxFactory.releasePageContext(_jspx_page_context);
    }
}

From source file:org.jasig.schedassist.portlet.VisibleScheduleTag.java

/**
 * Render a single week./*w ww  . j  a va  2s  .c  o m*/
 * 
 * @param writer
 * @param weekNumber
 * @param dailySchedules
 * @param scheduleBlockMap
 * @param renderRequest
 * @param renderResponse
 * @throws IOException
 */
protected void renderWeek(final JspWriter writer, final int weekNumber,
        final SortedMap<Date, List<AvailableBlock>> dailySchedules,
        final SortedMap<AvailableBlock, AvailableStatus> scheduleBlockMap, final RenderRequest renderRequest,
        final RenderResponse renderResponse) throws IOException {
    if (LOG.isDebugEnabled()) {
        LOG.debug("begin renderWeek for " + weekNumber);
    }
    final boolean hasBlocks = doesWeekHaveBlocks(dailySchedules);
    if (hasBlocks) {
        final SimpleDateFormat headFormat = new SimpleDateFormat("EEE M/d");
        writer.write("<div class=\"weekcontainer\" id=\"week" + weekNumber + "\">");
        for (Map.Entry<Date, List<AvailableBlock>> entry : dailySchedules.entrySet()) {
            final Date day = entry.getKey();
            final List<AvailableBlock> daySchedule = entry.getValue();
            if (LOG.isDebugEnabled()) {
                LOG.debug("in renderWeek weeknumber: " + weekNumber + ", day: " + day);
            }
            if (daySchedule.size() > 0) {
                writer.write("<div class=\"weekday\">");
                writer.write("<ul>");

                writer.write("<li class=\"dayhead\">");
                writer.write(headFormat.format(day));
                writer.write("</li>");
                for (AvailableBlock event : daySchedule) {
                    AvailableStatus eventStatus = scheduleBlockMap.get(event);
                    if (AvailableStatus.BUSY.equals(eventStatus)) {
                        renderBusyBlock(writer, event);
                    } else if (AvailableStatus.FREE.equals(eventStatus)) {
                        renderFreeBlock(writer, event, renderRequest, renderResponse);
                    } else if (AvailableStatus.ATTENDING.equals(eventStatus)) {
                        renderAttendingBlock(writer, event, renderRequest, renderResponse);
                    }
                }

                writer.write("</ul>");
                writer.write("</div> <!-- end weekday -->");
            }
        }

        writer.write("</div> <!-- end weekcontainer -->");
    } else {
        if (LOG.isDebugEnabled()) {
            LOG.debug("renderWeek has no blocks for weekNumber: " + weekNumber);
        }
    }
}

From source file:org.jasig.schedassist.portlet.VisibleScheduleTag.java

/**
 * Render a single {@link AvailableBlock} with {@link AvailableStatus#ATTENDING}.
 * //from   w  w  w  .  j a  v a 2 s  . c o m
 * @param writer
 * @param event
 * @param renderRequest
 * @param renderResponse
 * @throws IOException
 */
protected void renderAttendingBlock(final JspWriter writer, final AvailableBlock event,
        final RenderRequest renderRequest, final RenderResponse renderResponse) throws IOException {
    SimpleDateFormat stpFormat = new SimpleDateFormat("yyyyMMdd-HHmm");
    SimpleDateFormat idFormat = CommonDateOperations.getDateTimeFormat();
    SimpleDateFormat timeFormat = new SimpleDateFormat("h:mm a");
    String startTimeFormatted = stpFormat.format(event.getStartTime());
    String endTimeFormatted = stpFormat.format(event.getEndTime());
    String cancelTitle = getMessageSource().getMessage("cancel.my.appointment", null, null);
    writer.write("<li id=\"" + idFormat.format(event.getStartTime()) + "\" class=\"attending\" title=\""
            + cancelTitle + "\">");
    if (!previewMode) {
        PortletURL cancelUrl = renderResponse.createRenderURL();
        cancelUrl.setParameter("execution", flowExecutionKey);
        cancelUrl.setParameter("_eventId", "cancel");
        cancelUrl.setParameter("startTime", startTimeFormatted);
        cancelUrl.setParameter("endTime", endTimeFormatted);
        cancelUrl.setParameter("ownerId", renderRequest.getParameter("ownerId"));
        writer.write("<a href=\"" + cancelUrl.toString() + "\">");
    }
    writer.write("<img src=\"" + getSilkIconPrefix() + "calendar_delete.png\" alt=\"\"/>&nbsp;");
    writer.write("<span id=\"" + idFormat.format(event.getStartTime()) + "-text\">");
    writer.write(timeFormat.format(event.getStartTime()));
    writer.write(" - ");
    writer.write(timeFormat.format(event.getEndTime()));
    writer.write("</span>");
    if (!previewMode) {
        writer.write("</a>");
    }
    writer.write("</li>");
}

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

/**
 * @see javax.servlet.jsp.tagext.TagSupport#doEndTag()
 *///www.j  ava  2  s.  c  o  m
public int doEndTag() throws JspException {
    HttpServletRequest request = (HttpServletRequest) pageContext.getRequest();

    Content contentNode = getFirtMatchingNode();
    if (contentNode == null) {
        return EVAL_PAGE;
    }

    NodeData imageNodeData = contentNode.getNodeData(this.nodeDataName);

    if (!imageNodeData.isExist()) {
        return EVAL_PAGE;
    }

    FileProperties props = new FileProperties(contentNode, this.nodeDataName);
    String imgSrc = props.getProperty(FileProperties.PATH);

    String altNodeDataNameDef = this.altNodeDataName;
    if (StringUtils.isEmpty(altNodeDataNameDef)) {
        altNodeDataNameDef = nodeDataName + "Alt";
    }

    String alt = contentNode.getNodeData(altNodeDataNameDef).getString();

    if (StringUtils.isEmpty(alt)) {
        alt = props.getProperty(FileProperties.NAME_WITHOUT_EXTENSION);
    }

    JspWriter out = pageContext.getOut();

    // don't modify the original map, remember tag pooling
    Map attributes = new HashMap(htmlAttributes);
    attributes.put("title", alt);

    if (!attributes.containsKey("width") && !attributes.containsKey("height")) {
        String width = props.getProperty(FileProperties.PROPERTY_WIDTH);
        if (StringUtils.isNotEmpty(width)) {
            attributes.put("width", width);
        }

        String height = props.getProperty(FileProperties.PROPERTY_HEIGHT);
        if (StringUtils.isNotEmpty(height)) {
            attributes.put("height", height);
        }
    }

    try {
        if (StringUtils.lowerCase(imgSrc).endsWith(".swf")) {
            // handle flash movies

            out.write("<object type=\"application/x-shockwave-flash\" data=\"");
            out.write(request.getContextPath());
            out.write(imgSrc);
            out.write("\" ");
            writeAttributes(out, attributes);
            out.write(">");

            out.write("<param name=\"movie\" value=\"");
            out.write(request.getContextPath());
            out.write(imgSrc);
            out.write("\"/>");
            out.write("</object>");

        } else {

            attributes.put("alt", alt);

            out.write("<img src=\"");
            out.write(request.getContextPath());
            out.write(imgSrc);
            out.write("\" ");

            writeAttributes(out, attributes);
            out.write("/>");
        }
    } catch (IOException e) {
        // should never happen
        throw new NestableRuntimeException(e);
    }

    return super.doEndTag();
}

From source file:org.jasig.schedassist.web.VisibleScheduleTag.java

/**
 * Render a single {@link AvailableBlock} with {@link AvailableStatus#FREE}.
 * /*w w  w .  j av  a 2  s . c om*/
 * @param servletContext
 * @param writer
 * @param event
 * @throws IOException
 */
protected void renderFreeBlock(final ServletContext servletContext, final JspWriter writer,
        final AvailableBlock event) throws IOException {
    SimpleDateFormat stpFormat = new SimpleDateFormat("yyyyMMdd-HHmm");
    SimpleDateFormat idFormat = CommonDateOperations.getDateTimeFormat();
    SimpleDateFormat timeFormat = new SimpleDateFormat("h:mm a");
    SimpleDateFormat readableFormat = new SimpleDateFormat("EEE MMM d");
    String appointmentTitle;

    if (event.getVisitorLimit() > 1) {
        appointmentTitle = getMessageSource().getMessage("join.appointment.for",
                new Object[] { readableFormat.format(event.getStartTime()),
                        Integer.toString(event.getVisitorLimit() - event.getVisitorsAttending()),
                        event.getVisitorLimit() },
                null);
    } else {
        appointmentTitle = getMessageSource().getMessage("create.appointment.for",
                new Object[] { readableFormat.format(event.getStartTime()) }, null);
    }
    writer.write("<li id=\"" + idFormat.format(event.getStartTime()) + "\" class=\"free\" title=\""
            + appointmentTitle.toString() + "\">");
    if (!previewMode) {
        writer.write("<a href=\"create.html?startTime=" + stpFormat.format(event.getStartTime()) + "\">");
    }
    if (event.getVisitorLimit() > 1) {
        writer.write("<img src=\"" + getSilkIconPrefix(servletContext) + "group.png\" alt=\"\"/>&nbsp;");
    } else {
        writer.write("<img src=\"" + getSilkIconPrefix(servletContext) + "calendar_add.png\" alt=\"\"/>&nbsp;");
    }
    writer.write("<span id=\"" + idFormat.format(event.getStartTime()) + "-text\">");
    writer.write(timeFormat.format(event.getStartTime()));
    writer.write(" - ");
    writer.write(timeFormat.format(event.getEndTime()));
    writer.write("</span>");

    if (!previewMode) {
        writer.write("</a>");
    }
    writer.write("</li>");
}

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

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

    if (getResults() == null || getResults().isEmpty()) {
        return SKIP_BODY;
    }//from w  ww . j av  a2 s.  c om

    try {
        String prev = messageSource.getMessage("pages.previous.label", null, "&larr; Older", null);
        String next = messageSource.getMessage("pages.next.label", null, "Newer &rarr;", null);

        HttpServletRequest request = (HttpServletRequest) pageContext.getRequest();
        String path = new UrlPathHelper().getOriginatingRequestUri(request);

        HtmlTag nextTag = li(a(next).href("#")).cssClass("next disabled");
        if (getResults().getRange() != null) {
            if (getResults().hasNextPage()) {
                String nextParams = buildQueryParamsNext(getResults().getRange());
                nextTag = li(a(next).href(path, nextParams)).cssClass("next");
            }
        }

        HtmlTag prevTag = li(a(prev).href("#")).cssClass("previous disabled");
        if (getResults().getRange() != null) {
            if (getResults().hasPreviousPage()) {
                String nextParams = buildQueryParamsPrevious(getResults().getRange());
                prevTag = li(a(prev).href(path, nextParams)).cssClass("previous");
            }
        }

        HtmlTag html = ul(prevTag, nextTag).cssClass("pager");
        jspWriter.write(html.build());

    } catch (IOException e) {
        e.printStackTrace();
    }

    return SKIP_BODY;
}

From source file:org.jasig.schedassist.portlet.VisibleScheduleTag.java

/**
 * Render a single {@link AvailableBlock} with {@link AvailableStatus#FREE}.
 * /*w  w w. j a  va  2  s.c  o m*/
 * @param writer
 * @param event
 * @param renderRequest
 * @param renderResponse
 * @throws IOException
 */
protected void renderFreeBlock(final JspWriter writer, final AvailableBlock event,
        final RenderRequest renderRequest, final RenderResponse renderResponse) throws IOException {
    SimpleDateFormat stpFormat = new SimpleDateFormat("yyyyMMdd-HHmm");
    SimpleDateFormat idFormat = CommonDateOperations.getDateTimeFormat();
    SimpleDateFormat timeFormat = new SimpleDateFormat("h:mm a");
    SimpleDateFormat readableFormat = new SimpleDateFormat("EEE MMM d");
    String appointmentTitle;

    if (event.getVisitorLimit() > 1) {
        appointmentTitle = getMessageSource().getMessage("join.appointment.for",
                new Object[] { readableFormat.format(event.getStartTime()),
                        Integer.toString(event.getVisitorLimit() - event.getVisitorsAttending()),
                        event.getVisitorLimit() },
                null);
    } else {
        appointmentTitle = getMessageSource().getMessage("create.appointment.for",
                new Object[] { readableFormat.format(event.getStartTime()) }, null);
    }
    writer.write("<li id=\"" + idFormat.format(event.getStartTime()) + "\" class=\"free\" title=\""
            + appointmentTitle.toString() + "\">");
    if (!previewMode) {
        PortletURL createUrl = renderResponse.createRenderURL();
        createUrl.setParameter("_eventId", "create");
        createUrl.setParameter("execution", flowExecutionKey);
        createUrl.setParameter("startTime", stpFormat.format(event.getStartTime()));
        createUrl.setParameter("ownerId", renderRequest.getParameter("ownerId"));
        writer.write("<a href=\"" + createUrl.toString() + "\">");
    }
    if (event.getVisitorLimit() > 1) {
        writer.write("<img src=\"" + getSilkIconPrefix() + "group.png\" alt=\"\"/>&nbsp;");
    } else {
        writer.write("<img src=\"" + getSilkIconPrefix() + "calendar_add.png\" alt=\"\"/>&nbsp;");
    }
    writer.write("<span id=\"" + idFormat.format(event.getStartTime()) + "-text\">");
    writer.write(timeFormat.format(event.getStartTime()));
    writer.write(" - ");
    writer.write(timeFormat.format(event.getEndTime()));
    writer.write("</span>");

    if (!previewMode) {
        writer.write("</a>");
    }
    writer.write("</li>");
}

From source file:cn.vlabs.duckling.vwb.tags.LinkTag.java

public int doEndTag() {
    try {//  w ww . j  a  v a2 s .co  m
        if (!m_overrideAbsolute) {
            m_absolute = false;
        }

        JspWriter out = pageContext.getOut();
        String url = figureOutURL();

        switch (m_format) {
        case URL:
            out.print(url);
            break;
        default:
        case ANCHOR:
            StringBuffer sb = new StringBuffer(20);

            sb.append((m_class != null) ? "class=\"" + m_class + "\" " : "");
            sb.append((m_style != null) ? "style=\"" + m_style + "\" " : "");
            sb.append((m_target != null) ? "target=\"" + m_target + "\" " : "");
            sb.append((m_title != null) ? "title=\"" + m_title + "\" " : "");
            sb.append((m_rel != null) ? "rel=\"" + m_rel + "\" " : "");
            sb.append((m_accesskey != null) ? "accesskey=\"" + m_accesskey + "\" " : "");
            out.print("<a " + sb.toString() + " href=\"" + url + "\">");
            break;
        }

        // Add any explicit body content. This is not the intended use
        // of LinkTag, but happens to be the way it has worked previously.
        if (m_bodyContent != null) {
            String linktext = m_bodyContent.getString().trim();
            out.write(linktext);
        }

        // Finish off by closing opened anchor
        if (m_format == ANCHOR)
            out.print("</a>");
    } catch (Exception e) {
        // Yes, we want to catch all exceptions here, including
        // RuntimeExceptions
        log.error("Tag failed", e);
    }

    return EVAL_PAGE;
}