1 17 package org.alfresco.repo.security.permissions.impl.model; 18 19 import java.util.Collections ; 20 import java.util.HashSet ; 21 import java.util.Iterator ; 22 import java.util.Set ; 23 24 import org.alfresco.service.namespace.NamespacePrefixResolver; 25 import org.alfresco.service.namespace.QName; 26 import org.dom4j.Attribute; 27 import org.dom4j.Element; 28 29 33 public class PermissionSet implements XMLModelInitialisable 34 { 35 private static final String TYPE = "type"; 36 private static final String PERMISSION_GROUP = "permissionGroup"; 37 private static final String PERMISSION = "permission"; 38 private static final String EXPOSE = "expose"; 39 private static final String EXPOSE_ALL = "all"; 40 42 43 private QName qname; 44 45 private boolean exposeAll; 46 47 private Set <PermissionGroup> permissionGroups = new HashSet <PermissionGroup>(); 48 49 private Set <Permission> permissions = new HashSet <Permission>(); 50 51 public PermissionSet() 52 { 53 super(); 54 } 55 56 public void initialise(Element element, NamespacePrefixResolver nspr, PermissionModel permissionModel) 57 { 58 qname = QName.createQName(element.attributeValue(TYPE), nspr); 59 60 Attribute exposeAttribute = element.attribute(EXPOSE); 61 if(exposeAttribute != null) 62 { 63 exposeAll = exposeAttribute.getStringValue().equalsIgnoreCase(EXPOSE_ALL); 64 } 65 else 66 { 67 exposeAll = true; 68 } 69 70 for(Iterator pgit = element.elementIterator(PERMISSION_GROUP); pgit.hasNext(); ) 71 { 72 Element permissionGroupElement = (Element)pgit.next(); 73 PermissionGroup permissionGroup = new PermissionGroup(qname); 74 permissionGroup.initialise(permissionGroupElement, nspr, permissionModel); 75 permissionGroups.add(permissionGroup); 76 } 77 78 for(Iterator pit = element.elementIterator(PERMISSION); pit.hasNext(); ) 79 { 80 Element permissionElement = (Element)pit.next(); 81 Permission permission = new Permission(qname); 82 permission.initialise(permissionElement, nspr, permissionModel); 83 permissions.add(permission); 84 } 85 86 } 87 88 public Set <PermissionGroup> getPermissionGroups() 89 { 90 return Collections.unmodifiableSet(permissionGroups); 91 } 92 93 public Set <Permission> getPermissions() 94 { 95 return Collections.unmodifiableSet(permissions); 96 } 97 98 public QName getQName() 99 { 100 return qname; 101 } 102 103 public boolean exposeAll() 104 { 105 return exposeAll; 106 } 107 108 109 110 } 111 | Popular Tags |