View Javadoc

1   /**
2    * Copyright (C) 2005-2009 Alfresco Software Limited.
3    *
4    * This file is part of the Spring Surf Extension project.
5    *
6    * Licensed under the Apache License, Version 2.0 (the "License");
7    * you may not use this file except in compliance with the License.
8    * You may obtain a copy of the License at
9    *
10   *  http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing, software
13   * distributed under the License is distributed on an "AS IS" BASIS,
14   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15   * See the License for the specific language governing permissions and
16   * limitations under the License.
17   */
18  
19  package org.springframework.extensions.surf.studio;
20  
21  import javax.servlet.http.HttpServletRequest;
22  import javax.servlet.http.HttpSession;
23  
24  import org.springframework.extensions.config.WebStudioConfigElement;
25  
26  /**
27   * Default in-context state factory which produces session-bound
28   * in-context state objects
29   * 
30   * @author muzquiano
31   */
32  public class DefaultWebStudioStateProvider implements WebStudioStateProvider
33  {
34      public final static String SESSION_ATTR_WEBSTUDIO = "webstudio_incontext_state";
35  
36      protected WebStudioService webStudioService;
37      
38      /**
39       * Sets the web studio service.
40       * 
41       * @param webStudioService the new web studio service
42       */
43      public void setWebStudioService(WebStudioService webStudioService)
44      {
45          this.webStudioService = webStudioService;
46      }
47      
48      /**
49       * Gets the web studio service.
50       * 
51       * @return the web studio service
52       */
53      public WebStudioService getWebStudioService()
54      {
55          return this.webStudioService;
56      }
57      
58      /**
59       * Gets the web studio configuration.
60       * 
61       * @return the web studio configuration
62       */
63      public WebStudioConfigElement getWebStudioConfiguration()
64      {
65          return getWebStudioService().getWebStudioConfiguration();
66      }
67      
68      /*
69       * (non-Javadoc)
70       * 
71       * @see org.alfresco.web.studio.client.WebStudioStateProvider#provide(javax.servlet.http.HttpServletRequest)
72       */
73      public synchronized WebStudioStateBean provide(HttpServletRequest request)
74      {
75          HttpSession session = request.getSession();
76  
77          WebStudioStateBean state = (WebStudioStateBean) session
78                  .getAttribute(SESSION_ATTR_WEBSTUDIO);
79          if (state == null)
80          {
81              state = new WebStudioStateBean();
82              session.setAttribute(SESSION_ATTR_WEBSTUDIO, state);
83  
84              // initialize the client state with settings from
85              // Web Studio configuration
86  
87              /*
88              // applets
89              String[] appletIds = getWebStudioConfiguration().getAppletIds();
90              for (int i = 0; i < appletIds.length; i++)
91              {
92                  AppletDescriptor appletDescriptor = getWebStudioConfiguration()
93                          .getApplet(appletIds[i]);
94  
95                  // create client-state container for the applet
96                  AppletStateBean appletState = new AppletStateBean(
97                          appletDescriptor.getId());
98                  appletState.setTitle(appletDescriptor.getTitle());
99                  appletState.setDescription(appletDescriptor.getDescription());
100                 appletState.setClassname(appletDescriptor
101                         .getClassName());
102 
103                 // add this applet to the webstudio state
104                 state.applets.put(appletState.getId(), appletState);
105             }
106 
107             // applications
108             String[] appIds = getWebStudioConfiguration().getApplicationIds();
109             for (int i = 0; i < appIds.length; i++)
110             {
111                 ApplicationDescriptor appDescriptor = getWebStudioConfiguration()
112                         .getApplication(appIds[i]);
113 
114                 // create client-state container for the application
115                 ApplicationStateBean appState = new ApplicationStateBean(
116                         appDescriptor.getId());
117                 appState.setTitle(appDescriptor.getTitle());
118                 appState.setDescription(appDescriptor.getDescription());
119                 appState.setClassname(appDescriptor
120                         .getClassName());
121 
122                 // add this application to the webstudio state
123                 state.applications.put(appState.getId(), appState);
124 
125                 // walk the included applets
126                 List<String> includedAppletIds = appDescriptor
127                         .getAppletIncludes();
128                 for (int z = 0; z < includedAppletIds.size(); z++)
129                 {
130                     String appletId = (String) includedAppletIds.get(z);
131 
132                     AppletStateBean appletBean = state.getAppletState(appletId);
133                     if (appletBean != null)
134                     {
135                         appState.applets.put(appletBean.getId(), appletBean);
136                     }
137                 }
138             }
139             */
140         }
141 
142         return state;
143     }
144 }