KickJava   Java API By Example, From Geeks To Geeks.

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


1 // JahiaIntegerField
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.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         /***
22         * constructor
23         * YG
24         *
25         */

26     public JahiaIntegerField(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                     if (this.getValue() != null && !this.getValue().equals(""))
61                     {
62                         try {
63                             this.setObject(new Long JavaDoc( this.getValue() ));
64                         } catch (NumberFormatException JavaDoc e)
65                         {
66                             this.setObject(new Long JavaDoc( 0 ));
67                             this.setValue("");
68                         }
69                     }
70                     else
71                     {
72                         this.setObject(new Long JavaDoc( 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 JavaDoc( this.getValue() ));
84                     } catch (NumberFormatException JavaDoc e)
85                     {
86                         this.setObject(new Long JavaDoc( 0 ));
87                         this.setValue("");
88                     }
89
90                 }
91                 else
92                 {
93                     this.setObject(new Long JavaDoc( 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         // deprecated
108
// ServicesRegistry.getInstance().getJahiaFieldService().saveField( theField, 0, jParams );
109

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

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

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