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.atom;
20  
21  import java.util.HashMap;
22  import java.util.Map;
23  
24  import javax.xml.namespace.QName;
25  
26  import org.springframework.extensions.webscripts.Cache;
27  import org.springframework.extensions.webscripts.DeclarativeWebScript;
28  import org.springframework.extensions.webscripts.Status;
29  import org.springframework.extensions.webscripts.WebScriptException;
30  import org.springframework.extensions.webscripts.WebScriptRequest;
31  import org.springframework.extensions.webscripts.servlet.WebScriptServletRequest;
32  
33  
34  /**
35   * Abstract ATOM Web Script
36   *
37   * @author davidc
38   */
39  public abstract class AtomWebScript extends DeclarativeWebScript 
40  {
41      // dependencies
42      protected AbderaService abderaService;
43      
44      /**
45       * Sets the Abdera Service
46       * 
47       * @param abderaService
48       */
49      public void setAbderaService(AbderaService abderaService)
50      {
51         this.abderaService = abderaService; 
52      }
53  
54      /* (non-Javadoc)
55       * @see org.springframework.extensions.webscripts.DeclarativeWebScript#executeImpl(org.springframework.extensions.webscripts.WebScriptRequest, org.springframework.extensions.webscripts.Status, org.springframework.extensions.webscripts.Cache)
56       */
57      @SuppressWarnings("unchecked")
58      @Override
59      protected Map<String, Object> executeImpl(WebScriptRequest req, Status status, Cache cache)
60      {
61          if (!(req instanceof WebScriptServletRequest))
62          {
63              throw new WebScriptException("ATOM Web Scripts require servlet runtime");
64          }
65  
66          Map<String, Object> model = new HashMap<String, Object>();
67          model.put("slug", req.getHeader("Slug"));
68          model.put("type", req.getHeader("Content-Type"));
69          Map<String,QName> qnames = new HashMap<String,QName>();
70          qnames.putAll(abderaService.getNames());
71          Map<String,QName> scriptQnames = (Map<String,QName>)req.getServiceMatch().getWebScript().getDescription().getExtensions().get("qnames");
72          if (scriptQnames != null)
73          {
74              qnames.putAll(scriptQnames);
75          }
76          model.put("qnames", qnames);
77          return model;
78      }
79  
80  }