KickJava   Java API By Example, From Geeks To Geeks.

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


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.io.IOException JavaDoc;
26 import java.util.Hashtable JavaDoc;
27 import java.util.Set JavaDoc;
28 import java.util.Vector JavaDoc;
29
30 public class ContentSmallTextField extends ContentField implements ContentSimpleField {
31     private static org.apache.log4j.Logger logger
32             = org.apache.log4j.Logger.getLogger (ContentSmallTextField.class);
33
34
35     protected ContentSmallTextField (Integer JavaDoc ID,
36                                      Integer JavaDoc jahiaID,
37                                      Integer JavaDoc pageID,
38                                      Integer JavaDoc ctnid,
39                                      Integer JavaDoc fieldDefID,
40                                      Integer JavaDoc fieldType,
41                                      Integer JavaDoc connectType,
42                                      Integer JavaDoc aclID,
43                                      Vector JavaDoc activeAndStagingEntryStates,
44                                      Hashtable JavaDoc activeAndStagedDBValues) {
45         super (ID.intValue (), jahiaID.intValue (), pageID.intValue (), ctnid.intValue (), fieldDefID.intValue (),
46                 fieldType.intValue (), connectType.intValue (), aclID.intValue (), activeAndStagingEntryStates,
47                 activeAndStagedDBValues);
48     }
49
50     public static synchronized ContentSmallTextField createSmallText (int siteID,
51                                                                       int pageID,
52                                                                       int containerID,
53                                                                       int fieldDefID,
54                                                                       int parentAclID,
55                                                                       int aclID,
56                                                                       String JavaDoc text,
57                                                                       ParamBean jParams)
58             throws JahiaException {
59         ContentSmallTextField result =
60                 (ContentSmallTextField) ContentField.createField (siteID, pageID,
61                         containerID, fieldDefID,
62                         ContentFieldTypes.SMALLTEXT,
63                         ConnectionTypes.LOCAL,
64                         parentAclID, aclID);
65         EntrySaveRequest saveRequest = new EntrySaveRequest (jParams.getUser (),
66                 jParams.getLocale ().toString ());
67
68         result.setText (text, saveRequest);
69         return result;
70     }
71
72     /**
73      * Gets the String representation of this field. In case of an Application,
74      * it will be the output of the application, in case of a bigtext it will
75      * be the full content of the bigtext, etc. This is called by the public
76      * method getValue of ContentField, which does the entry resolving
77      * This method should call getDBValue to get the DBValue
78      * Note that until setField() is called, getValue returns always the
79      * same value, even if the content was set by a setter such as setText!!
80      */

81     public String JavaDoc getValue (ParamBean jParams, ContentObjectEntryState entryState)
82             throws JahiaException {
83         if (entryState == null) {
84             return "";
85         }
86         String JavaDoc result = this.getDBValue (entryState);
87
88         if (result == null || result.equals ("<empty>")) {
89             result = new String JavaDoc ();
90         }
91         return result;
92     }
93
94     /**
95      * Sets the String representation of this field.
96      * This method should call preSet and postSet.
97      */

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

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

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

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

176     protected void serializeContentToXML (XmlWriter xmlWriter,
177                                           XMLSerializationOptions xmlSerializationOptions,
178                                           ContentObjectEntryState entryState,
179                                           ParamBean paramBean) throws IOException JavaDoc {
180         try {
181             //String result = FormDataManager.getInstance().formDecode(getDBValue(entryState));
182
String JavaDoc result = getDBValue (entryState);
183             xmlWriter.writeCData (result);
184         } catch (JahiaException je) {
185             logger.debug ("Error while serializing small text field to XML : ", je);
186         }
187     }
188
189 }
190
Popular Tags