KickJava   Java API By Example, From Geeks To Geeks.

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


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 //
14
// FieldServices
15
// EV 31.10.2000
16
// FH 28.12.2000 Changed interface to abstract class
17
// DJ 05.01.2001 Changed almost everything
18
//
19

20 package org.jahia.services.fields;
21
22 import org.jahia.data.JahiaDOMObject;
23 import org.jahia.data.JahiaData;
24 import org.jahia.data.fields.JahiaField;
25 import org.jahia.data.fields.JahiaFieldDefinition;
26 import org.jahia.data.fields.JahiaFieldSet;
27 import org.jahia.exceptions.JahiaException;
28 import org.jahia.params.ParamBean;
29 import org.jahia.services.JahiaService;
30 import org.jahia.services.usermanager.JahiaUser;
31 import org.jahia.services.version.ActivationTestResults;
32 import org.jahia.services.version.EntryLoadRequest;
33 import org.jahia.services.version.JahiaSaveVersion;
34 import org.jahia.services.version.StateModificationContext;
35 import org.jahia.utils.xml.XMLSerializationOptions;
36 import org.jahia.utils.xml.XmlWriter;
37
38 import java.io.IOException JavaDoc;
39 import java.util.Map JavaDoc;
40 import java.util.Set JavaDoc;
41 import java.util.SortedSet JavaDoc;
42 import java.util.Vector JavaDoc;
43
44 public abstract class JahiaFieldService extends JahiaService {
45
46     /**
47      * create a JahiaField.
48      * The only method to instanciate a new JahiaField
49      * It call the constructor corresponding to the field type.
50      *
51      * @param ID
52      * @param jahiaID
53      * @param pageID
54      * @param ctnid
55      * @param fieldDefID
56      * @param fieldType
57      * @param connectType
58      * @param fieldValue
59      * @param rank
60      * @param aclID
61      * @param versionID
62      * @param workflowState
63      * @param languageCode
64      *
65      * @return
66      *
67      * @throws JahiaException
68      */

69     public abstract JahiaField createJahiaField (int ID,
70                                                  int jahiaID,
71                                                  int pageID,
72                                                  int ctnid,
73                                                  int fieldDefID,
74                                                  int fieldType,
75                                                  int connectType,
76                                                  String JavaDoc fieldValue,
77                                                  int rank,
78                                                  int aclID,
79                                                  int versionID,
80                                                  int workflowState,
81                                                  String JavaDoc languageCode)
82         throws JahiaException;
83
84     public abstract JahiaField createJahiaField (int ID,
85                                                  int jahiaID,
86                                                  int pageID,
87                                                  int ctnid,
88                                                  int fieldDefID,
89                                                  int fieldType,
90                                                  int connectType,
91                                                  String JavaDoc fieldValue,
92                                                  int rank,
93                                                  int aclID)
94         throws JahiaException;
95
96     /**
97      * clone page field
98      *
99      * @param fieldID the field to clone.
100      * @param newPageID The Id of the new page to which the cloned field must
101      * belong to.
102      */

103     public abstract void cloneField (int fieldID, int newPageID,
104                                      int parentAclID,
105                                      ParamBean jParams)
106         throws JahiaException;
107
108     /**
109      * clone page field
110      *
111      * @param fieldID the field to clone.
112      * @param newctnid the id of the container which contains the field
113      * equal 0 if the field is in a page.
114      * @param newPageID The Id of the new page to which the cloned field must
115      * belong to.
116      */

117     public abstract JahiaField cloneField (JahiaField theField, int newctnid,
118                                            int newPageID,
119                                            int parentAclID,
120                                            boolean childrenCloned)
121         throws JahiaException;
122
123     /**
124      * Builds the field structure for the specified page
125      *
126      * @param jData JahiaData
127      *
128      * @return a JahiaFieldSet object
129      */

130     public abstract JahiaFieldSet buildFieldStructureForPage (JahiaData jData,
131         EntryLoadRequest loadVersion)
132         throws JahiaException;
133
134     /**
135      * Gets all field IDs in a page (from page ID)
136      *
137      * @param pageID the page ID
138      *
139      * @return a Vector of Field list IDs
140      */

141     public abstract Vector JavaDoc getNonContainerFieldIDsInPage (int pageID)
142         throws JahiaException;
143
144     /**
145      * Gets all field IDs in a page in a specified workflow state
146      *
147      * @param pageID the page ID.
148      * @param loadVersion the workflow state field to load.
149      *
150      * @return A Vector of Integer corresponding to the field IDs.
151      */

152     public abstract Vector JavaDoc getNonContainerFieldIDsInPageByWorkflowState (int
153         pageID,
154         EntryLoadRequest loadVersion)
155         throws JahiaException;
156
157     /**
158      * Retrieves all the ContentFieldEntryStates for the fields on a page that
159      * are *NOT* contained in a container (ie directly attached to the page).
160      *
161      * @param pageID the identifier of the page for which to retrieve the
162      * field entry states
163      *
164      * @return a SortedSet of ContentFieldEntryState objects that contain the
165      * cumulation of all the field's entrystates.
166      *
167      * @throws JahiaException thrown if there was a problem retrieving field
168      * data from the database.
169      */

170     public abstract SortedSet JavaDoc getNonContainerFieldEntryStateInPage (int pageID)
171         throws JahiaException;
172
173     /**
174      * Given a page ID, get all the IDs of the page links contained in
175      * the page, whether of type DIRECT, INTERNAL or URL
176      *
177      * @param pageID the page ID
178      *
179      * @return a Vector of Field list IDs
180      */

181     public abstract Vector JavaDoc getPagefieldIDsInPage (int pageID)
182         throws JahiaException;
183
184     /**
185      * Gets a field ID from its name and page id
186      *
187      * @param fieldName the field name
188      * @param pageID the page ID
189      *
190      * @return a field id
191      */

192     public abstract int getFieldID (String JavaDoc fieldName, int pageID)
193         throws JahiaException;
194
195     /**
196      * Get all the fields ID (for the search engine)
197      *
198      * @return a Vector of field ids
199      */

200     public abstract Vector JavaDoc getAllFieldIDs ()
201         throws JahiaException;
202
203     /**
204      * Get all the fields ID for a gived site (for the search engine)
205      *
206      * @return a Vector of field ids
207      *
208      * @param int the site id
209      */

210     public abstract Vector JavaDoc getAllFieldIDs (int siteID)
211         throws JahiaException;
212
213     /**
214      * gets all the field definition ids
215      * to be changed, using a fielddefinition cache instead and changing the def registry.
216      *
217      * @return a Vector of field definition ids
218      */

219     public abstract Vector JavaDoc getAllFieldDefinitionIDs ()
220         throws JahiaException;
221
222     /***
223          * loads a field from the database, no other info than what's in the database<br>
224      * NO RIGHTS CHECK!
225      *
226      * @param fieldID the field ID
227      * @return a JahiaField object
228      * @see org.jahia.data.fields.JahiaField
229      *
230      */

231     /*
232       public abstract JahiaField loadFieldInfo( int fieldID )
233      throws JahiaException;
234       public abstract JahiaField loadFieldInfo( int fieldID, EntryLoadRequest loadVersion )
235      throws JahiaException;
236      */

237
238     /**
239      * loads a field from the database, according to the loadflags.
240      * Checks user's rights.
241      *
242      * @param fieldID the field ID
243      * @param loadFlag the load flags
244      *
245      * @return a JahiaField object
246      *
247      * @see org.jahia.data.fields.JahiaField
248      * @see org.jahia.data.fields.LoadFlags
249      */

250     public abstract JahiaField loadField (int fieldID, int loadFlag)
251         throws JahiaException;
252
253     /**
254      * loads a field from the database, with all values.
255      * Checks user's rights.
256      *
257      * @param fieldID the field ID
258      * @param jParams the ParamBean object with request and response
259      *
260      * @return a JahiaField object
261      *
262      * @see org.jahia.data.fields.JahiaField
263      * @see org.jahia.data.fields.LoadFlags
264      */

265     public abstract JahiaField loadField (int fieldID, ParamBean jParams)
266         throws JahiaException;
267
268     /**
269      * loads a field, and accept loadFlag and ParamBean <br>
270      * uses loadField ( int fieldID ) method to access cache/database.
271      * Checks user's rights.
272      *
273      * @param fieldID the field ID
274      * @param loadFlag the load flags
275      * @param jParam ParamBean
276      *
277      * @return a JahiaField object
278      */

279     public abstract JahiaField loadField (int fieldID, int loadFlag,
280                                           ParamBean jParams)
281         throws JahiaException;
282
283     public abstract JahiaField loadField (int fieldID, int loadFlag,
284                                           ParamBean jParams,
285                                           EntryLoadRequest loadVersion)
286         throws JahiaException;
287
288     /***
289      * saves a field<br>
290      * NO RIGHTS CHECK!
291      *
292      * @param theField the JahiaField to save
293      * @param parentAclID the Acl parent ID
294      *
295      */

296 // public abstract void saveField( JahiaField theField, int parentAclID )
297
// throws JahiaException;
298

299     /**
300      * saves a field if the user has the correct rights.
301      * Check user's rights
302      *
303      * @param theField the JahiaField to save
304      * @param parentAclID the Acl parent ID
305      * @param jParam ParamBean
306      */

307     public abstract void saveField (JahiaField theField, int parentAclID,
308                                     ParamBean jParams)
309         throws JahiaException;
310
311     /**
312      * deletes a field
313      *
314      * @param theField the JahiaField to delete
315      */

316     public abstract void deleteField (int fieldID, ParamBean jParams)
317         throws JahiaException;
318
319     /**
320      * Validates staged fields from a page, if the user has write+admin access to the fields
321      */

322     public abstract ActivationTestResults activateStagedFields (
323         Set languageCodes,
324         int pageID,
325         JahiaUser user, JahiaSaveVersion saveVersion,
326         ParamBean jParams, StateModificationContext stateModifContext)
327         throws JahiaException;
328
329     /**
330      * Marks all the fields in a page for deletion in a given set of languages
331      *
332      * @param pageID the page for which to mark fields for deletion
333      * @param user the user performing the operation
334      * @param languageCode the language to mark for deletion
335      * @param stateModifContext used to detect loops in deletion marking.
336      *
337      * @throws JahiaException thrown in case there are problems communicating
338      * with the persistant store.
339      */

340     public abstract void markPageFieldsLanguageForDeletion (int pageID,
341         JahiaUser user,
342         String JavaDoc languageCode,
343         StateModificationContext
344         stateModifContext)
345         throws JahiaException;
346
347     /**
348      * Tests fields to know if they are ready for an activation process,
349          * generating either warnings (such as a depending page not being validated)
350      * or errors (such as a mandatory language missing)
351      *
352      * @param pageID
353      * @param user
354      * @param saveVersion
355      * @param jParams
356      * @param withSubPages
357      *
358      * @return
359      *
360      * @throws JahiaException
361      */

362     public abstract ActivationTestResults areFieldsValidForActivation (
363         Set languageCodes,
364         int pageID,
365         JahiaUser user,
366         JahiaSaveVersion saveVersion,
367         ParamBean jParams,
368         StateModificationContext stateModifContext)
369         throws JahiaException;
370
371     /**
372      * Tests non container fields to know if they are ready for an activation
373      * process, generating either warnings (such as a depending page not being
374      * validated) or errors (such as a mandatory language missing). Non
375      * container fields are fields that are directly attached to a page and
376      * aren't contained in any container.
377      *
378      * @param pageID
379      * @param user
380      * @param saveVersion
381      * @param jParams
382      * @param withSubPages
383      *
384      * @return
385      *
386      * @throws JahiaException
387      */

388     public abstract ActivationTestResults
389         areNonContainerFieldsValidForActivation (
390         Set languageCodes,
391         int pageID,
392         JahiaUser user,
393         JahiaSaveVersion saveVersion,
394         ParamBean jParams,
395         StateModificationContext stateModifContext)
396         throws JahiaException;
397
398     /**
399      * Returns the staging workflow state of the fields for all the languages
400      * on the specified page.
401      * Normally as currently we only do state changes on a page basis these
402          * should all be equal. This does not retrieve the state of absolute fields.
403      *
404      * @param pageID the page id on which to retrieve the fields workflow state
405      *
406      * @return a Map that contains all the states of the languages for the
407      * fields on the page (for the moment we assume all the objects are in the
408      * same state)
409      *
410      * @throws JahiaException in the case we couldn't load a field.
411      */

412     public abstract Map JavaDoc getFieldsLanguagesState (int pageID)
413         throws JahiaException;
414
415     /**
416      * Sets the workflow state for all the field in a page for a given set
417      * of languages.
418      *
419          * @param languageCodes the set of language for which to change the state
420      * in the fields
421      * @param newWorkflowState the new workflow state for the fields
422      * @param pageID the page on which
423      * @param jParams a ParamBean used by the individual fields to change their
424      * state
425          * @param withSubPages specifies whether this operation should propagate
426          * to the child pages through the content page field.
427      *
428      * @throws JahiaException in the case there were problems communicating
429      * with the persistant storage system
430      */

431     public abstract void setFieldsLanguageStates (
432         Set languageCodes,
433         int newWorkflowState,
434         int pageID,
435         ParamBean jParams,
436         StateModificationContext stateModifContext)
437         throws JahiaException;
438
439     /**
440      * Loads a Field Definition by its id
441      *
442      * @param defID the field definition id
443      *
444      * @return a JahiaFieldDefinition object
445      *
446      * @see org.jahia.data.fields.JahiaFieldDefinition
447      */

448     public abstract JahiaFieldDefinition loadFieldDefinition (int defID)
449         throws JahiaException;
450
451     /**
452      * Load a field definition by it's siteID and definition name
453      *
454      * @param siteID the identifier for the site for which to load the
455      * definition
456      * @param definitionName the unique identifier name for the definition on
457      * the site
458      *
459      * @return a valid JahiaFieldDefinition object if found in the database.
460      *
461      * @throws JahiaException if there was a problem communicating with the
462      * database.
463      */

464     public abstract JahiaFieldDefinition loadFieldDefinition (int siteID,
465         String JavaDoc definitionName)
466         throws JahiaException;
467
468     /**
469      * Saves a Field Definition
470      *
471      * @param theDef the JahiaFieldDefinition object to save
472      *
473      * @see org.jahia.data.fields.JahiaFieldDefinition
474      */

475     public abstract void saveFieldDefinition (JahiaFieldDefinition theDef)
476         throws JahiaException;
477
478     /**
479      * Delete a Field Definition and it's sub definition.
480      *
481      * @param int the field def ID
482      */

483     public abstract void deleteFieldDefinition (int fieldDefID)
484         throws JahiaException;
485
486     //--------------------------------------------------------------------------
487
/**
488      * returns a DOM representation of all fields of a site
489      *
490      * @param int siteID
491      *
492      * @auhtor NK
493      */

494     public abstract JahiaDOMObject getFieldsAsDOM (int siteID)
495         throws JahiaException;
496
497     //--------------------------------------------------------------------------
498
/**
499      * returns a DOM representation of all field def of a site
500      *
501      * @param int siteID
502      *
503      * @auhtor NK
504      */

505     public abstract JahiaDOMObject getFieldDefsAsDOM (int siteID)
506         throws JahiaException;
507
508     //--------------------------------------------------------------------------
509
/**
510      * returns a DOM representation of all field def props of a site
511      *
512      * @param int siteID
513      *
514      * @auhtor NK
515      */

516     public abstract JahiaDOMObject getFieldDefPropsAsDOM (int siteID)
517         throws JahiaException;
518
519     //--------------------------------------------------------------------------
520
/**
521      * Returns a vector of all Acl ID used by fields for a site
522      * Need this for site extraction
523      *
524      * @param int siteID
525      *
526      * @auhtor NK
527      */

528     public abstract Vector JavaDoc getAclIDs (int siteID)
529         throws JahiaException;
530
531     /**
532      * Serializes in XML format all the fields on a page that are not within
533      * containers.
534      *
535      * @param xmlWriter the XML writer in which we ouput the XML
536      * @param xmlSerializationOptions the options that allow us to modify the
537      * behavior of the XML output.
538      * @param pageID the page ID for which to serialize the non container
539      * fields.
540      * @param paramBean specifies context of serialization, such as current
541      * user, current request parameters, entry load request, URL generation
542      * information such as ServerName, ServerPort, ContextPath, etc... URL
543      * generation is an important part of XML serialization and this is why
544      * we pass this parameter down, as well as user rights checking.
545      *
546      * @throws IOException occurs if there was an error writing to the
547      * XML writer.
548      */

549     public abstract void serializeNonContainerFieldsToXML (XmlWriter xmlWriter,
550         XMLSerializationOptions xmlSerializationOptions, int pageID,
551         ParamBean paramBean)
552         throws IOException JavaDoc;
553
554     /**
555      * Compose the file absolute path to a flat file containing the default value for a field definition.
556      *
557      * @param siteID
558      * @param name
559      *
560      * @return
561      */

562     public abstract String JavaDoc composeFieldDefDefaultValueFilePath (int siteID,
563         String JavaDoc name);
564
565     /**
566          * Purge all the fields on a given page, including all their versions, their
567      * subcontent, everything !
568      *
569      * @param pageID the page id for which to remove all the fields directly
570      * attached to the page.
571      *
572      * @throws JahiaException in the case where there was an error while
573      * removing all the content.
574      */

575     public abstract void purgePageFields (int pageID)
576         throws JahiaException;
577
578     /**
579      * Creates a JahiaField from a Content field.
580      *
581      * @param contentField the content field source
582      *
583      * @return a JahiaField corresponding to the language, workflow state and
584          * eventually version ID specified in the EntryLoadRequest object inside
585      * the ParamBean object.
586      *
587      * @throws JahiaException in case we have trouble loading or accessing the
588      * entry state of the content field.
589      */

590     public abstract JahiaField contentFieldToJahiaField (
591         ContentField contentField,
592         EntryLoadRequest entryLoadRequest)
593         throws JahiaException;
594
595     /**
596      * Invalidates a JahiaField cache entry.
597      * @param fieldID the identifier for the field entry to invalidate in the
598      * cache.
599      */

600     public abstract void invalidateCacheField (int fieldID);
601
602     /**
603      * reset the page preloaded fields status , so that the preloading operation
604      * can be performed again the next page access
605      *
606      * @param pageId int
607      */

608     public abstract void allowFieldsPreloadingForPage(int pageId);
609
610 } // end JahiaFieldServices
611
Popular Tags