ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/i-scream/projects/cms/source/server/uk/org/iscream/cms/server/core/ConfigurationManagerServant.java
(Generate patch)

Comparing projects/cms/source/server/uk/org/iscream/cms/server/core/ConfigurationManagerServant.java (file contents):
Revision 1.3 by ajm, Tue Nov 21 21:58:52 2000 UTC vs.
Revision 1.4 by ajm, Tue Nov 21 23:48:55 2000 UTC

# Line 96 | Line 96 | class ConfigurationManagerServant extends Configuratio
96          // if there is an entry
97          if (configFile != null) {
98              try {
99 <                // get the file list of includes etc
100 <                String fileList = getIncludedFiles(configFile);            
99 >                // get the file list of includes etc + the system config
100 >                String fileList = _systemConfigFile + ";" + getIncludedFiles(configFile, "");            
101                  _logRef.write(this.toString(), Logger.DEBUG, "config tree - " + fileList);
102                  
103                  // build the properites here from the filelist....
# Line 140 | Line 140 | class ConfigurationManagerServant extends Configuratio
140                  e.printStackTrace(System.out);
141              }
142              
143 <        // if there isn't an entry for he requested config
143 >        // if there isn't an entry for the requested config
144          } else {
145              _logRef.write(this.toString(), Logger.DEBUG, "no configured config, returning " + _systemConfigFile);
146              config = _systemConfig;
# Line 195 | Line 195 | class ConfigurationManagerServant extends Configuratio
195       * This function calls itself.
196       *
197       * @param currentFile the current file to be processed
198 <     *
198 >     * @param readFiles used for recursion purposes only, these are the files it has read so far
199 >     *
200       * @return the current list that has been constructed
201       *
202       * @throws IOException if there is trouble reading the file
203       * @throws FileNotFoundException is there is trouble finding the file
204 +     * @throws CircularIncludeException this is if a circular include is detected
205       */
206 <    private String getIncludedFiles(String currentFile) throws IOException, FileNotFoundException {
206 >    private String getIncludedFiles(String currentFile, String readFiles) throws IOException, FileNotFoundException, Exception {
207 >        
208 >        // check for circular include here
209 >        if (hasDuplicate(currentFile, readFiles) || currentFile.equals(_systemConfigFile)) {
210 >            throw new CircularIncludeException(currentFile + " is included more than once");
211 >        }
212 >        
213 >        // if there wasn't, we're gonna use this file, so make a note of it as read
214 >        // (note the use of the ";", this is for the hasDuplicate, function)
215 >        readFiles = readFiles + currentFile + ";";
216 >
217          Properties properties = new Properties();
218          properties.load(new FileInputStream(new File(_configPath, currentFile)));
219 +        
220 +        // get the include property
221          String includes = properties.getProperty("include");
222 +
223 +        // if we're the last file with no includes, return our name
224          if (includes == null) {
225              return currentFile;
226 +        
227 +        // otherwise, recurse over our includes
228          } else {
229              StringTokenizer st = new StringTokenizer(includes, ";");
230              String returnList= "";
231              while (st.hasMoreTokens()) {
232 <                String nextFile = st.nextToken();
215 <                returnList = getIncludedFiles(nextFile) + ";" + returnList;
232 >                returnList = getIncludedFiles(st.nextToken(), readFiles) + ";" + returnList;
233              }
234 +            
235              return returnList + currentFile;
236          }
237      }
238  
239      /**
240 +     * This simple method checks to see if a given
241 +     * file exists in the given list.
242 +     *
243 +     * @param file the file to check the list for
244 +     * @param fileList the list to check
245 +     *
246 +     * @return if the given file appeard in the list
247 +     */
248 +    private boolean hasDuplicate(String file, String fileList) {
249 +        StringTokenizer st = new StringTokenizer(fileList, ";");
250 +        while (st.hasMoreTokens()) {
251 +            if (file.equals(st.nextToken())) {
252 +                return true;
253 +            }
254 +        }
255 +        return false;
256 +    }
257 +
258 +    /**
259       * Opens and loads the system configuration into the
260       * local reference _systemConfig
261       */
262      private void loadSystemConfig() {
263 <        _logRef.write(this.toString(), Logger.SYSMSG, "reloading" + _systemConfigFile);
263 >        _logRef.write(this.toString(), Logger.SYSMSG, "reloading " + _systemConfigFile);
264          // get a reference to the system config and store it
265          try {
266              // create the properties for the configuration

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines