001/* 002 * (C) Copyright 2006-2011 Nuxeo SA (http://nuxeo.com/) and others. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 * 016 * Contributors: 017 * <a href="mailto:at@nuxeo.com">Anahide Tchertchian</a> 018 * 019 * $Id$ 020 */ 021 022package org.nuxeo.ecm.core.api.tree; 023 024import java.util.List; 025 026import org.nuxeo.ecm.core.api.DocumentModel; 027import org.nuxeo.ecm.core.api.LifeCycleConstants; 028 029/** 030 * Default filter for tree elements. 031 * <p> 032 * Filters using facets and types criteria. Also filters documents that are in the "deleted" life cycle state. 033 * 034 * @author Anahide Tchertchian 035 */ 036public class DefaultDocumentTreeFilter implements DocumentTreeFilter { 037 038 private static final long serialVersionUID = 1L; 039 040 protected List<String> includedFacets; 041 042 protected List<String> excludedFacets; 043 044 protected List<String> excludedTypes; 045 046 @Override 047 public boolean accept(DocumentModel document) { 048 String docType = document.getType(); 049 if (excludedTypes != null && excludedTypes.contains(docType)) { 050 return false; 051 } 052 // exclude deleted documents from tree 053 if (LifeCycleConstants.DELETED_STATE.equals(document.getCurrentLifeCycleState())) { 054 return false; 055 } 056 // XXX AT: this could have not been copied from FacetFilter if fields 057 // were not private there. 058 if (excludedFacets != null) { 059 for (String exc : excludedFacets) { 060 if (document.hasFacet(exc)) { 061 return false; 062 } 063 } 064 } 065 if (includedFacets != null) { 066 for (String req : includedFacets) { 067 if (!document.hasFacet(req)) { 068 return false; 069 } 070 } 071 } 072 return true; 073 } 074 075 @Override 076 public List<String> getIncludedFacets() { 077 return includedFacets; 078 } 079 080 @Override 081 public void setIncludedFacets(List<String> includedFacets) { 082 this.includedFacets = includedFacets; 083 } 084 085 @Override 086 public List<String> getExcludedFacets() { 087 return excludedFacets; 088 } 089 090 @Override 091 public void setExcludedFacets(List<String> excludedFacets) { 092 this.excludedFacets = excludedFacets; 093 } 094 095 @Override 096 public List<String> getExcludedTypes() { 097 return excludedTypes; 098 } 099 100 @Override 101 public void setExcludedTypes(List<String> excludedTypes) { 102 this.excludedTypes = excludedTypes; 103 } 104 105}