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.webapp.internal.ui;
22  
23  import java.util.MissingResourceException;
24  import java.util.ResourceBundle;
25  
26  import org.apache.cactus.eclipse.webapp.internal.Webapp;
27  import org.eclipse.core.resources.IWorkspace;
28  import org.eclipse.core.resources.ResourcesPlugin;
29  import org.eclipse.core.runtime.IPluginDescriptor;
30  import org.eclipse.jdt.core.IJavaProject;
31  import org.eclipse.ui.plugin.AbstractUIPlugin;
32  
33  /**
34   * The main plugin class to be used in the desktop.
35   * 
36   * @version $Id: WebappPlugin.java 238816 2004-02-29 16:36:46Z vmassol $
37   */
38  public class WebappPlugin extends AbstractUIPlugin
39  {
40      /**
41       * The shared instance.
42       */
43      private static WebappPlugin plugin;
44      /**
45       * Resource bundle.
46       */
47      private ResourceBundle resourceBundle;
48  
49      /**
50       * The constructor.
51       * @param theDescriptor the descriptor for this plugin
52       */
53      public WebappPlugin(final IPluginDescriptor theDescriptor)
54      {
55          super(theDescriptor);
56          plugin = this;
57          try
58          {
59              resourceBundle =
60                  ResourceBundle.getBundle("webapp.webappPluginResources");
61          }
62          catch (MissingResourceException x)
63          {
64              resourceBundle = null;
65          }
66      }
67  
68      /**
69       * Returns the shared instance.
70       * @return the instance of this plugin
71       */
72      public static WebappPlugin getDefault()
73      {
74          return plugin;
75      }
76  
77      /**
78       * Returns the workspace instance.
79       * @return the instance of the current workspace
80       */
81      public static IWorkspace getWorkspace()
82      {
83          return ResourcesPlugin.getWorkspace();
84      }
85  
86      /**
87       * Returns the string from the plugin's resource bundle,
88       * or 'key' if not found.
89       * @param theKey the key of the resource to return
90       * @return the string
91       */
92      public static String getResourceString(final String theKey)
93      {
94          ResourceBundle bundle = WebappPlugin.getDefault().getResourceBundle();
95          try
96          {
97              return bundle.getString(theKey);
98          }
99          catch (MissingResourceException e)
100         {
101             return theKey;
102         }
103     }
104 
105     /**
106      * Returns the plugin's resource bundle
107      * @return the resource bundle
108      */
109     public final ResourceBundle getResourceBundle()
110     {
111         return resourceBundle;
112     }
113 
114     /**
115      * @return the plugin identifier
116      */
117     public static String getPluginId()
118     {
119         return getDefault().getDescriptor().getUniqueIdentifier();
120     }
121 
122     /**
123      * @param theJavaProject the Java project to get the webapp from
124      * @return the webapp associated to the given Java project
125      */
126     public static Webapp getWebapp(final IJavaProject theJavaProject)
127     {
128         return new Webapp(theJavaProject);
129     }
130 }