@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");
        //String subnavID = (String)request.getAttribute("subnavID");

        // If the pageID is null, use the subPageID to set it. If both the pageID and
        // 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().isEmpty()) {
                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<Element> items = subnav.elements();
                    if (!items.isEmpty()) {
                        buf.append("<ul>");
                        // Now print all items:
                        for (Element item : items) {
                            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 = value.replaceAll("\\[id]", clean(subitemID));
                                value = value.replaceAll("\\[name]", clean(AdminConsole.getAdminText(subitemName, pluginName)));
                                value = value.replaceAll("\\[description]", clean(AdminConsole.getAdminText(subitemDescr, pluginName)));
                                value = value.replaceAll("\\[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<Element> 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 = 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 = svalue.replaceAll("\\[id]", clean(sibID));
                                        svalue = svalue.replaceAll("\\[name]", clean(AdminConsole.getAdminText(sibName, pluginName)));
                                        svalue = svalue.replaceAll("\\[description]", clean(AdminConsole.getAdminText(sibDescr, pluginName)));
                                        svalue = svalue.replaceAll("\\[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;
    }
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.
xmppserver/src/main/java/org/jivesoftware/admin/SidebarTag.java