KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > lenya > cms > publishing > PublishingEnvironment


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: PublishingEnvironment.java 42598 2004-03-01 16:18:28Z gregor $ */
19
20 package org.apache.lenya.cms.publishing;
21
22 import java.io.File JavaDoc;
23
24 import org.apache.avalon.framework.configuration.Configurable;
25 import org.apache.avalon.framework.configuration.Configuration;
26 import org.apache.avalon.framework.configuration.DefaultConfigurationBuilder;
27 import org.apache.log4j.Category;
28
29
30 public class PublishingEnvironment implements Configurable {
31     private static Category log = Category.getInstance(PublishingEnvironment.class);
32     public static final String JavaDoc CONFIGURATION_FILE = "config" + File.separator + "publishing" +
33         File.separator + "publisher.xconf";
34     public static final String JavaDoc PUBLICATION_PREFIX = "lenya" + File.separator + "pubs" +
35         File.separator;
36     public static final String JavaDoc PUBLICATION_PATH = "publication-path";
37     public static final String JavaDoc PARAMETER_AUTHORING_PATH = "authoring-path";
38     public static final String JavaDoc PARAMETER_TREE_AUTHORING_PATH = "tree-authoring-path";
39     public static final String JavaDoc PARAMETER_LIVE_PATH = "live-path";
40     public static final String JavaDoc PARAMETER_TREE_LIVE_PATH = "tree-live-path";
41     public static final String JavaDoc PARAMETER_REPLICATION_PATH = "replication-path";
42     public static final String JavaDoc PARAMETER_EXPORT_PATH = "export-path";
43     public static final String JavaDoc PARAMETER_SUBSTITUTE_REGEXP = "substitute-regexp";
44     public static final String JavaDoc PARAMETER_SUBSTITUTE_REPLACEMENT = "substitute-replacement";
45     private String JavaDoc publicationPath;
46     private String JavaDoc replicationDirectory;
47     private String JavaDoc authoringPath;
48     private String JavaDoc livePath;
49     private String JavaDoc treeAuthoringPath;
50     private String JavaDoc treeLivePath;
51     private String JavaDoc exportDirectory;
52     private String JavaDoc substituteExpression;
53     private String JavaDoc substituteReplacement;
54
55     /**
56      * Creates a new PublishingEnvironment object.
57      *
58      * @param contextPath DOCUMENT ME!
59      * @param publicationId DOCUMENT ME!
60      */

61     public PublishingEnvironment(String JavaDoc contextPath, String JavaDoc publicationId) {
62         this(PublishingEnvironment.getPublicationPath(contextPath, publicationId));
63         log.debug("Context Path and Publication Id: " + contextPath + "::" + publicationId);
64     }
65
66     /**
67      * Creates a new PublishingEnvironment object.
68      *
69      * @param publicationPath DOCUMENT ME!
70      */

71     public PublishingEnvironment(String JavaDoc publicationPath) {
72         setPublicationPath(publicationPath);
73
74         String JavaDoc configurationFilePath = publicationPath + CONFIGURATION_FILE;
75
76         File JavaDoc configurationFile = new File JavaDoc(configurationFilePath);
77
78         try {
79             DefaultConfigurationBuilder builder = new DefaultConfigurationBuilder();
80             Configuration configuration = builder.buildFromFile(configurationFile);
81             configure(configuration);
82         } catch (Exception JavaDoc e) {
83             log.info(
84                 "Did not load publishing configuration from publisher.xconf (No such file or directory: " + configurationFile + "). " +
85                 "That means you can't access all PublishingEnvironment parameters and you should only " +
86                 "use the AntTask. But don't panic, this file has been DEPRECATED.");
87         }
88     }
89
90     /**
91      * DOCUMENT ME!
92      *
93      * @param configuration DOCUMENT ME!
94      *
95      * @throws org.apache.avalon.framework.configuration.ConfigurationException DOCUMENT ME!
96      */

97     public void configure(org.apache.avalon.framework.configuration.Configuration configuration)
98         throws org.apache.avalon.framework.configuration.ConfigurationException {
99         // authoring
100
setAuthoringPath(configuration.getChild("authoring").getChild("documents").getAttribute("href"));
101         setTreeAuthoringPath(configuration.getChild("authoring").getChild("tree").getAttribute("href"));
102
103         // replication
104
setReplicationDirectory(configuration.getChild("replication").getChild("pending-documents")
105                                              .getAttribute("href"));
106
107         // live
108
setLivePath(configuration.getChild("live").getChild("documents").getAttribute("href"));
109         setTreeLivePath(configuration.getChild("live").getChild("tree").getAttribute("href"));
110
111         // export
112
setExportDirectory(configuration.getChild("export").getChild("destination").getAttribute("href"));
113         setSubstituteExpression(configuration.getChild("export").getChild("substitution")
114                                              .getAttribute("regexp"));
115         setSubstituteReplacementExpression(configuration.getChild("export").getChild("substitution")
116                                                         .getAttribute("replacement"));
117
118         log.debug("CONFIGURATION:\nauthoring path=" + getAuthoringPath() + "\nlive path=" +
119             getLivePath());
120         log.debug("CONFIGURATION:\ntree authoring path=" + getTreeAuthoringPath() +
121             "\ntree live path=" + getTreeLivePath());
122
123         log.debug("CONFIGURATION:\nDirectory Prefix: HREF=" + getExportDirectory());
124         log.debug("CONFIGURATION:\nPrefix Substitute: HREF=" + getSubstituteExpression());
125
126         log.debug("CONFIGURATION:\nReplication Directory: HREF=" + getReplicationDirectory());
127     }
128
129     /**
130      * Returns the publication directory.
131      *
132      * @return DOCUMENT ME!
133      */

134     public String JavaDoc getPublicationPath() {
135         return publicationPath;
136     }
137
138     /**
139      * Returns the publication directory.
140      */

141     public File JavaDoc getPublicationDirectory() {
142         return new File JavaDoc(getPublicationPath());
143     }
144
145     protected void setPublicationPath(String JavaDoc path) {
146         publicationPath = path;
147     }
148
149     /**
150      * DOCUMENT ME!
151      *
152      * @return DOCUMENT ME!
153      */

154     public String JavaDoc getAuthoringPath() {
155         return authoringPath;
156     }
157
158     protected void setAuthoringPath(String JavaDoc path) {
159         authoringPath = path;
160     }
161
162     /**
163      * DOCUMENT ME!
164      *
165      * @return DOCUMENT ME!
166      */

167     public String JavaDoc getLivePath() {
168         return livePath;
169     }
170
171     protected void setLivePath(String JavaDoc path) {
172         livePath = path;
173     }
174
175     /**
176      * DOCUMENT ME!
177      *
178      * @return DOCUMENT ME!
179      */

180     public String JavaDoc getTreeAuthoringPath() {
181         return treeAuthoringPath;
182     }
183
184     protected void setTreeAuthoringPath(String JavaDoc path) {
185         treeAuthoringPath = path;
186     }
187
188     /**
189      * DOCUMENT ME!
190      *
191      * @return DOCUMENT ME!
192      */

193     public String JavaDoc getTreeLivePath() {
194         return treeLivePath;
195     }
196
197     protected void setTreeLivePath(String JavaDoc path) {
198         treeLivePath = path;
199     }
200
201     /**
202      * DOCUMENT ME!
203      *
204      * @return DOCUMENT ME!
205      */

206     public String JavaDoc getReplicationDirectory() {
207         return replicationDirectory;
208     }
209
210     protected void setReplicationDirectory(String JavaDoc directory) {
211         replicationDirectory = directory;
212     }
213
214     /**
215      * DOCUMENT ME!
216      *
217      * @return DOCUMENT ME!
218      */

219     public String JavaDoc getExportDirectory() {
220         return exportDirectory;
221     }
222
223     protected void setExportDirectory(String JavaDoc directory) {
224         exportDirectory = directory;
225     }
226
227     /**
228      * DOCUMENT ME!
229      *
230      * @return DOCUMENT ME!
231      */

232     public String JavaDoc getSubstituteExpression() {
233         return substituteExpression;
234     }
235
236     protected void setSubstituteExpression(String JavaDoc substitute) {
237         substituteExpression = substitute;
238     }
239
240     /**
241      * Set replacement string, which was read from publisher.xconf
242      */

243     protected void setSubstituteReplacementExpression(String JavaDoc replacement) {
244         substituteReplacement = replacement;
245     }
246
247     /**
248      * Get the replacement string, which was read from publisher.xconf
249      *
250      * @return The replacement string
251      */

252     public String JavaDoc getSubstituteReplacement() {
253         return substituteReplacement;
254     }
255
256     /**
257      * DOCUMENT ME!
258      *
259      * @param servletContextPath DOCUMENT ME!
260      * @param publicationId DOCUMENT ME!
261      *
262      * @return DOCUMENT ME!
263      */

264     public static String JavaDoc getPublicationPath(String JavaDoc servletContextPath, String JavaDoc publicationId) {
265         if (!servletContextPath.endsWith(File.separator)) {
266             servletContextPath += File.separator;
267         }
268
269         return servletContextPath + PUBLICATION_PREFIX + publicationId + File.separator;
270     }
271 }
272
Popular Tags