KickJava   Java API By Example, From Geeks To Geeks.

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


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 ContentIntegerField extends ContentField implements ContentSimpleField {
30     private static org.apache.log4j.Logger logger
31             = org.apache.log4j.Logger.getLogger (ContentIntegerField.class);
32
33     protected ContentIntegerField (Integer JavaDoc ID,
34                                    Integer JavaDoc jahiaID,
35                                    Integer JavaDoc pageID,
36                                    Integer JavaDoc ctnid,
37                                    Integer JavaDoc fieldDefID,
38                                    Integer JavaDoc fieldType,
39                                    Integer JavaDoc connectType,
40                                    Integer JavaDoc aclID,
41                                    Vector JavaDoc activeAndStagingEntryStates,
42                                    Hashtable JavaDoc activeAndStagedDBValues) {
43         super (ID.intValue (), jahiaID.intValue (), pageID.intValue (), ctnid.intValue (), fieldDefID.intValue (),
44                 fieldType.intValue (), connectType.intValue (), aclID.intValue (), activeAndStagingEntryStates,
45                 activeAndStagedDBValues);
46     }
47
48     public static synchronized ContentIntegerField createInteger (int siteID,
49                                                                   int pageID, int containerID,
50                                                                   int fieldDefID,
51                                                                   int parentAclID, int aclID,
52                                                                   int value, ParamBean jParams)
53             throws JahiaException {
54         ContentIntegerField result =
55                 (ContentIntegerField) ContentField.createField (siteID, pageID,
56                         containerID, fieldDefID,
57                         ContentFieldTypes.INTEGER,
58                         ConnectionTypes.LOCAL,
59                         parentAclID, aclID);
60         EntrySaveRequest saveRequest = new EntrySaveRequest (jParams.getUser (),
61                 ContentField.SHARED_LANGUAGE);
62
63         result.setInteger (value, saveRequest);
64         return result;
65     }
66
67
68     /**
69      * Gets the String representation of this field. In case of an Application,
70      * it will be the output of the application, in case of a bigtext it will
71      * be the full content of the bigtext, etc. This is called by the public
72      * method getValue of ContentField, which does the entryState resolving
73      * This method should call getDBValue to get the DBValue
74      */

75     public String JavaDoc getValue (ParamBean jParams, ContentObjectEntryState entryState)
76             throws JahiaException {
77         //return FormDataManager.getInstance().formDecode(getDBValue(entryState));
78
return getDBValue (entryState);
79     }
80
81     /**
82      * Sets the String representation of this field.
83      * This method should call preSet and postSet.
84      */

85     public void setInteger (int value, EntrySaveRequest saveRequest) throws JahiaException {
86         preSet (String.valueOf (value), saveRequest);
87     }
88
89     /**
90      * get the Value that will be added to the search engine for this field.
91      * for a bigtext it will be the content of the bigtext, for an application
92      * the string will be empty!
93      * Do not return null, return an empty string instead.
94      *
95      * @param jParams the jParam containing the loadVersion and locales
96      */

97     public String JavaDoc getValueForSearch (ParamBean jParams, ContentObjectEntryState entryState)
98             throws JahiaException {
99         //return FormDataManager.getInstance().formDecode(getDBValue(entryState));
100
return getDBValue (entryState);
101     }
102
103     /**
104      * This method is called when there is a workflow state change
105      * Such as staged mode -> active mode (validation), active -> inactive (for versioning)
106      * and also staged mode -> other staged mode (workflow)
107      * This method should not write/change the DBValue, the service handles that.
108      *
109      * @param fromEntryState the entry state that is currently was in the database
110      * @param toEntryState the entry state that will be written to the database
111      * @param jParams ParamBean object used to get information about the user
112      * doing the request, the current locale, etc...
113      *
114      * @return null if the entry state change wasn't an activation, otherwise it
115      * returns an object that contains the status of the activation (whether
116      * successfull, partial or failed, as well as messages describing the
117      * warnings during the activation process)
118      */

119     public ActivationTestResults changeEntryState (ContentObjectEntryState fromEntryState,
120                                                    ContentObjectEntryState toEntryState,
121                                                    ParamBean jParams,
122                                                    StateModificationContext stateModifContext)
123             throws JahiaException {
124         return new ActivationTestResults ();
125     }
126
127     protected ActivationTestResults isContentValidForActivation (
128             Set JavaDoc languageCodes,
129             ParamBean jParams,
130             StateModificationContext stateModifContext) throws JahiaException {
131         /** @todo to be implemented */
132         return new ActivationTestResults ();
133     }
134
135     /**
136      * Is this kind of field shared (i.e. not one version for each language, but one version for every language)
137      */

138     public boolean isShared () {
139         return true;
140     }
141
142     /**
143      * This is called on all content fields to have them serialized only their
144      * specific part. The actual field metadata seriliazing is handled by the
145      * ContentField class. This method is called multiple times per field
146      * according to the workflow state, languages and versioning entries we
147      * want to serialize.
148      *
149      * @param xmlWriter the XML writer object in which to write the XML output
150      * @param xmlSerializationOptions options used to activate/bypass certain
151      * output of elements.
152      * @param entryState the ContentFieldEntryState for which to generate the
153      * XML export.
154      * @param paramBean specifies context of serialization, such as current
155      * user, current request parameters, entry load request, URL generation
156      * information such as ServerName, ServerPort, ContextPath, etc... URL
157      * generation is an important part of XML serialization and this is why
158      * we pass this parameter down, as well as user rights checking.
159      *
160      * @throws IOException in case there was an error writing to the Writer
161      * output object.
162      */

163     protected void serializeContentToXML (XmlWriter xmlWriter,
164                                           XMLSerializationOptions xmlSerializationOptions,
165                                           ContentObjectEntryState entryState,
166                                           ParamBean paramBean) throws java.io.IOException JavaDoc {
167         try {
168             //String result = FormDataManager.getInstance().formDecode(getDBValue(entryState));
169
String JavaDoc result = getDBValue (entryState);
170             xmlWriter.writeText (result);
171         } catch (JahiaException je) {
172             logger.debug ("Error while serializing small text field to XML : ", je);
173         }
174     }
175
176 }
177
Popular Tags