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.sakaiproject.metaobj.shared.control.tag.ListScrollTag.java

/**
 * Default processing of the end tag returning EVAL_PAGE.
 *
 * @return EVAL_PAGE/*from   ww w. j av  a 2s  . c  o  m*/
 * @throws javax.servlet.jsp.JspException if an error occurred while processing this tag
 * @see javax.servlet.jsp.tagext.Tag#doEndTag
 */

public int doEndTag() throws JspException {

    // Don't display paging if only one page needed to display
    if (listScroll.getHideOnePageScroll() && listScroll.getFirstItem() <= 1
            && listScroll.getLastItem() == listScroll.getTotal()) {
        listScroll = null;
        listScrollExpression = DEFAULT_LIST_SCROLL;
        listUrl = null;
        return EVAL_PAGE;
    }

    JspWriter writer = pageContext.getOut();

    String first = myResources.getString("listScroll_first");
    String previous = myResources.getString("listScroll_previous");
    String next = myResources.getString("listScroll_next");
    String last = myResources.getString("listScroll_last");
    String viewing = MessageFormat.format(myResources.getString("listScroll_viewing"),
            new Object[] { listScroll.getFirstItem(), listScroll.getLastItem(), listScroll.getTotal() });

    try {

        writer.write("<div ");
        if (className != null) {
            writer.write("class=\"" + className + "\"");
        }
        writer.write(">");

        //  <input type="button" value="Next" onclick="window.document.location='url'">
        writer.write("<div class=\"instruction\">");
        writer.write(viewing);
        writer.write("</div>");
        writer.write("<input type=\"button\" value=\"" + first + "\" onclick=\"window.document.location=\'");
        writer.write(listUrl + "&" + ListScroll.STARTING_INDEX_TAG + "=0");
        writer.write("\'\"");
        if (listScroll.getPrevIndex() == -1) {
            writer.write(" disabled=\"disabled\" ");
        }
        writer.write(" />");

        writer.write("&nbsp;");

        writer.write("<input type=\"button\" value=\"" + previous + "\" onclick=\"window.document.location=\'");
        writer.write(listUrl + "&" + ListScroll.STARTING_INDEX_TAG + "=" + listScroll.getPrevIndex());
        writer.write("\'\"");
        if (listScroll.getPrevIndex() == -1) {
            writer.write(" disabled=\"disabled\" ");
        }
        writer.write(" />");

        writer.write("<input type=\"button\" value=\"" + next + "\" onclick=\"window.document.location=\'");
        writer.write(listUrl + "&" + ListScroll.STARTING_INDEX_TAG + "=" + listScroll.getNextIndex());
        writer.write("\'\"");
        if (listScroll.getNextIndex() == -1) {
            writer.write(" disabled=\"disabled\" ");
        }
        writer.write(" />");

        writer.write("&nbsp;");

        writer.write("<input type=\"button\" value=\"" + last + "\" onclick=\"window.document.location=\'");
        writer.write(listUrl + "&" + ListScroll.STARTING_INDEX_TAG + "=" + Integer.MAX_VALUE);
        writer.write("\'\"");
        if (listScroll.getNextIndex() == -1) {
            writer.write(" disabled=\"disabled\" ");
        }
        writer.write(" />");

        writer.write("</div>");

        writer.write("<br />");

    } catch (IOException e) {
        logger.error("", e);
        throw new JspException(e);
    }

    listScroll = null;
    listScrollExpression = DEFAULT_LIST_SCROLL;
    listUrl = null;

    return EVAL_PAGE;
}

From source file:org.sakaiproject.metaobj.shared.control.tag.RichTextWrapperTag.java

public int doStartTag() throws JspException {
    JspWriter writer = pageContext.getOut();

    String textAreaId = (String) ExpressionUtil.evalNotNull("richTextWrapper", "textAreaId", getTextAreaId(),
            String.class, this, pageContext);

    try {//from   w  ww . ja  v a  2s .  c  om

        writer.write("<script type=\"text/javascript\" defer=\"1\">sakai.editor.launch('" + textAreaId
                + "');</script>");

        /*
        String editor = ServerConfigurationService.getString("wysiwyg.editor");
        if(editor != null && !editor.equalsIgnoreCase("FCKeditor"))
        {
        //          Render JavaScripts.
           //writeExternalScripts(locale, writer);
           writer.write("<script type=\"text/javascript\" src=\"/library/editor/HTMLArea/sakai_editor.js\"></script>\n");
           writer.write("<script type=\"text/javascript\" defer=\"1\">chef_setupformattedtextarea('"+textAreaId+"');</script>");
                   
        } else {
                
           String collectionId = getContentHostingService().getSiteCollection(ToolManager.getCurrentPlacement().getContext());
           String tagFocus = ServerConfigurationService.getString("tags.focus");
           boolean resourceSearch = EditorConfiguration.enableResourceSearch();
                   
           writer.write("<script type=\"text/javascript\" src=\"/library/editor/FCKeditor/sakai_fckconfig.js\"></script>\n");
           writer.write("<script type=\"text/javascript\" defer=\"1\">\n");
           if(resourceSearch)
           {
              // need to set document.__pid to placementId
              String placementId = ToolManager.getCurrentPlacement().getId();
              writer.write("\t\tdocument.__pid=\"" + placementId + "\";\n");
                      
              // need to set document.__baseUrl to baseUrl
              String baseUrl = ServerConfigurationService.getToolUrl() + "/" + Web.escapeUrl(placementId);
              writer.write("\t\tdocument.__baseUrl=\"" + baseUrl + "\";\n");
           }
           writer.write("\t\tvar inputArea = document.getElementById('"+textAreaId+"');\n");
           writer.write("\t\tvar cols = document.getElementById('"+textAreaId+"').cols;\n");
           writer.write("\t\tvar rows = document.getElementById('"+textAreaId+"').rows;\n");
           writer.write("\t\tvar width = 450 * cols / 80;\n");
           writer.write("\t\tvar height = 50 * rows / 4;\n");
                   
                   
           writer.write("\t\tchef_setupfcktextarea('"+
          textAreaId+"', width, height, '" + collectionId + "', '" + tagFocus + "', '" + Boolean.toString(resourceSearch) + "');\n");
           writer.write("\t\tvar f = document.getElementById('"+textAreaId+"').form;\n" +
              "\t\tif (typeof f.onsubmit != \"function\") f.onsubmit = function() {};\n");
           writer.write("</script>");
        }
        */

    } catch (IOException e) {
        logger.error("", e);
        throw new JspException(e);
    }
    return EVAL_BODY_INCLUDE;
}

