01: /*
02: * Copyright 2004 Outerthought bvba and Schaubroeck nv
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
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: package org.outerj.daisy.frontend.util;
17:
18: import org.apache.cocoon.Constants;
19: import org.apache.cocoon.environment.Context;
20: import org.apache.avalon.framework.context.ContextException;
21:
22: import java.util.Properties;
23:
24: public class WikiDataDirHelper {
25: private static String daisyWikiDataDir;
26: private static Properties resolveProperties;
27: private static final String DAISYWIKI_DATA_PROPNAME = "daisywiki.data";
28:
29: static {
30: daisyWikiDataDir = System.getProperty(DAISYWIKI_DATA_PROPNAME);
31:
32: resolveProperties = new Properties(System.getProperties());
33: if (daisyWikiDataDir != null)
34: resolveProperties.setProperty(DAISYWIKI_DATA_PROPNAME,
35: daisyWikiDataDir);
36: }
37:
38: public static String getWikiDataDir(
39: org.apache.avalon.framework.context.Context context) {
40: String contextWikiData = getDataDirFromContext(context);
41: if (contextWikiData != null)
42: return contextWikiData;
43: else if (daisyWikiDataDir != null)
44: return daisyWikiDataDir;
45: else
46: throw new RuntimeException(
47: "The property that specifies the location of the Daisy Wiki data directory (daisywiki.data) is neither specified as Java system property, nor as Servlet context initialization parameter.");
48: }
49:
50: public static Properties getResolveProperties(
51: org.apache.avalon.framework.context.Context context) {
52: String contextWikiData = getDataDirFromContext(context);
53: if (contextWikiData != null) {
54: Properties resolveProperties = new Properties(System
55: .getProperties());
56: resolveProperties.setProperty(DAISYWIKI_DATA_PROPNAME,
57: contextWikiData);
58: return resolveProperties;
59: } else {
60: return resolveProperties;
61: }
62: }
63:
64: private static String getDataDirFromContext(
65: org.apache.avalon.framework.context.Context context) {
66: Context servletContext;
67: try {
68: servletContext = (Context) context
69: .get(Constants.CONTEXT_ENVIRONMENT_CONTEXT);
70: } catch (ContextException e) {
71: throw new RuntimeException(e);
72: }
73: return servletContext.getInitParameter(DAISYWIKI_DATA_PROPNAME);
74: }
75: }
|