1 package com.openedit.users.filesystem; 2 3 import java.io.File ; 4 import java.io.IOException ; 5 import java.io.InputStreamReader ; 6 import java.io.Reader ; 7 import java.net.URL ; 8 import java.util.ArrayList ; 9 import java.util.Enumeration ; 10 import java.util.Iterator ; 11 import java.util.List ; 12 13 import com.openedit.OpenEditException; 14 import com.openedit.OpenEditRuntimeException; 15 import com.openedit.config.Configuration; 16 import com.openedit.config.XMLConfiguration; 17 import com.openedit.page.Page; 18 import com.openedit.page.manage.PageManager; 19 import com.openedit.users.Permission; 20 import com.openedit.util.XmlUtil; 21 22 public class PermissionsManager 23 { 24 protected List fieldSystemPermissionGroups; 25 protected PermissionGroup fieldUserPermissionGroup; 26 protected long fieldLastEditTime; 27 protected PageManager fieldPageManager; 28 protected File fieldRootDir; 29 30 public PermissionsManager() 31 { 32 } 33 34 35 public void addSystemPermissions(Reader inReader) 36 { 37 PermissionGroup group = loadPermissions(inReader); 38 getSystemPermissionGroups().add(group); 39 } 40 41 protected PermissionGroup loadPermissions(Reader inReader) 42 { 43 List permissions = new ArrayList (); 44 XMLConfiguration userManagerConfig = new XMLConfiguration(); 45 userManagerConfig.populate(new XmlUtil().getXml(inReader,"UTF-8")); 46 47 PermissionGroup pgroup = new PermissionGroup(); 48 String name = userManagerConfig.getAttribute("name"); 49 pgroup.setName(name); 50 51 permissions = new ArrayList ( ); 52 53 for (Iterator iter = userManagerConfig.getChildren("permission").iterator(); iter.hasNext();) 54 { 55 Configuration permissionElem = (Configuration)iter.next(); 56 57 String desc = permissionElem.getAttribute("description"); 58 if ( desc == null) 59 { 60 desc = permissionElem.getValue(); 61 } 62 permissions.add( new Permission(permissionElem.getAttribute("id"),desc)); 63 } 64 pgroup.setPermissions(permissions); 65 return pgroup; 66 } 67 68 public PermissionGroup loadPermissions(Page inPage) throws OpenEditException 69 { 70 if( !inPage.exists()) 71 { 72 return new PermissionGroup(); 73 } 74 return loadPermissions(inPage.getReader()); 75 } 76 77 public List getSystemPermissionGroups() 78 { 79 if (fieldSystemPermissionGroups == null) 80 { 81 fieldSystemPermissionGroups = new ArrayList (); 82 } 83 return fieldSystemPermissionGroups; 84 } 85 86 public void setSystemPermissionGroups(List inSystemPermissions) 87 { 88 fieldSystemPermissionGroups = inSystemPermissions; 89 } 90 91 public List getSystemPermissions() 92 { 93 List permissions = new ArrayList (); 94 for (Iterator iter = getSystemPermissionGroups().iterator(); iter.hasNext();) 95 { 96 PermissionGroup group = (PermissionGroup) iter.next(); 97 permissions.addAll(group.getPermissions()); 98 } 99 return permissions; 100 } 101 102 public PageManager getPageManager() 103 { 104 return fieldPageManager; 105 } 106 107 public void setPageManager(PageManager inPageManager) 108 { 109 fieldPageManager = inPageManager; 110 } 111 112 public void loadPermissions() 113 { 114 try 115 { 116 117 129 try 130 { 131 Enumeration pluginDefs = getClass().getClassLoader().getResources( "permissions.xml" ); 132 while( pluginDefs.hasMoreElements() ) 133 { 134 URL url = (URL ) pluginDefs.nextElement(); 135 addSystemPermissions( new InputStreamReader (url.openStream() ) ); 136 } 137 } catch ( IOException ex) 138 { 139 throw new OpenEditRuntimeException(ex); 140 } 141 142 143 } 144 catch ( Exception ex) 145 { 146 throw new OpenEditRuntimeException(ex); 147 } 148 } 149 163 public File getRootDir() 164 { 165 return fieldRootDir; 166 } 167 168 public void setRootDir(File inRootDir) 169 { 170 fieldRootDir = inRootDir; 171 } 172 173 } 174 | Popular Tags |