1 17 package org.alfresco.repo.policy; 18 19 import java.util.ArrayList ; 20 import java.util.HashMap ; 21 import java.util.List ; 22 import java.util.Map ; 23 24 import org.alfresco.service.cmr.dictionary.DictionaryService; 25 import org.alfresco.service.cmr.repository.NodeRef; 26 import org.alfresco.service.namespace.QName; 27 28 33 public class BehaviourFilterImpl implements BehaviourFilter 34 { 35 ThreadLocal <List <QName>> classFilter = new ThreadLocal <List <QName>>(); 37 ThreadLocal <Map <NodeRef,List <QName>>> nodeRefFilter = new ThreadLocal <Map <NodeRef,List <QName>>>(); 38 39 private DictionaryService dictionaryService; 41 42 45 public void setDictionaryService(DictionaryService dictionaryService) 46 { 47 this.dictionaryService = dictionaryService; 48 } 49 50 53 public boolean disableBehaviour(QName className) 54 { 55 List <QName> classNames = classFilter.get(); 56 if (classNames == null) 57 { 58 classNames = new ArrayList <QName>(); 59 classFilter.set(classNames); 60 } 61 boolean alreadyDisabled = classNames.contains(className); 62 if (!alreadyDisabled) 63 { 64 classNames.add(className); 65 } 66 return alreadyDisabled; 67 } 68 69 72 public boolean disableBehaviour(NodeRef nodeRef, QName className) 73 { 74 Map <NodeRef,List <QName>> filters = nodeRefFilter.get(); 75 if (filters == null) 76 { 77 filters = new HashMap <NodeRef,List <QName>>(); 78 nodeRefFilter.set(filters); 79 } 80 List <QName> classNames = filters.get(nodeRef); 81 if (classNames == null) 82 { 83 classNames = new ArrayList <QName>(); 84 filters.put(nodeRef, classNames); 85 } 86 boolean alreadyDisabled = classNames.contains(className); 87 if (!alreadyDisabled) 88 { 89 classNames.add(className); 90 } 91 return alreadyDisabled; 92 } 93 94 97 public void enableBehaviour(QName className) 98 { 99 List <QName> classNames = classFilter.get(); 100 if (classNames != null) 101 { 102 classNames.remove(className); 103 } 104 } 105 106 109 public void enableBehaviour(NodeRef nodeRef, QName className) 110 { 111 Map <NodeRef,List <QName>> filters = nodeRefFilter.get(); 112 if (filters != null) 113 { 114 List <QName> classNames = filters.get(nodeRef); 115 if (classNames != null) 116 { 117 classNames.remove(className); 118 } 119 if (classNames.size() == 0) 120 { 121 filters.remove(nodeRef); 122 } 123 } 124 } 125 126 129 public void enableBehaviours(NodeRef nodeRef) 130 { 131 Map <NodeRef,List <QName>> filters = nodeRefFilter.get(); 132 if (filters != null) 133 { 134 filters.remove(nodeRef); 135 } 136 } 137 138 141 public void enableAllBehaviours() 142 { 143 Map <NodeRef,List <QName>> filters = nodeRefFilter.get(); 144 if (filters != null) 145 { 146 filters.clear(); 147 } 148 } 149 150 153 public boolean isEnabled(NodeRef nodeRef, QName className) 154 { 155 if (!isEnabled(className)) 157 { 158 return false; 159 } 160 161 Map <NodeRef,List <QName>> nodeFilters = nodeRefFilter.get(); 163 if (nodeFilters != null) 164 { 165 List <QName> nodeClassFilters = nodeFilters.get(nodeRef); 166 if (nodeClassFilters != null) 167 { 168 boolean filtered = nodeClassFilters.contains(className); 169 if (filtered) 170 { 171 return false; 172 } 173 for (QName filterName : nodeClassFilters) 174 { 175 filtered = dictionaryService.isSubClass(className, filterName); 176 if (filtered) 177 { 178 return false; 179 } 180 } 181 } 182 } 183 184 return true; 185 } 186 187 190 public boolean isEnabled(QName className) 191 { 192 List <QName> classFilters = classFilter.get(); 194 if (classFilters != null) 195 { 196 boolean filtered = classFilters.contains(className); 197 if (filtered) 198 { 199 return false; 200 } 201 for (QName filterName : classFilters) 202 { 203 filtered = dictionaryService.isSubClass(className, filterName); 204 if (filtered) 205 { 206 return false; 207 } 208 } 209 } 210 211 return true; 212 } 213 214 217 public boolean isActivated() 218 { 219 List <QName> classFilters = classFilter.get(); 220 Map <NodeRef,List <QName>> nodeFilters = nodeRefFilter.get(); 221 return (classFilters != null && !classFilters.isEmpty()) || (nodeFilters != null && !nodeFilters.isEmpty()); 222 } 223 224 } 225 | Popular Tags |