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