001/* 002 * (C) Copyright 2006-2018 Nuxeo (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 */ 020 021package org.nuxeo.ecm.core.api.tree; 022 023import java.util.List; 024 025import org.nuxeo.ecm.core.api.DocumentModel; 026 027/** 028 * Default filter for tree elements. 029 * <p> 030 * Filters using facets and types criteria. Also filters documents that are in the trash. 031 * 032 * @author Anahide Tchertchian 033 */ 034public class DefaultDocumentTreeFilter implements DocumentTreeFilter { 035 036 protected List<String> includedFacets; 037 038 protected List<String> excludedFacets; 039 040 protected List<String> excludedTypes; 041 042 @Override 043 public boolean accept(DocumentModel document) { 044 String docType = document.getType(); 045 if (excludedTypes != null && excludedTypes.contains(docType)) { 046 return false; 047 } 048 // exclude trashed documents from tree 049 if (document.isTrashed()) { 050 return false; 051 } 052 // XXX AT: this could have not been copied from FacetFilter if fields 053 // were not private there. 054 if (excludedFacets != null) { 055 for (String exc : excludedFacets) { 056 if (document.hasFacet(exc)) { 057 return false; 058 } 059 } 060 } 061 if (includedFacets != null) { 062 for (String req : includedFacets) { 063 if (!document.hasFacet(req)) { 064 return false; 065 } 066 } 067 } 068 return true; 069 } 070 071 @Override 072 public List<String> getIncludedFacets() { 073 return includedFacets; 074 } 075 076 @Override 077 public void setIncludedFacets(List<String> includedFacets) { 078 this.includedFacets = includedFacets; 079 } 080 081 @Override 082 public List<String> getExcludedFacets() { 083 return excludedFacets; 084 } 085 086 @Override 087 public void setExcludedFacets(List<String> excludedFacets) { 088 this.excludedFacets = excludedFacets; 089 } 090 091 @Override 092 public List<String> getExcludedTypes() { 093 return excludedTypes; 094 } 095 096 @Override 097 public void setExcludedTypes(List<String> excludedTypes) { 098 this.excludedTypes = excludedTypes; 099 } 100 101}