From source file:org.silverpeas.core.contribution.content.form.AbstractForm.java

/**
 * Prints the javascripts which will be used to control the new values given to the data record
 * fields. The error messages may be adapted to a local language. The RecordTemplate gives the
 * field type and constraints. The RecordTemplate gives the local label too. Never throws an
 * Exception but log a a trace and writes an empty string when :
 * <UL>//from  w  w w.  j  av  a 2s. c o m
 * <LI>a field is unknown by the template.
 * <LI>a field has not the required type.
 * </UL>
 * @param jw the JSP writer into which the javascript is written.
 * @param pagesContext the JSP page context.
 */
@Override
public void displayScripts(final JspWriter jw, final PagesContext pagesContext) {
    try {
        String language = pagesContext.getLanguage();
        StringWriter sw = new StringWriter();
        PrintWriter out = new PrintWriter(sw, true);

        boolean jsAdded = false;
        if (StringUtil.isDefined(pagesContext.getComponentId()) && StringUtil.isDefined(getName())) {
            ComponentInstLight component = OrganizationControllerProvider.getOrganisationController()
                    .getComponentInstLight(pagesContext.getComponentId());
            if (component != null && component.isWorkflow()) {
                out.append("<script type=\"text/javascript\" src=\"/weblib/workflows/")
                        .append(component.getName()).append("/").append(getName()).append(".js\"></script>\n");
                jsAdded = true;
            }
        }

        if (!jsAdded) {
            out.append(getJavascriptSnippet());
        }

        PagesContext pc = new PagesContext(pagesContext);
        pc.incCurrentFieldIndex(1);

        out.append(Util.getJavascriptIncludes(language)).append("\n<script type=\"text/javascript\">\n")
                .append("   var errorNb = 0;\n").append("   var errorMsg = \"\";\n")
                .append("function addXMLError(message) {\n").append("   errorMsg+=\"  - \"+message+\"\\n\";\n")
                .append("   errorNb++;\n").append("}\n").append("function getXMLField(fieldName) {\n")
                .append("   return document.getElementById(fieldName);\n").append("}\n")
                .append("function ifCorrectFormExecute(callback) {\n").append("   errorMsg = \"\";\n")
                .append("   errorNb = 0;\n").append("   var field;\n").append("   \n\n");

        for (FieldTemplate fieldTemplate : fieldTemplates) {
            if (fieldTemplate != null) {
                String fieldDisplayerName = fieldTemplate.getDisplayerName();
                String fieldType = fieldTemplate.getTypeName();
                String fieldName = fieldTemplate.getFieldName();
                boolean mandatory = fieldTemplate.isMandatory();
                FieldDisplayer fieldDisplayer;
                try {
                    if (fieldDisplayerName == null || fieldDisplayerName.isEmpty()) {
                        fieldDisplayerName = getTypeManager().getDisplayerName(fieldType);
                    }
                    fieldDisplayer = getTypeManager().getDisplayer(fieldType, fieldDisplayerName);

                    if (fieldDisplayer != null) {
                        int nbFieldsToDisplay = fieldTemplate.getMaximumNumberOfOccurrences();
                        for (int i = 0; i < nbFieldsToDisplay; i++) {
                            String currentFieldName = Util.getFieldOccurrenceName(fieldName, i);
                            ((GenericFieldTemplate) fieldTemplate).setFieldName(currentFieldName);
                            if (i > 0) {
                                ((GenericFieldTemplate) fieldTemplate).setMandatory(false);
                            }
                            out.append("   field = document.getElementById(\"").append(currentFieldName)
                                    .append("\");\n");
                            out.append("   if (field == null) {\n");
                            // try to find field by name
                            out.append("  var $field = $(\"input[name=").append(currentFieldName)
                                    .append("]\");\n");
                            out.append("  field = $field.length ? $field[0] : null;\n");
                            out.println("}");
                            out.append(" if (field != null) {\n");
                            fieldDisplayer.displayScripts(out, fieldTemplate, pc);
                            out.println("}");
                            pc.incCurrentFieldIndex(
                                    fieldDisplayer.getNbHtmlObjectsDisplayed(fieldTemplate, pc));
                        }

                        // set original data
                        ((GenericFieldTemplate) fieldTemplate).setFieldName(fieldName);
                        ((GenericFieldTemplate) fieldTemplate).setMandatory(mandatory);
                    }
                } catch (FormException e) {
                    SilverLogger.getLogger(this).error(e.getMessage(), e);
                }
            }
        }

        out.append("   \n\n").append("   switch(errorNb)\n").append("   {\n").append("   case 0 :\n")
                .append("      callback.call(this);\n").append("      break;\n").append("   case 1 :\n")
                .append("      errorMsg = \"").append(Util.getString("GML.ThisFormContains", language))
                .append(" 1 ").append(Util.getString("GML.error", language)).append(" : \\n \" + errorMsg;\n")
                .append("      jQuery.popup.error(errorMsg);\n").append("      break;\n")
                .append("   default :\n").append("      errorMsg = \"")
                .append(Util.getString("GML.ThisFormContains", language)).append(" \" + errorNb + \" ")
                .append(Util.getString("GML.errors", language)).append(" :\\n \" + errorMsg;\n")
                .append("      jQuery.popup.error(errorMsg);\n").append("   }\n").append("}\n")
                .append("   \n\n");

        out.append("function showOneMoreField(fieldName) {\n");
        out.append("$('.field_'+fieldName+' ." + REPEATED_FIELD_CSS_HIDE + ":first').removeClass('"
                + REPEATED_FIELD_CSS_HIDE + "').addClass('" + REPEATED_FIELD_CSS_SHOW + "');\n");
        out.append("if ($('.field_'+fieldName+' ." + REPEATED_FIELD_CSS_HIDE + "').length == 0) {\n");
        out.append(" $('#form-row-'+fieldName+' #moreField-'+fieldName).hide();\n");
        out.append("}\n");
        out.append("}\n");

        out.append("</script>\n");
        out.flush();
        jw.write(sw.toString());
    } catch (java.io.IOException e) {
        SilverLogger.getLogger(this).error(e.getMessage(), e);
    }
}

