KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > mullassery > act > util > ResourceUtil


1 /*
2  * The Apache Software License, Version 1.1
3  *
4  * Copyright (c) 2000-2002 The Apache Software Foundation. All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions are met: 1.
8  * Redistributions of source code must retain the above copyright notice, this
9  * list of conditions and the following disclaimer. 2. Redistributions in
10  * binary form must reproduce the above copyright notice, this list of
11  * conditions and the following disclaimer in the documentation and/or other
12  * materials provided with the distribution. 3. The end-user documentation
13  * included with the redistribution, if any, must include the following
14  * acknowlegement: "This product includes software developed by the Apache
15  * Software Foundation (http://www.apache.org/)." Alternately, this
16  * acknowlegement may appear in the software itself, if and wherever such
17  * third-party acknowlegements normally appear. 4. The names "The Jakarta
18  * Project", "Ant", and "Apache Software Foundation" must not be used to
19  * endorse or promote products derived from this software without prior written
20  * permission. For written permission, please contact apache@apache.org. 5.
21  * Products derived from this software may not be called "Apache" nor may
22  * "Apache" appear in their names without prior written permission of the
23  * Apache Group.
24  *
25  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
26  * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
27  * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
28  * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
29  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
30  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
31  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
32  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
33  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
34  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35  * ====================================================================
36  *
37  * This software consists of voluntary contributions made by many individuals
38  * on behalf of the Apache Software Foundation. For more information on the
39  * Apache Software Foundation, please see <http://www.apache.org/> .
40  */

41
42 package com.mullassery.act.util;
43 import java.io.File JavaDoc;
44
45 import org.w3c.dom.Element JavaDoc;
46
47 /**
48  * @author Abey Mullassery
49  *
50  */

51 public final class ResourceUtil {
52     public static final String JavaDoc ACT_BUNDLE_NAME = "act";
53     public static final String JavaDoc ACT_HOME = "ACT_HOME";
54     public static final String JavaDoc ACT_MRU_FILE_PROPERTY_NAME = "mruFile";
55     public static final String JavaDoc ACT_MRU_XML = "act-mru.xml";
56     public static final String JavaDoc ACT_TASKS_FILE_PROPERTY_NAME = "tasksFile";
57     public static final String JavaDoc ACT_TASKS_XML = "act-tasks.xml";
58     public static final String JavaDoc ACT_SETTINGS_FILE_PROPERTY_NAME = "settingsFile";
59     public static final String JavaDoc ACT_SETTINGS_XML = "act-settings.xml";
60     public static Element JavaDoc actMRUElement;
61     public static File JavaDoc actMRUFile;
62     public static Element JavaDoc actSettingsElement;
63     public static File JavaDoc actSettingsFile;
64     public static Element JavaDoc actTasksElement;
65     public static File JavaDoc actTasksFile;
66
67     public static String JavaDoc actDir;
68
69     /**
70      *
71      */

72     private ResourceUtil() {
73     }
74
75     public static File JavaDoc getMRUFile() {
76         if (actMRUFile != null)
77             return actMRUFile;
78         actMRUFile = new File JavaDoc(ACT_MRU_XML);
79         return actMRUFile;
80     }
81
82     public static File JavaDoc getTasksFile() {
83         if (actTasksFile != null)
84             return actTasksFile;
85         actTasksFile = new File JavaDoc(ACT_TASKS_XML);
86         return actTasksFile;
87     }
88
89     public static File JavaDoc getSettingsFile() {
90         if (actSettingsFile != null)
91             return actSettingsFile;
92         actSettingsFile = searchFile(ACT_SETTINGS_XML);
93         return actSettingsFile;
94     }
95
96     //check in current directory, then ACT_HOME and them user.home and then
97
// defaults to current working directory
98
public static File JavaDoc searchFile(String JavaDoc fName) {
99         String JavaDoc dir = actDir;
100         File JavaDoc f = null;
101         if (dir != null && dir.length() > 0) {
102             f = new File JavaDoc(dir + File.separator + fName);
103             if (f.exists() && f.isFile())
104                 return f;
105         }
106         dir = ".";
107         if (dir != null && dir.length() > 0) {
108             f = new File JavaDoc(dir + File.separator + fName);
109             if (f.exists() && f.isFile())
110                 return f;
111         }
112         dir = System.getProperty("user.home");
113         if (dir != null && dir.length() > 0) {
114             f = new File JavaDoc(dir + File.separator + fName);
115             if (f.exists() && f.isFile())
116                 return f;
117         }
118         dir = System.getProperty(ACT_HOME);
119         if (dir != null && dir.length() > 0) {
120             f = new File JavaDoc(dir + File.separator + fName);
121             if (f.exists() && f.isFile())
122                 return f;
123         }
124         return new File JavaDoc("." + File.separator + fName);
125     }
126
127 }
128
Popular Tags