1 23 package org.infoglue.cms.applications.workflowtool.function; 24 25 import java.util.Locale ; 26 import java.util.Map ; 27 28 import javax.servlet.http.HttpServletRequest ; 29 30 import org.apache.log4j.Logger; 31 import org.infoglue.cms.applications.common.Session; 32 import org.infoglue.cms.applications.workflowtool.util.InfoglueWorkflowBase; 33 import org.infoglue.cms.security.InfoGluePrincipal; 34 35 import com.opensymphony.module.propertyset.PropertySet; 36 import com.opensymphony.workflow.FunctionProvider; 37 import com.opensymphony.workflow.WorkflowException; 38 39 42 public abstract class InfoglueFunction extends InfoglueWorkflowBase implements FunctionProvider 43 { 44 private final static Logger logger = Logger.getLogger(InfoglueFunction.class.getName()); 45 46 49 private static final String REQUEST_PARAMETER = "request"; 50 51 54 public static final String PRINCIPAL_PARAMETER = "principal"; 55 56 59 public static final String LOCALE_PARAMETER = "locale"; 60 61 64 private Locale locale; 65 66 69 private InfoGluePrincipal principal; 70 71 74 public InfoglueFunction() 75 { 76 super(); 77 } 78 79 87 public final void execute(final Map transientVars, final Map args, final PropertySet ps) throws WorkflowException 88 { 89 try 90 { 91 storeContext(transientVars, args, ps); 92 logger.debug(getClass().getName() + ".execute()--------- START"); 93 initialize(); 94 execute(); 95 logger.debug(getClass().getName() + ".execute()--------- STOP"); 96 } 97 catch(Exception e) 98 { 99 throwException(e); 100 } 101 } 102 103 109 protected void initialize() throws WorkflowException 110 { 111 super.initialize(); 112 initializeLocale(); 113 initializePrincipal(); 114 } 115 116 123 private void initializeLocale() throws WorkflowException 124 { 125 if(parameterExists(LOCALE_PARAMETER)) 126 { 127 locale = (Locale ) getParameter(LOCALE_PARAMETER); 128 } 129 else 130 { 131 locale = getSession().getLocale(); 132 } 133 } 134 135 142 private void initializePrincipal() throws WorkflowException 143 { 144 if(parameterExists(PRINCIPAL_PARAMETER)) 145 { 146 principal = (InfoGluePrincipal) getParameter(PRINCIPAL_PARAMETER); 147 } 148 else 149 { 150 principal = getSession().getInfoGluePrincipal(); 151 } 152 } 153 154 157 private Session getSession() throws WorkflowException 158 { 159 return new Session(((HttpServletRequest ) getParameter(REQUEST_PARAMETER)).getSession()); 160 } 161 162 167 protected abstract void execute() throws WorkflowException; 168 169 172 protected final String getRequestParameter(final String key) 173 { 174 Object value = getParameters().get(key); 175 if(value != null && value.getClass().isArray()) 176 { 177 final String [] values = (String []) value; 178 value = (values.length == 1) ? values[0] : null; 179 } 180 return (value == null) ? null : value.toString(); 181 } 182 183 184 189 protected final Locale getLocale() throws WorkflowException 190 { 191 return locale; 192 } 193 194 199 protected final InfoGluePrincipal getPrincipal() 200 { 201 return principal; 202 } 203 204 209 protected final void setFunctionStatus(final String status) 210 { 211 logger.debug("setFunctionStatus(" + status + ")"); 212 getPropertySet().setString(FUNCTION_STATUS_PROPERTYSET_KEY, status); 213 } 214 } 215 | Popular Tags |