From source file:org.silverpeas.core.contribution.content.form.form.XmlSearchForm.java

/**
 * Prints the HTML layout of the dataRecord using the RecordTemplate to extract labels and extra
 * informations. The value formats may be adapted to a local language. Never throws an Exception
 * but log a silvertrace and writes an empty string when :
 * <UL>//from   w  ww .j a  v a  2  s  .c  o m
 * <LI>a field is unknown by the template.
 * <LI>a field has not the required type.
 * </UL>
 */
@Override
public void display(JspWriter jw, PagesContext pagesContext, DataRecord record) {

    try {
        String language = pagesContext.getLanguage();
        StringWriter sw = new StringWriter();
        PrintWriter out = new PrintWriter(sw, true);

        if (pagesContext.getPrintTitle() && title != null && title.length() > 0) {
            out.println("<table CELLPADDING=0 CELLSPACING=2 BORDER=0 WIDTH=\"98%\" CLASS=intfdcolor>");
            out.println("<tr>");
            out.println("<td CLASS=intfdcolor4 NOWRAP>");
            out.println("<table CELLPADDING=0 CELLSPACING=0 BORDER=0 WIDTH=\"100%\">");
            out.println("<tr>");
            out.println("<td class=\"intfdcolor\" nowrap width=\"100%\">");
            out.println("<img border=\"0\" src=\"" + Util.getIcon("px") + "\" width=5><span class=txtNav>"
                    + title + "</span>");
            out.println("</td>");
            out.println("</tr>");
            out.println("</table>");
            out.println("</td>");
            out.println("</tr>");
            out.println("</table>");
        }

        Iterator<FieldTemplate> itFields = null;
        if (fieldTemplates != null) {
            itFields = this.fieldTemplates.iterator();
        }

        if (itFields != null && itFields.hasNext()) {
            if (pagesContext.isBorderPrinted()) {
                out.println(
                        "<table width=\"98%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\" class=intfdcolor4>");
                out.println("<tr>");
                out.println("<td nowrap>");
                out.println(
                        "<table border=\"0\" cellspacing=\"0\" cellpadding=\"5\" class=\"contourintfdcolor\" width=\"100%\">");
            } else {
                out.println("<table width=\"98%\" border=\"0\" cellspacing=\"0\" cellpadding=\"5\">");
            }
            out.println("<input TYPE=\"hidden\" NAME=id VALUE=\"" + record.getId() + "\">");

            out.flush();
            jw.write(sw.toString());
            PagesContext pc = new PagesContext(pagesContext);
            pc.setNbFields(fieldTemplates.size());
            pc.incCurrentFieldIndex(1);

            // calcul lastFieldIndex
            int lastFieldIndex = -1;
            lastFieldIndex += Integer.parseInt(pc.getCurrentFieldIndex());
            FieldTemplate fieldTemplate;
            String fieldType;
            String fieldDisplayerName;
            FieldDisplayer fieldDisplayer = null;

            while (itFields.hasNext()) {
                fieldTemplate = itFields.next();
                if (fieldTemplate != null) {
                    fieldType = fieldTemplate.getTypeName();
                    fieldDisplayerName = fieldTemplate.getDisplayerName();
                    try {
                        if (fieldDisplayerName == null || fieldDisplayerName.equals("")) {
                            fieldDisplayerName = getTypeManager().getDisplayerName(fieldType);
                        }

                        fieldDisplayer = getTypeManager().getDisplayer(fieldType, fieldDisplayerName);
                        if (fieldDisplayer != null) {
                            lastFieldIndex += fieldDisplayer.getNbHtmlObjectsDisplayed(fieldTemplate, pc);
                        }
                    } catch (FormException fe) {
                        SilverLogger.getLogger(this).error(fe.getMessage(), fe);
                    }
                }
            }
            pc.setLastFieldIndex(lastFieldIndex);

            String fieldLabel;
            itFields = this.fieldTemplates.iterator();
            while (itFields.hasNext()) {
                fieldTemplate = itFields.next();
                if (fieldTemplate != null) {
                    String fieldName = fieldTemplate.getFieldName();
                    fieldLabel = fieldTemplate.getLabel(language);
                    fieldType = fieldTemplate.getTypeName();
                    fieldDisplayerName = fieldTemplate.getDisplayerName();
                    try {
                        if (!StringUtil.isDefined(fieldDisplayerName)) {
                            fieldDisplayerName = getTypeManager().getDisplayerName(fieldType);
                        }
                        fieldDisplayer = getTypeManager().getDisplayer(fieldType, fieldDisplayerName);
                    } catch (FormException fe) {
                        SilverLogger.getLogger(this).error(fe.getMessage(), fe);
                    }

                    if (fieldDisplayer != null) {
                        sw = new StringWriter();
                        out = new PrintWriter(sw, true);
                        out.println("<tr align=center>");
                        out.println("<td class=\"txtlibform\" align=left width=\"200\">");
                        if (StringUtil.isDefined(fieldLabel)) {
                            out.println(fieldLabel);
                        } else {
                            out.println("&nbsp;");
                        }
                        out.println("</td>");
                        out.println("<td valign=\"baseline\" align=left>");
                        try {
                            fieldDisplayer.display(out, record.getField(fieldName), fieldTemplate, pc);
                        } catch (FormException fe) {
                            SilverLogger.getLogger(this).error(fe.getMessage(), fe);
                        }
                        out.println("</td>");
                        out.println("</tr>");
                        out.flush();
                        jw.write(sw.toString());
                        pc.incCurrentFieldIndex(fieldDisplayer.getNbHtmlObjectsDisplayed(fieldTemplate, pc));
                    }
                }
            }
            sw = new StringWriter();
            out = new PrintWriter(sw, true);
            if (pagesContext.isBorderPrinted()) {
                out.println("</table>");
                out.println("</td>");
                out.println("</tr>");
            }
            out.println("</table>");
            out.flush();
            jw.write(sw.toString());
        }
    } catch (java.io.IOException fe) {
        SilverLogger.getLogger(this).error(fe.getMessage(), fe);
    }
}

