KickJava   Java API By Example, From Geeks To Geeks.

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


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

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

99     public void setText (String JavaDoc value, EntrySaveRequest saveRequest) throws JahiaException {
100         if (!ContentField.SHARED_LANGUAGE.equals (saveRequest.getLanguageCode ())) {
101             logger.debug ("Found non shared language in setting, enforcing shared language...");
102             saveRequest.setLanguageCode (ContentField.SHARED_LANGUAGE);
103         }
104         preSet (value, saveRequest);
105     }
106
107     /**
108      * get the Value that will be added to the search engine for this field.
109      * for a bigtext it will be the content of the bigtext, for an application
110      * the string will be empty!
111      * Do not return null, return an empty string instead.
112      *
113      * @param jParams the jParam containing the loadVersion and locales
114      */

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

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

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

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