1 4 package org.jahia.data.fields; 5 6 import java.util.Properties ; 7 8 import org.apache.regexp.RE; 9 import org.apache.regexp.RESyntaxException; 10 import org.jahia.data.FormDataManager; 11 import org.jahia.exceptions.JahiaException; 12 import org.jahia.params.ParamBean; 13 import org.jahia.registries.ServicesRegistry; 14 import org.jahia.services.fields.ContentBigTextField; 15 import org.jahia.services.fields.ContentField; 16 import org.jahia.services.files.JahiaTextFileService; 17 import org.jahia.services.version.ContentObjectEntryState; 18 import org.jahia.services.version.EntryLoadRequest; 19 import org.jahia.services.version.EntrySaveRequest; 20 import org.jahia.utils.JahiaConsole; 21 import org.jahia.utils.JahiaTools; 22 23 public class JahiaBigTextField extends JahiaField implements JahiaAllowApplyChangeToAllLangField 24 { 25 26 31 public JahiaBigTextField(Integer ID, 32 Integer jahiaID, 33 Integer pageID, 34 Integer ctnid, 35 Integer fieldDefID, 36 Integer fieldType, 37 Integer connectType, 38 String fieldValue, 39 Integer rank, 40 Integer aclID, 41 Integer versionID, 42 Integer versionStatus, 43 String languageCode) 44 { 45 super(ID, jahiaID, pageID, ctnid, fieldDefID, fieldType, connectType, 46 fieldValue, rank, aclID, versionID, versionStatus, languageCode); 47 48 if ( isShared() ){ 49 this.languageCode = ContentField.SHARED_LANGUAGE; 50 } 51 } 53 64 65 public void load(int loadFlag, ParamBean jParams) 66 throws JahiaException { 67 68 JahiaConsole.println(CLASS_NAME + ".load", "Loading big text field..."); 69 ContentBigTextField contentBigTextField = (ContentBigTextField)ContentBigTextField.getField(getID()); 70 JahiaConsole.println(CLASS_NAME + ".load", getValue()); 71 72 String val = null; 73 74 if ( this.getWorkflowState() > ContentObjectEntryState.WORKFLOW_STATE_ACTIVE 75 && this.getVersionID() == EntryLoadRequest.DELETED_WORKFLOW_STATE ){ 76 ContentObjectEntryState entryState = 77 new ContentObjectEntryState(ContentObjectEntryState.WORKFLOW_STATE_START_STAGING, 78 0,this.getLanguageCode()); 79 val = contentBigTextField.getValue(entryState); 80 } else { 81 val = contentBigTextField.getValue(jParams); 82 } 83 84 this.setRawValue(val); 85 86 this.setValue(FormDataManager.getInstance().htmlEncode(val)); 88 89 92 94 153 } 154 155 public boolean save(ParamBean jParams) 156 throws JahiaException { 157 158 JahiaConsole.println(CLASS_NAME + ".save", "Save Big Text..."); 159 ContentBigTextField contentBigTextField = (ContentBigTextField) ContentBigTextField.getField(getID()); 160 EntrySaveRequest saveRequest = new EntrySaveRequest(jParams.getUser(), this.getLanguageCode()); 161 contentBigTextField.setText(getValue(), saveRequest); 162 163 ServicesRegistry.getInstance().getJahiaSearchService().indexField(getID(), true, jParams, true); 164 165 200 return true; 201 } 202 203 public void delete(ParamBean jParams) 204 throws JahiaException 205 { 206 240 } 241 242 public String getEngineName() 243 { 244 return "org.jahia.engines.shared.BigText_Field"; 245 } 246 247 public String getFieldContent4Ranking() 248 { 249 String fieldInfo = this.getValue(); 250 fieldInfo = JahiaTools.html2text(fieldInfo); 251 try { 252 fieldInfo = (new RE("<(.*?)>")).subst(fieldInfo,""); 253 } catch (RESyntaxException re) { 254 JahiaConsole.println("JahiaBigTextField.getFieldContent4Ranking",re.toString()); 255 } catch (Throwable t) { 256 JahiaConsole.println("JahiaBigTextField.getFieldContent4Ranking",t.toString()); 257 } 258 259 if (fieldInfo.length() > 30) 260 { 261 fieldInfo = fieldInfo.substring(0,30) +" ..."; 262 } 263 264 fieldInfo = JahiaTools.text2html(fieldInfo); 265 return fieldInfo; 266 } 267 268 public String getIconNameOff() 269 { 270 return "bigtext"; 271 } 272 273 public String getIconNameOn() 274 { 275 return "bigtext_on"; 276 } 277 278 public JahiaField cloneField(int newctnid, int newPageID, int clonedAclID, boolean childrenCloned) 279 throws JahiaException 280 { 281 JahiaField clonedField = ServicesRegistry.getInstance().getJahiaFieldService(). 282 createJahiaField(0, this.getJahiaID(), 283 newPageID, newctnid, 284 this.getFieldDefID(), this.getType(), 285 this.getConnectType(), 286 this.getValue(), this.getRank(), 287 clonedAclID, this.getVersionID(), this.getWorkflowState(), 288 this.getLanguageCode()); 289 290 if (clonedField == null) 292 { 293 throw new JahiaException ("Could not clone field.", 294 "Could not instanciate a new JahiaField object.", 295 JahiaException.PAGE_ERROR, JahiaException.CRITICAL_SEVERITY); 296 } 297 298 clonedField.setRawValue(this.getRawValue()); 299 clonedField.setObject( this.getObject() ); 300 clonedField.setProperties( (Properties )(this.getProperties()).clone() ); 301 302 return clonedField; 303 } 304 305 public Object clone() 306 { 307 Object objItem = this.getObject(); 308 JahiaBigTextField bt = new JahiaBigTextField (new Integer (ID), new Integer (jahiaID), 309 new Integer (pageID), 310 new Integer (ctnid), 311 new Integer (fieldDefID), 312 new Integer (fieldType), 313 new Integer (connectType), 314 fieldValue, new Integer (rank), 315 new Integer (aclID), 316 new Integer (versionID), 317 new Integer (workflowState), 318 new String (getLanguageCode())); 319 bt.setObject(objItem); 320 return bt; 321 } 322 323 328 private JahiaTextFileService getTextFileService(){ 329 330 return ServicesRegistry.getInstance().getJahiaTextFileService(); 331 } 332 333 private final String CLASS_NAME = this.getClass().getName(); 334 335 338 public boolean isShared (){ 339 return false; 340 } 341 342 348 public void copyValueInAnotherLanguage (JahiaField aField,ParamBean jParams) 349 throws JahiaException { 350 if ( aField == null ){ 351 return; 352 } 353 aField.setValue(this.getValue()); 354 aField.setRawValue(this.getValue()); 355 aField.setObject(this.getObject()); 356 } 357 358 } 359 | Popular Tags |