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<String, Filter>(); 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 private static final long serialVersionUID = 1L; 071 072 @Override 073 public boolean accept(DocumentModel doc) { 074 return !doc.isImmutable() && !doc.isProxy(); 075 } 076 } 077 078 static class LinkDocFilter implements Filter { 079 private static final long serialVersionUID = 1L; 080 081 @Override 082 public boolean accept(DocumentModel doc) { 083 return !doc.isImmutable() && doc.isProxy(); 084 } 085 } 086 087 static class PublishedDocFilter implements Filter { 088 private static final long serialVersionUID = 1L; 089 090 @Override 091 public boolean accept(DocumentModel doc) { 092 return doc.isImmutable() && doc.isProxy(); 093 } 094 } 095 096 static class ProxyDocFilter implements Filter { 097 private static final long serialVersionUID = 1L; 098 099 @Override 100 public boolean accept(DocumentModel doc) { 101 return doc.isProxy(); 102 } 103 } 104 105 static class VersionDocFilter implements Filter { 106 private static final long serialVersionUID = 1L; 107 108 @Override 109 public boolean accept(DocumentModel doc) { 110 return doc.isVersion(); 111 } 112 } 113 114 static class ImmutableDocFilter implements Filter { 115 private static final long serialVersionUID = 1L; 116 117 @Override 118 public boolean accept(DocumentModel doc) { 119 return doc.isImmutable(); 120 } 121 } 122 123 static class MutableDocFilter implements Filter { 124 private static final long serialVersionUID = 1L; 125 126 @Override 127 public boolean accept(DocumentModel doc) { 128 return !doc.isImmutable(); 129 } 130 } 131 132}