Search in sources :

Example 21 with JspWriter

use of javax.servlet.jsp.JspWriter in project Openfire by igniterealtime.

the class SidebarTag method doEndTag.

/**
     * Gets the {@link AdminPageBean} instance from the request. If it doesn't exist then execution is stopped
     * and nothing is printed. If it exists, retrieve values from it and render the sidebar items. The body content
     * of the tag is assumed to have an A tag in it with tokens to replace (see class description) as well
     * as having a subsidebar tag..
     *
     * @return {@link #EVAL_PAGE} after rendering the tabs.
     * @throws JspException if an exception occurs while rendering the sidebar items.
     */
@Override
public int doEndTag() throws JspException {
    // Start by getting the request from the page context
    HttpServletRequest request = (HttpServletRequest) pageContext.getRequest();
    // Check for body of this tag and the child tag
    if (getBodyContent().getString() == null) {
        throw new JspException("Error, no template (body value) set for the sidebar tag.");
    }
    if (subsidebarTag.getBody() == null) {
        throw new JspException("Error, no template (body value) set for the subsidebar tag");
    }
    // Get the initial subpage and page IDs
    String subPageID = (String) request.getAttribute("subPageID");
    String pageID = (String) request.getAttribute("pageID");
    // subPageIDs are null, return because these are key to execution of the tag.
    if (subPageID != null || pageID != null) {
        if (pageID == null) {
            Element subPage = AdminConsole.getElemnetByID(subPageID);
            pageID = subPage.getParent().getParent().attributeValue("id");
        }
        // Top level menu items
        if (AdminConsole.getModel().elements().size() > 0) {
            JspWriter out = pageContext.getOut();
            StringBuilder buf = new StringBuilder();
            Element current = null;
            Element subcurrent = null;
            Element subnav = null;
            if (subPageID != null) {
                subcurrent = AdminConsole.getElemnetByID(subPageID);
            }
            current = AdminConsole.getElemnetByID(pageID);
            if (current != null) {
                subnav = current.getParent();
            }
            Element currentTab = (Element) AdminConsole.getModel().selectSingleNode("//*[@id='" + pageID + "']/ancestor::tab");
            boolean isSubmenu = false;
            if (subcurrent != null) {
                isSubmenu = subcurrent.getParent().getParent().getName().equals("item");
            }
            // Loop through all items in the root, print them out
            if (currentTab != null && subnav != null) {
                Element sidebar = subnav.getParent().getParent();
                //String header = sidebar.attributeValue("name");
                String pluginName = sidebar.attributeValue("plugin");
                // Print the header:
                String hcss = getHeadercss();
                if (hcss == null) {
                    hcss = "";
                }
                Collection items = subnav.elements();
                if (items.size() > 0) {
                    buf.append("<ul>");
                    // Now print all items:
                    for (Object itemObj : items) {
                        Element item = (Element) itemObj;
                        String subitemID = item.attributeValue("id");
                        String subitemName = item.attributeValue("name");
                        String subitemURL = item.attributeValue("url");
                        String subitemDescr = item.attributeValue("description");
                        pluginName = item.attributeValue("plugin");
                        String value = getBodyContent().getString();
                        if (value != null) {
                            value = StringUtils.replace(value, "[id]", clean(subitemID));
                            value = StringUtils.replace(value, "[name]", clean(AdminConsole.getAdminText(subitemName, pluginName)));
                            value = StringUtils.replace(value, "[description]", clean(AdminConsole.getAdminText(subitemDescr, pluginName)));
                            value = StringUtils.replace(value, "[url]", request.getContextPath() + "/" + clean(subitemURL));
                        }
                        String css = getCss();
                        boolean isCurrent = item.equals(current);
                        boolean showSubmenu = subPageID != null;
                        if (isCurrent && !showSubmenu) {
                            css = getCurrentcss();
                        }
                        buf.append("<li class=\"").append(css).append("\">").append(value).append("</li>");
                        // Print out a submenu if one exists:
                        if (isSubmenu && isCurrent) {
                            // Get the parent of the current item so we can get its
                            // items - those will be siblings of the current item:
                            Iterator siblings = subcurrent.getParent().elementIterator();
                            boolean hadNext = siblings.hasNext();
                            if (hadNext) {
                                // Print out beginning UL
                                buf.append("<li class=\"\"><ul class=\"subitems\">\n");
                                // Print the header LI
                                String subheader = subcurrent.getParent().attributeValue("name");
                                pluginName = subcurrent.getParent().attributeValue("plugin");
                                buf.append("<li class=\"").append(hcss).append("\">").append(clean(AdminConsole.getAdminText(subheader, pluginName))).append("</li>");
                            }
                            String extraParams = (String) request.getAttribute("extraParams");
                            while (siblings.hasNext()) {
                                Element sibling = (Element) siblings.next();
                                String sibID = sibling.attributeValue("id");
                                String sibName = sibling.attributeValue("name");
                                String sibDescr = sibling.attributeValue("description");
                                String sibURL = sibling.attributeValue("url");
                                pluginName = sibling.attributeValue("plugin");
                                if (extraParams != null) {
                                    sibURL += ((sibURL.indexOf('?') > -1 ? "&" : "?") + extraParams);
                                }
                                boolean isSubCurrent = sibling.equals(subcurrent);
                                String subcss = getCss();
                                if (isSubCurrent) {
                                    subcss = getCurrentcss();
                                }
                                String svalue = getSubsidebarTag().getBody();
                                if (svalue != null) {
                                    svalue = StringUtils.replace(svalue, "[id]", clean(sibID));
                                    svalue = StringUtils.replace(svalue, "[name]", clean(AdminConsole.getAdminText(sibName, pluginName)));
                                    svalue = StringUtils.replace(svalue, "[description]", clean(AdminConsole.getAdminText(sibDescr, pluginName)));
                                    svalue = StringUtils.replace(svalue, "[url]", request.getContextPath() + "/" + clean(sibURL));
                                }
                                buf.append("<li class=\"").append(subcss).append("\">").append(svalue).append("</li>\n");
                            }
                            if (hadNext) {
                                // Print out ending UL
                                buf.append("</ul></li>\n");
                            }
                        }
                    }
                    buf.append("</ul>");
                    try {
                        out.write(buf.toString());
                    } catch (IOException e) {
                        throw new JspException(e);
                    }
                }
            }
        }
    }
    return EVAL_PAGE;
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) JspException(javax.servlet.jsp.JspException) Element(org.dom4j.Element) Iterator(java.util.Iterator) Collection(java.util.Collection) IOException(java.io.IOException) JspWriter(javax.servlet.jsp.JspWriter)

