001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017: package org.apache.jetspeed.capabilities.impl;
018:
019: import java.util.ArrayList;
020: import java.util.Collection;
021:
022: import org.apache.commons.collections.CollectionUtils;
023: import org.apache.jetspeed.capabilities.Capability;
024: import org.apache.jetspeed.capabilities.MediaType;
025: import org.apache.jetspeed.capabilities.MimeType;
026:
027: /**
028: * Default bean like implementation of MediaTypeEntry interface
029: * suitable for serializing with Castor
030: *
031: * @author <a href="mailto:raphael@apache.org">Rapha\u00ebl Luta</a>
032: * @version $Id: MediaTypeImpl.java 516448 2007-03-09 16:25:47Z ate $
033: */
034: public class MediaTypeImpl implements MediaType {
035: protected String characterSet;
036: private Collection capabilities;
037: private Collection mimetypes;
038: private int mediatypeId;
039: private String title;
040: private String description;
041:
042: private String name; // MediaTypeEntry name
043:
044: public MediaTypeImpl() {
045: }
046:
047: public MediaTypeImpl(long id, String name, int _hidden,
048: String mimeType, String title, String description,
049: String image, String role) {
050: this .mimetypes.add(mimeType);
051: }
052:
053: /**
054: * Implements the equals operation so that 2 elements are equal if
055: * all their member values are equal.
056: */
057: public boolean equals(Object object) {
058: if (this == object)
059: return true;
060: if (object == null)
061: return false;
062:
063: MediaTypeImpl obj = (MediaTypeImpl) object;
064:
065: if (this .name != null) {
066: if (!name.equals(obj.name)) {
067: return false;
068: }
069: } else {
070: if (obj.name != null) {
071: return false;
072: }
073: }
074:
075: if (this .description != null) {
076: if (!description.equals(obj.description)) {
077: return false;
078: }
079: } else {
080: if (obj.description != null) {
081: return false;
082: }
083: }
084:
085: if (characterSet != null) {
086: if (!characterSet.equals(obj.characterSet)) {
087: return false;
088: }
089: } else {
090: if (obj.characterSet != null) {
091: return false;
092: }
093: }
094:
095: if (this .title != null) {
096: if (!title.equals(obj.title)) {
097: return false;
098: }
099: } else {
100: if (obj.title != null) {
101: return false;
102: }
103: }
104:
105: if (mimetypes != null) {
106: if (!CollectionUtils.isEqualCollection(mimetypes,
107: obj.mimetypes)) {
108: return false;
109: }
110: } else {
111: if (obj.mimetypes != null) {
112: return false;
113: }
114: }
115:
116: if (capabilities != null) {
117: if (!(CollectionUtils.isEqualCollection(capabilities,
118: obj.capabilities)))
119: return false;
120: } else {
121: if (obj.capabilities != null) {
122: return false;
123: }
124: }
125:
126: return true;
127: }
128:
129: /** @return the character set associated with this MediaType */
130: public String getCharacterSet() {
131: return this .characterSet;
132: }
133:
134: /** Sets the character set associated with this MediaType */
135: public void setCharacterSet(String charSet) {
136: this .characterSet = charSet;
137: }
138:
139: public Collection getCapabilities() {
140: return this .capabilities;
141: }
142:
143: public void setCapabilities(Collection capabilities) {
144: this .capabilities = capabilities;
145: }
146:
147: public Collection getMimetypes() {
148: return this .mimetypes;
149: }
150:
151: public void setMimetypes(Collection mimetypes) {
152: this .mimetypes = mimetypes;
153: }
154:
155: public void addMimetype(MimeType mimeType) {
156: if (mimetypes == null)
157: mimetypes = new ArrayList();
158: if (!mimetypes.contains(mimeType.getName())) {
159: mimetypes.add(mimeType);
160: }
161: }
162:
163: public void addCapability(Capability capability) {
164: if (capabilities == null)
165: capabilities = new ArrayList();
166: if (!capabilities.contains(capability.getName())) {
167: capabilities.add(capability);
168: }
169: }
170:
171: public void removeMimetype(String name) {
172: mimetypes.remove(name);
173: }
174:
175: /**
176: * Set MediaType ID -- Assigns ID
177: * @param id
178: */
179: public void setMediatypeId(int id) {
180: this .mediatypeId = id;
181: }
182:
183: /**
184: * Get MediaType ID -- Return ID
185: * @return MediaTypeID
186: */
187: public int getMediatypeId() {
188: return this .mediatypeId;
189: }
190:
191: /**
192: * Set name ob MediaTypeEntry
193: */
194: public void setName(String name) {
195: this .name = name;
196: }
197:
198: /**
199: * Get name ob MediaTypeEntry
200: */
201:
202: public String getName() {
203: return this .name;
204: }
205:
206: public String getTitle() {
207: return this .title;
208: }
209:
210: public void setTitle(String title) {
211: this .title = title;
212: }
213:
214: public String getDescription() {
215: return this .description;
216: }
217:
218: public void setDescription(String desc) {
219: this.description = desc;
220: }
221: }
|