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 private static final long serialVersionUID = 1L; 037 038 protected List<String> includedFacets; 039 040 protected List<String> excludedFacets; 041 042 protected List<String> excludedTypes; 043 044 @Override 045 public boolean accept(DocumentModel document) { 046 String docType = document.getType(); 047 if (excludedTypes != null && excludedTypes.contains(docType)) { 048 return false; 049 } 050 // exclude trashed documents from tree 051 if (document.isTrashed()) { 052 return false; 053 } 054 // XXX AT: this could have not been copied from FacetFilter if fields 055 // were not private there. 056 if (excludedFacets != null) { 057 for (String exc : excludedFacets) { 058 if (document.hasFacet(exc)) { 059 return false; 060 } 061 } 062 } 063 if (includedFacets != null) { 064 for (String req : includedFacets) { 065 if (!document.hasFacet(req)) { 066 return false; 067 } 068 } 069 } 070 return true; 071 } 072 073 @Override 074 public List<String> getIncludedFacets() { 075 return includedFacets; 076 } 077 078 @Override 079 public void setIncludedFacets(List<String> includedFacets) { 080 this.includedFacets = includedFacets; 081 } 082 083 @Override 084 public List<String> getExcludedFacets() { 085 return excludedFacets; 086 } 087 088 @Override 089 public void setExcludedFacets(List<String> excludedFacets) { 090 this.excludedFacets = excludedFacets; 091 } 092 093 @Override 094 public List<String> getExcludedTypes() { 095 return excludedTypes; 096 } 097 098 @Override 099 public void setExcludedTypes(List<String> excludedTypes) { 100 this.excludedTypes = excludedTypes; 101 } 102 103}