1 15 19 package org.jahia.engines; 20 21 import java.lang.reflect.InvocationTargetException ; 22 import java.lang.reflect.Method ; 23 import java.util.ArrayList ; 24 import java.util.HashMap ; 25 26 import org.jahia.data.fields.FieldTypes; 27 import org.jahia.data.fields.JahiaField; 28 import org.jahia.engines.audit.ManageLogs_Engine; 29 import org.jahia.engines.shared.Undefined_Field; 30 import org.jahia.exceptions.JahiaException; 31 import org.jahia.exceptions.JahiaUpdateLockException; 32 import org.jahia.params.ParamBean; 33 import org.jahia.registries.ServicesRegistry; 34 import org.jahia.services.audit.JahiaAuditLogManagerService; 35 import org.jahia.utils.JahiaObjectTool; 36 37 38 public class EngineToolBox { 39 40 private static EngineToolBox instance = null; 41 42 private static final String MSG_INTERNAL_ERROR = new String ( 43 "Audit Log Manager internal error"); 44 private static final String JSP_LOGFORM = "/jsp/jahia/engines/audit/viewlogs.jsp"; 45 private static final String JSP_FLUSHCONFIRM = "/jsp/jahia/engines/audit/flushconfirm.jsp"; 47 48 private JahiaAuditLogManagerService mAuditLogManager = null; 50 51 52 private static final org.apache.log4j.Logger logger = 53 org.apache.log4j.Logger.getLogger (EngineToolBox.class); 54 55 56 59 private EngineToolBox () { 60 logger.info ("***** Starting EngineToolBox *****"); 61 } 62 63 64 67 public static synchronized EngineToolBox getInstance () { 68 if (instance == null) { 69 instance = new EngineToolBox (); 70 } 71 return instance; 72 } 73 74 75 78 public boolean authoriseRender (ParamBean jParams) { 79 return (jParams.getOperationMode () == ParamBean.EDIT); 80 } 82 83 88 public boolean processFieldTypes (ParamBean jParams, 89 int mode, 90 HashMap engineMap) 91 throws JahiaException, 92 JahiaUpdateLockException { 93 boolean out = true; 94 JahiaField theField = (JahiaField) engineMap.get ("theField"); 95 96 int pageDefID = jParams.getPage ().getPageTemplateID (); 97 98 int fieldType = theField.getDefinition ().getType (pageDefID); 99 logger.debug(" field type is " + fieldType); 100 if ((fieldType == FieldTypes.UNDEFINED) || (fieldType < 0)) { 101 fieldType = theField.getType (); 102 } 103 105 String engineName = theField.getEngineName (); 106 if (fieldType == FieldTypes.UNDEFINED) { 107 out = Undefined_Field.getInstance (). 108 handleField (jParams, new Integer (mode), engineMap); 109 } else { 110 111 try { 114 Class theParams[] = null; 115 Method thisMethod = Class.forName (engineName). 118 getDeclaredMethod ("getInstance", theParams); 119 Object args[] = null; 120 Object engine = thisMethod.invoke (null, args); 121 122 Class theParams2[] = {Class.forName ( 123 "org.jahia.params.ParamBean"), 124 Class.forName ("java.lang.Integer"), 125 Class.forName ("java.util.HashMap")}; 126 127 Method thisMethod2 = Class.forName (engineName). 130 getDeclaredMethod ("handleField", theParams2); 131 132 Object args2[] = {jParams, new Integer (mode), engineMap}; 133 out = ((Boolean ) thisMethod2.invoke (engine, args2)).booleanValue (); 134 135 logger.debug("Editing " + engineName. 136 substring (engineName.lastIndexOf (".")) + " !"); 137 138 } catch (ClassNotFoundException cnfe) { 139 throw new JahiaException ("EngineToolBox:processFieldTypes", 140 "Class not found!", 141 JahiaException.PAGE_ERROR, JahiaException.CRITICAL_SEVERITY, cnfe); 142 143 } catch (NoSuchMethodException nsme) { 144 throw new JahiaException ("EngineToolBox:processFieldTypes", 145 "Method not found!", 146 JahiaException.PAGE_ERROR, JahiaException.CRITICAL_SEVERITY, nsme); 147 148 } catch (IllegalAccessException iae) { 149 throw new JahiaException ("EngineToolBox:processFieldTypes", 150 "Illegal access", 151 JahiaException.PAGE_ERROR, JahiaException.CRITICAL_SEVERITY, iae); 152 153 } catch (InvocationTargetException ite) { 154 155 ite.printStackTrace (); 156 157 throw new JahiaException ("EngineToolBox:processFieldTypes", 158 "InvocationTarget exception", 159 JahiaException.PAGE_ERROR, JahiaException.CRITICAL_SEVERITY, ite); 160 } 161 } 162 163 169 ServicesRegistry.getInstance().getJahiaFieldService().invalidateCacheField(theField.getID()); 170 return out; 171 } 173 174 179 public void displayScreen (ParamBean jParams, HashMap engineMap) 180 throws JahiaException { 181 EngineRenderer.getInstance ().render (jParams, engineMap); 182 } 184 185 192 public void loadLogData (ParamBean jParams, int objectType, HashMap engineMap) 193 throws JahiaException { 194 195 int flushLogs = 0; 197 String output; 198 int deletedRows = 0; 199 200 String userAgent = jParams.getRequest ().getHeader ("user-agent"); 202 if (jParams.getRequest ().getParameter ("flush") != null) { 204 flushLogs = Integer.parseInt (jParams.getRequest ().getParameter ("flush")); 205 } 206 int objectID = JahiaObjectTool.getInstance ().getObjectID (objectType, engineMap); 207 String objectName = JahiaObjectTool.getInstance ().getObjectName (objectType, 208 engineMap); 209 210 ServicesRegistry registry = ServicesRegistry.getInstance (); 212 if (registry != null) { 213 mAuditLogManager = registry.getJahiaAuditLogManagerService (); 214 if (mAuditLogManager == null) { 215 throw new JahiaException (MSG_INTERNAL_ERROR, "Properties Engine could not get the Audit Log Manager Service instance.", 216 JahiaException.SERVICE_ERROR, JahiaException.CRITICAL_SEVERITY); 217 } 218 } else { 219 throw new JahiaException (MSG_INTERNAL_ERROR, "Properties Engine could not get the Service Registry instance.", 220 JahiaException.REGISTRY_ERROR, JahiaException.CRITICAL_SEVERITY); 221 } 222 223 engineMap.put ("flushLogs", new Integer (flushLogs)); 225 engineMap.put ("sendLogsURL", 226 ManageLogs_Engine.getInstance ().renderLink (jParams, "")); 227 engineMap.put ("objectTypeName", 228 JahiaObjectTool.getInstance ().getObjectTypeName (objectType)); 229 engineMap.put ("objectIDObj", new Integer (objectID)); 230 engineMap.put ("objectName", objectName); 231 engineMap.put ("userAgent", userAgent); 232 233 switch (flushLogs) { 239 case 1: 240 output = registry.getJahiaFetcherService ().fetchServlet (jParams, 241 JSP_FLUSHCONFIRM); 242 break; 243 244 case 2: 245 deletedRows = mAuditLogManager.flushLogs (objectType, objectID, jParams); 246 247 default: 248 ArrayList logData = mAuditLogManager.getLog (objectType, objectID, 249 jParams); 250 engineMap.put ("logData", logData); 251 engineMap.put ("deletedRows", new Integer (deletedRows)); 252 output = registry.getJahiaFetcherService ().fetchServlet (jParams, JSP_LOGFORM); 253 } 254 engineMap.put ("logForm", output); 255 256 } 258 } | Popular Tags |