KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > opencms > loader > CmsMimeType


1 /*
2  * File : $Source: /usr/local/cvs/opencms/src/org/opencms/loader/CmsMimeType.java,v $
3  * Date : $Date: 2006/09/22 15:17:03 $
4  * Version: $Revision: 1.2 $
5  *
6  * This library is part of OpenCms -
7  * the Open Source Content Mananagement System
8  *
9  * Copyright (C) 2002 - 2006 Alkacon Software (http://www.alkacon.com)
10  *
11  * This library is free software; you can redistribute it and/or
12  * modify it under the terms of the GNU Lesser General Public
13  * License as published by the Free Software Foundation; either
14  * version 2.1 of the License, or (at your option) any later version.
15  *
16  * This library is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19  * Lesser General Public License for more details.
20  *
21  * For further information about Alkacon Software, please see the
22  * company website: http://www.alkacon.com
23  *
24  * For further information about OpenCms, please see the
25  * project website: http://www.opencms.org
26  *
27  * You should have received a copy of the GNU Lesser General Public
28  * License along with this library; if not, write to the Free Software
29  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
30  */

31 package org.opencms.loader;
32
33 import java.util.Locale JavaDoc;
34
35 /**
36  * Describes a MIME type configured in OpenCms.<p>
37  *
38  * @author Alexander Kandzior
39  *
40  * @version $Revision: 1.2 $
41  *
42  * @since 7.0.0
43  */

44 public class CmsMimeType implements Comparable JavaDoc {
45
46     /** Indicates if this a MIME type read from the OpenCms configuration. */
47     private boolean m_configured;
48
49     /** The MIME type file extension. */
50     private String JavaDoc m_extension;
51
52     /** The MIME type description. */
53     private String JavaDoc m_type;
54
55     /**
56      * Default constructor for MIME types.<p>
57      *
58      * If the extension does not start with a dot '.', then a dot is automatically added
59      * as a prefix.<p>
60      *
61      * @param extension the MIME type extension
62      * @param type the MIME type description
63      */

64     public CmsMimeType(String JavaDoc extension, String JavaDoc type) {
65
66         this(extension, type, true);
67     }
68
69     /**
70      * Special constructor for "marked" MIME types.<p>
71      *
72      * If the extension does not start with a dot '.', then a dot is automatically added
73      * as a prefix.<p>
74      *
75      * @param extension the MIME type extension
76      * @param type the MIME type description
77      * @param configured indicates if this a MIME type read from the OpenCms configuration
78      */

79     public CmsMimeType(String JavaDoc extension, String JavaDoc type, boolean configured) {
80
81         m_extension = String.valueOf(extension).toLowerCase(Locale.ENGLISH);
82         if (!(m_extension.charAt(0) == '.')) {
83             m_extension = "." + m_extension;
84         }
85         m_type = String.valueOf(type).toLowerCase(Locale.ENGLISH);
86         m_configured = configured;
87     }
88
89     /**
90      * MIME-types are compared according to the type first, and to the extension second.<p>
91      *
92      * @see java.lang.Comparable#compareTo(java.lang.Object)
93      */

94     public int compareTo(Object JavaDoc obj) {
95
96         if (obj == this) {
97             return 0;
98         }
99         if (obj instanceof CmsMimeType) {
100             int result = m_type.compareTo(((CmsMimeType)obj).m_type);
101             if (result == 0) {
102                 result = m_extension.compareTo(((CmsMimeType)obj).m_extension);
103             }
104             return result;
105         }
106         return 0;
107     }
108
109     /**
110      * MIME-types are equal is the extension is equal.<p>
111      *
112      * @see java.lang.Object#equals(java.lang.Object)
113      */

114     public boolean equals(Object JavaDoc obj) {
115
116         if (obj == this) {
117             return true;
118         }
119         if (obj instanceof CmsMimeType) {
120             return ((CmsMimeType)obj).m_extension.equals(m_extension);
121         }
122         return false;
123     }
124
125     /**
126      * Returns the MIME type file extension.<p>
127      *
128      * @return the MIME type file extension
129      */

130     public String JavaDoc getExtension() {
131
132         return m_extension;
133     }
134
135     /**
136      * Returns the MIME type description.<p>
137      *
138      * @return the MIME type description
139      */

140     public String JavaDoc getType() {
141
142         return m_type;
143     }
144
145     /**
146      * The hash code of MIME types is build only from the extension.<p>
147      *
148      * @see java.lang.Object#hashCode()
149      */

150     public int hashCode() {
151
152         return m_extension.hashCode();
153     }
154
155     /**
156      * Returns <code>true</code> if this MIME type has been read from the OpenCms configuration.<p>
157      *
158      * @return <code>true</code> if this MIME type has been read from the OpenCms configuration
159      */

160     public boolean isConfigured() {
161
162         return m_configured;
163     }
164 }
Popular Tags