KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > lenya > cms > rc > RCEnvironment


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

17
18 /* $Id: RCEnvironment.java 42598 2004-03-01 16:18:28Z gregor $ */
19
20 package org.apache.lenya.cms.rc;
21
22 import java.io.File JavaDoc;
23 import java.util.HashMap JavaDoc;
24 import java.util.Map JavaDoc;
25
26 import org.apache.avalon.framework.configuration.Configurable;
27 import org.apache.avalon.framework.configuration.Configuration;
28 import org.apache.avalon.framework.configuration.DefaultConfigurationBuilder;
29 import org.apache.log4j.Category;
30
31 public class RCEnvironment implements Configurable {
32     private static Category log = Category.getInstance(RCEnvironment.class);
33     public static final String JavaDoc CONFIGURATION_FILE = "lenya" + File.separator + "config" +
34         File.separator + "rc" + File.separator + "revision-controller.xconf";
35     public static final String JavaDoc RCML_DIRECTORY = "rcml-directory";
36     public static final String JavaDoc BACKUP_DIRECTORY = "backup-directory";
37     private String JavaDoc rcmlDirectory;
38     private String JavaDoc backupDirectory;
39     
40     private static Map JavaDoc instances = new HashMap JavaDoc();
41     
42     /**
43      * Returns the singleton RC environment for this context path.
44      * @param contextPath The context path (the Lenya webapp directory).
45      * @return An RC environment.
46      */

47     public static RCEnvironment getInstance(String JavaDoc contextPath) {
48         RCEnvironment instance = (RCEnvironment) instances.get(contextPath);
49         if (instance == null) {
50             instance = new RCEnvironment(contextPath);
51             instances.put(contextPath, instance);
52         }
53         return instance;
54     }
55
56     /**
57      * Creates a new RCEnvironment object.
58      *
59      * @param contextPath DOCUMENT ME!
60      */

61     public RCEnvironment(String JavaDoc contextPath) {
62         log.debug("context path:" + contextPath);
63
64         String JavaDoc configurationFilePath = contextPath + "/" + CONFIGURATION_FILE;
65         log.debug("configuration file path:" + configurationFilePath);
66
67         File JavaDoc configurationFile = new File JavaDoc(configurationFilePath);
68
69         try {
70             DefaultConfigurationBuilder builder = new DefaultConfigurationBuilder();
71             Configuration configuration = builder.buildFromFile(configurationFile);
72             configure(configuration);
73         } catch (Exception JavaDoc e) {
74             log.error("Cannot load revision controller configuration! ", e);
75         }
76     }
77
78     /**
79      * DOCUMENT ME!
80      *
81      * @param configuration DOCUMENT ME!
82      *
83      * @throws org.apache.avalon.framework.configuration.ConfigurationException DOCUMENT ME!
84      */

85     public void configure(org.apache.avalon.framework.configuration.Configuration configuration)
86         throws org.apache.avalon.framework.configuration.ConfigurationException {
87         // revision controller
88
setRCMLDirectory(configuration.getChild("rcmlDirectory").getAttribute("href"));
89         setBackupDirectory(configuration.getChild("backupDirectory").getAttribute("href"));
90
91         log.debug("CONFIGURATION:\nRCML Directory: HREF=" + getRCMLDirectory());
92         log.debug("CONFIGURATION:\nBackup Directory: HREF=" + getBackupDirectory());
93     }
94
95     /**
96      * DOCUMENT ME!
97      *
98      * @return DOCUMENT ME!
99      */

100     public String JavaDoc getRCMLDirectory() {
101         return rcmlDirectory;
102     }
103
104     /**
105      * Set the rcml directory
106      *
107      * @param rcmlDir the path to the rcml directory
108      */

109     protected void setRCMLDirectory(String JavaDoc rcmlDir) {
110         rcmlDirectory = rcmlDir;
111     }
112
113     /**
114      * DOCUMENT ME!
115      *
116      * @return DOCUMENT ME!
117      */

118     public String JavaDoc getBackupDirectory() {
119         return backupDirectory;
120     }
121
122     /**
123      * Set the backup directory
124      *
125      * @param backupDir path to the backup directory
126      */

127     protected void setBackupDirectory(String JavaDoc backupDir) {
128         backupDirectory = backupDir;
129     }
130 }
131
Popular Tags