KickJava   Java API By Example, From Geeks To Geeks.

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


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.apache.regexp.RE;
16 import org.apache.regexp.RESyntaxException;
17 import org.jahia.data.ConnectionTypes;
18 import org.jahia.exceptions.JahiaException;
19 import org.jahia.params.ParamBean;
20 import org.jahia.params.DummyServletRequestWrapper;
21 import org.jahia.registries.ServicesRegistry;
22 import org.jahia.services.version.ActivationTestResults;
23 import org.jahia.services.version.ContentObjectEntryState;
24 import org.jahia.services.version.EntrySaveRequest;
25 import org.jahia.services.version.StateModificationContext;
26 import org.jahia.utils.xml.XMLSerializationOptions;
27 import org.jahia.utils.xml.XmlWriter;
28
29 import java.io.IOException JavaDoc;
30 import java.util.Hashtable JavaDoc;
31 import java.util.Set JavaDoc;
32 import java.util.Vector JavaDoc;
33
34 /**
35  * @author NK
36  */

37 public class ContentApplicationField extends ContentField {
38
39     private static org.apache.log4j.Logger logger =
40             org.apache.log4j.Logger.getLogger (ContentApplicationField.class);
41
42     protected ContentApplicationField (Integer JavaDoc ID,
43                                        Integer JavaDoc jahiaID,
44                                        Integer JavaDoc pageID,
45                                        Integer JavaDoc ctnid,
46                                        Integer JavaDoc fieldDefID,
47                                        Integer JavaDoc fieldType,
48                                        Integer JavaDoc connectType,
49                                        Integer JavaDoc aclID,
50                                        Vector JavaDoc activeAndStagingEntryStates,
51                                        Hashtable JavaDoc activeAndStagedDBValues) {
52         super (ID.intValue (), jahiaID.intValue (), pageID.intValue (), ctnid.intValue (),
53                 fieldDefID.intValue (),
54                 fieldType.intValue (), connectType.intValue (), aclID.intValue (),
55                 activeAndStagingEntryStates, activeAndStagedDBValues);
56     }
57
58     public static synchronized ContentApplicationField createApplication (int siteID,
59                                                                           int pageID,
60                                                                           int containerID,
61                                                                           int fieldDefID,
62                                                                           int parentAclID,
63                                                                           int aclID,
64                                                                           int appID,
65                                                                           ParamBean jParams)
66             throws JahiaException {
67         ContentApplicationField result =
68                 (ContentApplicationField) ContentField.createField (siteID, pageID,
69                         containerID, fieldDefID,
70                         ContentFieldTypes.APPLICATION,
71                         ConnectionTypes.LOCAL,
72                         parentAclID, aclID);
73         EntrySaveRequest saveRequest = new EntrySaveRequest (jParams.getUser (),
74                 ContentField.SHARED_LANGUAGE);
75
76         result.setAppID (appID, saveRequest);
77         return result;
78     }
79
80
81     /**
82      * Gets the String representation of this field. In case of an Application,
83      * it will be the output of the application, in case of a bigtext it will
84      * be the full content of the bigtext, etc. This is called by the public
85      * method getValue of ContentField, which does the entryState resolving
86      * This method should call getDBValue to get the DBValue
87      */

88     public String JavaDoc getValue (ParamBean jParams, ContentObjectEntryState entryState)
89             throws JahiaException {
90
91         logger.debug ("Loading app value...");
92
93         ServicesRegistry tmpServicesRegistry = ServicesRegistry.getInstance ();
94
95         String JavaDoc appID = getDBValue (entryState);
96         if (appID.equals ("<empty>")) {
97             return new String JavaDoc ();
98         }
99
100         String JavaDoc tmpValue = "";
101
102         if (jParams != null && jParams.getRealRequest() != null
103                 && !(jParams.getRealRequest() instanceof DummyServletRequestWrapper)) {
104             tmpValue = ServicesRegistry.getInstance ().
105                     getJahiaApplicationsDispatchingService ().
106                     getAppOutput (this.getID (), appID, jParams);
107         }
108         if (tmpValue != null) {
109             try {
110                 tmpValue = (new RE ("</?html>", RE.MATCH_CASEINDEPENDENT)).
111                         subst (tmpValue, "");
112             } catch (RESyntaxException e) {
113                 logger.debug (".getValue, exeption : " + e.toString ());
114             }
115
116             try {
117                 tmpValue = new StringBuffer JavaDoc ().append ("<html>").
118                         append (tmpValue).append ("</html>").toString ();
119             } catch (Throwable JavaDoc t) {
120                 t.printStackTrace ();
121             }
122             //tmpValue = FormDataManager.getInstance().formDecode(tmpValue);
123
} else {
124             tmpValue = new String JavaDoc ();
125         }
126         return tmpValue;
127     }
128
129     /**
130      * Sets the String representation of this field.
131      * This method should call preSet and postSet.
132      */

133     public void setAppID (int value, EntrySaveRequest saveRequest) throws JahiaException {
134         ContentObjectEntryState verInfo = preSet (String.valueOf (value), saveRequest);
135         logger.debug ("Saving application field...");
136     }
137
138     /**
139      * get the Value that will be added to the search engine for this field.
140      * for a bigtext it will be the content of the bigtext, for an application
141      * the string will be empty!
142      * Do not return null, return an empty string instead.
143      *
144      * @param jParams the jParam containing the loadVersion and locales
145      */

146     public String JavaDoc getValueForSearch (ParamBean jParams, ContentObjectEntryState entryState)
147             throws JahiaException {
148         //return FormDataManager.getInstance().formDecode(getDBValue(entryState));
149
return getDBValue (entryState);
150     }
151
152     /**
153      * This method is called when there is a workflow state change
154      * Such as staged mode -> active mode (validation), active -> inactive (for versioning)
155      * and also staged mode -> other staged mode (workflow)
156      * This method should not write/change the DBValue, the service handles that.
157      *
158      * @param fromEntryState the entry state that is currently was in the database
159      * @param toEntryState the entry state that will be written to the database
160      * @param jParams ParamBean object used to get information about the user
161      * doing the request, the current locale, etc...
162      *
163      * @return null if the entry state change wasn't an activation, otherwise it
164      * returns an object that contains the status of the activation (whether
165      * successfull, partial or failed, as well as messages describing the
166      * warnings during the activation process)
167      */

168     public ActivationTestResults changeEntryState (ContentObjectEntryState fromEntryState,
169                                                    ContentObjectEntryState toEntryState,
170                                                    ParamBean jParams,
171                                                    StateModificationContext stateModifContext)
172             throws JahiaException {
173         return new ActivationTestResults ();
174     }
175
176     protected ActivationTestResults isContentValidForActivation (
177             Set JavaDoc languageCodes,
178             ParamBean jParams,
179             StateModificationContext stateModifContext) throws JahiaException {
180         /** @todo to be implemented */
181         return new ActivationTestResults ();
182     }
183
184     //--------------------------------------------------------------------------
185
/**
186      * Is this kind of field shared (i.e. not one version for each language,
187      * but one version for every language)
188      */

189     public boolean isShared () {
190         return true;
191     }
192
193     /**
194      * This is called on all content fields to have them serialized only their
195      * specific part. The actual field metadata seriliazing is handled by the
196      * ContentField class. This method is called multiple times per field
197      * according to the workflow state, languages and versioning entries we
198      * want to serialize.
199      *
200      * @param xmlWriter the XML writer object in which to write the XML output
201      * @param xmlSerializationOptions options used to activate/bypass certain
202      * output of elements.
203      * @param entryState the ContentFieldEntryState for which to generate the
204      * XML export.
205      * @param paramBean specifies context of serialization, such as current
206      * user, current request parameters, entry load request, URL generation
207      * information such as ServerName, ServerPort, ContextPath, etc... URL
208      * generation is an important part of XML serialization and this is why
209      * we pass this parameter down, as well as user rights checking.
210      *
211      * @throws IOException in case there was an error writing to the Writer
212      * output object.
213      */

214     protected void serializeContentToXML (XmlWriter xmlWriter,
215                                           XMLSerializationOptions xmlSerializationOptions,
216                                           ContentObjectEntryState entryState,
217                                           ParamBean paramBean) throws IOException JavaDoc {
218
219         /**
220          * @todo FIXME : not yet implemented.
221          */

222         xmlWriter.writeCData ("NOT YET IMPLEMENTED");
223     }
224
225     protected boolean isEntryInitialized (ContentObjectEntryState curEntryState)
226         throws JahiaException {
227         String JavaDoc entryValue = getDBValue(curEntryState);
228         if (entryValue == null) {
229             return false;
230         }
231         if (!entryValue.equals("") &&
232             !entryValue.equals("<empty>")) {
233             return true;
234         }
235         return false;
236     }
237
238
239 }
240
Popular Tags