1 4 package org.jahia.data.fields; 5 6 import java.util.Properties ; 7 8 import org.jahia.data.ConnectionTypes; 9 import org.jahia.data.FormDataManager; 10 import org.jahia.exceptions.JahiaException; 11 import org.jahia.params.ParamBean; 12 import org.jahia.registries.ServicesRegistry; 13 import org.jahia.services.fields.ContentField; 14 import org.jahia.services.fields.ContentSmallTextField; 15 import org.jahia.services.version.EntrySaveRequest; 16 import org.jahia.sharing.FieldSharingManager; 17 18 public class JahiaSmallTextField extends JahiaField implements JahiaSimpleField, JahiaAllowApplyChangeToAllLangField 19 { 20 21 26 public JahiaSmallTextField(Integer ID, 27 Integer jahiaID, 28 Integer pageID, 29 Integer ctnid, 30 Integer fieldDefID, 31 Integer fieldType, 32 Integer connectType, 33 String fieldValue, 34 Integer rank, 35 Integer aclID, 36 Integer versionID, 37 Integer versionStatus, 38 String languageCode) 39 { 40 super(ID, jahiaID, pageID, ctnid, fieldDefID, fieldType, connectType, 41 fieldValue, rank, aclID, versionID, versionStatus, languageCode); 42 43 if ( isShared() ){ 44 this.languageCode = ContentField.SHARED_LANGUAGE; 45 } 46 47 } 49 50 public void load(int loadFlag, ParamBean jParams) 51 throws JahiaException 52 { 53 switch (this.getConnectType()) 54 { 55 case (ConnectionTypes.LOCAL) : 56 if (!this.getValue().equals("<empty>")) { 58 String fieldValue = this.getValue(); 59 this.setRawValue(fieldValue); 60 this.setValue(FormDataManager.getInstance().htmlEncode(fieldValue)); 61 } 62 break; 63 case (ConnectionTypes.DATASOURCE) : 64 if ((loadFlag & LoadFlags.DATASOURCE) != 0) { 65 this.setValue( FieldSharingManager.getInstance().getRemoteFieldValue( 66 this.getValue() )); 67 } 68 } 69 70 } 71 72 public String getEngineName() 73 { 74 return "org.jahia.engines.shared.SmallText_Field"; 75 } 76 77 public boolean save(ParamBean jParams) 78 throws JahiaException 79 { 80 84 EntrySaveRequest saveRequest = new EntrySaveRequest(jParams.getUser(),getLanguageCode()); 86 ContentSmallTextField contentField = (ContentSmallTextField)ContentField.getField(getID()); 87 contentField.setText(getValue(),saveRequest); 88 ServicesRegistry.getInstance().getJahiaSearchService().indexField(getID(), true, jParams, true); 89 return true; 90 } 91 92 public String getValue() { 93 return fieldValue; 94 } 95 96 public void delete(ParamBean jParams) 97 throws JahiaException 98 { 99 ; 100 } 101 102 public String getFieldContent4Ranking() 103 { 104 return this.getValue(); 105 } 106 107 public String getIconNameOff() 108 { 109 return "smalltext"; 110 } 111 112 public String getIconNameOn() 113 { 114 return "smalltext_on"; 115 } 116 117 public JahiaField cloneField(int newctnid, int newPageID, int clonedAclID, boolean childrenCloned) 118 throws JahiaException 119 { 120 JahiaField clonedField = ServicesRegistry.getInstance().getJahiaFieldService(). 121 createJahiaField(0, this.getJahiaID(), 122 newPageID, newctnid, 123 this.getFieldDefID(), this.getType(), 124 this.getConnectType(), 125 this.getValue(), this.getRank(), 126 clonedAclID, this.getVersionID(), this.getWorkflowState(), 127 this.getLanguageCode()); 128 129 if (clonedField == null) 131 { 132 throw new JahiaException ("Could not clone field.", 133 "Could not instanciate a new JahiaField object.", 134 JahiaException.PAGE_ERROR, JahiaException.CRITICAL_SEVERITY); 135 } 136 137 clonedField.setRawValue(this.getRawValue()); 138 clonedField.setObject( this.getObject() ); 139 clonedField.setProperties( (Properties )(this.getProperties()).clone() ); 140 141 return clonedField; 142 } 143 144 public Object clone() 145 { 146 Object objItem = this.getObject(); 147 148 JahiaSmallTextField st = new JahiaSmallTextField (new Integer (ID), new Integer (jahiaID), 149 new Integer (pageID), 150 new Integer (ctnid), 151 new Integer (fieldDefID), 152 new Integer (fieldType), 153 new Integer (connectType), 154 fieldValue, new Integer (rank), 155 new Integer (aclID), 156 new Integer (versionID), 157 new Integer (workflowState), 158 new String (getLanguageCode()) ); 159 st.setObject(objItem); 160 return st; 161 } 162 163 166 public boolean isShared (){ 167 return false; 168 } 169 170 176 public void copyValueInAnotherLanguage (JahiaField aField,ParamBean jParams) 177 throws JahiaException { 178 if ( aField == null ){ 179 return; 180 } 181 aField.setValue(this.getValue()); 182 aField.setRawValue(this.getValue()); 183 aField.setObject(this.getObject()); 184 } 185 186 } 187 | Popular Tags |