1 4 package com.openedit.modules; 5 6 import java.io.File ; 7 import java.util.ArrayList ; 8 import java.util.Iterator ; 9 import java.util.List ; 10 11 import org.springframework.beans.factory.BeanFactory; 12 import org.springframework.beans.factory.BeanFactoryAware; 13 14 import com.openedit.ModuleManager; 15 import com.openedit.Secured; 16 import com.openedit.WebPageRequest; 17 import com.openedit.page.PageAction; 18 import com.openedit.page.manage.PageManager; 19 import com.openedit.users.User; 20 import com.openedit.users.UserManager; 21 22 25 public abstract class BaseModule implements BeanFactoryAware, Secured 26 { 27 protected BeanFactory fieldBeanFactory; 28 protected List fieldPermissions; 29 protected List fieldRestrictedMethods; 30 31 public PageManager getPageManager() 32 { 33 return (PageManager)getBeanFactory().getBean( "pageManager" ); 34 } 35 36 public UserManager getUserManager() 37 { 38 return (UserManager)getBeanFactory().getBean( "userManager" ); 39 } 40 41 public BeanFactory getBeanFactory() 42 { 43 return fieldBeanFactory; 44 } 45 public void setBeanFactory( BeanFactory beanFactory ) 46 { 47 fieldBeanFactory = beanFactory; 48 } 49 50 public ModuleManager getModuleManager() 51 { 52 return (ModuleManager) getBeanFactory().getBean( "moduleManager" ); 53 } 54 public BaseModule getModule(String inName) 55 { 56 return getModuleManager().getModule( inName ); 57 } 58 59 public File getRoot() 60 { 61 return (File ) getBeanFactory().getBean( "root" ); 62 } 63 64 67 public void shutdown() 68 { 69 } 70 71 public List getPermissions() 72 { 73 return fieldPermissions; 74 } 75 76 public void setPermissions(List inPermissions) 77 { 78 fieldPermissions = inPermissions; 79 } 80 81 public void setPermission(String inPermission) 82 { 83 fieldPermissions = new ArrayList (); 84 fieldPermissions.add(inPermission); 85 } 86 87 public void setRestrictedMethods(List inMethods) 88 { 89 fieldRestrictedMethods = inMethods; 90 } 91 92 public boolean canRun(WebPageRequest inReq, String inMethodName) 93 { 94 if (fieldPermissions == null) 95 { 96 return true; 97 } 98 99 if (getRestrictedMethods() == null || getRestrictedMethods().contains(inMethodName)) 100 { 101 User user = inReq.getUser(); 102 if (user == null) 103 { 104 return false; 105 } 106 107 for (Iterator iter = getPermissions().iterator(); iter.hasNext();) 108 { 109 String permission = (String ) iter.next(); 110 if (!user.hasPermission(permission)) 111 { 112 return false; 113 } 114 } 115 } 116 117 return true; 118 } 119 120 public List getRestrictedMethods() 121 { 122 return fieldRestrictedMethods; 123 } 124 125 protected String findValue(String inName, WebPageRequest inRequest) 126 { 127 String name = null; 128 PageAction inAction = inRequest.getCurrentAction(); 129 if( inAction != null && inAction.getConfig() != null) 130 { 131 name = inAction.getConfig().getChildValue( inName ); 132 } 133 if( name == null) 134 { 135 name = inRequest.getPage().get(inName); 136 } 137 if( name == null) 138 { 139 name = inRequest.getRequestParameter(inName); 140 } 141 name = inRequest.getPage().getPageSettings().replaceProperty(name); 142 return name; 143 } 144 } 145
| Popular Tags
|