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.webscripts;
20  
21  import java.util.Map;
22  
23  import org.springframework.extensions.surf.FrameworkUtil;
24  import org.springframework.extensions.surf.RequestContext;
25  import org.springframework.extensions.webscripts.DeclarativeWebScript;
26  import org.springframework.extensions.webscripts.WebScriptRequest;
27  import org.springframework.extensions.webscripts.WebScriptResponse;
28  
29  /**
30   * Base Web Script implementation for Web Studio Web Scripts
31   * 
32   * This extends from DeclarativeSiteWebScript so as to provide
33   * root-scoped objects directly from the Web Framework (Surf).
34   * 
35   * It also introduces a new root-scoped object called "webstudio"
36   * 
37   * @author muzquiano
38   */
39  public class DeclarativeWebStudioWebScript extends DeclarativeWebScript
40  {
41      private static final String ROOT_SCOPE_WEB_STUDIO = "webstudio";
42  
43      /*
44       * (non-Javadoc)
45       * 
46       * @see org.alfresco.web.scripts.DeclarativeSiteWebScript#createScriptParameters(org.alfresco.web.scripts.WebScriptRequest,
47       *      org.alfresco.web.scripts.WebScriptResponse, java.util.Map)
48       */
49      protected Map<String, Object> createScriptParameters(WebScriptRequest req,
50              WebScriptResponse res, Map<String, Object> customParams)
51      {
52          Map<String, Object> params = super.createScriptParameters(req, res,
53                  customParams);
54          
55          // add in the "webstudio" object
56          RequestContext context = FrameworkUtil.getCurrentRequestContext();
57          if (context != null)
58          {
59              ScriptWebStudio scriptWebStudio = new ScriptWebStudio(context);
60              scriptWebStudio.setModel(params);
61              params.put(ROOT_SCOPE_WEB_STUDIO, scriptWebStudio);
62          }
63          return params;
64      }
65  }