KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > forrest > conf > ForrestConfUtils


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

17 package org.apache.forrest.conf;
18
19 import org.apache.commons.lang.SystemUtils;
20
21 /**
22  * Utility class for accessing the base properties used in Forrest. The main
23  * values are the locations of the <b>source </b> directories and of the
24  * <b>forrest </b> directories. The values are gotten from the
25  *
26  * <pre>
27  * forrest.properties
28  * </pre>
29  *
30  * ant property file and resolved relative to the java system properties named
31  *
32  * <pre>
33  * forrest.home
34  * </pre>
35  *
36  * and
37  *
38  * <pre>
39  * project.home
40  * </pre>, that the forrest scripts set using the calling directory and the
41  * environment variable
42  *
43  * <pre>
44  * FORREST_HOME
45  * </pre>. If Forrest is run from a war, it won't have these properties set, so
46  * the directories are resolved relative to the current directory, that in this
47  * case is the forrest webapp root.
48  */

49 public class ForrestConfUtils
50 {
51     public final static String JavaDoc defaultHome = "context:/";
52
53     private final static String JavaDoc getSystemProperty(String JavaDoc propertyName) {
54
55         //if the property is not set, default to the webapp context
56
String JavaDoc propertyValue = System.getProperty(propertyName, defaultHome);
57         return propertyValue;
58     }
59
60     public static String JavaDoc getForrestHome() throws Exception JavaDoc {
61
62         //NOTE: Don't do this:
63
//
64
// forrestHome = System.getenv("FORREST_HOME");
65
//
66
// as it will get FORREST_HOME even when the app
67
// is run as a .war
68
return getSystemProperty("forrest.home");
69     }
70
71     public static String JavaDoc getProjectHome() throws Exception JavaDoc {
72         String JavaDoc projectHome = getSystemProperty("project.home");
73         if (projectHome.equals(defaultHome)) {
74             projectHome = defaultHome + SystemUtils.FILE_SEPARATOR + "/project";
75         }
76         return projectHome;
77     }
78
79     public static String JavaDoc getContextHome() throws Exception JavaDoc {
80         String JavaDoc forrestHome = getForrestHome();
81         String JavaDoc contextHome;
82         if (forrestHome.equals(defaultHome)) {
83             contextHome = defaultHome;
84         } else {
85             //FIXME: HARDCODE VALUE
86
//
87
contextHome = forrestHome + SystemUtils.FILE_SEPARATOR + "main/webapp";
88         }
89         return contextHome;
90     }
91
92     /**
93      * For backwards compatibility, alias old skin names to new ones. This must
94      * be kept in sync with aliasing in forrest.build.xml/init-props
95      *
96      * @param properties to filter
97      */

98     public static void aliasSkinProperties(AntProperties props) {
99         String JavaDoc skinName = props.getProperty("project.skin");
100         if (skinName.equals("crust")) {
101             setSkinToUse(props, "krysalis-site");
102         } else if (skinName.equals("avalon-tigris")
103                         || skinName.equals("tigris-style")) {
104             setSkinToUse(props, "tigris");
105         } else if (skinName.equals("forrest-css")) {
106             setSkinToUse(props, "pelt");
107         }
108     }
109
110     /**
111      * Set which skin is to be used
112      *
113      * @param properties to filter
114      * @param the skin name
115      */

116     private static void setSkinToUse(AntProperties props, String JavaDoc skinStoUse) {
117         // AntProperties.setProperty doesn't let you override, so we have to remove the property then add it again
118
props.remove("project.skin");
119         props.setProperty("project.skin", skinStoUse);
120     }
121
122 }
123
Popular Tags