KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jahia > services > fields > ContentBooleanField


1 //
2
// ____.
3
// __/\ ______| |__/\. _______
4
// __ .____| | \ | +----+ \
5
// _______| /--| | | - \ _ | : - \_________
6
// \\______: :---| : : | : | \________>
7
// |__\---\_____________:______: :____|____:_____\
8
// /_____|
9
//
10
// . . . i n j a h i a w e t r u s t . . .
11
//
12

13 package org.jahia.services.fields;
14
15 import org.jahia.data.ConnectionTypes;
16 import org.jahia.exceptions.JahiaException;
17 import org.jahia.params.ParamBean;
18 import org.jahia.services.version.ActivationTestResults;
19 import org.jahia.services.version.ContentObjectEntryState;
20 import org.jahia.services.version.EntrySaveRequest;
21 import org.jahia.services.version.StateModificationContext;
22 import org.jahia.utils.xml.XMLSerializationOptions;
23 import org.jahia.utils.xml.XmlWriter;
24
25 import java.util.Hashtable JavaDoc;
26 import java.util.Set JavaDoc;
27 import java.util.Vector JavaDoc;
28
29 public class ContentBooleanField extends ContentField implements ContentSimpleField {
30     private static org.apache.log4j.Logger logger
31             = org.apache.log4j.Logger.getLogger (ContentBooleanField.class);
32
33     //--------------------------------------------------------------------------
34
protected ContentBooleanField (Integer JavaDoc ID,
35                                    Integer JavaDoc jahiaID,
36                                    Integer JavaDoc pageID,
37                                    Integer JavaDoc ctnid,
38                                    Integer JavaDoc fieldDefID,
39                                    Integer JavaDoc fieldType,
40                                    Integer JavaDoc connectType,
41                                    Integer JavaDoc aclID,
42                                    Vector JavaDoc activeAndStagingEntryStates,
43                                    Hashtable JavaDoc activeAndStagedDBValues) {
44         super (ID.intValue (), jahiaID.intValue (), pageID.intValue (),
45                 ctnid.intValue (), fieldDefID.intValue (), fieldType.intValue (),
46                 connectType.intValue (), aclID.intValue (),
47                 activeAndStagingEntryStates, activeAndStagedDBValues);
48     }
49
50     //--------------------------------------------------------------------------
51
public static synchronized ContentBooleanField
52             createBoolean (int siteID,
53                            int pageID,
54                            int containerID,
55                            int fieldDefID,
56                            int parentAclID, int aclID,
57                            boolean value,
58                            ParamBean jParams)
59             throws JahiaException {
60         ContentBooleanField result =
61                 (ContentBooleanField)
62                 ContentField.createField (siteID, pageID, containerID,
63                         fieldDefID, ContentFieldTypes.BOOLEAN,
64                         ConnectionTypes.LOCAL, parentAclID,
65                         aclID);
66
67         EntrySaveRequest saveRequest =
68                 new EntrySaveRequest (jParams.getUser (),
69                         ContentField.SHARED_LANGUAGE);
70
71         result.setValue (value, saveRequest);
72         return result;
73     }
74
75     //--------------------------------------------------------------------------
76
/**
77      * Gets the String representation of this field. In case of an Application,
78      * it will be the output of the application, in case of a bigtext it will
79      * be the full content of the bigtext, etc. This is called by the public
80      * method getValue of ContentField, which does the entryState resolving
81      * This method should call getDBValue to get the DBValue
82      */

83     public String JavaDoc getValue (ParamBean jParams,
84                                ContentObjectEntryState entryState)
85             throws JahiaException {
86         //return FormDataManager.getInstance().formDecode(getDBValue(entryState));
87
return getDBValue (entryState);
88     }
89
90     //--------------------------------------------------------------------------
91
/**
92      * Sets the String representation of this field.
93      * This method should call preSet and postSet.
94      */

95     public void setValue (boolean value,
96                           EntrySaveRequest saveRequest)
97             throws JahiaException {
98
99         preSet ((value) ? "true" : "false", saveRequest);
100
101     }
102
103     //--------------------------------------------------------------------------
104
/**
105      * get the Value that will be added to the search engine for this field.
106      * for a bigtext it will be the content of the bigtext, for an application
107      * the string will be empty!
108      * Do not return null, return an empty string instead.
109      *
110      * @param jParams the jParam containing the loadVersion and locales
111      */

112     public String JavaDoc getValueForSearch (ParamBean jParams,
113                                      ContentObjectEntryState entryState)
114             throws JahiaException {
115         //return FormDataManager.getInstance().formDecode(getDBValue(entryState));
116
return getDBValue (entryState);
117     }
118
119     //--------------------------------------------------------------------------
120
/**
121      * This method is called when there is a workflow state change
122      * Such as staged mode -> active mode (validation), active -> inactive (for versioning)
123      * and also staged mode -> other staged mode (workflow)
124      * This method should not write/change the DBValue, the service handles that.
125      *
126      * @param fromEntryState the entry state that is currently was in the database
127      * @param toEntryState the entry state that will be written to the database
128      * @param jParams ParamBean object used to get information about the user
129      * doing the request, the current locale, etc...
130      *
131      * @return null if the entry state change wasn't an activation, otherwise it
132      * returns an object that contains the status of the activation (whether
133      * successfull, partial or failed, as well as messages describing the
134      * warnings during the activation process)
135      */

136     public ActivationTestResults changeEntryState (ContentObjectEntryState fromEntryState,
137                                                    ContentObjectEntryState toEntryState,
138                                                    ParamBean jParams,
139                                                    StateModificationContext stateModifContext)
140             throws JahiaException {
141         return new ActivationTestResults ();
142     }
143
144     //--------------------------------------------------------------------------
145
protected ActivationTestResults isContentValidForActivation (
146             Set JavaDoc languageCodes,
147             ParamBean jParams,
148             StateModificationContext stateModifContext)
149             throws JahiaException {
150         /** @todo to be implemented */
151         return new ActivationTestResults ();
152     }
153
154     //--------------------------------------------------------------------------
155
/**
156      * Is this kind of field shared (i.e. not one version for each language,
157      * but one version for every language)
158      */

159     public boolean isShared () {
160         return true;
161     }
162
163     /**
164      * This is called on all content fields to have them serialized only their
165      * specific part. The actual field metadata seriliazing is handled by the
166      * ContentField class. This method is called multiple times per field
167      * according to the workflow state, languages and versioning entries we
168      * want to serialize.
169      *
170      * @param xmlWriter the XML writer object in which to write the XML output
171      * @param xmlSerializationOptions options used to activate/bypass certain
172      * output of elements.
173      * @param entryState the ContentFieldEntryState for which to generate the
174      * XML export.
175      * @param paramBean specifies context of serialization, such as current
176      * user, current request parameters, entry load request, URL generation
177      * information such as ServerName, ServerPort, ContextPath, etc... URL
178      * generation is an important part of XML serialization and this is why
179      * we pass this parameter down, as well as user rights checking.
180      *
181      * @throws IOException in case there was an error writing to the Writer
182      * output object.
183      */

184     protected void serializeContentToXML (XmlWriter xmlWriter,
185                                           XMLSerializationOptions
186             xmlSerializationOptions,
187                                           ContentObjectEntryState entryState,
188                                           ParamBean paramBean)
189             throws java.io.IOException JavaDoc {
190         try {
191             //String result = FormDataManager.getInstance().formDecode(getDBValue(entryState));
192
String JavaDoc result = getDBValue (entryState);
193             xmlWriter.writeText (result);
194         } catch (JahiaException je) {
195             logger.debug ("Error while serializing small text field to XML : ", je);
196         }
197     }
198
199
200 }
201
Popular Tags