01: /*
02: * This file is part of PFIXCORE.
03: *
04: * PFIXCORE is free software; you can redistribute it and/or modify
05: * it under the terms of the GNU Lesser General Public License as published by
06: * the Free Software Foundation; either version 2 of the License, or
07: * (at your option) any later version.
08: *
09: * PFIXCORE is distributed in the hope that it will be useful,
10: * but WITHOUT ANY WARRANTY; without even the implied warranty of
11: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12: * GNU Lesser General Public License for more details.
13: *
14: * You should have received a copy of the GNU Lesser General Public License
15: * along with PFIXCORE; if not, write to the Free Software
16: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17: */
18:
19: package de.schlund.pfixxml.config;
20:
21: import javax.servlet.ServletContext;
22:
23: import de.schlund.pfixxml.resources.DocrootResource;
24: import de.schlund.pfixxml.resources.DocrootResourceProvider;
25:
26: /**
27: * Used to set global configuration values. Should only be used from initialization
28: * code. Settings can be read by all code using {@link de.schlund.pfixxml.config.GlobalConfig}.
29: * Only one of {@link #setDocroot(String)} and {@link #setServletContext(ServletContext)}
30: * may be used and this method may only be called once. Otherwise an
31: * {@link java.lang.IllegalStateException} will be thrown.
32: * {@link #setDocroot(String)} is be preferred to {@link #setServletContext(ServletContext)}
33: * which should only be used in WAR mode, when the docroot is not available.
34: *
35: * @author Sebastian Marsching <sebastian.marsching@1und1.de>
36: */
37: public class GlobalConfigurator {
38:
39: /**
40: * Sets path to Pustefix docroot.
41: *
42: * @param path Absolute path to docroot. Must be an absolute pathname with no
43: * trailing slash.
44: */
45: public static void setDocroot(String path) {
46: if (!path.startsWith("/")) {
47: throw new IllegalArgumentException(
48: "Path has to be absolute");
49: }
50: if (path.endsWith("/")) {
51: path = path.substring(0, path.length() - 1);
52: }
53: GlobalConfig.setDocroot(path);
54: }
55:
56: /**
57: * Sets servlet context. May only be used in WAR-mode when Pustefix is not
58: * shared across several servlet contexts.
59: *
60: * @param context the only servlet context used by this instance of Pustefix
61: */
62: public static void setServletContext(ServletContext context) {
63: GlobalConfig.setServletContext(context);
64: }
65:
66: /**
67: * Sets provider for instances of {@link DocrootResource}.
68: * Can only be used if neither docroot path nor servlet context is set.
69: *
70: * @param provider the provider used to resolve docroot resources
71: */
72: public static void setDocrootResourceProvider(
73: DocrootResourceProvider provider) {
74: GlobalConfig.setDocrootResourceProvider(provider);
75: }
76: }
|