KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > beehive > netui > tags > html > Area


1 package org.apache.beehive.netui.tags.html;
2
3 import org.apache.beehive.netui.tags.ByRef;
4 import org.apache.beehive.netui.tags.rendering.AbstractHtmlState;
5 import org.apache.beehive.netui.tags.rendering.TagRenderingBase;
6 import org.apache.beehive.netui.tags.rendering.WriteRenderAppender;
7
8 import javax.servlet.http.HttpServletRequest JavaDoc;
9 import javax.servlet.jsp.JspException JavaDoc;
10
11 /**
12  * @jsptagref.tagdescription
13  * Generates a URL-encoded area to a specified URI.
14  * @example In this sample, an area tag is written with the shape, coords, href, and alt attributes,
15  * for an image map associated with the "someDefaultPic.jpg" image.
16  * <p>The following &lt;netui> tags...</p>
17  * <pre> &lt;netui:image SRC="someDefaultPic.jpg" alt="a default picture" usemap="#defaultMap"/>
18  * &lt;map id="defaultMap" name="defaultMap">
19  * &lt;netui:area shape="rect" coords="0,0,80,80" HREF="bigPicture.jsp" alt="big picture of the image"/>
20  * &lt;/map></pre>
21  *
22  * <p>...output the following HTML:</p>
23  * <pre> &lt;img SRC="someDefaultPic.jpg" usemap="#defaultMap" alt="a default picture">
24  * &lt;map id="defaultMap" name="defaultMap">
25  * &lt;area HREF="bigPicture.jsp" shape="rect" alt="big picture of the image" coords="0,0,80,80">
26  * &lt;/map></pre>
27  * @netui:tag name="area" description="Generates a URL-encoded area to a specified URI."
28  * @see Attribute
29  * @see java.lang.String
30  */

31 public class Area extends AnchorBase
32 {
33     protected static final String JavaDoc REQUIRED_ATTR = "tagId, href, action";
34
35     /**
36      * Returns the name of the Tag.
37      */

38     public String JavaDoc getTagName()
39     {
40         return "Area";
41     }
42
43     /**
44      * This method will return the state associated with the tag. This is used by this
45      * base class to access the individual state objects created by the tags.
46      * @return a subclass of the <code>AbstractHtmlState</code> class.
47      */

48     public AbstractHtmlState getState()
49     {
50         return _state;
51     }
52
53     /**
54      * Sets the property to specify the alt text of the image.
55      * @param alt the image alignment.
56      * @jsptagref.attributedescription Specifies alternate text for the area.
57      * @jsptagref.databindable false
58      * @jsptagref.attributesyntaxvalue <i>string_alt</i>
59      * @netui:attribute required="false" rtexprvalue="true"
60      * description="Specifies alternate text for the area."
61      */

62     public void setAlt(String JavaDoc alt)
63     {
64         _state.registerAttribute(AbstractHtmlState.ATTR_GENERAL, ALT, alt, true);
65     }
66
67     /**
68      * Prepare the hyperlink for rendering
69      * @throws javax.servlet.jsp.JspException if a JSP exception has occurred
70      */

71     public int doStartTag() throws JspException JavaDoc
72     {
73         if (hasErrors())
74             return SKIP_BODY;
75         return EVAL_BODY_BUFFERED;
76     }
77
78     /**
79      * Render the hyperlink.
80      * @throws JspException if a JSP exception has occurred
81      */

82     public int doEndTag() throws JspException JavaDoc
83     {
84         // report errors that may have occurred when the required attributes are being set
85
if (hasErrors())
86             return reportAndExit(EVAL_PAGE);
87
88         // build the anchor into the results
89
ByRef script = new ByRef();
90
91         WriteRenderAppender writer = new WriteRenderAppender(pageContext);
92         HttpServletRequest JavaDoc request = (HttpServletRequest JavaDoc) pageContext.getRequest();
93         TagRenderingBase trb = TagRenderingBase.Factory.getRendering(TagRenderingBase.AREA_TAG, request);
94
95         if (!createAnchorBeginTag(request, script, trb, writer, REQUIRED_ATTR)) {
96             if (!script.isNull())
97                 write(script.getRef().toString());
98             return reportAndExit(EVAL_PAGE);
99         }
100
101         assert(trb != null) : "trb is null";
102         trb.doEndTag(writer);
103
104         if (!script.isNull())
105             write(script.getRef().toString());
106
107         // Render the remainder to the output stream
108
localRelease();
109         return EVAL_PAGE;
110     }
111 }
112
Popular Tags