From source file:org.wso2.carbon.ui.taglibs.Breadcrumb.java

/**
 * JSP end tag for breadcrumb tag/* w  ww.j a v a2 s.  c  o m*/
 */
public int doEndTag() throws JspException {
    String disableBreadCrumbs = System.getProperty(disableBreadCrumbsProperty);
    boolean isBreadCrumbDisabled = (disableBreadCrumbs == null) ? false
            : disableBreadCrumbs.equalsIgnoreCase("true");
    String breadcrumbConent = "";
    String cookieContent = "";
    JspWriter writer = pageContext.getOut();
    if (isBreadCrumbDisabled) {
        try {
            writer.write("");
        } catch (IOException e) {
            //do nothing
        }
        return 0;
    }

    StringBuffer content = new StringBuffer();

    if (request != null) {
        String retainLastBreadcrumbStr = request.getParameter("retainlastbc");
        if (log.isDebugEnabled()) {
            log.debug("BreadcrumbTag : " + request.getPathTranslated());
        }

        String path = (String) request.getAttribute("javax.servlet.include.request_uri");

        // now path contains value similar to following. eg: path =
        // /carbon/userstore/index.jsp
        // Find last occurance of "carbon". This is the starting of web app context.
        int carbonLocation = path.lastIndexOf("carbon");
        String jspFilePath = path.substring(carbonLocation, path.length());
        // now, jspFilePath = carbon/service-mgt/list_service_main.jsp
        // now, replace 'carbon' and you get path to real file name
        jspFilePath = jspFilePath.replaceFirst("carbon", "..");

        //Find subcontext before jsp file
        int lastIndexofSlash = jspFilePath.lastIndexOf('/');
        String subContextToJSP = jspFilePath.substring(0, lastIndexofSlash);

        //Find jsp file name
        String jspFileName = jspFilePath.substring(lastIndexofSlash + 1, jspFilePath.length());
        //save query string for current url
        String queryString = request.getQueryString();

        //creating a new breadcrumb item for page request
        BreadCrumbItem breadCrumbItem = new BreadCrumbItem();
        //creating breadcrumb id using jsp file path
        //This is guaranteed to be unique for a subcontext (eg: /modulemgt,/service-listing)
        breadCrumbItem.setId(jspFileName);

        Locale locale = CarbonUIUtil.getLocaleFromSession(request);
        String text = CarbonUIUtil.geti18nString(label, resourceBundle, locale);
        breadCrumbItem.setConvertedText(text);

        //if request contains parameter 'toppage', override the value of this.topPage with
        //the value set in request.
        //This is useful when same page is being used @ different levels. 
        //eg: wsdl2code/index.jsp
        //This page is being called from Tools -> WSDL2Code & Service Details -> Generate Client
        String topPageParameter = request.getParameter("toppage");
        if (topPageParameter != null) {
            boolean topPageParamValue = Boolean.valueOf(topPageParameter).booleanValue();
            if (log.isDebugEnabled()) {
                log.debug("toppage value set from request parameter.(" + topPageParamValue + ").");
            }
            this.topPage = topPageParamValue;
        }

        if (!topPage) {
            // need to add this url as a breadcrumb
            HashMap<String, List<BreadCrumbItem>> links = (HashMap<String, List<BreadCrumbItem>>) request
                    .getSession().getAttribute("page-breadcrumbs");

            String partUrl = "";
            if (queryString != null) {
                partUrl = jspFilePath + "?" + queryString;
            } else {
                partUrl = jspFilePath;
            }

            if (links != null) {
                //check if a breadcrumb exists for given sub context
                List<BreadCrumbItem> breadcrumbsForSubContext = links.get(subContextToJSP);
                int size = 0;
                if (breadcrumbsForSubContext != null) {
                    int sizeOfSubContextBreadcrumbs = breadcrumbsForSubContext.size();
                    //removing to stop this array getting grown with duplicates
                    ArrayList idsToRemove = new ArrayList();
                    for (int a = 0; a < sizeOfSubContextBreadcrumbs; a++) {
                        if (breadcrumbsForSubContext.get(a).getId().equals(jspFileName)) {
                            idsToRemove.add(a);
                        }
                    }
                    if (idsToRemove.size() > 0) {
                        for (Object anIdsToRemove : idsToRemove) {
                            Integer i = (Integer) anIdsToRemove;
                            breadcrumbsForSubContext.remove(i.intValue());
                        }
                    }

                    size = breadcrumbsForSubContext.size();
                    breadCrumbItem.setOrder(size + 1);
                    breadCrumbItem.setLink(partUrl);
                    breadcrumbsForSubContext.add(breadCrumbItem);
                    links.put(subContextToJSP, breadcrumbsForSubContext);
                    request.getSession().setAttribute("page-breadcrumbs", links);
                } else {
                    breadcrumbsForSubContext = new ArrayList<BreadCrumbItem>();
                    breadCrumbItem.setOrder(size + 1);
                    breadCrumbItem.setLink(partUrl);
                    breadcrumbsForSubContext.add(breadCrumbItem);
                    links.put(subContextToJSP, breadcrumbsForSubContext);
                    request.getSession().setAttribute("page-breadcrumbs", links);
                }
            } else {
                HashMap<String, List<BreadCrumbItem>> tmp = new HashMap<String, List<BreadCrumbItem>>();
                // Going inside for the first time
                breadCrumbItem.setOrder(1);
                breadCrumbItem.setLink(partUrl);
                List<BreadCrumbItem> list = new ArrayList<BreadCrumbItem>();
                list.add(breadCrumbItem);
                tmp.put(subContextToJSP, list);
                request.getSession().setAttribute("page-breadcrumbs", tmp);
            }
        }
        boolean retainLastBreadcrumb = false;
        if (retainLastBreadcrumbStr != null) {
            retainLastBreadcrumb = Boolean.parseBoolean(retainLastBreadcrumbStr);
        }

        BreadCrumbGenerator breadCrumbGenerator = new BreadCrumbGenerator();
        HashMap<String, String> generatedContent = breadCrumbGenerator.getBreadCrumbContent(request,
                breadCrumbItem, jspFilePath, topPage, retainLastBreadcrumb);
        breadcrumbConent = generatedContent.get("html-content");
        cookieContent = generatedContent.get("cookie-content");
    }

    content.append("<script type=\"text/javascript\">\n");
    content.append("    setCookie('current-breadcrumb', '" + cookieContent + "');\n");
    content.append("    document.onload=setBreadcrumDiv();\n");
    content.append("    function setBreadcrumDiv () {\n");
    content.append("        var breadcrumbDiv = document.getElementById('breadcrumb-div');\n");
    if (!hidden) {
        content.append("        breadcrumbDiv.innerHTML = '" + breadcrumbConent + "';\n");
    } else {
        //do not print breadcrumb
        content.append("        breadcrumbDiv.innerHTML = '';\n");
    }
    content.append("    }\n");
    content.append("</script>\n");

    try {
        writer.write(content.toString());
    } catch (IOException e) {
        String msg = "Cannot write breadcrumb tag content";
        log.error(msg, e);

        try {
            //exit gracefully
            writer.write("");
        } catch (IOException e1) {
            //do nothing
        }
    }
    return 0;
}

