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.beans.factory.InitializingBean;
24  
25  
26  /**
27   * A map of mimetypes indexed by format.
28   * 
29   * @author davidc
30   */
31  public class FormatMap implements InitializingBean
32  {
33      private FormatRegistry registry;
34      private String agent;
35      private Map<String, String> formats;
36      private Map<String, String> mimetypes;
37      
38  
39      /**
40       * Sets the Format Registry
41       * 
42       * @param registry
43       */
44      public void setRegistry(FormatRegistry registry)
45      {
46          this.registry = registry;
47      }
48      
49      /**
50       * Sets the User Agent for which the formats apply
51       * 
52       * @param agent
53       */
54      public void setAgent(String agent)
55      {
56          this.agent = agent;
57      }
58      
59      /**
60       * Sets the formats
61       * 
62       * @param formats
63       */
64      public void setFormats(Map<String, String> formats)
65      {
66          this.formats = formats;
67      }
68      
69      /**
70       * Sets the mimetypes
71       *  
72       * @param mimetypes
73       */
74      public void setMimetypes(Map<String, String> mimetypes)
75      {
76          this.mimetypes = mimetypes;
77      }
78  
79      /* (non-Javadoc)
80       * @see org.springframework.beans.factory.InitializingBean#afterPropertiesSet()
81       */
82      public void afterPropertiesSet() throws Exception
83      {
84          if (formats != null)
85          {
86              registry.addFormats(agent, formats);
87          }
88          if (mimetypes != null)
89          {
90              registry.addMimetypes(agent, mimetypes);
91          }
92      }
93      
94  }