1 13 package org.jahia.services.fields; 14 15 import org.jahia.data.ConnectionTypes; 16 import org.jahia.data.fields.JahiaFieldDefinition; 17 import org.jahia.exceptions.JahiaException; 18 import org.jahia.params.ParamBean; 19 import org.jahia.registries.JahiaFieldDefinitionsRegistry; 20 import org.jahia.registries.ServicesRegistry; 21 import org.jahia.services.pages.ContentPage; 22 import org.jahia.services.usermanager.JahiaUser; 23 import org.jahia.services.version.*; 24 import org.jahia.utils.LanguageCodeConverters; 25 import org.jahia.utils.xml.XMLSerializationOptions; 26 import org.jahia.utils.xml.XmlWriter; 27 28 import java.io.IOException ; 29 import java.util.ArrayList ; 30 import java.util.Hashtable ; 31 import java.util.Set ; 32 import java.util.Vector ; 33 34 35 public class ContentBigTextField extends ContentField { 36 37 private static org.apache.log4j.Logger logger 38 = org.apache.log4j.Logger.getLogger (ContentBigTextField.class); 39 40 41 protected ContentBigTextField (Integer ID, 42 Integer jahiaID, 43 Integer pageID, 44 Integer ctnid, 45 Integer fieldDefID, 46 Integer fieldType, 47 Integer connectType, 48 Integer aclID, 49 Vector activeAndStagingEntryStates, 50 Hashtable activeAndStagedDBValues) { 51 super (ID.intValue (), jahiaID.intValue (), pageID.intValue (), 52 ctnid.intValue (), fieldDefID.intValue (), fieldType.intValue (), 53 connectType.intValue (), aclID.intValue (), 54 activeAndStagingEntryStates, activeAndStagedDBValues); 55 } 56 57 public static synchronized ContentBigTextField 59 createBigText (int siteID, int pageID, int containerID, 60 int fieldDefID, int parentAclID, int aclID, 61 String text, ParamBean jParams) 62 throws JahiaException { 63 64 ContentBigTextField result = 65 (ContentBigTextField) ContentField.createField (siteID, pageID, 66 containerID, fieldDefID, 67 ContentFieldTypes.BIGTEXT, 68 ConnectionTypes.LOCAL, 69 parentAclID, aclID); 70 EntrySaveRequest saveRequest = 71 new EntrySaveRequest (jParams.getUser (), 72 jParams.getLocale ().toString ()); 73 74 result.setText (text, saveRequest); 75 return result; 76 } 77 78 86 public String getValue (ParamBean jParams, 87 ContentObjectEntryState entryState) 88 throws JahiaException { 89 90 logger.debug ("Loading big text field..."); 91 92 JahiaFieldDefinition theDef = JahiaFieldDefinitionsRegistry. 93 getInstance ().getDefinition ( 94 this.getFieldDefID ()); 95 int pageDefID = -1; 96 if (entryState != null) { 97 pageDefID = 98 ContentPage.getPage (this.getPageID ()).getDefinitionID ( 99 new EntryLoadRequest (entryState)); 100 } else { 101 pageDefID = ServicesRegistry.getInstance ().getJahiaPageService (). 102 lookupPage (this.getPageID (), jParams). 103 getPageTemplateID (); 104 } 105 106 String result = ServicesRegistry.getInstance () 107 .getJahiaTextFileService () 108 .loadBigTextValue (this.getSiteID (), 109 this.getPageID (), 110 this.getID (), 111 theDef.getDefaultValue (pageDefID), 112 entryState.getVersionID (), 113 entryState.getWorkflowState (), 114 entryState.getLanguageCode ()); 115 116 if (result == null || result.equals ("<empty>")) { 117 result = new String (); 118 } 119 125 return result; 126 } 127 128 133 public void setText (String value, EntrySaveRequest saveRequest) throws JahiaException { 134 ContentObjectEntryState verInfo = preSet ("<text>", saveRequest); 135 logger.debug ("Saving big text field..." + verInfo.toString ()); 136 137 ServicesRegistry.getInstance ().getJahiaTextFileService ().saveContents ( 138 this.getSiteID (), 139 this.getPageID (), 140 this.getID (), 141 value, 142 verInfo.getVersionID (), 143 verInfo.getWorkflowState (), 144 verInfo.getLanguageCode ()); 145 146 } 147 148 155 public String getValueForSearch (ParamBean jParams, ContentObjectEntryState entryState) { 156 return new String (); 157 } 158 159 176 public ActivationTestResults changeEntryState (ContentObjectEntryState fromEntryState, 177 ContentObjectEntryState toEntryState, 178 ParamBean jParams, 179 StateModificationContext stateModifContext) 180 throws JahiaException { 181 182 logger.debug ("From " + fromEntryState.toString () 183 + " To " + toEntryState.toString ()); 184 185 ActivationTestResults activationResults = new ActivationTestResults (); 186 try { 187 ServicesRegistry.getInstance ().getJahiaTextFileService (). 188 renameFile ( 189 this.getSiteID (), 190 this.getPageID (), 191 this.getID (), 192 fromEntryState.getVersionID (), 193 fromEntryState.getWorkflowState (), 194 fromEntryState.getLanguageCode (), 195 196 this.getSiteID (), 197 this.getPageID (), 198 this.getID (), 199 toEntryState.getVersionID (), 200 toEntryState.getWorkflowState (), 201 toEntryState.getLanguageCode () 202 ); 203 activationResults.setStatus (ActivationTestResults.COMPLETED_OPERATION_STATUS); 204 } catch (Throwable t) { 205 t.printStackTrace (); 206 activationResults.setStatus (ActivationTestResults.FAILED_OPERATION_STATUS); 207 } 208 return activationResults; 209 } 210 211 protected ActivationTestResults isContentValidForActivation ( 213 Set languageCodes, 214 ParamBean jParams, 215 StateModificationContext stateModifContext) 216 throws JahiaException { 217 218 219 return new ActivationTestResults (); 220 } 221 222 231 public void copyEntry (EntryStateable fromEntryState, 232 EntryStateable toEntryState) 233 throws JahiaException { 234 235 int fromVersionID = fromEntryState.getVersionID (); 236 237 if (fromEntryState.getWorkflowState () 238 == ContentObjectEntryState.WORKFLOW_STATE_VERSIONING_DELETED) { 239 ContentObjectEntryState entryState = 242 new ContentObjectEntryState (fromEntryState); 243 ContentObjectEntryState archiveEntryState = 244 getClosestVersionedEntryState (entryState, true); 245 if (archiveEntryState != null) { 246 fromVersionID = archiveEntryState.getVersionID (); 247 } 248 } 249 250 ServicesRegistry.getInstance ().getJahiaTextFileService ().copyFile ( 251 this.getSiteID (), 252 this.getPageID (), 253 this.getID (), 254 fromVersionID, 255 fromEntryState.getWorkflowState (), 256 fromEntryState.getLanguageCode (), 257 258 this.getSiteID (), 259 this.getPageID (), 260 this.getID (), 261 toEntryState.getVersionID (), 262 toEntryState.getWorkflowState (), 263 toEntryState.getLanguageCode () 264 ); 265 266 super.copyEntry (fromEntryState, toEntryState); 267 } 268 269 279 public void deleteEntry (EntryStateable deleteEntryState) 280 throws JahiaException { 281 ServicesRegistry.getInstance ().getJahiaTextFileService ().deleteFile ( 282 this.getSiteID (), 283 this.getPageID (), 284 this.getID (), 285 deleteEntryState.getVersionID (), 286 deleteEntryState.getWorkflowState (), 287 deleteEntryState.getLanguageCode ()); 288 289 super.deleteEntry (deleteEntryState); 290 } 291 292 297 public boolean isShared () { 298 return false; 299 } 300 301 322 protected void serializeContentToXML (XmlWriter xmlWriter, 323 XMLSerializationOptions xmlSerializationOptions, 324 ContentObjectEntryState entryState, 325 ParamBean paramBean) throws IOException { 326 try { 327 JahiaFieldDefinition theDef = JahiaFieldDefinitionsRegistry. 328 getInstance ().getDefinition ( 329 this.getFieldDefID ()); 330 331 int pageDefID = ServicesRegistry.getInstance ().getJahiaPageService (). 332 lookupContentPage (this.getPageID (), true). 333 getPageTemplateID (EntryLoadRequest.CURRENT); 334 335 String result = ServicesRegistry.getInstance () 336 .getJahiaTextFileService () 337 .loadBigTextValue (this.getSiteID (), 338 this.getPageID (), 339 this.getID (), 340 theDef.getDefaultValue (pageDefID), 341 entryState.getVersionID (), 342 entryState.getWorkflowState (), 343 entryState.getLanguageCode ()); 344 345 if (result == null || result.equals ("<empty>")) { 346 result = new String (); 347 } else { 348 } 350 xmlWriter.writeCData (result); 351 } catch (JahiaException je) { 352 logger.debug ("Error while serializing bigtext to XML : ", je); 353 } 354 } 355 356 protected void purgeContent () 357 throws JahiaException { 358 } 361 362 377 protected void markContentLanguageForDeletion (JahiaUser user, 378 String languageCode, 379 StateModificationContext stateModifContext) 380 throws JahiaException { 381 ArrayList locales = new ArrayList (); 382 locales.add (LanguageCodeConverters.languageCodeToLocale (languageCode)); 383 EntryLoadRequest loadRequest = new EntryLoadRequest ( 384 EntryLoadRequest.ACTIVE_WORKFLOW_STATE, 0, locales); 385 ContentObjectEntryState fromEntryState = getEntryState (loadRequest); 386 ContentObjectEntryState toEntryState = new ContentObjectEntryState ( 387 ContentObjectEntryState.WORKFLOW_STATE_START_STAGING, -1, languageCode); 388 if (fromEntryState != null && toEntryState != null) { 389 ServicesRegistry.getInstance ().getJahiaTextFileService ().copyFile ( 390 this.getSiteID (), 391 this.getPageID (), 392 this.getID (), 393 fromEntryState.getVersionID (), 394 fromEntryState.getWorkflowState (), 395 fromEntryState.getLanguageCode (), 396 397 this.getSiteID (), 398 this.getPageID (), 399 this.getID (), 400 toEntryState.getVersionID (), 401 toEntryState.getWorkflowState (), 402 toEntryState.getLanguageCode () 403 ); 404 } 405 return; 406 } 407 408 409 } | Popular Tags |