From source file:org.wso2.carbon.ui.taglibs.ItemGroupSelector.java

public int doEndTag() throws JspException {

    String selectAllInPage = (selectAllInPageKey != null) ? selectAllInPageKey : "Select all in this page";
    String selectAll = (selectAllKey != null) ? selectAllKey : "Select all in all pages";
    String selectNone = (selectNoneKey != null) ? selectNoneKey : "Select none";
    String addRemove = (addRemoveKey != null) ? addRemoveKey : "Remove";

    if (resourceBundle != null) {
        try {//from  w w w .  j  a v  a 2 s  .co m
            Locale locale = JSi18n.getLocaleFromPageContext(pageContext);
            ResourceBundle bundle = ResourceBundle.getBundle(resourceBundle, locale);
            selectAllInPage = bundle.getString(selectAllInPageKey);
            selectAll = bundle.getString(selectAllKey);
            selectNone = bundle.getString(selectNoneKey);
            if (addRemoveKey != null) {
                addRemove = bundle.getString(addRemoveKey);
            } else {
                addRemove = "";
            }
        } catch (Exception e) {
            log.warn("Error while i18ning ItemGroupSelector", e);
        }
    }

    JspWriter writer = pageContext.getOut();

    String content = "<table>" + "<tr>" + "<td><a href=\"#\" onclick=\"" + selectAllInPageFunction
            + ";return false;\"  " + "style=\"cursor:pointer\">" + selectAllInPage + "</a>&nbsp<b>|</b>&nbsp;"
            + "</td>";
    if (numberOfPages > 1) {
        content += "<td><a href=\"#\" onclick=\"" + selectAllFunction + ";return false;\"  "
                + "style=\"cursor:pointer\">" + selectAll + "</a>&nbsp<b>|</b>&nbsp;</td>";
    }

    content += "<td><a href=\"#\" onclick=\"" + selectNoneFunction + ";return false;\"  "
            + "style=\"cursor:pointer\">" + selectNone + "</a></td>" + "<td width=\"20%\">&nbsp;</td>";

    if (addRemoveButtonId != null) {

        content += ("<td><a href='#' id=\"" + addRemoveButtonId + "\" onclick=\"" + addRemoveFunction
                + ";return false;\">" + addRemove);
        content += "</a></td>";

    }
    content += (extraHtml != null ? "<td>" + extraHtml + "</td>" : "") + "</tr>" + "</table>";
    try {
        writer.write(content);
    } catch (IOException e) {
        String msg = "Cannot write ItemSelector tag content";
        log.error(msg, e);
        throw new JspException(msg, e);
    }
    return 0;
}

