KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > taglibs > gnat > deltreeTag


1 /*
2  * Copyright 1999,2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16
17 package org.apache.taglibs.gnat;
18
19 import org.apache.taglibs.gnat.util.*;
20 import javax.servlet.jsp.*;
21 import javax.servlet.jsp.tagext.*;
22 import java.io.*;
23 import java.util.*;
24
25 public class deltreeTag extends TagSupport
26 {
27     private String JavaDoc dir = "";
28     private File _f;
29     private ResourceBundle gnatRB = ListResourceBundle.getBundle("org.apache.taglibs.gnat.util.GnatTagStrings");
30     private ResourceBundle gnatERB = ListResourceBundle.getBundle("org.apache.taglibs.gnat.util.GnatExceptionStrings");
31         
32     public void setDir(String JavaDoc dir)
33     {
34         this.dir = dir;
35     }
36
37     /**
38     * Deletes a directory and all its files and subdirectories.
39     */

40     public int doEndTag() throws JspException
41     {
42         if (!dir.equals(""))
43         {
44             _f = FileUtil.resolveFile(null,dir);
45             
46             try
47             {
48                 FileUtil.forceDelete(_f);
49             }
50             catch(IOException ioe)
51             {
52                 throw new JspTagException(gnatRB.getString("deltree.tag") +": "+ ioe.getMessage());
53             }
54         }
55         else
56         {
57             throw new JspTagException(gnatRB.getString("deltree.tag") +": "+ gnatERB.getString("empty.dir.attribute"));
58         }
59         return EVAL_PAGE;
60     }
61
62     /* Put tag attribute accessors down here, out of the way, since they're more for
63        JavaBean completeness than programmer use.
64      */

65     public String JavaDoc getDir()
66     {
67         return dir;
68     }
69 }
70
Popular Tags