001: /**********************************************************************************
002: * $URL$
003: * $Id$
004: ***********************************************************************************
005: *
006: * Copyright (c) 2005, 2006 The Sakai Foundation.
007: *
008: * Licensed under the Educational Community License, Version 1.0 (the"License");
009: * you may not use this file except in compliance with the License.
010: * You may obtain a copy of the License at
011: *
012: * http://www.opensource.org/licenses/ecl1.php
013: *
014: * Unless required by applicable law or agreed to in writing, software
015: * distributed under the License is distributed on an "AS IS" BASIS,
016: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
017: * See the License for the specific language governing permissions and
018: * limitations under the License.
019: *
020: **********************************************************************************/package org.sakaiproject.tool.assessment.qti.util;
021:
022: import java.io.FileInputStream;
023: import java.io.IOException;
024: import java.util.Properties;
025:
026: import org.apache.commons.logging.Log;
027: import org.apache.commons.logging.LogFactory;
028:
029: /**
030: * Utility class used for accessing settings and security directories
031: * (and associated Properties).
032: *
033: * @author <a href="mailto:lance@indiana.edu">Lance Speelmon</a>
034: * @version $Id: PathInfo.java 1288 2005-08-19 02:58:02Z esmiley@stanford.edu $
035: */
036: public class PathInfo {
037: private static Log log = LogFactory.getLog(PathInfo.class);
038: private static final String SETTINGS_DIR = "/org/sakaiproject/settings/sam";
039: private static final String SECURITY_DIR = "/org/sakaiproject/security/sam";
040: private static PathInfo _INSTANCE = new PathInfo();
041: private String basePathToSecurity = "";
042: private String basePathToSettings = "";
043: private String pathToSecurity = "";
044: private String pathToSettings = "";
045:
046: /**
047: * Returns an instance of PathInfo.
048: *
049: * @return
050: */
051: public static PathInfo getInstance() {
052: log.debug("getInstance()");
053:
054: return _INSTANCE;
055: }
056:
057: /**
058: * Constructor should never be exposed. Singleton pattern.
059: */
060: private PathInfo() {
061: log.debug("new PathInfo()");
062: }
063:
064: /**
065: * Returns a Properties from the security directory.
066: *
067: * @param fileName
068: *
069: * @return
070: *
071: * @throws IOException
072: */
073: public Properties getSecurityProperties(String fileName)
074: throws IOException {
075: if (log.isDebugEnabled()) {
076: log.debug("getSecurityProperties(String " + fileName + ")");
077: }
078:
079: Properties props = null;
080: props = new Properties();
081: props
082: .load(new FileInputStream(pathToSecurity + "/"
083: + fileName));
084:
085: return props;
086: }
087:
088: /**
089: * Load properties from a file.
090: *
091: * @param fileName file name
092: *
093: * @return Properties object
094: *
095: * @throws IOException in reading file
096: */
097: public Properties getSettingsProperties(String fileName)
098: throws IOException {
099: if (log.isDebugEnabled()) {
100: log.debug("getSettingsProperties(String " + fileName + ")");
101: }
102:
103: Properties props = null;
104: props = new Properties();
105: props
106: .load(new FileInputStream(pathToSettings + "/"
107: + fileName));
108:
109: return props;
110: }
111:
112: /**
113: * Get base path string to security.
114: *
115: * @return the path
116: */
117: public String getBasePathToSecurity() {
118: log.debug("getBasePathToSecurity()");
119:
120: return basePathToSecurity;
121: }
122:
123: /**
124: * Set base path to security.
125: *
126: * @param basePathToSettings DOCUMENTATION PENDING
127: *
128: * @throws IllegalArgumentException if this is invalid path.
129: */
130: public void setBasePathToSecurity(String basePathToSecurity)
131: throws IllegalArgumentException {
132: if (log.isDebugEnabled()) {
133: log.debug("setBasePathToSecurity(String "
134: + basePathToSecurity + ")");
135: }
136:
137: if (basePathToSecurity == null) {
138: throw new IllegalArgumentException(
139: "illegal String basePathToSecurity argument: "
140: + basePathToSecurity);
141: }
142:
143: synchronized (this .basePathToSecurity) {
144: this .basePathToSecurity = basePathToSecurity;
145: }
146:
147: synchronized (this .pathToSecurity) {
148: this .pathToSecurity = this .basePathToSecurity
149: + SECURITY_DIR;
150: }
151: }
152:
153: /**
154: * Get base path string to settings.
155: *
156: * @return the path
157: */
158: public String getBasePathToSettings() {
159: log.debug("getBasePathToSettings()");
160:
161: return basePathToSettings;
162: }
163:
164: /**
165: * Set base path to settings.
166: *
167: * @param basePathToSettings DOCUMENTATION PENDING
168: *
169: * @throws IllegalArgumentException if this is invalid path.
170: */
171: public void setBasePathToSettings(String basePathToSettings)
172: throws IllegalArgumentException {
173: if (log.isDebugEnabled()) {
174: log.debug("setBasePathToSettings(String "
175: + basePathToSettings + ")");
176: }
177:
178: if (basePathToSettings == null) {
179: throw new IllegalArgumentException(
180: "illegal String basePathToSettings argument: "
181: + basePathToSettings);
182: }
183:
184: synchronized (this .basePathToSettings) {
185: this .basePathToSettings = basePathToSettings;
186: }
187:
188: synchronized (this .pathToSettings) {
189: this .pathToSettings = this .basePathToSettings
190: + SETTINGS_DIR;
191: }
192: }
193:
194: /**
195: * Get base path string to security.
196: *
197: * @return the path
198: */
199: public String getPathToSecurity() {
200: return pathToSecurity;
201: }
202:
203: /**
204: * Get base path string to settings.
205: *
206: * @return the path
207: */
208: public String getPathToSettings() {
209: return pathToSettings;
210: }
211: }
|