From source file:org.wso2.carbon.ui.taglibs.JSi18n.java

public int doEndTag() throws JspException {
    if (request != null) {
        // Retrieve locale from either session or request headers
        Locale locale = getLocaleFromPageContext(pageContext);

        String jsString = "<script type=\"text/javascript\" src='../yui/build/utilities/utilities.js'></script>"
                + "<script type=\"text/javascript\" src='../yui/build/yahoo/yahoo-min.js'></script>"
                + "<script type=\"text/javascript\" src='../yui/build/json/json-min.js'></script>"
                + "<script type=\"text/javascript\"> var "
                + ((getNamespace() != null) ? getNamespace() + "_" : "") + "tmpPairs = '{";

        boolean firstPair = true;

        // Retrieve the default carbon JS resource bundle
        ResourceBundle defaultBunndle = ResourceBundle.getBundle(ORG_WSO2_CARBON_I18N_JSRESOURCES, locale);

        // Retrieve keys from the default bundle
        for (Enumeration e = defaultBunndle.getKeys(); e.hasMoreElements();) {
            String key = (String) e.nextElement();
            String value = defaultBunndle.getString(key);
            if (firstPair) {
                jsString = jsString + "\"" + key + "\":\"" + value + "\"";
                firstPair = false;/*from w w  w.  j av a2 s. c  om*/
            } else {
                jsString = jsString + ",\"" + key + "\":\"" + value + "\"";
            }
        }

        if (resourceBundle != null) {
            // Retrieve the resource bundle
            ResourceBundle bundle = ResourceBundle.getBundle(resourceBundle, locale);

            // Retrieve keys from the user defined bundle
            for (Enumeration e = bundle.getKeys(); e.hasMoreElements();) {
                String key = (String) e.nextElement();
                String value = bundle.getString(key);
                if (firstPair) {
                    jsString = jsString + "\"" + key + "\":\"" + value + "\"";
                    firstPair = false;
                } else {
                    jsString = jsString + ",\"" + key + "\":\"" + value + "\"";
                }
            }
        }

        jsString = jsString + "}'; var " + getI18nObjectName() + " = YAHOO.lang.JSON.parse("
                + ((getNamespace() != null) ? getNamespace() + "_" : "") + "tmpPairs);</script>";

        StringBuffer content = new StringBuffer();
        content.append(jsString);

        // Write to output
        JspWriter writer = pageContext.getOut();
        try {
            writer.write(content.toString());
        } catch (IOException e) {
            String msg = "Cannot write i18n tag content";
            log.error(msg, e);

            try {
                //exit gracefully
                writer.write("");
            } catch (IOException e1) {
                /*do nothing*/}
        }

    }

    return 0;
}

From source file:org.wso2.carbon.ui.taglibs.Paginator.java

