2011/08/05 - Jakarta Cactus has been retired.

For more information, please explore the Attic.

View Javadoc

1   /* 
2    * ========================================================================
3    * 
4    * Licensed to the Apache Software Foundation (ASF) under one or more
5    * contributor license agreements.  See the NOTICE file distributed with
6    * this work for additional information regarding copyright ownership.
7    * The ASF licenses this file to You under the Apache License, Version 2.0
8    * (the "License"); you may not use this file except in compliance with
9    * the License.  You may obtain a copy of the License at
10   * 
11   *   http://www.apache.org/licenses/LICENSE-2.0
12   * 
13   * Unless required by applicable law or agreed to in writing, software
14   * distributed under the License is distributed on an "AS IS" BASIS,
15   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16   * See the License for the specific language governing permissions and
17   * limitations under the License.
18   * 
19   * ========================================================================
20   */
21  package org.apache.cactus.eclipse.runner.ui;
22  
23  import java.util.Hashtable;
24  
25  import org.eclipse.jface.preference.IPreferenceStore;
26  
27  /**
28   * Central class for managing the Cactus preferences.
29   * 
30   * @version $Id: CactusPreferences.java 238816 2004-02-29 16:36:46Z vmassol $
31   */
32  public class CactusPreferences
33  {
34      /**
35       * The protocol scheme component of the context URL (either 'http' or 
36       * 'https') preference.
37       */
38      public static final String CONTEXT_URL_SCHEME = "contextURL_Scheme";
39  
40      /**
41       * The host component of the context URL preference. 
42       */
43      public static final String CONTEXT_URL_HOST = "contextURL_Host";
44  
45      /**
46       * The port component of the context URL preference.
47       */
48      public static final String CONTEXT_URL_PORT = "contextURL_Port";
49  
50      /**
51       * The path component of the context URL preference.
52       */
53      public static final String CONTEXT_URL_PATH = "contextURL_Path";
54  
55      /**
56       * The temp directory used by the plugin to set up containers.
57       */
58      public static final String TEMP_DIR = "temp_Dir";
59  
60      /**
61       * id for the Jetty container selection preference.
62       */
63      public static final String JETTY = "jetty";
64  
65      /**
66       * id for the jetty.xml location preference.
67       */
68      public static final String JETTY_XML = "jetty_xml";
69  
70      /**
71       * @return the context URL that should be used by the client, as 
72       * configured in the plug-in preferences.
73       */
74      public static String getContextURL()
75      {
76          IPreferenceStore store = CactusPlugin.getDefault().getPreferenceStore();
77          StringBuffer buf =
78              new StringBuffer()
79                  .append(store.getString(CONTEXT_URL_SCHEME))
80                  .append("://")
81                  .append(store.getString(CONTEXT_URL_HOST))
82                  .append(":")
83                  .append(store.getInt(CONTEXT_URL_PORT))
84                  .append("/")
85                  .append(store.getString(CONTEXT_URL_PATH));
86          String result = buf.toString();
87          return result;
88      }
89  
90      /**
91       * @return the context URL port that should be used by the client, as 
92       * configured in the plug-in preferences.
93       */
94      public static int getContextURLPort()
95      {
96          IPreferenceStore store = CactusPlugin.getDefault().getPreferenceStore();
97          int result = store.getInt(CONTEXT_URL_PORT);
98          return result;
99      }
100 
101     /**
102      * @return the context URL path that should be used by the client, as 
103      * configured in the plug-in preferences.
104      */
105     public static String getContextURLPath()
106     {
107         IPreferenceStore store = CactusPlugin.getDefault().getPreferenceStore();
108         String result = store.getString(CONTEXT_URL_PATH);
109         return result;
110     }
111 
112     /**
113      * @return the temp directory used by cactus, as 
114      * configured in the plug-in preferences.
115      */
116     public static String getTempDir()
117     {
118         IPreferenceStore store = CactusPlugin.getDefault().getPreferenceStore();
119         String result = store.getString(TEMP_DIR);
120         return result;
121     }
122 
123     /**
124      * @param theContainerId container id
125      * @return the home directory for the given container id.
126      */
127     public static String getContainerDir(String theContainerId)
128     {
129         IPreferenceStore store = CactusPlugin.getDefault().getPreferenceStore();
130         String result = store.getString(theContainerId);
131         return result;
132     }
133 
134     /**
135      * @return true if Jetty is selected
136      */
137     public static boolean getJetty()
138     {
139         IPreferenceStore store = CactusPlugin.getDefault().getPreferenceStore();
140         boolean result = store.getBoolean(JETTY);
141         return result;
142     }
143 
144     /**
145      * @return the jetty.xml location
146      */
147     public static String getJettyXML()
148     {
149         IPreferenceStore store = CactusPlugin.getDefault().getPreferenceStore();
150         String result = store.getString(JETTY_XML);
151         return result;
152     }
153 
154     /**
155      * @return the ContainerHome array
156      */
157     public static Hashtable getContainerHomes()
158     {
159         Hashtable containerHomes = new Hashtable();
160         String[] containerIds = CactusPlugin.getContainerIds();
161 
162             for (int i = 0; i < containerIds.length; i++)
163             {
164                 String currentId = containerIds[i];
165                 String currentContainerDir = getContainerDir(currentId);
166                 if (!currentContainerDir.equals(""))
167                 {
168                     containerHomes.put(currentId, currentContainerDir);
169                 }
170 
171             }
172         return containerHomes;
173     }
174 }