KickJava   Java API By Example, From Geeks To Geeks.

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


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

26     public JahiaBooleanField(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("") && (this.getValue().equals("true") || this.getValue().equals("false")))
62                     {
63                         this.setObject(new Boolean JavaDoc( this.getValue() ));
64                     }
65                     else
66                     {
67                         this.setObject(new Boolean JavaDoc( "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 JavaDoc( this.getValue() ));
80                 }
81                 else
82                 {
83                     this.setObject(new Boolean JavaDoc( "true" ));
84                 }
85             }
86         }
87
88     }
89
90     public boolean save(ParamBean jParams)
91     throws JahiaException
92     {
93         //setValue( FormDataManager.getInstance().encode( getValue() ) );
94

95         // 0 for parentAclID in saveField, because field already exists
96
// -> field already has an aclID
97
// -> no need to create a new one
98

99         // deprecated
100
// ServicesRegistry.getInstance().getJahiaFieldService().saveField( theField, 0, jParams );
101

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 JavaDoc 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 JavaDoc getEngineName()
121     {
122         return "org.jahia.engines.shared.Boolean_Field";
123     }
124
125     public String JavaDoc getFieldContent4Ranking()
126     {
127         return this.getValue();
128     }
129
130     public String JavaDoc getIconNameOff()
131     {
132         return "01_off";
133     }
134
135     public String JavaDoc 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         //toDebug("cloneField(): value = "+this.getValue());
153
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 JavaDoc)(this.getProperties()).clone() );
163
164         return clonedField;
165     }
166
167     public Object JavaDoc clone()
168     {
169         Object JavaDoc objItem = this.getObject();
170         JahiaBooleanField bf = new JahiaBooleanField (new Integer JavaDoc(ID), new Integer JavaDoc(jahiaID),
171                                         new Integer JavaDoc(pageID),
172                                         new Integer JavaDoc(ctnid),
173                                         new Integer JavaDoc(fieldDefID),
174                                         new Integer JavaDoc(fieldType),
175                                         new Integer JavaDoc(connectType),
176                                         fieldValue, new Integer JavaDoc(rank),
177                                         new Integer JavaDoc(aclID),
178                                         new Integer JavaDoc(versionID),
179                                         new Integer JavaDoc(workflowState),
180                                         new String JavaDoc(getLanguageCode()));
181         bf.setObject(objItem);
182         return bf;
183     }
184
185     /**
186      * Is this kind of field shared (i.e. not one version for each language, but one version for every language)
187      */

188     public boolean isShared (){
189         return true;
190     }
191
192     /**
193      * Copy the internal value of current language to another language.
194      * Must be implemented by conctrete field for specific implementation.
195      *
196      * @param aField A same field in another language
197      */

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