Source code: com/aendvari/tethys/tag/inset/DefineTag.java
1 /*
2 * DefineTag.java
3 *
4 * Copyright (c) 2001, 2002 Aendvari, Ltd. All Rights Reserved.
5 *
6 * See the file LICENSE for terms of use.
7 *
8 */
9
10 package com.aendvari.tethys.tag.inset;
11
12 import java.util.*;
13 import java.io.IOException;
14
15 import javax.servlet.*;
16 import javax.servlet.http.*;
17 import javax.servlet.jsp.*;
18 import javax.servlet.jsp.tagext.*;
19
20 import com.aendvari.common.model.*;
21
22 import com.aendvari.tethys.context.*;
23 import com.aendvari.tethys.context.inset.*;
24
25 import com.aendvari.tethys.tag.*;
26
27
28 /**
29 * <p>Implementation class for the inset "define" tag.</p>
30 *
31 * @author Scott Milne
32 *
33 */
34
35 public class DefineTag extends InsetBodyTag
36 {
37 /* Variables. */
38
39 /** The name of the tag. */
40 protected String name;
41
42 /** The inset definition. */
43 protected Inset inset;
44
45
46 /* Constructor */
47
48 public DefineTag()
49 {
50 super();
51
52 inset = null;
53 name = null;
54 }
55
56 /* Attributes */
57
58 public void setName(String name) { this.name = name; }
59 public String getName() { return name; }
60
61 public String getBody() { return bodyContent.getString(); }
62
63
64 /**
65 * Start the tag by evaluating body into existing out stream.
66 *
67 */
68
69 public int doStartTag() throws JspException
70 {
71 // establish tag context
72 establishInsetContext();
73
74 // get the inset map
75 ContextMap contextMap = InsetTagData.getData(
76 pageContext, getDataScope()).getInsetMap();
77
78 // create new inset
79 inset = new Inset(
80 insetContext.extendLocation(name),
81 "");
82
83 // now set this context into the request
84 contextMap.addContext(inset);
85
86 // make inset object new context of tag
87 insetContext = inset;
88
89 //
90 // COMPATIBILITY NOTICE
91 //
92 // If you are using JSP 1.1, this value is non-functional, use the following instead:
93 //
94 // EVAL_BODY_TAG
95 //
96 return EVAL_BODY_BUFFERED;
97 }
98
99 /**
100 * Process the end tag by putting this define into it's parent
101 * "include" tag. If a parent tag is not found, it is stored into
102 * the page definition list.
103 *
104 */
105
106 public int doEndTag() throws JspException
107 {
108 // place body content
109 inset.setContent(getBody());
110
111 return EVAL_PAGE;
112 }
113
114 /**
115 * Release all allocated resources.
116 *
117 */
118
119 public void release()
120 {
121 super.release();
122
123 name = null;
124 inset = null;
125 }
126 }
127