View Javadoc

1   package com.atlassian.plugin.refimpl.webresource;
2   
3   import com.atlassian.plugin.PluginAccessor;
4   import com.atlassian.plugin.refimpl.ContainerManager;
5   import com.atlassian.plugin.refimpl.ParameterUtils;
6   import com.atlassian.plugin.webresource.WebResourceIntegration;
7   
8   import java.util.HashMap;
9   import java.util.Map;
10  
11  import javax.servlet.ServletContext;
12  
13  public class SimpleWebResourceIntegration implements WebResourceIntegration
14  {
15      private final String systemBuildNumber;
16      private final ThreadLocal<Map<String, Object>> requestCache = new ThreadLocal<Map<String,Object>>() {
17          @Override
18          protected Map<String, Object> initialValue()
19          {
20              // if it's null, we just create a new one.. tho this means results from one request will affect the next request
21              // on this same thread because we don't ever clean it up from a filter or anything - definitely not for use in
22              // production!
23              return new HashMap<String, Object>();
24          }
25      };
26  
27      public SimpleWebResourceIntegration(final ServletContext servletContext)
28      {
29          // we fake the build number by using the startup time which will force anything cached by clients to be
30          // reloaded after a restart
31          systemBuildNumber = String.valueOf(System.currentTimeMillis());
32      }
33  
34      public String getBaseUrl()
35      {
36          return ParameterUtils.getBaseUrl();
37      }
38  
39      public PluginAccessor getPluginAccessor()
40      {
41          return ContainerManager.getInstance().getPluginAccessor();
42      }
43  
44      public Map<String, Object> getRequestCache()
45      {
46          return requestCache.get();
47      }
48  
49      public String getSystemBuildNumber()
50      {
51          return systemBuildNumber;
52      }
53  
54      public String getSystemCounter()
55      {
56          return "1";
57      }
58  }