001: /**********************************************************************************
002: * $URL: https://source.sakaiproject.org/svn/osp/tags/sakai_2-4-1/common/tool-lib/src/java/org/theospi/portfolio/shared/tool/BaseFormResourceFilter.java $
003: * $Id: BaseFormResourceFilter.java 22558 2007-03-13 19:16:50Z jimeng@umich.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.shared.tool;
021:
022: import java.util.ArrayList;
023: import java.util.List;
024: import java.util.Vector;
025:
026: import org.sakaiproject.content.api.ContentResource;
027: import org.sakaiproject.content.api.ContentResourceFilter;
028: import org.sakaiproject.content.api.ResourceToolAction;
029: import org.sakaiproject.content.api.ResourceType;
030: import org.sakaiproject.entity.api.ResourceProperties;
031:
032: /**
033: * This class implements the typical form type filter.
034: * This will be a registered bean with the component manager that
035: * application components can extend to control the list of forms.
036: */
037: public class BaseFormResourceFilter implements ContentResourceFilter {
038:
039: private boolean viewAll = true;
040: private List formTypes = new ArrayList();
041:
042: public boolean allowSelect(ContentResource resource) {
043: String formType = resource.getProperties().getProperty(
044: ResourceProperties.PROP_STRUCTOBJ_TYPE);
045:
046: if (getFormTypes().contains(formType)) {
047: return true;
048: } else {
049: return false;
050: }
051: }
052:
053: public boolean allowView(ContentResource contentResource) {
054: if (isViewAll()) {
055: return true;
056: }
057:
058: return allowSelect(contentResource);
059: }
060:
061: public List getFormTypes() {
062: return formTypes;
063: }
064:
065: /**
066: * The list of form types to allow. The passed in content resource
067: * will be tested to see if the resouce's type is included in the
068: * list.
069: * @param formTypes
070: */
071: public void setFormTypes(List formTypes) {
072: this .formTypes = formTypes;
073: }
074:
075: public boolean isViewAll() {
076: return viewAll;
077: }
078:
079: /**
080: * boolean to indicate if all resources should be viewable.
081: *
082: * If this is false, then the viewable resources will be based on the
083: * mime types and extention set in the other properties.
084: * @param viewAll
085: */
086: public void setViewAll(boolean viewAll) {
087: this .viewAll = viewAll;
088: }
089:
090: /* (non-Javadoc)
091: * @see org.sakaiproject.content.api.ContentResourceFilter#filterAllowedActions(java.util.List)
092: */
093: public List<ResourceToolAction> filterAllowedActions(
094: List<ResourceToolAction> actions) {
095: List<ResourceToolAction> allowed = new Vector<ResourceToolAction>();
096: for (ResourceToolAction action : actions) {
097: if (ResourceType.TYPE_METAOBJ.equals(action.getTypeId())) {
098: allowed.add(action);
099: }
100: }
101: return allowed;
102: }
103: }
|