001: /**********************************************************************************
002: * $URL: https://source.sakaiproject.org/svn/metaobj/tags/sakai_2-4-1/metaobj-api/api/src/java/org/sakaiproject/metaobj/shared/model/MimeType.java $
003: * $Id: MimeType.java 8052 2006-04-20 18:16:21Z ggolden@umich.edu $
004: ***********************************************************************************
005: *
006: * Copyright (c) 2004, 2005, 2006 The Sakai Foundation.
007: *
008: * Licensed under the Educational Community License, Version 1.0 (the "License");
009: * you may not use this file except in compliance with the License.
010: * You may obtain a copy of the License at
011: *
012: * http://www.opensource.org/licenses/ecl1.php
013: *
014: * Unless required by applicable law or agreed to in writing, software
015: * distributed under the License is distributed on an "AS IS" BASIS,
016: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
017: * See the License for the specific language governing permissions and
018: * limitations under the License.
019: *
020: **********************************************************************************/package org.sakaiproject.metaobj.shared.model;
021:
022: /**
023: * @author rpembry
024: * <p/>
025: * <p/>
026: * Based roughly on javax.activation.MimeType, which is
027: * "A Multipurpose Internet Mail Extension (MIME) type, as defined in RFC 2045 and 2046."
028: */
029: public class MimeType {
030:
031: public final static MimeType MIMETYPE_PDF = new MimeType(
032: "application", "pdf");
033:
034: private String primaryType;
035: private String subType;
036:
037: public MimeType() {
038: ;
039: }
040:
041: public MimeType(String rawdata) {
042: setValue(rawdata);
043: }
044:
045: public MimeType(String primaryType, String subType) {
046: this .primaryType = primaryType;
047: this .subType = subType;
048: }
049:
050: public void setValue(String value) {
051: String[] parts = value.split("/");
052: this .primaryType = parts[0];
053: if (parts.length > 1) {
054: this .subType = parts[1];
055: }
056: }
057:
058: /**
059: * @return Returns the primaryType.
060: */
061: public String getPrimaryType() {
062: return primaryType;
063: }
064:
065: /**
066: * @param primaryType The primaryType to set.
067: */
068: public void setPrimaryType(String primaryType) {
069: this .primaryType = primaryType;
070: }
071:
072: /**
073: * @return Returns the subType.
074: */
075: public String getSubType() {
076: return subType;
077: }
078:
079: /**
080: * @param subType The subType to set.
081: */
082: public void setSubType(String subType) {
083: this .subType = subType;
084: }
085:
086: public String getDescription() {
087: return getValue();
088: }
089:
090: /* (non-Javadoc)
091: * @see java.lang.Object#equals(java.lang.Object)
092: */
093: public boolean equals(Object o) {
094: if (this == o) {
095: return true;
096: }
097: if (!(o instanceof MimeType)) {
098: return false;
099: }
100:
101: final MimeType mimeType = (MimeType) o;
102:
103: if (primaryType != null ? !primaryType
104: .equals(mimeType.primaryType)
105: : mimeType.primaryType != null) {
106: return false;
107: }
108: if (subType != null ? !subType.equals(mimeType.subType)
109: : mimeType.subType != null) {
110: return false;
111: }
112:
113: return true;
114: }
115:
116: /* (non-Javadoc)
117: * @see java.lang.Object#hashCode()
118: */
119: public int hashCode() {
120: return this .getValue().hashCode();
121: }
122:
123: public String getValue() {
124: return this .primaryType + "/" + this .subType;
125: }
126:
127: /* (non-Javadoc)
128: * @see java.lang.Object#toString()
129: */
130: public String toString() {
131: return this.getValue();
132: }
133: }
|