View Javadoc
1   package com.atlassian.plugin.servlet;
2   
3   import com.atlassian.plugin.servlet.descriptors.BaseServletModuleDescriptor;
4   
5   import javax.servlet.Servlet;
6   import javax.servlet.ServletConfig;
7   import javax.servlet.ServletContext;
8   import java.util.Collections;
9   import java.util.Enumeration;
10  
11  /**
12   * Instances of the PluginServletConfig are passed to plugins servlet {@link Servlet} init() method. It provides
13   * access to the init parameters defined in the plugin xml as well as the ServletContext shared by other filters and
14   * servlets in the plugin.
15   */
16  public final class PluginServletConfig implements ServletConfig {
17      private final BaseServletModuleDescriptor<?> descriptor;
18      private final ServletContext servletContext;
19  
20      public PluginServletConfig(BaseServletModuleDescriptor<?> descriptor, ServletContext servletContext) {
21          this.descriptor = descriptor;
22          this.servletContext = servletContext;
23      }
24  
25      public String getServletName() {
26          return descriptor.getDisplayName();
27      }
28  
29      public ServletContext getServletContext() {
30          return servletContext;
31      }
32  
33      public String getInitParameter(String s) {
34          return descriptor.getInitParams().get(s);
35      }
36  
37      public Enumeration<String> getInitParameterNames() {
38          return Collections.enumeration(descriptor.getInitParams().keySet());
39      }
40  }