public int doEndTag() throws JspException {
    String next = "next";
    String prev = "prev";
    if (resourceBundle != null) {
        try {// ww w .  ja v  a  2  s . c  om
            Locale locale = JSi18n.getLocaleFromPageContext(pageContext);
            ResourceBundle bundle = ResourceBundle.getBundle(resourceBundle, locale);
            next = bundle.getString(nextKey);
            prev = bundle.getString(prevKey);
        } catch (Exception e) {
            log.warn("Error while i18ning paginator", e);
        }
    }

    JspWriter writer = pageContext.getOut();

    String content = "<table><tr>";
    if (numberOfPages > 1) {
        if (pageNumber > 0) {
            if (!"post".equals(action)) {
                content += "<td><strong><a href=\"" + page + "?" + pageNumberParameterName + "=0" + "&"
                        + parameters + "\">&lt;&lt;first" + "&nbsp;&nbsp;</a></strong></td>"
                        + "<td><strong><a href=\"" + page + "?" + pageNumberParameterName + "="
                        + (pageNumber - 1) + "&" + parameters + "\">" + "&lt;&nbsp;" + prev
                        + "&nbsp;&nbsp;</a></strong></td>";
            } else {
                content += "<td><strong><a href=# onclick=\"doPaginate('" + page + "','"
                        + pageNumberParameterName + "','" + (0) + "')\">&lt;&lt;first"
                        + "&nbsp;&nbsp;</a></strong></td>" + "<td><strong><a href=# onclick=\"doPaginate('"
                        + page + "','" + pageNumberParameterName + "','" + (pageNumber - 1) + "')\">"
                        + "&lt;&nbsp;" + prev + "&nbsp;&nbsp;</a></strong></td>";
            }
        } else {
            content += "<td ><strong ><span style=\"color:gray\">" + "&lt;&lt; first " + "&nbsp;&nbsp;&lt;"
                    + prev + "&nbsp;&nbsp;</span></strong></td>";
        }

        if (showPageNumbers) {
            int firstLinkNo;
            int lastLinkNo;
            if (noOfPageLinksToDisplay % 2 == 0) {

                if ((pageNumber - (noOfPageLinksToDisplay / 2 - 1)) < 0) {
                    firstLinkNo = 0;
                } else {
                    firstLinkNo = pageNumber - (noOfPageLinksToDisplay / 2 - 1);
                }

                if ((pageNumber + noOfPageLinksToDisplay / 2) > numberOfPages - 1) {
                    lastLinkNo = numberOfPages - 1;
                } else {
                    lastLinkNo = pageNumber + noOfPageLinksToDisplay / 2;
                }

            } else {
                if ((pageNumber - (int) Math.floor(noOfPageLinksToDisplay / 2)) < 0) {
                    firstLinkNo = 0;
                } else {
                    firstLinkNo = pageNumber - (int) Math.floor(noOfPageLinksToDisplay / 2);
                }

                if ((pageNumber + (int) Math.floor(noOfPageLinksToDisplay / 2)) > numberOfPages - 1) {
                    lastLinkNo = numberOfPages - 1;
                } else {
                    lastLinkNo = pageNumber + (int) Math.floor(noOfPageLinksToDisplay / 2);
                }
            }
            if (firstLinkNo != 0) {
                content += "<td><strong> ... &nbsp;&nbsp;</strong></td> ";
            }
            for (int i = firstLinkNo; i <= lastLinkNo; i++) {
                if (i == pageNumber) {
                    content += "<td><strong>" + (i + 1) + "&nbsp;&nbsp;</strong></td>";
                } else {
                    if (!"post".equals(action)) {
                        content += "<td><strong><a href=\"" + page + "?" + pageNumberParameterName + "=" + i
                                + "&" + parameters + "\">" + (i + 1) + " &nbsp;&nbsp;</a></strong></td>";
                    } else {
                        content += "<td><strong>" + "<a href=# onclick=\"doPaginate('" + page + "','"
                                + pageNumberParameterName + "','" + (i) + "')\">" + (i + 1)
                                + " &nbsp;&nbsp;</a></strong></td>";
                    }
                }
            }

            if (lastLinkNo != numberOfPages - 1) {
                content += "<td><strong> ... &nbsp;&nbsp;</strong></td> ";
            }
        } else {
            content += "<td><strong> Page &nbsp;&nbsp;" + (pageNumber + 1) + " of  " + numberOfPages
                    + " &nbsp;&nbsp;</strong></td>";
        }

        if (pageNumber < numberOfPages - 1) {
            if (!"post".equals(action)) {
                content += "<td ><strong ><a href =\"" + page + "?" + pageNumberParameterName + "="
                        + (pageNumber + 1) + "&" + parameters + "\">" + next + "&nbsp;&gt;</a></strong></td>"
                        + "<td ><strong ><a href =\"" + page + "?" + pageNumberParameterName + "="
                        + (numberOfPages - 1) + "&" + parameters + "\">" + "&nbsp;&nbsp;last"
                        + "&nbsp;&gt;&gt;</a></strong></td>";
            } else {
                content += "<td ><strong><a href=# onclick=\"doPaginate('" + page + "','"
                        + pageNumberParameterName + "','" + (pageNumber + 1) + "')\">" + next
                        + "&nbsp;&gt;</a></strong></td>" + "<td ><strong ><a href=# onclick=\"doPaginate('"
                        + page + "','" + pageNumberParameterName + "','" + (numberOfPages - 1) + "')\">"
                        + "&nbsp;&nbsp;last" + "&nbsp;&gt;&gt;</a></strong></td>";
            }
        } else {
            content += "<td ><strong ><span style=\"color:gray\">" + next + " &gt;&nbsp;&nbsp;" + "last"
                    + "&gt;&gt; " + "</span></strong></td>";
        }
    }
    content += "</tr ></table > ";
    try {
        writer.write(content);
    } catch (IOException e) {
        String msg = "Cannot write paginator tag content";
        log.error(msg, e);
        throw new JspException(msg, e);
    }
    return 0;
}

From source file:org.wso2.carbon.ui.taglibs.ResourcePaginator.java

