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.om.portlet.impl;
018:
019: import java.io.Serializable;
020: import java.util.ArrayList;
021: import java.util.Collection;
022: import java.util.Iterator;
023:
024: import javax.portlet.PortletMode;
025:
026: import org.apache.jetspeed.om.common.portlet.ContentTypeSetComposite;
027: import org.apache.pluto.om.portlet.ContentType;
028:
029: /**
030: * @author <a href="mailto:weaver@apache.org">Scott T. Weaver</a>
031: */
032: public class ContentTypeSetImpl implements ContentTypeSetComposite,
033: Serializable {
034:
035: protected Collection innerCollection;
036:
037: public ContentTypeSetImpl() {
038: innerCollection = new ArrayList();
039: }
040:
041: public ContentTypeSetImpl(Collection collection) {
042: innerCollection = collection;
043: }
044:
045: public boolean supportsPortletMode(PortletMode mode) {
046: // Always support "VIEW". Some portlet vendors do not indicate view
047: // in the deployment descriptor.
048: if (mode.equals(PortletMode.VIEW)) {
049: return true;
050: }
051:
052: Iterator itr = innerCollection.iterator();
053: while (itr.hasNext()) {
054: ContentType p = (ContentType) itr.next();
055: if (p.supportsPortletMode(mode)) {
056: return true;
057: }
058: }
059:
060: return false;
061: }
062:
063: /**
064: * @see org.apache.pluto.om.portlet.ContentTypeSet#get(java.lang.String)
065: */
066: public ContentType get(String contentType) {
067: Iterator itr = innerCollection.iterator();
068: while (itr.hasNext()) {
069: ContentType p = (ContentType) itr.next();
070: if (p.getContentType().equals(contentType)) {
071: return p;
072: }
073: }
074:
075: return null;
076: }
077:
078: /**
079: * @see java.util.Collection#add(java.lang.Object)
080: */
081: public boolean add(Object o) {
082: ContentType cType = (ContentType) o;
083:
084: return innerCollection.add(cType);
085: }
086:
087: /**
088: * @see java.util.Collection#remove(java.lang.Object)
089: */
090: public boolean remove(Object o) {
091: ContentType cType = (ContentType) o;
092:
093: return innerCollection.remove(cType);
094: }
095:
096: /**
097: * @see org.apache.jetspeed.om.common.portlet.ContentTypeSetComposite#addContentType(org.apache.pluto.om.portlet.ContentType)
098: */
099: public void addContentType(ContentType contentType) {
100: add(contentType);
101: }
102:
103: /**
104: * @see org.apache.pluto.om.portlet.ContentTypeSet#iterator()
105: */
106: public Iterator iterator() {
107: return innerCollection.iterator();
108: }
109:
110: /**
111: * @return
112: */
113: public Collection getInnerCollection() {
114: return innerCollection;
115: }
116:
117: /**
118: * @param collection
119: */
120: public void setInnerCollection(Collection collection) {
121: innerCollection = collection;
122: }
123:
124: }
|