KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > idaremedia > antx > mktemp > Mkdirs


1 /**
2  * $Id: Mkdirs.java 180 2007-03-15 12:56:38Z ssmc $
3  * Copyright 2005 iDare Media, Inc. All rights reserved.
4  *
5  * Originally written by iDare Media, Inc. for release into the public domain. This
6  * library, source form and binary form, is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public License (LGPL) as published
8  * by the Free Software Foundation; either version 2.1 of the License, or (at your option)
9  * any later version.<p>
10  *
11  * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
12  * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13  * See the GNU LGPL for more details.<p>
14  *
15  * You should have received a copy of the GNU Lesser General Public License along with this
16  * library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite
17  * 330, Boston, MA 02111-1307 USA. The GNU LGPL can be found online at
18  * http://www.fsf.org/copyleft/lesser.html<p>
19  *
20  * This product has been influenced by several projects within the open-source community.
21  * The JWare developers wish to acknowledge the open-source community's support. For more
22  * information regarding the open-source products used within JWare, please visit the
23  * JWare website.
24  *----------------------------------------------------------------------------------------*
25  * WEBSITE- http://www.jware.info EMAIL- inquiries@jware.info
26  *----------------------------------------------------------------------------------------*
27  **/

28
29 package com.idaremedia.antx.mktemp;
30
31 import java.io.File JavaDoc;
32
33 import org.apache.tools.ant.BuildException;
34 import org.apache.tools.ant.Project;
35
36 import com.idaremedia.antx.Iteration;
37 import com.idaremedia.antx.apis.Requester;
38 import com.idaremedia.antx.parameters.FeedbackLevel;
39
40 /**
41  * Wrapper utility to create a collection of directories using the Java mkdirs API.
42  * Copied from JWare/SAMS (BaseUrlsTools).
43  *
44  * @since JWare/AntX 0.5
45  * @author ssmc, &copy;2005 <a HREF="http://www.jware.info">iDare&nbsp;Media,&nbsp;Inc.</a>
46  * @version 0.5
47  * @.safety multiple
48  * @.group impl,helper
49  **/

50
51 final class Mkdirs
52 {
53     /**
54      * Ensures the named path refers to a readable directory. Will create directory
55      * (including all parent directories) if necessary.
56      * @param dir directory to be created (or checked) (non-null)
57      * @param haltiferror set true if this method should signal error when cannot
58      * complete request.
59      * @param fb problem reporting level (non-null)
60      * @param clnt problem reporting conduit (non-null)
61      * @throws BuildException if unable to create directories or non-directory
62      * already exists.
63      **/

64     static boolean run(File JavaDoc dir, boolean haltiferror, FeedbackLevel fb, Requester clnt)
65         throws BuildException
66     {
67         boolean okidoki=true;
68         if (!dir.exists()) {
69             try {
70                 dir.mkdirs();
71                 if (fb.getIndex()<FeedbackLevel.QUIET_INDEX) {
72                     clnt.log("Directory created: "+dir.getPath(),
73                               Project.MSG_INFO);
74                 }
75             }
76             catch (SecurityException JavaDoc secX) {
77                 String JavaDoc message = Iteration.uistrs().get("task.cant.access.dir",
78                                                         dir.getPath());
79                 if (haltiferror) {
80                     clnt.problem(message, Project.MSG_ERR);
81                     throw new BuildException(message, secX, clnt.getLocation());
82                 }
83                 if (fb.getIndex()<FeedbackLevel.QUIET_INDEX) {//not-none|*quiet
84
clnt.problem(message, Project.MSG_WARN);
85                 }
86                 okidoki=false;
87             }
88         }
89         else if (!dir.isDirectory() || !dir.canWrite() || !dir.canRead()) {
90             String JavaDoc message;
91             if (!dir.isDirectory()) {
92                 message = "mktemp.mkdirs.file.exists";
93             } else {
94                 message = "task.cant.access.dir";
95             }
96             message = Iteration.uistrs().get(message,dir.getPath());
97             if (haltiferror) {
98                 clnt.problem(message, Project.MSG_ERR);
99                 throw new BuildException(message, clnt.getLocation());
100             }
101             if (fb.getIndex()<=FeedbackLevel.QUIET_INDEX) {//not-none|veryquiet
102
clnt.problem(message, Project.MSG_WARN);
103             }
104             okidoki=false;
105         }
106         return okidoki;
107     }
108
109
110     private Mkdirs()
111     {
112     }
113 }
114
115
116 /* end-of-Mkdirs.java */
Popular Tags