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.List;
22  import java.util.Map;
23  import java.util.Map.Entry;
24  
25  import org.apache.abdera.factory.ExtensionFactory;
26  import org.springframework.beans.factory.InitializingBean;
27  import org.springframework.extensions.surf.exception.WebScriptsPlatformException;
28  
29  
30  /**
31   * Abdera Extension.
32   * 
33   * Mechanism for registering Atom extensions including QNames and
34   * Factories for managing the retrieval and setting of extensions.
35   * 
36   * @author davidc
37   */
38  public class AbderaExtension implements InitializingBean
39  {
40      private AbderaServiceImpl abderaService;
41      private String defaultNamespace = null;
42      private Map<String, String> qnames = null;
43      private List<ExtensionFactory> extensionFactories = null;
44      
45      /**
46       * @param abderaService
47       */
48      public void setAbderaService(AbderaServiceImpl abderaService)
49      {
50          this.abderaService = abderaService;
51      }
52      
53      /**
54       * @param defaultNamespace
55       */
56      public void setDefaultNamespace(String defaultNamespace)
57      {
58          this.defaultNamespace = defaultNamespace;
59      }
60  
61      /**
62       * @param qnames
63       */
64      public void setQNames(Map<String, String> qnames)
65      {
66          this.qnames = qnames;
67      }
68  
69      /**
70       * @param extensionFactories
71       */
72      public void setExtensionFactories(List<ExtensionFactory> extensionFactories)
73      {
74          this.extensionFactories = extensionFactories;
75      }
76  
77      /* (non-Javadoc)
78       * @see org.springframework.beans.factory.InitializingBean#afterPropertiesSet()
79       */
80      public void afterPropertiesSet()
81          throws Exception
82      {
83          if (abderaService == null)
84          {
85              throw new WebScriptsPlatformException("Abdera Service not specified");
86          }
87          
88          // register qname extensions
89          if (qnames != null)
90          {
91              for (Entry<String, String> entry : qnames.entrySet())
92              {
93                  String qname = entry.getValue();
94                  if (defaultNamespace != null && qname.indexOf('{') == -1)
95                  {
96                      qname = "{" + defaultNamespace + "}" + qname;
97                  }
98                  abderaService.registerQName(entry.getKey(), qname);
99              }
100         }
101         
102         // register extension factories
103         if (extensionFactories != null)
104         {
105             for (ExtensionFactory extensionFactory : extensionFactories)
106             {
107                 abderaService.registerExtensionFactory(extensionFactory);
108             }
109         }
110     }
111 
112 }