Example 22 with JspWriter

use of javax.servlet.jsp.JspWriter in project Openfire by igniterealtime.

the class SubnavTag method doEndTag.

/**
     * Gets the {@link AdminPageBean} instance from the request. If it doesn't exist then execution is stopped
     * and nothing is printed. If it exists, retrieve values from it and render the sidebar items. The body content
     * of the tag is assumed to have an A tag in it with tokens to replace (see class description) as well
     * as having a subsidebar tag..
     *
     * @return {@link #EVAL_PAGE} after rendering the tabs.
     * @throws JspException if an exception occurs while rendering the sidebar items.
     */
@Override
public int doEndTag() throws JspException {
    // Start by getting the request from the page context
    HttpServletRequest request = (HttpServletRequest) pageContext.getRequest();
    // Check for body of this tag and the child tag
    if (getBodyContent().getString() == null) {
        throw new JspException("Error, no template (body value) set for the sidebar tag.");
    }
    // Get the initial subpage and page IDs
    String subPageID = (String) request.getAttribute("subPageID");
    String pageID = (String) request.getAttribute("pageID");
    // subPageIDs are null, return because these are key to execution of the tag.
    if (subPageID != null || pageID != null) {
        if (pageID == null) {
            Element subPage = AdminConsole.getElemnetByID(subPageID);
            pageID = subPage.getParent().getParent().attributeValue("id");
        }
        // Top level menu items
        if (AdminConsole.getModel().elements().size() > 0) {
            JspWriter out = pageContext.getOut();
            StringBuilder buf = new StringBuilder();
            Element current = null;
            Element subcurrent = null;
            Element subnav = null;
            if (subPageID != null) {
                subcurrent = AdminConsole.getElemnetByID(subPageID);
            }
            current = AdminConsole.getElemnetByID(pageID);
            if (current != null) {
                if (subcurrent != null) {
                    subnav = subcurrent.getParent().getParent().getParent();
                } else {
                    subnav = current.getParent();
                }
            }
            Element currentTab = (Element) AdminConsole.getModel().selectSingleNode("//*[@id='" + pageID + "']/ancestor::tab");
            // Loop through all items in the root, print them out
            if (currentTab != null) {
                Collection items = currentTab.elements();
                if (items.size() > 0) {
                    buf.append("<ul>");
                    for (Object itemObj : items) {
                        Element item = (Element) itemObj;
                        if (item.elements().size() > 0) {
                            Element firstSubItem = (Element) item.elements().get(0);
                            String pluginName = item.attributeValue("plugin");
                            String subitemID = item.attributeValue("id");
                            String subitemName = item.attributeValue("name");
                            String subitemURL = firstSubItem.attributeValue("url");
                            String subitemDescr = item.attributeValue("description");
                            String value = getBodyContent().getString();
                            if (value != null) {
                                value = StringUtils.replace(value, "[id]", clean(subitemID));
                                value = StringUtils.replace(value, "[name]", clean(AdminConsole.getAdminText(subitemName, pluginName)));
                                value = StringUtils.replace(value, "[description]", clean(AdminConsole.getAdminText(subitemDescr, pluginName)));
                                value = StringUtils.replace(value, "[url]", request.getContextPath() + "/" + clean(subitemURL));
                            }
                            String css = getCss();
                            boolean isCurrent = subnav != null && item.equals(subnav);
                            if (isCurrent) {
                                css = getCurrentcss();
                            }
                            buf.append("<li class=\"").append(css).append("\">").append(value).append("</li>");
                        }
                    }
                    buf.append("</ul>");
                    try {
                        out.write(buf.toString());
                    } catch (IOException e) {
                        throw new JspException(e);
                    }
                }
            }
        }
    }
    return EVAL_PAGE;
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) JspException(javax.servlet.jsp.JspException) Element(org.dom4j.Element) Collection(java.util.Collection) IOException(java.io.IOException) JspWriter(javax.servlet.jsp.JspWriter)

