KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > alfresco > web > config > MimeTypeConfigElement


1 /*
2  * Copyright (C) 2005 Alfresco, Inc.
3  *
4  * Licensed under the Mozilla Public License version 1.1
5  * with a permitted attribution clause. You may obtain a
6  * copy of the License at
7  *
8  * http://www.alfresco.org/legal/license.txt
9  *
10  * Unless required by applicable law or agreed to in writing,
11  * software distributed under the License is distributed on an
12  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
13  * either express or implied. See the License for the specific
14  * language governing permissions and limitations under the
15  * License.
16  */

17 package org.alfresco.web.config;
18
19 import java.util.HashMap JavaDoc;
20 import java.util.Map JavaDoc;
21
22 import org.alfresco.config.ConfigElement;
23 import org.alfresco.config.element.ConfigElementAdapter;
24
25 /**
26  * @author Kevin Roast
27  */

28 public final class MimeTypeConfigElement extends ConfigElementAdapter
29 {
30    /**
31     * Default Constructor
32     */

33    public MimeTypeConfigElement()
34    {
35       super(MimeTypesElementReader.ELEMENT_MIMETYPES);
36    }
37    
38    /**
39     * Constructor
40     *
41     * @param mappings Map of mimetype elements to use
42     */

43    public MimeTypeConfigElement(Map JavaDoc<String JavaDoc, String JavaDoc> mappings)
44    {
45       super(MimeTypesElementReader.ELEMENT_MIMETYPES);
46       this.mimetypes = mappings;
47    }
48
49    /**
50     * @see org.alfresco.config.element.ConfigElementAdapter#combine(org.alfresco.config.ConfigElement)
51     */

52    public ConfigElement combine(ConfigElement configElement)
53    {
54       MimeTypeConfigElement combined = new MimeTypeConfigElement(this.mimetypes);
55       
56       if (configElement instanceof MimeTypeConfigElement)
57       {
58          combined.mimetypes.putAll( ((MimeTypeConfigElement)configElement).mimetypes );
59       }
60       
61       return combined;
62    }
63    
64    /**
65     * Add a mimetype extension mapping to the config element
66     *
67     * @param ext extension to map against
68     * @param mimetype mimetype content type for the specified extension
69     */

70    public void addMapping(String JavaDoc ext, String JavaDoc mimetype)
71    {
72       this.mimetypes.put(ext, mimetype);
73    }
74    
75    /**
76     * Return the mimetype for the specified extension
77     *
78     * @param ext File
79     *
80     * @return mimetype content type or null if not found
81     */

82    public String JavaDoc getMimeType(String JavaDoc ext)
83    {
84       return this.mimetypes.get(ext);
85    }
86    
87    private Map JavaDoc<String JavaDoc, String JavaDoc> mimetypes = new HashMap JavaDoc<String JavaDoc, String JavaDoc>(89, 1.0f);
88 }
89
Popular Tags