KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > finalist > jag > taglib > WriteTag


1 /* Copyright (C) 2003 Finalist IT Group
2  *
3  * This file is part of JAG - the Java J2EE Application Generator
4  *
5  * JAG is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  * JAG is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  * You should have received a copy of the GNU General Public License
14  * along with JAG; if not, write to the Free Software
15  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16  */

17
18 package com.finalist.jag.taglib;
19
20
21 import com.finalist.jag.*;
22 import com.finalist.jag.taglib.util.RequestUtil;
23 import com.finalist.jaggenerator.Utils;
24
25 import java.util.*;
26
27
28 /**
29  * Class WriteTag
30  *
31  *
32  * @author Wendel D. de Witte
33  * @version %I%, %G%
34  */

35 public class WriteTag extends TagSupport {
36
37    /** Field name */
38    private String JavaDoc name = null;
39
40    /** Field property */
41    private String JavaDoc property = null;
42
43    /** Field display */
44    private String JavaDoc display = null;
45
46    /** Field pathEnable */
47    private String JavaDoc pathEnable = null;
48
49    /////////////////////////////////////
50

51    /**
52     * Method setName
53     *
54     *
55     * @param name
56     *
57     */

58    public void setName(String JavaDoc name) {
59       this.name = name;
60    }
61
62    /**
63     * Method setValue
64     *
65     *
66     * @param property
67     *
68     */

69    public void setProperty(String JavaDoc property) {
70       this.property = property;
71    }
72
73    /**
74     * Method getName
75     *
76     *
77     * @return
78     *
79     */

80    public String JavaDoc getName() {
81       return (this.name);
82    }
83
84    /**
85     * Method getValue
86     *
87     *
88     * @return
89     *
90     */

91    public String JavaDoc getProperty() {
92       return (this.property);
93    }
94
95    /**
96     * Method getSensitive
97     *
98     *
99     * @return
100     *
101     */

102    public String JavaDoc getDisplay() {
103       return (this.display);
104    }
105
106    /**
107     * Method setDisplay
108     *
109     *
110     * @param display
111     *
112     */

113    public void setDisplay(String JavaDoc display) {
114       this.display = display;
115    }
116
117    /**
118     * Method getPathenable
119     *
120     *
121     * @return
122     *
123     */

124    public String JavaDoc getPathenable() {
125       return (this.pathEnable);
126    }
127
128    /**
129     * Method setPathenable
130     *
131     *
132     * @param pathEnable
133     *
134     */

135    public void setPathenable(String JavaDoc pathEnable) {
136       this.pathEnable = pathEnable;
137    }
138
139    /**
140     * Method doStartTag
141     *
142     *
143     * @return
144     *
145     * @throws JagException
146     *
147     */

148    public int doStartTag() throws JagException {
149
150       SessionContext session = getPageContext().getSessionContext();
151       String JavaDoc value = RequestUtil.lookupString(getPageContext(),
152             name, property);
153
154       if (value == null) {
155          throw new JagException("WriteTag: Invalid name field \"" + name
156                + "\" (property=\"" + property + "\")");
157       }
158
159       if (display != null) {
160          display = display.toLowerCase();
161
162          if (display.equals("lower")) {
163             value = value.toLowerCase();
164          }
165          else if (display.equals("upper")) {
166             value = value.toUpperCase();
167          }
168          else if (display.equals("sentensize")) {
169             if (value.length() > 1) {
170                String JavaDoc tmp = value.substring(0, 1).toUpperCase();
171
172                value = value.substring(1);
173                value = tmp + value;
174             } else {
175                value = value.toUpperCase();
176             }
177          }
178          else if (display.equals("desentensize")) {
179             if (value.length() > 1) {
180                String JavaDoc tmp = value.substring(0, 1).toLowerCase();
181
182                value = value.substring(1);
183                value = tmp + value;
184             } else {
185                value = value.toLowerCase();
186             }
187          }
188          else if (display.equals("crazy_struts")) {
189             //anElephant --> anElephant
190
//aHorse --> AHorse
191
if (value.length() > 1 &&
192                   Character.isLowerCase(value.charAt(0)) && Character.isUpperCase(value.charAt(1))) {
193                value = Character.toUpperCase(value.charAt(0)) + value.substring(1);
194             }
195          }
196       }
197
198       if ((pathEnable != null) && pathEnable.equals("true")) {
199          value = value.replace('.', '/');
200       }
201
202       getWriter().print(value);
203
204       return (EVAL_PAGE);
205    }
206
207 }
Popular Tags