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