1 14 package org.jahia.engines.versioning; 15 16 import java.util.ArrayList ; 17 import java.util.HashMap ; 18 19 import org.jahia.data.fields.JahiaField; 20 import org.jahia.data.fields.JahiaVersioningContentFieldFacade; 21 import org.jahia.data.fields.LoadFlags; 22 import org.jahia.data.JahiaData; 23 import org.jahia.exceptions.JahiaException; 24 import org.jahia.params.ParamBean; 25 import org.jahia.registries.ServicesRegistry; 26 import org.jahia.services.version.EntryLoadRequest; 27 import org.jahia.utils.LanguageCodeConverters; 28 import org.jahia.engines.JahiaEngine; 29 30 35 public class VersioningEngine implements JahiaEngine { 36 37 public static final String ENGINE_NAME = "versioning"; 38 public static final String JSP_FILE = "/jsp/jahia/engines/versioning/versioning.jsp"; 39 private static VersioningEngine instance = null; 40 41 42 private static final org.apache.log4j.Logger logger = 43 org.apache.log4j.Logger.getLogger (VersioningEngine.class); 44 45 46 49 private VersioningEngine () { 50 logger.debug ("***** Starting " + VersioningEngine.class.getName () + " engine *****"); 51 } 52 53 56 public static synchronized VersioningEngine getInstance () { 57 if (instance == null) { 58 instance = new VersioningEngine (); 59 } 60 return instance; 61 } 62 63 75 public boolean handleAction (ParamBean jParams, int mode, HashMap engineMap, int objType, 76 Object obj) 77 throws JahiaException { 78 logger.debug ("Started : mode:" + mode); 79 return true; 80 81 90 } 91 92 93 104 public boolean load (ParamBean jParams, HashMap engineMap, int objType, Object obj) 105 throws JahiaException { 106 if (obj != null && obj instanceof JahiaField) { 107 JahiaField theField = (JahiaField) obj; 108 109 ArrayList localeList = jParams.getSite ().getLanguageSettingsAsLocales (false); 110 111 JahiaVersioningContentFieldFacade versioningContentFieldFacade = 112 (JahiaVersioningContentFieldFacade) engineMap 113 .get ("versioningContentFieldFacade_" + theField.getID ()); 114 if (versioningContentFieldFacade == null) { 115 versioningContentFieldFacade = 116 this.loadVersioningContentFieldFacade (theField.getID (), LoadFlags.ALL, 117 jParams, localeList); 118 engineMap.put ("versioningContentFieldFacade_" + theField.getID (), 119 versioningContentFieldFacade); 120 } 121 jParams.getRequest ().setAttribute ("versioningContentFieldFacade", 122 versioningContentFieldFacade); 123 124 } 125 String output = ServicesRegistry.getInstance ().getJahiaFetcherService ().fetchServlet ( 126 jParams, JSP_FILE); 127 engineMap.put ("versioningForm", output); 128 return true; 129 } 130 131 132 143 public boolean update (ParamBean jParams, HashMap engineMap, int objType, Object obj) 144 throws JahiaException { 145 String restore_action = jParams.getRequest ().getParameter ("restore_action"); 146 147 if ("restore".equals (restore_action)) { 148 String versionID = jParams.getRequest ().getParameter ("versionid"); 149 if (versionID == null) { 150 return true; 151 } 152 if (obj != null && obj instanceof JahiaField) { 153 JahiaField theField = (JahiaField) obj; 154 JahiaVersioningContentFieldFacade versioningContentFieldFacade = 155 (JahiaVersioningContentFieldFacade) engineMap 156 .get ("versioningContentFieldFacade_" + theField.getID ()); 157 if (versioningContentFieldFacade == null) { 158 return false; 159 } 160 161 String languageCode = (String ) engineMap.get ("languageCode"); 162 ArrayList locales = new ArrayList (); 163 locales.add (LanguageCodeConverters.languageCodeToLocale (languageCode)); 164 165 EntryLoadRequest entryLoadRequest = 166 new EntryLoadRequest (EntryLoadRequest.VERSIONED_WORKFLOW_STATE, 167 Integer.parseInt (versionID), locales); 168 JahiaField versionedField = versioningContentFieldFacade.getField ( 169 entryLoadRequest); 170 if (versionedField == null) { 171 return false; 172 } 173 179 180 JahiaField updatedField = (JahiaField) engineMap.get ("theField"); 182 if (updatedField == null) { 183 return false; 184 } else { 185 versionedField.copyValueToAnotherField (updatedField, jParams); 186 } 187 } 188 } 189 return true; 190 } 191 192 203 public boolean save (ParamBean jParams, HashMap engineMap, int objType, Object obj) 204 throws JahiaException { 205 return true; 206 } 207 208 213 private JahiaVersioningContentFieldFacade loadVersioningContentFieldFacade (int fieldID, 214 int loadFlag, 215 ParamBean jParams, 216 ArrayList locales) 217 throws JahiaException { 218 JahiaVersioningContentFieldFacade versContentFieldFacade = 219 new JahiaVersioningContentFieldFacade (fieldID, loadFlag, jParams, locales); 220 221 return versContentFieldFacade; 222 } 223 224 public boolean authoriseRender (ParamBean jParams) { 225 return false; 226 } 227 228 public String renderLink (ParamBean jParams, Object theObj) throws JahiaException { 229 return ENGINE_NAME; 230 } 231 232 public boolean needsJahiaData (ParamBean jParams) { 233 return false; 234 } 235 236 public void handleActions (ParamBean jParams, JahiaData jData) throws JahiaException { 237 } 238 239 244 public final String getName () { 245 return ENGINE_NAME; } 247 248 } | Popular Tags |