001: /**********************************************************************************
002: * $URL: https://source.sakaiproject.org/svn/sam/tags/sakai_2-4-1/samigo-app/src/java/org/sakaiproject/tool/assessment/settings/PathInfo.java $
003: * $Id: PathInfo.java 17056 2006-10-11 16:29:51Z ktsao@stanford.edu $
004: ***********************************************************************************
005: *
006: * Copyright (c) 2004, 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.settings;
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 17056 2006-10-11 16:29:51Z ktsao@stanford.edu $
035: */
036: public class PathInfo
037: //extends AbstractCompositeObject
038: {
039: private static Log log = LogFactory.getLog(OjbConfigListener.class);
040: private static final String SETTINGS_DIR = "/org/sakaiproject/settings/sam";
041: private static final String SECURITY_DIR = "/org/sakaiproject/security/sam";
042: private static PathInfo _INSTANCE = new PathInfo();
043: private String basePathToSecurity = "";
044: private String basePathToSettings = "";
045: private String pathToSecurity = "";
046: private String pathToSettings = "";
047:
048: /**
049: * Returns an instance of PathInfo.
050: *
051: * @return
052: */
053: public static PathInfo getInstance() {
054: log.debug("getInstance()");
055:
056: return _INSTANCE;
057: }
058:
059: /**
060: * Constructor should never be exposed. Singleton pattern.
061: */
062: private PathInfo() {
063: log.debug("new PathInfo()");
064: }
065:
066: /**
067: * Returns a Properties from the security directory.
068: *
069: * @param fileName
070: *
071: * @return
072: *
073: * @throws IOException
074: */
075: public Properties getSecurityProperties(String fileName)
076: throws IOException {
077: if (log.isDebugEnabled()) {
078: log.debug("getSecurityProperties(String " + fileName + ")");
079: }
080:
081: Properties props = null;
082: props = new Properties();
083: props
084: .load(new FileInputStream(pathToSecurity + "/"
085: + fileName));
086:
087: return props;
088: }
089:
090: /**
091: * DOCUMENTATION PENDING
092: *
093: * @param fileName DOCUMENTATION PENDING
094: *
095: * @return DOCUMENTATION PENDING
096: *
097: * @throws IOException DOCUMENTATION PENDING
098: */
099: public Properties getSettingsProperties(String fileName)
100: throws IOException {
101: if (log.isDebugEnabled()) {
102: log.debug("getSettingsProperties(String " + fileName + ")");
103: }
104:
105: Properties props = null;
106: props = new Properties();
107: props
108: .load(new FileInputStream(pathToSettings + "/"
109: + fileName));
110:
111: return props;
112: }
113:
114: /**
115: * DOCUMENTATION PENDING
116: *
117: * @return DOCUMENTATION PENDING
118: */
119: public String getBasePathToSecurity() {
120: log.debug("getBasePathToSecurity()");
121:
122: return basePathToSecurity;
123: }
124:
125: /**
126: * DOCUMENTATION PENDING
127: *
128: * @param basePathToSecurity DOCUMENTATION PENDING
129: *
130: * @throws IllegalArgumentException DOCUMENTATION PENDING
131: */
132: public void setBasePathToSecurity(String basePathToSecurity)
133: throws IllegalArgumentException {
134: if (log.isDebugEnabled()) {
135: log.debug("setBasePathToSecurity(String "
136: + basePathToSecurity + ")");
137: }
138:
139: if (basePathToSecurity == null) {
140: throw new IllegalArgumentException(
141: "basePathToSecurity is null");
142: }
143:
144: synchronized (this .basePathToSecurity) {
145: this .basePathToSecurity = basePathToSecurity;
146: }
147:
148: synchronized (this .pathToSecurity) {
149: this .pathToSecurity = this .basePathToSecurity
150: + SECURITY_DIR;
151: }
152: }
153:
154: /**
155: * DOCUMENTATION PENDING
156: *
157: * @return DOCUMENTATION PENDING
158: */
159: public String getBasePathToSettings() {
160: log.debug("getBasePathToSettings()");
161:
162: return basePathToSettings;
163: }
164:
165: /**
166: * DOCUMENTATION PENDING
167: *
168: * @param basePathToSettings DOCUMENTATION PENDING
169: *
170: * @throws IllegalArgumentException DOCUMENTATION PENDING
171: */
172: public void setBasePathToSettings(String basePathToSettings)
173: throws IllegalArgumentException {
174: if (log.isDebugEnabled()) {
175: log.debug("setBasePathToSettings(String "
176: + basePathToSettings + ")");
177: }
178:
179: if (basePathToSettings == null) {
180: throw new IllegalArgumentException(
181: "basePathToSettings is null");
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: * DOCUMENT ME!
196: *
197: * @return
198: */
199: public String getPathToSecurity() {
200: return pathToSecurity;
201: }
202:
203: /**
204: * DOCUMENT ME!
205: *
206: * @return
207: */
208: public String getPathToSettings() {
209: return pathToSettings;
210: }
211: }
|