public int doEndTag() throws JspException {
    if (getNumberOfPages() < 2) {
        // Pagination is not required.
        return 0;
    }/*from   www .j av  a 2s.co  m*/
    String next = "Next";
    String prev = "Prev";
    String pageName = "Page {0}";
    if (getResourceBundle() != null) {
        try {
            Locale locale = JSi18n.getLocaleFromPageContext(pageContext);
            ResourceBundle bundle = ResourceBundle.getBundle(getResourceBundle(), locale);
            next = bundle.getString(getNextKey());
            prev = bundle.getString(getPrevKey());
        } catch (Exception e) {
            log.warn("Error while i18ning paginator", e);
        }
    }

    JspWriter writer = pageContext.getOut();

    StringBuffer content = new StringBuffer("<tr><td ");
    if (tdColSpan > 0) {
        content.append("colspan=\"").append(tdColSpan).append("\" ");
    }
    content.append("class=\"pagingRow\" style=\"text-align:center;padding-top:10px; padding-bottom:10px;\">");

    if (getPageNumber() == 1) {
        content.append("<span class=\"disableLink\">< ").append(prev).append("</span>");
    } else {
        content.append("<a class=\"pageLinks\" title=\"")
                .append(pageName.replace("{0}", Integer.toString(getPageNumber() - 1))).append("\"");
        if (getPaginationFunction() != null) {
            content.append("onclick=\"")
                    .append(getPaginationFunction().replace("{0}", Integer.toString(getPageNumber() - 1)))
                    .append("\"");
        }
        content.append(">< ").append(prev).append("</a>");
    }
    if (getNumberOfPages() <= 10) {
        for (int pageItem = 1; pageItem <= getNumberOfPages(); pageItem++) {
            content.append("<a title=\"").append(pageName.replace("{0}", Integer.toString(pageItem)))
                    .append("\" class=\"");
            if (getPageNumber() == pageItem) {
                content.append("pageLinks-selected\"");
            } else {
                content.append("pageLinks\"");
            }
            if (getPaginationFunction() != null) {
                content.append("onclick=\"")
                        .append(getPaginationFunction().replace("{0}", Integer.toString(pageItem)))
                        .append("\"");
            }
            content.append(">").append(pageItem).append("</a>");
        }
    } else {
        // FIXME: The equals comparisons below looks buggy. Need to test whether the desired
        // behaviour is met, when there are more than ten pages.
        String place = MIDDLE;
        int pageItemFrom = getPageNumber() - 2;
        int pageItemTo = getPageNumber() + 2;

        if (getNumberOfPages() - getPageNumber() <= 5) {
            place = END;
        }
        if (getPageNumber() <= 5) {
            place = START;
        }

        if (START.equals(place)) {
            pageItemFrom = 1;
            pageItemTo = 7;
        }
        if (END.equals(place)) {
            pageItemFrom = getNumberOfPages() - 7;
            pageItemTo = getNumberOfPages();
        }

        if (END.equals(place) || MIDDLE.equals(place)) {
            for (int pageItem = 1; pageItem <= 2; pageItem++) {
                content.append("<a title=\"").append(pageName.replace("{0}", Integer.toString(pageItem)))
                        .append("\" class=\"pageLinks\"");
                if (getPaginationFunction() != null) {
                    content.append("onclick=\"")
                            .append(getPaginationFunction().replace("{0}", Integer.toString(pageItem)))
                            .append("\"");
                }
                content.append(">").append(pageItem).append("</a>");
            }
            content.append("...");
        }

        for (int pageItem = pageItemFrom; pageItem <= pageItemTo; pageItem++) {
            content.append("<a title=\"").append(pageName.replace("{0}", Integer.toString(pageItem)))
                    .append("\" class=\"");
            if (getPageNumber() == pageItem) {
                content.append("pageLinks-selected\"");
            } else {
                content.append("pageLinks\"");
            }
            if (getPaginationFunction() != null) {
                content.append("onclick=\"")
                        .append(getPaginationFunction().replace("{0}", Integer.toString(pageItem)))
                        .append("\"");
            }
            content.append(">").append(pageItem).append("</a>");
        }

        if (START.equals(place) || MIDDLE.equals(place)) {
            content.append("...");
            for (int pageItem = (getNumberOfPages() - 1); pageItem <= getNumberOfPages(); pageItem++) {

                content.append("<a title=\"").append(pageName.replace("{0}", Integer.toString(pageItem)))
                        .append("\" class=\"pageLinks\"");
                if (getPaginationFunction() != null) {
                    content.append("onclick=\"")
                            .append(getPaginationFunction().replace("{0}", Integer.toString(pageItem)))
                            .append("\"");
                }
                content.append("style=\"margin-left:5px;margin-right:5px;\">").append(pageItem).append("</a>");
            }
        }
    }
    if (getPageNumber() == getNumberOfPages()) {
        content.append("<span class=\"disableLink\">").append(next).append(" ></span>");
    } else {
        content.append("<a class=\"pageLinks\" title=\"")
                .append(pageName.replace("{0}", Integer.toString(getPageNumber() + 1))).append("\"");
        if (getPaginationFunction() != null) {
            content.append("onclick=\"")
                    .append(getPaginationFunction().replace("{0}", Integer.toString(getPageNumber() + 1)))
                    .append("\"");
        }
        content.append(">").append(next).append(" ></a>");
    }
    content.append("<span id=\"xx").append(getPageNumber()).append("\" style=\"display:none\" /></td></tr>");
    try {
        writer.write(content.toString());
    } catch (IOException e) {
        String msg = "Cannot write paginator tag content";
        log.error(msg, e);
        throw new JspException(msg, e);
    }
    return 0;
}

From source file:org.wso2.carbon.ui.taglibs.SimpleItemGroupSelector.java

public int doEndTag() throws JspException {
    String selectAll = "Select all in all pages";
    String selectNone = "Select none";
    if (resourceBundle != null) {
        try {//from w w  w . j  av  a 2s  .  c om
            Locale locale = JSi18n.getLocaleFromPageContext(pageContext);
            ResourceBundle bundle = ResourceBundle.getBundle(resourceBundle, locale);
            selectAll = bundle.getString(selectAllKey);
            selectNone = bundle.getString(selectNoneKey);
        } catch (Exception e) {
            log.warn("Error while i18ning SimpleItemGroupSelector", e);
        }
    }

    JspWriter writer = pageContext.getOut();

    String content = "<a href=\"#\" onclick=\"" + selectAllFunction + ";return false;\"  "
            + "style=\"cursor:pointer\">" + selectAll + "</a>&nbsp<b>|</b>&nbsp;" + "<a href=\"#\" onclick=\""
            + selectNoneFunction + ";return false;\"  " + "style=\"cursor:pointer\">" + selectNone + "</a>";
    try {
        writer.write(content);
    } catch (IOException e) {
        String msg = "Cannot write SimpleItemGroupSelector tag content";
        log.error(msg, e);
        throw new JspException(msg, e);
    }
    return 0;
}