Example 23 with JspWriter

use of javax.servlet.jsp.JspWriter in project Openfire by igniterealtime.

the class TabsTag method doEndTag.

/**
     * Gets the {@link AdminPageBean} instance from the request. If it doesn't exist then execution is stopped
     * and nothing is printed. If it exists, retrieve values from it and render the tabs. The body content
     * of the tag is assumed to have an A tag in it with tokens to replace (see class description).
     *
     * @return {@link #EVAL_PAGE} after rendering the tabs.
     * @throws JspException if an exception occurs while rendering the tabs.
     */
@Override
public int doEndTag() throws JspException {
    HttpServletRequest request = (HttpServletRequest) pageContext.getRequest();
    // Get the page data bean from the request:
    // If the page info bean is not in the request then no tab will be selected - so, it'll fail gracefully
    String pageID = (String) request.getAttribute("pageID");
    String subPageID = (String) request.getAttribute("subPageID");
    if (pageID == null) {
        Element subPage = AdminConsole.getElemnetByID(subPageID);
        if (subPage != null) {
            pageID = subPage.getParent().getParent().attributeValue("id");
        }
    }
    // Get tabs from the model:
    List tabs = AdminConsole.getModel().selectNodes("//tab");
    if (tabs.size() > 0) {
        JspWriter out = pageContext.getOut();
        // Build up the output in a buffer (is probably faster than a bunch of out.write's)
        StringBuilder buf = new StringBuilder();
        if (!justlinks) {
            buf.append("<ul>");
        }
        String body = getBodyContent().getString();
        // For each tab, print out an <LI>.
        Element currentTab = null;
        if (pageID != null) {
            currentTab = (Element) AdminConsole.getModel().selectSingleNode("//*[@id='" + pageID + "']/ancestor::tab");
        }
        for (int i = 0; i < tabs.size(); i++) {
            Element tab = (Element) tabs.get(i);
            String value = body;
            if (value != null) {
                // The URL for the tab should be the URL of the first item in the tab.
                String pluginName = tab.attributeValue("plugin");
                value = StringUtils.replace(value, "[id]", clean(tab.attributeValue("id")));
                value = StringUtils.replace(value, "[url]", request.getContextPath() + "/" + clean(tab.attributeValue("url")));
                value = StringUtils.replace(value, "[name]", clean(AdminConsole.getAdminText(tab.attributeValue("name"), pluginName)));
                value = StringUtils.replace(value, "[description]", clean(AdminConsole.getAdminText(tab.attributeValue("description"), pluginName)));
            }
            String css = getCss();
            if (tab.equals(currentTab)) {
                css = getCurrentcss();
            }
            if (!justlinks) {
                buf.append("<li class=\"").append(css).append("\">");
            }
            if (justlinks && i > 0) {
                buf.append(" | ");
            }
            buf.append(value);
            if (!justlinks) {
                buf.append("</li>");
            }
        }
        if (!justlinks) {
            buf.append("</ul>");
        }
        try {
            out.write(buf.toString());
        } catch (IOException ioe) {
            throw new JspException(ioe.getMessage());
        }
    }
    return EVAL_PAGE;
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) JspException(javax.servlet.jsp.JspException) Element(org.dom4j.Element) List(java.util.List) IOException(java.io.IOException) JspWriter(javax.servlet.jsp.JspWriter)

Example 24 with JspWriter

use of javax.servlet.jsp.JspWriter in project head by mifos.

the class BulkEntryTag method doStartTag.

