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.ContentFloatField; 15 import org.jahia.services.version.EntrySaveRequest; 16 import org.jahia.sharing.FieldSharingManager; 17 18 public class JahiaFloatField extends JahiaField implements JahiaSimpleField, JahiaAllowApplyChangeToAllLangField 19 { 20 21 26 public JahiaFloatField(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 this.setRawValue(this.getValue()); 59 this.setValue(FormDataManager.getInstance().htmlEncode(this.getValue())); 60 61 if (this.getValue() != null && !this.getValue().equals("")) 62 { 63 try { 64 this.setObject(new Double ( this.getValue() )); 65 } catch (NumberFormatException e) 66 { 67 this.setObject(new Double ( 0.0 )); 68 this.setValue(""); 69 } 70 } 71 else 72 { 73 this.setObject(new Double ( 0.0 )); 74 } 75 } 76 break; 77 case (ConnectionTypes.DATASOURCE) : 78 if ((loadFlag & LoadFlags.DATASOURCE) != 0) { 79 this.setValue( FieldSharingManager.getInstance().getRemoteFieldValue( 80 this.getValue() )); 81 if (this.getValue() != null && !this.getValue().equals("")) 82 { 83 try { 84 this.setObject(new Double ( this.getValue() )); 85 } catch (NumberFormatException e) 86 { 87 this.setObject(new Double ( 0.0 )); 88 this.setValue(""); 89 } 90 } 91 else 92 { 93 this.setObject(new Double ( 0.0 )); 94 } 95 } 96 } 97 98 } 99 100 public boolean save(ParamBean jParams) 101 throws JahiaException 102 { 103 107 EntrySaveRequest saveRequest = new EntrySaveRequest(jParams.getUser(),getLanguageCode()); 108 ContentFloatField contentField = (ContentFloatField)ContentField.getField(getID()); 109 try { 110 if (!"<empty>".equals(getValue()) && getValue().length() > 0){ 111 contentField.setFloat(Float.valueOf(getValue()).floatValue(), saveRequest); 112 ServicesRegistry.getInstance().getJahiaSearchService().indexField(getID(), true, jParams, true); 113 } else { 114 return false; 115 } 116 } catch ( Throwable t ){ 117 t.printStackTrace(); 118 return false; 119 } 120 return true; 121 } 122 123 public void delete(ParamBean jParams) 124 throws JahiaException 125 { 126 ; 127 } 128 129 public String getEngineName() 130 { 131 return "org.jahia.engines.shared.Float_Field"; 132 } 133 134 public String getFieldContent4Ranking() 135 { 136 return this.getValue(); 137 } 138 139 public String getIconNameOff() 140 { 141 return "r_off"; 142 } 143 144 public String getIconNameOn() 145 { 146 return "r_on"; 147 } 148 149 public JahiaField cloneField(int newctnid, int newPageID, int clonedAclID, boolean childrenCloned) 150 throws JahiaException 151 { 152 JahiaField clonedField = ServicesRegistry.getInstance().getJahiaFieldService(). 153 createJahiaField(0, this.getJahiaID(), 154 newPageID, newctnid, 155 this.getFieldDefID(), this.getType(), 156 this.getConnectType(), 157 this.getValue(), this.getRank(), 158 clonedAclID, this.getVersionID(), this.getWorkflowState(), 159 this.getLanguageCode()); 160 161 if (clonedField == null) 163 { 164 throw new JahiaException ("Could not clone field.", 165 "Could not instanciate a new JahiaField object.", 166 JahiaException.PAGE_ERROR, JahiaException.CRITICAL_SEVERITY); 167 } 168 169 clonedField.setRawValue(this.getRawValue()); 170 clonedField.setObject( this.getObject() ); 171 clonedField.setProperties( (Properties )(this.getProperties()).clone() ); 172 173 return clonedField; 174 } 175 176 public Object clone() 177 { 178 Object objItem = this.getObject(); 179 JahiaFloatField ff = new JahiaFloatField (new Integer (ID), new Integer (jahiaID), 180 new Integer (pageID), 181 new Integer (ctnid), 182 new Integer (fieldDefID), 183 new Integer (fieldType), 184 new Integer (connectType), 185 fieldValue, new Integer (rank), 186 new Integer (aclID), 187 new Integer (versionID), 188 new Integer (workflowState), 189 new String (getLanguageCode()) ); 190 ff.setObject(objItem); 191 return ff; 192 } 193 194 197 public boolean isShared (){ 198 return true; 199 } 200 201 207 public void copyValueInAnotherLanguage (JahiaField aField,ParamBean jParams) 208 throws JahiaException { 209 if ( aField == null ){ 210 return; 211 } 212 aField.setValue(this.getValue()); 213 aField.setRawValue(this.getValue()); 214 aField.setObject(this.getObject()); 215 } 216 217 } 218 | Popular Tags |