001: /**********************************************************************************
002: * $URL:https://source.sakaiproject.org/svn/osp/trunk/presentation/api/src/java/org/theospi/portfolio/presentation/model/PresentationItemDefinition.java $
003: * $Id:PresentationItemDefinition.java 9134 2006-05-08 20:28:42Z chmaurer@iupui.edu $
004: ***********************************************************************************
005: *
006: * Copyright (c) 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.theospi.portfolio.presentation.model;
021:
022: import org.sakaiproject.metaobj.shared.model.IdentifiableObject;
023: import org.sakaiproject.metaobj.shared.model.MimeType;
024: import org.theospi.portfolio.shared.model.ItemDefinitionMimeType;
025:
026: import java.io.Serializable;
027: import java.util.HashSet;
028: import java.util.Iterator;
029: import java.util.Set;
030:
031: public class PresentationItemDefinition extends IdentifiableObject
032: implements Serializable {
033: private PresentationTemplate presentationTemplate;
034: /**
035: * the artifact type
036: */
037: private String type;
038: private String name;
039: private String title;
040: private String description;
041: private boolean allowMultiple;
042: private Set mimeTypes = new HashSet();
043: private String externalType = null;
044: private int sequence = -1;
045: private transient String action;
046: private transient Integer newSequence = null;
047:
048: static final long serialVersionUID = -6220810277272518156l;
049:
050: public boolean getHasMimeTypes() {
051: return (type != null && type.equals("fileArtifact"));
052: }
053:
054: public PresentationTemplate getPresentationTemplate() {
055: return presentationTemplate;
056: }
057:
058: public String getAction() {
059: return action;
060: }
061:
062: public void setAction(String action) {
063: this .action = action;
064: }
065:
066: public String getType() {
067: return type;
068: }
069:
070: public String getName() {
071: return name;
072: }
073:
074: public String getTitle() {
075: return title;
076: }
077:
078: public String getDescription() {
079: return description;
080: }
081:
082: public boolean getAllowMultiple() {
083: return isAllowMultiple();
084: }
085:
086: public void setType(String type) {
087: this .type = type;
088: }
089:
090: public void setName(String name) {
091: this .name = name;
092: }
093:
094: public void setTitle(String title) {
095: this .title = title;
096: }
097:
098: public void setDescription(String description) {
099: this .description = description;
100: }
101:
102: public boolean isAllowMultiple() {
103: return allowMultiple;
104: }
105:
106: public void setAllowMultiple(boolean allowMultiple) {
107: this .allowMultiple = allowMultiple;
108: }
109:
110: public void setPresentationTemplate(
111: PresentationTemplate presentationTemplate) {
112: this .presentationTemplate = presentationTemplate;
113: }
114:
115: public Set getMimeTypes() {
116: return mimeTypes;
117: }
118:
119: public void setMimeTypes(Set mimeTypes) {
120: this .mimeTypes = mimeTypes;
121: }
122:
123: public String getExternalType() {
124: return externalType;
125: }
126:
127: public void setExternalType(String externalType) {
128: this .externalType = externalType;
129: }
130:
131: public int hashCode() {
132: if (getId() != null) {
133: return getId().hashCode();
134: }
135: return (type != null && name != null) ? (type + name)
136: .hashCode() : 0;
137: }
138:
139: public boolean allowsMimeType(MimeType mimeType) {
140: if (!getHasMimeTypes()) {
141: return true;
142: }
143:
144: if (getMimeTypes() == null || getMimeTypes().isEmpty()) {
145: return true;
146: }
147:
148: for (Iterator i = getMimeTypes().iterator(); i.hasNext();) {
149: ItemDefinitionMimeType currentType = (ItemDefinitionMimeType) i
150: .next();
151:
152: if (currentType.getSecondary() != null) {
153: if (mimeType.getSubType().equals(
154: currentType.getSecondary())
155: && mimeType.getPrimaryType().equals(
156: currentType.getPrimary())) {
157: return true;
158: }
159: } else {
160: if (mimeType.getPrimaryType().equals(
161: currentType.getPrimary())) {
162: return true;
163: }
164: }
165: }
166:
167: return false;
168: }
169:
170: public int getSequence() {
171: return sequence;
172: }
173:
174: public void setSequence(int sequence) {
175: this .sequence = sequence;
176: newSequence = null;
177: }
178:
179: public int getNewSequence() {
180: if (newSequence == null) {
181: return sequence;
182: }
183: return newSequence.intValue();
184: }
185:
186: public void setNewSequence(int newSequence) {
187: this .newSequence = new Integer(newSequence);
188: }
189: }
|