KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > outerj > daisy > frontend > util > WikiDataDirHelper


1 /*
2  * Copyright 2004 Outerthought bvba and Schaubroeck nv
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 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 JavaDoc;
23
24 public class WikiDataDirHelper {
25     private static String JavaDoc daisyWikiDataDir;
26     private static Properties JavaDoc resolveProperties;
27     private static final String JavaDoc DAISYWIKI_DATA_PROPNAME = "daisywiki.data";
28
29     static {
30         daisyWikiDataDir = System.getProperty(DAISYWIKI_DATA_PROPNAME);
31
32         resolveProperties = new Properties JavaDoc(System.getProperties());
33         if (daisyWikiDataDir != null)
34             resolveProperties.setProperty(DAISYWIKI_DATA_PROPNAME, daisyWikiDataDir);
35     }
36
37     public static String JavaDoc getWikiDataDir(org.apache.avalon.framework.context.Context context) {
38         String JavaDoc contextWikiData = getDataDirFromContext(context);
39         if (contextWikiData != null)
40             return contextWikiData;
41         else if (daisyWikiDataDir != null)
42             return daisyWikiDataDir;
43         else
44             throw new RuntimeException JavaDoc("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.");
45     }
46
47     public static Properties JavaDoc getResolveProperties(org.apache.avalon.framework.context.Context context) {
48         String JavaDoc contextWikiData = getDataDirFromContext(context);
49         if (contextWikiData != null) {
50             Properties JavaDoc resolveProperties = new Properties JavaDoc(System.getProperties());
51             resolveProperties.setProperty(DAISYWIKI_DATA_PROPNAME, contextWikiData);
52             return resolveProperties;
53         } else {
54             return resolveProperties;
55         }
56     }
57
58     private static String JavaDoc getDataDirFromContext(org.apache.avalon.framework.context.Context context) {
59         Context servletContext;
60         try {
61             servletContext = (Context)context.get(Constants.CONTEXT_ENVIRONMENT_CONTEXT);
62         } catch (ContextException e) {
63             throw new RuntimeException JavaDoc(e);
64         }
65         return servletContext.getInitParameter(DAISYWIKI_DATA_PROPNAME);
66     }
67 }
68
Popular Tags