KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jahia > data > fields > JahiaFloatField


1 // JahiaFloatField
2
// YG 08.08.2001
3

4 package org.jahia.data.fields;
5
6 import java.util.Properties JavaDoc;
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         /***
22         * constructor
23         * YG
24         *
25         */

26     public JahiaFloatField(Integer JavaDoc ID,
27                             Integer JavaDoc jahiaID,
28                             Integer JavaDoc pageID,
29                             Integer JavaDoc ctnid,
30                             Integer JavaDoc fieldDefID,
31                             Integer JavaDoc fieldType,
32                             Integer JavaDoc connectType,
33                             String JavaDoc fieldValue,
34                             Integer JavaDoc rank,
35                             Integer JavaDoc aclID,
36                             Integer JavaDoc versionID,
37                             Integer JavaDoc versionStatus,
38                             String JavaDoc 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     } // end constructor
48

49
50     public void load(int loadFlag, ParamBean jParams)
51     throws JahiaException
52     {
53         switch (this.getConnectType())
54         {
55             case (ConnectionTypes.LOCAL) :
56                 //this.setValue(this.getValue());
57
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 JavaDoc( this.getValue() ));
65                         } catch (NumberFormatException JavaDoc e)
66                         {
67                             this.setObject(new Double JavaDoc( 0.0 ));
68                             this.setValue("");
69                         }
70                     }
71                     else
72                     {
73                         this.setObject(new Double JavaDoc( 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 JavaDoc( this.getValue() ));
85                         } catch (NumberFormatException JavaDoc e)
86                         {
87                             this.setObject(new Double JavaDoc( 0.0 ));
88                             this.setValue("");
89                         }
90                 }
91                 else
92                 {
93                     this.setObject(new Double JavaDoc( 0.0 ));
94                 }
95             }
96         }
97
98     }
99
100     public boolean save(ParamBean jParams)
101     throws JahiaException
102     {
103         // 0 for parentAclID in saveField, because field already exists
104
// -> field already has an aclID
105
// -> no need to create a new one
106

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 JavaDoc 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 JavaDoc getEngineName()
130     {
131         return "org.jahia.engines.shared.Float_Field";
132     }
133
134     public String JavaDoc getFieldContent4Ranking()
135     {
136         return this.getValue();
137     }
138
139     public String JavaDoc getIconNameOff()
140     {
141         return "r_off";
142     }
143
144     public String JavaDoc 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         //toDebug("cloneField(): value = "+this.getValue());
162
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 JavaDoc)(this.getProperties()).clone() );
172
173         return clonedField;
174     }
175
176     public Object JavaDoc clone()
177     {
178         Object JavaDoc objItem = this.getObject();
179         JahiaFloatField ff = new JahiaFloatField (new Integer JavaDoc(ID), new Integer JavaDoc(jahiaID),
180                                         new Integer JavaDoc(pageID),
181                                         new Integer JavaDoc(ctnid),
182                                         new Integer JavaDoc(fieldDefID),
183                                         new Integer JavaDoc(fieldType),
184                                         new Integer JavaDoc(connectType),
185                                         fieldValue, new Integer JavaDoc(rank),
186                                         new Integer JavaDoc(aclID),
187                                         new Integer JavaDoc(versionID),
188                                         new Integer JavaDoc(workflowState),
189                                         new String JavaDoc(getLanguageCode()) );
190         ff.setObject(objItem);
191         return ff;
192     }
193
194     /**
195      * Is this kind of field shared (i.e. not one version for each language, but one version for every language)
196      */

197     public boolean isShared (){
198         return true;
199     }
200
201     /**
202      * Copy the internal value of current language to another language.
203      * Must be implemented by conctrete field for specific implementation.
204      *
205      * @param aField A same field in another language
206      */

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