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 * bstefanescu 018 */ 019package org.nuxeo.ecm.automation.core.events; 020 021import java.util.HashMap; 022import java.util.Map; 023 024import org.nuxeo.ecm.core.api.DocumentModel; 025import org.nuxeo.ecm.core.api.Filter; 026 027/** 028 * Create filters that are able to filter documents on their attribute (Regular Doc, Published Doc, Version, Link, 029 * Proxy, Immutable, Mutable) 030 * 031 * @author <a href="mailto:bs@nuxeo.com">Bogdan Stefanescu</a> 032 */ 033public class DocumentAttributeFilterFactory { 034 035 private DocumentAttributeFilterFactory() { 036 } 037 038 public static final String ANY_DOC = "Any"; 039 040 public static final String REGULAR_DOC = "Regular Document"; 041 042 public static final String LINK_DOC = "Document Link"; 043 044 public static final String PUBLISHED_DOC = "Published Document"; 045 046 public static final String PROXY_DOC = "Document Proxy"; 047 048 public static final String VERSION_DOC = "Document Version"; 049 050 public static final String IMMUTABLE_DOC = "Immutable Document"; 051 052 public static final String MUTABLE_DOC = "Mutable Document"; 053 054 protected static final Map<String, Filter> filters = new HashMap<>(); 055 static { 056 filters.put(REGULAR_DOC, new RegularDocFilter()); 057 filters.put(LINK_DOC, new LinkDocFilter()); 058 filters.put(PUBLISHED_DOC, new PublishedDocFilter()); 059 filters.put(PROXY_DOC, new ProxyDocFilter()); 060 filters.put(VERSION_DOC, new VersionDocFilter()); 061 filters.put(IMMUTABLE_DOC, new ImmutableDocFilter()); 062 filters.put(MUTABLE_DOC, new MutableDocFilter()); 063 } 064 065 public static Filter getFilter(String attr) { 066 return filters.get(attr); 067 } 068 069 static class RegularDocFilter implements Filter { 070 @Override 071 public boolean accept(DocumentModel doc) { 072 return !doc.isImmutable() && !doc.isProxy(); 073 } 074 } 075 076 static class LinkDocFilter implements Filter { 077 @Override 078 public boolean accept(DocumentModel doc) { 079 return !doc.isImmutable() && doc.isProxy(); 080 } 081 } 082 083 static class PublishedDocFilter implements Filter { 084 @Override 085 public boolean accept(DocumentModel doc) { 086 return doc.isImmutable() && doc.isProxy(); 087 } 088 } 089 090 static class ProxyDocFilter implements Filter { 091 @Override 092 public boolean accept(DocumentModel doc) { 093 return doc.isProxy(); 094 } 095 } 096 097 static class VersionDocFilter implements Filter { 098 @Override 099 public boolean accept(DocumentModel doc) { 100 return doc.isVersion(); 101 } 102 } 103 104 static class ImmutableDocFilter implements Filter { 105 @Override 106 public boolean accept(DocumentModel doc) { 107 return doc.isImmutable(); 108 } 109 } 110 111 static class MutableDocFilter implements Filter { 112 @Override 113 public boolean accept(DocumentModel doc) { 114 return !doc.isImmutable(); 115 } 116 } 117 118}