01: /*
02: * Copyright 2005-2006 the original author or authors.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
05: * in compliance with the License. You may obtain a copy of the License at
06: *
07: * http://www.apache.org/licenses/LICENSE-2.0
08: *
09: * Unless required by applicable law or agreed to in writing, software distributed under the License
10: * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
11: * or implied. See the License for the specific language governing permissions and limitations under
12: * the License.
13: */
14:
15: /*
16: * Copyright 2005-2006 the original author or authors.
17: *
18: * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
19: * in compliance with the License. You may obtain a copy of the License at
20: *
21: * http://www.apache.org/licenses/LICENSE-2.0
22: *
23: * Unless required by applicable law or agreed to in writing, software distributed under the License
24: * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
25: * or implied. See the License for the specific language governing permissions and limitations under
26: * the License.
27: */
28:
29: package org.strecks.builder;
30:
31: import java.io.IOException;
32: import java.io.InputStream;
33: import java.util.Properties;
34:
35: import org.apache.commons.logging.Log;
36: import org.apache.commons.logging.LogFactory;
37:
38: /**
39: * A class containing static configuration-related utility methods
40: * @author Phil Zoio
41: */
42: public class ConfigUtils {
43:
44: private static Log log = LogFactory.getLog(ConfigUtils.class);
45:
46: public static Properties loadProperties(String resourceName) {
47: Properties properties = new Properties();
48: InputStream stream = ConfigUtils.class
49: .getResourceAsStream(resourceName);
50:
51: try {
52: properties.load(stream);
53: } catch (IOException e) {
54: log.warn("No " + resourceName
55: + " found on classpath. Using default settings.");
56: } catch (Exception e) {
57: log.warn("Could not load " + resourceName);
58: }
59: return properties;
60: }
61:
62: public static String getPropertiesFileName(String prefix) {
63: if (prefix != null && prefix.startsWith("/"))
64: prefix = prefix.substring(1);
65:
66: if (prefix != null && prefix.trim().length() > 0) {
67: String name = "/strecks_" + prefix + ".properties";
68: return name;
69: } else {
70: return "/strecks.properties";
71: }
72: }
73: }
|