KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > raptus > owxv3 > libtags > FieldTag


1 /*
2  * eAdmin/OWX
3  * Copyright (C) 1996-2003 OWX-Project Team <owx-team@gmx.net>
4  */

5 package com.raptus.owxv3.libtags;
6
7 import java.util.Locale JavaDoc;
8
9 import javax.servlet.jsp.*;
10 import javax.servlet.jsp.tagext.TagSupport JavaDoc;
11
12 import org.apache.struts.Globals;
13 import org.apache.struts.util.*;
14
15 import com.raptus.owxv3.api.FieldContainerIFace;
16
17 /**
18  *
19  * <hr>
20  * <table width="100%" border="0">
21  * <tr>
22  * <td width="24%"><b>Filename</b></td><td width="76%">FieldTag.java</td>
23  * </tr>
24  * <tr>
25  * <td width="24%"><b>Author</b></td><td width="76%">REEA</td>
26  * </tr>
27  * <tr>
28  * <td width="24%"><b>Date</b></td><td width="76%">29th of April 2002</td>
29  * </tr>
30  * </table>
31  * <hr>
32  * <table width="100%" border="0">
33  * <tr>
34  * <td width="24%"><b>Date / Author</b></td><td width="76%"><b>Changes</b></td>
35  * </tr>
36  * </table>
37  * <hr>
38  */

39 public class FieldTag extends TagSupport JavaDoc {
40
41
42     // ------------------------------------------------------------- Properties
43

44     /**
45      *The name of the bean holding the fields
46      */

47     protected String JavaDoc name;
48     
49     public String JavaDoc getName()
50     {
51         return name;
52     }
53     public void setName(String JavaDoc s)
54     {
55         name=s;
56     }
57     
58     protected String JavaDoc scope=null;
59     
60     public String JavaDoc getScope()
61     {
62         return scope;
63     }
64     public void setScope(String JavaDoc s)
65     {
66         scope=s;
67     }
68     
69     /**
70      *The field requested
71      */

72     protected String JavaDoc field;
73     
74     public String JavaDoc getField()
75     {
76         return field;
77     }
78     public void setField(String JavaDoc s)
79     {
80         field=s;
81     }
82     
83     /**
84      *To use filter (escape html content) or not
85      */

86     protected boolean filter=false;
87     public boolean getFilter()
88     {
89         return filter;
90     }
91     public void setFilter(boolean f)
92     {
93         filter=f;
94     }
95     
96     /**
97      *The default action is to write the field value to output,
98      *if this is specified the field value will be available as a bean
99      */

100     protected String JavaDoc toBean=null;
101     
102     public String JavaDoc getToBean()
103     {
104         return toBean;
105     }
106     public void setToBean(String JavaDoc s)
107     {
108         toBean=s;
109     }
110     
111     
112     
113     // --------------------------------------------------------- Public Methods
114

115
116     /**
117      * Process the start tag.
118      *
119      * @exception JspException if a JSP exception has occurred
120      */

121     public int doStartTag() throws JspException
122     {
123         Object JavaDoc bean = RequestUtils.lookup(pageContext, name, scope);
124         
125         if(bean == null)
126         {
127              JspException e = new JspException("Cannot retrieve bean:" + name + " from scope:" + scope);
128              RequestUtils.saveException(pageContext, e);
129              throw e;
130         }
131         if(!(bean instanceof FieldContainerIFace))
132         {
133              JspException e = new JspException("Bean does not implement FieldContanierIFace.");
134              RequestUtils.saveException(pageContext, e);
135              throw e;
136         }
137         
138         FieldContainerIFace fc = (FieldContainerIFace) bean;
139         Locale JavaDoc userLocale = (Locale JavaDoc)pageContext.getAttribute(Globals.LOCALE_KEY, PageContext.SESSION_SCOPE);
140         String JavaDoc fieldValue = fc.getField(field,userLocale);
141         if(fieldValue==null) fieldValue="";
142         if(filter)
143         {
144             fieldValue=ResponseUtils.filter(fieldValue);
145         }
146         if(toBean==null)
147         {
148             //print
149
ResponseUtils.write(pageContext, fieldValue);
150         }
151         else
152         {
153             //to bean
154
pageContext.setAttribute(toBean, fieldValue, PageContext.PAGE_SCOPE);
155         }
156     // Continue processing this page
157
return (SKIP_BODY);
158         
159
160     }
161
162
163     /**
164      * Release any acquired resources.
165      */

166     public void release()
167     {
168     super.release();
169         name=null;
170         scope=null;
171         field=null;
172         filter=false;
173         toBean=null;
174     }
175
176 }
177
178 // eof
179

180
181
Popular Tags