FileDocCategorySizeDatePackage
ClassicMenuItemTag.javaAPI DocExample2907Tue Feb 28 11:34:06 GMT 2006com.ora.jsp.tags.xmp

ClassicMenuItemTag

public class ClassicMenuItemTag extends BodyTagSupport
This class is a custom action for conditionally inserting HTML links in a navigation menu.

If the action is used in a page requested with a URL corresponding to the page attribute, only the HTML text is included. Otherwise an HTML link (<a>...</a>) element is used to enclose the HTML text. The action also "URL rewrites" the page URL (embeds a session ID, if needed).

author
Hans Bergsten, Gefion software
version
2.0

Fields Summary
private String
page
Constructors Summary
Methods Summary
public intdoEndTag()
Writes either the body content as-is or enclosed in an HTML link element to the current JspWriter, depending on if the request URI matches the page attribute value or not. The content is enclosed in an HTML link element (<a>...</a>) if the page attribute doesn't correspond to the current page and the link is "URL rewritten" (a session ID is added, if needed), and the result is written to the current JspWriter.

        HttpServletRequest request =
            (HttpServletRequest) pageContext.getRequest();
        String requestURI = request.getServletPath();
        // Convert the specified page URI to a context-relative URI
        String pageURI = StringFormat.toContextRelativeURI(page, requestURI);

        StringBuffer text = null;
        String body = getBodyContent().getString();
        if (requestURI.equals(pageURI)) {
            text = new StringBuffer(body);
        }
        else {
            // Add the text as an HTML reference if page is not current page
            String contextPath = request.getContextPath();
            String uri = contextPath + pageURI;
            HttpServletResponse res = 
                (HttpServletResponse) pageContext.getResponse();
            text = new StringBuffer("<a href=\"");
            text.append(res.encodeURL(uri)).append("\">").
                append(body).append("</a>");
        }
        try {
            JspWriter out = getPreviousOut();
            out.print(text);
        }
        catch (IOException e) {}
        return EVAL_PAGE;
    
public voidrelease()
Releases all instance variables.

        page = null;
        super.release();
    
public voidsetPage(java.lang.String page)
Sets the page attribute.

param
page the page URI value

        this.page = page;