KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jahia > data > fields > JahiaBigTextField


1 // JahiaBigTextField
2
// YG 17.07.2001
3

4 package org.jahia.data.fields;
5
6 import java.util.Properties JavaDoc;
7
8 import org.apache.regexp.RE;
9 import org.apache.regexp.RESyntaxException;
10 import org.jahia.data.FormDataManager;
11 import org.jahia.exceptions.JahiaException;
12 import org.jahia.params.ParamBean;
13 import org.jahia.registries.ServicesRegistry;
14 import org.jahia.services.fields.ContentBigTextField;
15 import org.jahia.services.fields.ContentField;
16 import org.jahia.services.files.JahiaTextFileService;
17 import org.jahia.services.version.ContentObjectEntryState;
18 import org.jahia.services.version.EntryLoadRequest;
19 import org.jahia.services.version.EntrySaveRequest;
20 import org.jahia.utils.JahiaConsole;
21 import org.jahia.utils.JahiaTools;
22
23 public class JahiaBigTextField extends JahiaField implements JahiaAllowApplyChangeToAllLangField
24 {
25
26         /***
27         * constructor
28         * YG 17.07.2001
29         *
30         */

31     public JahiaBigTextField(Integer JavaDoc ID,
32                             Integer JavaDoc jahiaID,
33                             Integer JavaDoc pageID,
34                             Integer JavaDoc ctnid,
35                             Integer JavaDoc fieldDefID,
36                             Integer JavaDoc fieldType,
37                             Integer JavaDoc connectType,
38                             String JavaDoc fieldValue,
39                             Integer JavaDoc rank,
40                             Integer JavaDoc aclID,
41                             Integer JavaDoc versionID,
42                             Integer JavaDoc versionStatus,
43                             String JavaDoc languageCode)
44     {
45         super(ID, jahiaID, pageID, ctnid, fieldDefID, fieldType, connectType,
46               fieldValue, rank, aclID, versionID, versionStatus, languageCode);
47
48         if ( isShared() ){
49             this.languageCode = ContentField.SHARED_LANGUAGE;
50         }
51     } // end constructor
52

53     /*
54     public String getValue() {
55
56         System.out.println("------ BIG TEXT . getValue");
57
58         switch (this.getConnectType()) {
59             default :
60                 return super.getValue();
61         }
62     }
63     */

64
65     public void load(int loadFlag, ParamBean jParams)
66     throws JahiaException {
67
68         JahiaConsole.println(CLASS_NAME + ".load", "Loading big text field...");
69         ContentBigTextField contentBigTextField = (ContentBigTextField)ContentBigTextField.getField(getID());
70         JahiaConsole.println(CLASS_NAME + ".load", getValue());
71
72         String JavaDoc val = null;
73
74         if ( this.getWorkflowState() > ContentObjectEntryState.WORKFLOW_STATE_ACTIVE
75              && this.getVersionID() == EntryLoadRequest.DELETED_WORKFLOW_STATE ){
76             ContentObjectEntryState entryState =
77                     new ContentObjectEntryState(ContentObjectEntryState.WORKFLOW_STATE_START_STAGING,
78                     0,this.getLanguageCode());
79             val = contentBigTextField.getValue(entryState);
80         } else {
81             val = contentBigTextField.getValue(jParams);
82         }
83
84         this.setRawValue(val);
85
86         //this.setValue(FormDataManager.getInstance().formDecode(val));
87
this.setValue(FormDataManager.getInstance().htmlEncode(val));
88
89 // int jahiaID, int pageID, int fieldID, String defaultValue, int versionID,
90
// int workflowState, String languageCode)
91

92 // fieldValue = contentBigTextField.getValue(jParams);
93

94 /* JahiaFieldDefinition theDef = JahiaFieldDefinitionsRegistry.
95                              getInstance().getDefinition(
96                              this.getFieldDefID() );
97         int pageDefID = ServicesRegistry.getInstance().getJahiaPageService().
98                         lookupPage (this.getPageID(), jParams).
99                         getPageTemplateID();
100
101
102         if ((loadFlag & LoadFlags.BIGTEXT) != 0)
103         {
104             switch (this.getConnectType())
105             {
106                 case (ConnectionTypes.LOCAL) :
107                     this.setValue((this.getTextFileService()).loadContents(
108                         this.getJahiaID(), this.getPageID(),
109                         this.getID(), theDef.getDefaultValue(pageDefID),
110                         this.getVersionID(), this.getVersionStatus() ));
111
112                     if (!this.getValue().equals("<empty>")) {
113                         this.setRawValue(this.getValue());
114                         this.setValue(FormDataManager.getInstance().
115                             decode(this.getValue()));
116                      }
117                      break;
118                 // JB 02.08.2001 - Add HTMLEditor Types
119                 case (ConnectionTypes.HTMLEDITOR) :
120                       this.setValue((this.getTextFileService()).loadContents(
121                         this.getJahiaID(), this.getPageID(),
122                         this.getID(), theDef.getDefaultValue(pageDefID),
123                         this.getVersionID(), this.getVersionStatus() ));
124
125                     if (!this.getValue().equals("<empty>")) {
126                         this.setRawValue(this.getValue());
127                         this.setValue(FormDataManager.getInstance().
128                             decode(this.getValue()));
129                      }
130                      break;
131                 case (ConnectionTypes.HTMLEDITORAX) :
132                       this.setValue((this.getTextFileService()).loadContents(
133                         this.getJahiaID(), this.getPageID(),
134                         this.getID(), theDef.getDefaultValue(pageDefID),
135                         this.getVersionID(), this.getVersionStatus() ));
136
137                     if (!this.getValue().equals("<empty>")) {
138                         this.setRawValue(this.getValue());
139                         this.setValue(FormDataManager.getInstance().
140                             decode(this.getValue()));
141                      }
142                      break;
143                 case (ConnectionTypes.DATASOURCE) :
144                     if ((loadFlag & LoadFlags.DATASOURCE) != 0) {
145                         this.setValue( JahiaDataSourceManager.
146                             getInstance().fields().getInstance().
147                             getRemoteFieldValue( this.getValue() ) );
148                      }
149                      break;
150             }
151         }
152 */

153     }
154
155     public boolean save(ParamBean jParams)
156     throws JahiaException {
157
158       JahiaConsole.println(CLASS_NAME + ".save", "Save Big Text...");
159       ContentBigTextField contentBigTextField = (ContentBigTextField) ContentBigTextField.getField(getID());
160       EntrySaveRequest saveRequest = new EntrySaveRequest(jParams.getUser(), this.getLanguageCode());
161       contentBigTextField.setText(getValue(), saveRequest);
162
163       ServicesRegistry.getInstance().getJahiaSearchService().indexField(getID(), true, jParams, true);
164
165 /* String tmpVal = "<text>";
166         switch (this.getConnectType())
167         {
168             case (ConnectionTypes.LOCAL) :
169                 tmpVal = (this.getTextFileService()).saveContents(
170                           this.getJahiaID(),
171                           this.getPageID(),
172                           this.getID(),
173                           this.getValue(),
174                           this.getVersionID(),
175                           this.getVersionStatus() );
176                 break;
177             // JB 02.08.2001 - Add HTMLEditor Types
178             case (ConnectionTypes.HTMLEDITOR) :
179                 tmpVal = (this.getTextFileService()).saveContents(
180                           this.getJahiaID(),
181                           this.getPageID(),
182                           this.getID(),
183                           this.getValue(),
184                           this.getVersionID(),
185                           this.getVersionStatus() );
186                 break;
187             case (ConnectionTypes.HTMLEDITORAX) :
188                 tmpVal = (this.getTextFileService()).saveContents(
189                           this.getJahiaID(),
190                           this.getPageID(),
191                           this.getID(),
192                           this.getValue(),
193                           this.getVersionID(),
194                           this.getVersionStatus() );
195                 break;
196             case (ConnectionTypes.DATASOURCE) :
197                 tmpVal = this.getValue();
198                 break;
199         }*/

200       return true;
201     }
202
203     public void delete(ParamBean jParams)
204     throws JahiaException
205     {
206 /* if (this.getConnectType() == ConnectionTypes.LOCAL) {
207             //String fileName = this.getValue();
208             String fileName = (this.getTextFileService()).getFileName(
209                           this.getJahiaID(),
210                           this.getPageID(),
211                           this.getID(),
212                           this.getVersionID(),
213                           this.getVersionStatus() );
214
215             FileUtils.getInstance().deleteFile( fileName );
216         }
217
218         // JB 02.08.2001 - Add HTMLEditor Types
219         if (this.getConnectType() == ConnectionTypes.HTMLEDITOR) {
220             String fileName = (this.getTextFileService()).getFileName(
221                           this.getJahiaID(),
222                           this.getPageID(),
223                           this.getID(),
224                           this.getVersionID(),
225                           this.getVersionStatus() );
226
227             FileUtils.getInstance().deleteFile( fileName );
228         }
229         if (this.getConnectType() == ConnectionTypes.HTMLEDITORAX) {
230             String fileName = (this.getTextFileService()).getFileName(
231                           this.getJahiaID(),
232                           this.getPageID(),
233                           this.getID(),
234                           this.getVersionID(),
235                           this.getVersionStatus() );
236
237             FileUtils.getInstance().deleteFile( fileName );
238         }
239 */

240     }
241
242     public String JavaDoc getEngineName()
243     {
244         return "org.jahia.engines.shared.BigText_Field";
245     }
246
247     public String JavaDoc getFieldContent4Ranking()
248     {
249         String JavaDoc fieldInfo = this.getValue();
250         fieldInfo = JahiaTools.html2text(fieldInfo);
251         try {
252             fieldInfo = (new RE("<(.*?)>")).subst(fieldInfo,"");
253         } catch (RESyntaxException re) {
254             JahiaConsole.println("JahiaBigTextField.getFieldContent4Ranking",re.toString());
255         } catch (Throwable JavaDoc t) {
256             JahiaConsole.println("JahiaBigTextField.getFieldContent4Ranking",t.toString());
257         }
258
259         if (fieldInfo.length() > 30)
260         {
261             fieldInfo = fieldInfo.substring(0,30) +" ...";
262         }
263
264         fieldInfo = JahiaTools.text2html(fieldInfo);
265         return fieldInfo;
266     }
267
268     public String JavaDoc getIconNameOff()
269     {
270         return "bigtext";
271     }
272
273     public String JavaDoc getIconNameOn()
274     {
275         return "bigtext_on";
276     }
277
278     public JahiaField cloneField(int newctnid, int newPageID, int clonedAclID, boolean childrenCloned)
279     throws JahiaException
280     {
281         JahiaField clonedField = ServicesRegistry.getInstance().getJahiaFieldService().
282                                  createJahiaField(0, this.getJahiaID(),
283                                  newPageID, newctnid,
284                                  this.getFieldDefID(), this.getType(),
285                                  this.getConnectType(),
286                                  this.getValue(), this.getRank(),
287                                  clonedAclID, this.getVersionID(), this.getWorkflowState(),
288                                  this.getLanguageCode());
289
290         //toDebug("cloneField(): value = "+this.getValue());
291
if (clonedField == null)
292         {
293             throw new JahiaException ("Could not clone field.",
294                 "Could not instanciate a new JahiaField object.",
295                 JahiaException.PAGE_ERROR, JahiaException.CRITICAL_SEVERITY);
296         }
297
298         clonedField.setRawValue(this.getRawValue());
299         clonedField.setObject( this.getObject() );
300         clonedField.setProperties( (Properties JavaDoc)(this.getProperties()).clone() );
301
302         return clonedField;
303     }
304
305     public Object JavaDoc clone()
306     {
307         Object JavaDoc objItem = this.getObject();
308         JahiaBigTextField bt = new JahiaBigTextField (new Integer JavaDoc(ID), new Integer JavaDoc(jahiaID),
309                                         new Integer JavaDoc(pageID),
310                                         new Integer JavaDoc(ctnid),
311                                         new Integer JavaDoc(fieldDefID),
312                                         new Integer JavaDoc(fieldType),
313                                         new Integer JavaDoc(connectType),
314                                         fieldValue, new Integer JavaDoc(rank),
315                                         new Integer JavaDoc(aclID),
316                                         new Integer JavaDoc(versionID),
317                                         new Integer JavaDoc(workflowState),
318                                         new String JavaDoc(getLanguageCode()));
319         bt.setObject(objItem);
320         return bt;
321     }
322
323     /**
324     * Method getTextFileService
325     * @author NK
326     * @return a JahiaTextFileService instance
327     */

328    private JahiaTextFileService getTextFileService(){
329
330       return ServicesRegistry.getInstance().getJahiaTextFileService();
331    }
332
333    private final String JavaDoc CLASS_NAME = this.getClass().getName();
334
335     /**
336      * Is this kind of field shared (i.e. not one version for each language, but one version for every language)
337      */

338     public boolean isShared (){
339         return false;
340     }
341
342     /**
343      * Copy the internal value of current language to another language.
344      * Must be implemented by conctrete field for specific implementation.
345      *
346      * @param aField A same field in another language
347      */

348     public void copyValueInAnotherLanguage (JahiaField aField,ParamBean jParams)
349     throws JahiaException {
350         if ( aField == null ){
351             return;
352         }
353         aField.setValue(this.getValue());
354         aField.setRawValue(this.getValue());
355         aField.setObject(this.getObject());
356     }
357
358 }
359
Popular Tags