FileDocCategorySizeDatePackage
MenuItemTag.javaAPI DocExample2858Tue Feb 28 11:34:06 GMT 2006com.ora.jsp.tags

MenuItemTag

public class MenuItemTag extends SimpleTagSupport
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
3.0

Fields Summary
private String
page
Constructors Summary
Methods Summary
public voiddoTag()
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.

        JspFragment body = getJspBody();
        if (body == null) {
	    throw new JspTagException("'menuItem' used without a body");
	}
	
        PageContext pageContext = (PageContext) getJspContext();
        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);

        if (requestURI.equals(pageURI)) {
            // Add the body as-is
            body.invoke(null);
        }
        else {
            // Add the body as the text of an HTML link to page
            String uri = request.getContextPath() + pageURI;
            HttpServletResponse response = 
                (HttpServletResponse) pageContext.getResponse();

            StringWriter evalResult = new StringWriter();
            StringBuffer buff = evalResult.getBuffer();
            buff.append("<a href=\"").append(response.encodeURL(uri)).
                append("\">");
            body.invoke(evalResult);
            buff.append("</a>");
            getJspContext().getOut().print(buff);
        }
    
public voidsetPage(java.lang.String page)
Sets the page attribute.

param
page the page URI value

        this.page = page;