@SuppressWarnings("unchecked")
@Override
public int doStartTag() throws JspException {
    HttpServletRequest request = (HttpServletRequest) pageContext.getRequest();
    JspWriter out = pageContext.getOut();
    StringBuilder builder = new StringBuilder();
    CollectionSheetEntryGridDto bulkEntry = null;
    try {
        bulkEntry = (CollectionSheetEntryGridDto) SessionUtils.getAttribute(CollectionSheetEntryConstants.BULKENTRY, request);
    } catch (PageExpiredException e) {
        logger.error("Page expired getting BulkEntryBO.");
    }
    if (null != bulkEntry) {
        List<ProductDto> loanProducts = bulkEntry.getLoanProducts();
        List<ProductDto> savingsProducts = bulkEntry.getSavingProducts();
        try {
            final List<CustomValueListElementDto> custAttTypes = (List<CustomValueListElementDto>) SessionUtils.getAttribute(CollectionSheetEntryConstants.CUSTOMERATTENDANCETYPES, request);
            String method = request.getParameter(CollectionSheetEntryConstants.METHOD);
            generateTagData(bulkEntry, loanProducts, savingsProducts, custAttTypes, method, builder);
        } catch (ApplicationException ae) {
            throw new JspException(ae);
        } catch (SystemException se) {
            throw new JspException(se);
        }
    }
    try {
        out.write(builder.toString());
    } catch (IOException ioe) {
        throw new JspException(ioe);
    }
    return SKIP_BODY;
}
Also used : CustomValueListElementDto(org.mifos.application.master.business.CustomValueListElementDto) PageExpiredException(org.mifos.framework.exceptions.PageExpiredException) IOException(java.io.IOException) JspWriter(javax.servlet.jsp.JspWriter) HttpServletRequest(javax.servlet.http.HttpServletRequest) JspException(javax.servlet.jsp.JspException) ApplicationException(org.mifos.framework.exceptions.ApplicationException) SystemException(org.mifos.framework.exceptions.SystemException) List(java.util.List) ProductDto(org.mifos.application.servicefacade.ProductDto) CollectionSheetEntryGridDto(org.mifos.application.collectionsheet.business.CollectionSheetEntryGridDto)

Example 25 with JspWriter

use of javax.servlet.jsp.JspWriter in project head by mifos.

the class TableTag method getMultipleData.

private void getMultipleData(List list, Locale locale, Integer currentValue) throws TableTagTypeParserException, TableTagParseException, TableTagException, JspException, IOException, PageExpiredException {
    StringBuilder result = new StringBuilder();
    JspWriter out = pageContext.getOut();
    createStartTable(result, true, false);
    out.write(result.toString());
    int number = ((currentValue - 1) * pageSize);
    for (Object object : list) {
        Table table = helperMultipleData(object, locale);
        if (table != null) {
            displayDataMultiple(object, table, ++number, locale);
        } else {
            throw new JspException(MessageLookup.getLocalizedMessage(TableTagConstants.TABLENOTFOUND_ERROR));
        }
    }
    result = new StringBuilder();
    createEndTable(result, false);
    String action = (String) SessionUtils.getAttribute("action", pageContext.getSession());
    out.write(result.toString());
    String currentFlowkey = (String) ((HttpServletRequest) pageContext.getRequest()).getAttribute(Constants.CURRENTFLOWKEY);
    String perspective = (String) ((HttpServletRequest) pageContext.getRequest()).getAttribute(RequestConstants.PERSPECTIVE);
    out.write(PageScroll.getPages(currentValue, pageSize, size, action, currentFlowkey, locale, perspective));
    out.write("</table></td></tr>");
    out.write("</table>");
}
Also used : JspException(javax.servlet.jsp.JspException) JspWriter(javax.servlet.jsp.JspWriter)

Aggregations

JspWriter (javax.servlet.jsp.JspWriter)46 JspException (javax.servlet.jsp.JspException)20 IOException (java.io.IOException)19 HttpServletRequest (javax.servlet.http.HttpServletRequest)9 Properties (java.util.Properties)6 HtmlCode (org.compiere.util.HtmlCode)6 org.apache.ecs.xhtml.select (org.apache.ecs.xhtml.select)5 ArrayList (java.util.ArrayList)3 Iterator (java.util.Iterator)3 List (java.util.List)3 HttpSession (javax.servlet.http.HttpSession)3 JspContext (javax.servlet.jsp.JspContext)3 PageContext (javax.servlet.jsp.PageContext)3 org.apache.ecs.xhtml.option (org.apache.ecs.xhtml.option)3 Element (org.dom4j.Element)3 StringWriter (java.io.StringWriter)2 Collection (java.util.Collection)2 StudyBean (org.akaza.openclinica.bean.managestudy.StudyBean)2 DisplaySectionBean (org.akaza.openclinica.bean.submit.DisplaySectionBean)2 org.apache.ecs.xhtml.br (org.apache.ecs.xhtml.br)2