KickJava   Java API By Example, From Geeks To Geeks.

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


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
22 import java.util.*;
23
24 import com.finalist.jag.*;
25 import com.finalist.jag.taglib.util.RequestUtil;
26
27
28 /**
29  * Class FileTag
30  *
31  *
32  * @author Wendel D. de Witte
33  * @version %I%, %G%
34  */

35 public class FileTag extends TagBodySupport {
36
37     /** Field path */
38     private String JavaDoc path = null;
39
40     /** Field title */
41     private String JavaDoc title = null;
42
43     /** Field ext */
44     private String JavaDoc ext = null;
45
46     /** Field name */
47     private String JavaDoc name = null;
48
49     /** Field property */
50     private String JavaDoc property = null;
51
52     /** Field counter */
53     protected int counter = 0;
54
55
56     /**
57      * Method setName
58      *
59      *
60      * @param name
61      *
62      */

63     public void setName(String JavaDoc name) {
64         this.name = name;
65     }
66
67     /**
68      * Method setValue
69      *
70      *
71      * @param property
72      *
73      */

74     public void setProperty(String JavaDoc property) {
75         this.property = property;
76     }
77
78     /**
79      * Method getName
80      *
81      *
82      * @return
83      *
84      */

85     public String JavaDoc getName() {
86         return (this.name);
87     }
88
89     /**
90      * Method getValue
91      *
92      *
93      * @return
94      *
95      */

96     public String JavaDoc getProperty() {
97         return (this.property);
98     }
99
100     /**
101      * Method getPath
102      *
103      *
104      * @return
105      *
106      */

107     public String JavaDoc getPath() {
108         return (this.path);
109     }
110
111     /**
112      * Method setPath
113      *
114      *
115      * @param path
116      *
117      */

118     public void setPath(String JavaDoc path) {
119         this.path = path;
120     }
121
122     /**
123      * Method getTitle
124      *
125      *
126      * @return
127      *
128      */

129     public String JavaDoc getTitle() {
130         return (this.title);
131     }
132
133     /**
134      * Method setTitle
135      *
136      *
137      * @param title
138      *
139      */

140     public void setTitle(String JavaDoc title) {
141         this.title = title;
142     }
143
144     /**
145      * Method getExt
146      *
147      *
148      * @return
149      *
150      */

151     public String JavaDoc getExt() {
152         return (this.ext);
153     }
154
155     /**
156      * Method setExt
157      *
158      *
159      * @param ext
160      *
161      */

162     public void setExt(String JavaDoc ext) {
163         this.ext = ext;
164     }
165
166     /**
167      * Method doStartTag
168      *
169      *
170      * @return
171      *
172      * @throws JagException
173      *
174      */

175     public int doStartTag() throws JagException {
176         return (EVAL_PAGE);
177     }
178
179     /**
180      * Method doAfterBodyTag
181      *
182      *
183      * @return
184      *
185      * @throws JagException
186      *
187      */

188     public int doAfterBodyTag() throws JagException {
189
190         counter++;
191         // Retrieve the file title from the tag body.
192
if ((title == null) || (title.length() < 1)) {
193             if (counter == 1) {
194                 return (EVAL_BODY_TAG);
195             }
196             else {
197                 title = getBodyText();
198                 title = title.replace('\n',' ');
199                 title = title.replace('\r',' ');
200                 title = title.trim();
201             }
202         }
203         // Construct the filepath
204
StringBuffer JavaDoc filePath = new StringBuffer JavaDoc();
205
206         if ((path != null) && (path.length() > 0)) {
207             filePath.append(path);
208         }
209         else if(name != null && property != null)
210         {
211             String JavaDoc value = RequestUtil.lookupString(getPageContext(), name,
212                                                     property);
213             if (value == null) {
214                 throw new JagException("WriteTag: Invalid name field >"
215                                        + name + "<");
216             }
217
218             filePath.append(value);
219         }
220
221         filePath.append(title);
222
223         if ((ext != null) && (ext.length() > 0)) {
224             filePath.append(".");
225             filePath.append(ext);
226         }
227         // Create a new file entry.
228
getWriter().createNewFile(filePath);
229         return (SKIP_CLEAR_BODY);
230     }
231 }
232 ;
Popular Tags