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.repo.security.permissions.PermissionReference; 25 import org.alfresco.repo.security.permissions.impl.AbstractPermissionReference; 26 import org.alfresco.repo.security.permissions.impl.PermissionReferenceImpl; 27 import org.alfresco.service.namespace.NamespacePrefixResolver; 28 import org.alfresco.service.namespace.QName; 29 import org.dom4j.Attribute; 30 import org.dom4j.Element; 31 32 37 public class PermissionGroup extends AbstractPermissionReference implements XMLModelInitialisable 38 { 39 41 private static final String NAME = "name"; 42 43 private static final String EXTENDS = "extends"; 44 45 private static final String ALLOW_FULL_CONTOL = "allowFullControl"; 46 47 private static final String INCLUDE_PERMISSION_GROUP = "includePermissionGroup"; 48 49 private static final String PERMISSION_GROUP = "permissionGroup"; 50 51 private static final String TYPE = "type"; 52 53 private static final String EXPOSE = "expose"; 54 55 private static final String REQUIRES_TYPE = "requiresType"; 56 57 private String name; 58 59 private QName type; 60 61 private boolean extendz; 62 63 private boolean isExposed; 64 65 private boolean allowFullControl; 66 67 private QName container; 68 69 private Set <PermissionReference> includedPermissionGroups = new HashSet <PermissionReference>(); 70 71 private boolean requiresType; 72 73 public PermissionGroup(QName container) 74 { 75 super(); 76 this.container = container; 77 } 78 79 public void initialise(Element element, NamespacePrefixResolver nspr, PermissionModel permissionModel) 80 { 81 name = element.attributeValue(NAME); 83 Attribute att = element.attribute(ALLOW_FULL_CONTOL); 85 if (att != null) 86 { 87 allowFullControl = Boolean.parseBoolean(att.getStringValue()); 88 } 89 else 90 { 91 allowFullControl = false; 92 } 93 94 att = element.attribute(REQUIRES_TYPE); 95 if (att != null) 96 { 97 requiresType = Boolean.parseBoolean(att.getStringValue()); 98 } 99 else 100 { 101 requiresType = true; 102 } 103 104 att = element.attribute(EXTENDS); 105 if (att != null) 106 { 107 extendz = Boolean.parseBoolean(att.getStringValue()); 108 } 109 else 110 { 111 extendz = false; 112 } 113 114 att = element.attribute(EXPOSE); 115 if (att != null) 116 { 117 isExposed = Boolean.parseBoolean(att.getStringValue()); 118 } 119 else 120 { 121 isExposed = true; 122 } 123 124 att = element.attribute(TYPE); 125 if (att != null) 126 { 127 type = QName.createQName(att.getStringValue(),nspr); 128 } 129 else 130 { 131 type = null; 132 } 133 134 136 for (Iterator ipgit = element.elementIterator(INCLUDE_PERMISSION_GROUP); ipgit.hasNext(); ) 137 { 138 QName qName; 139 Element includePermissionGroupElement = (Element) ipgit.next(); 140 Attribute typeAttribute = includePermissionGroupElement.attribute(TYPE); 141 if (typeAttribute != null) 142 { 143 qName = QName.createQName(typeAttribute.getStringValue(), nspr); 144 } 145 else 146 { 147 qName = container; 148 } 149 String refName = includePermissionGroupElement.attributeValue(PERMISSION_GROUP); 150 PermissionReference permissionReference = new PermissionReferenceImpl(qName, refName); 151 includedPermissionGroups.add(permissionReference); 152 } 153 } 154 155 public Set <PermissionReference> getIncludedPermissionGroups() 156 { 157 return Collections.unmodifiableSet(includedPermissionGroups); 158 } 159 160 public String getName() 161 { 162 return name; 163 } 164 165 public boolean isAllowFullControl() 166 { 167 return allowFullControl; 168 } 169 170 public QName getQName() 171 { 172 return container; 173 } 174 175 public boolean isExtends() 176 { 177 return extendz; 178 } 179 180 public QName getTypeQName() 181 { 182 return type; 183 } 184 185 public boolean isExposed() 186 { 187 return isExposed; 188 } 189 190 191 public boolean isTypeRequired() 192 { 193 return requiresType; 194 } 195 } 196 | Popular Tags |