KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > opencms > jsp > CmsJspTagContentLoad


1 /*
2  * File : $Source: /usr/local/cvs/opencms/src/org/opencms/jsp/CmsJspTagContentLoad.java,v $
3  * Date : $Date: 2006/10/26 12:25:35 $
4  * Version: $Revision: 1.33 $
5  *
6  * This library is part of OpenCms -
7  * the Open Source Content Mananagement System
8  *
9  * Copyright (c) 2005 Alkacon Software GmbH (http://www.alkacon.com)
10  *
11  * This library is free software; you can redistribute it and/or
12  * modify it under the terms of the GNU Lesser General Public
13  * License as published by the Free Software Foundation; either
14  * version 2.1 of the License, or (at your option) any later version.
15  *
16  * This library is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19  * Lesser General Public License for more details.
20  *
21  * For further information about Alkacon Software GmbH, please see the
22  * company website: http://www.alkacon.com
23  *
24  * For further information about OpenCms, please see the
25  * project website: http://www.opencms.org
26  *
27  * You should have received a copy of the GNU Lesser General Public
28  * License along with this library; if not, write to the Free Software
29  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
30  */

31
32 package org.opencms.jsp;
33
34 import org.opencms.file.CmsFile;
35 import org.opencms.file.CmsObject;
36 import org.opencms.file.CmsResource;
37 import org.opencms.file.CmsResourceFilter;
38 import org.opencms.file.collectors.I_CmsResourceCollector;
39 import org.opencms.flex.CmsFlexController;
40 import org.opencms.i18n.CmsEncoder;
41 import org.opencms.i18n.CmsLocaleManager;
42 import org.opencms.main.CmsException;
43 import org.opencms.main.CmsIllegalArgumentException;
44 import org.opencms.main.OpenCms;
45 import org.opencms.util.CmsMacroResolver;
46 import org.opencms.util.CmsStringUtil;
47 import org.opencms.workplace.editors.directedit.CmsDirectEditButtonSelection;
48 import org.opencms.workplace.editors.directedit.CmsDirectEditMode;
49 import org.opencms.workplace.editors.directedit.CmsDirectEditParams;
50 import org.opencms.xml.I_CmsXmlDocument;
51 import org.opencms.xml.content.CmsXmlContentFactory;
52
53 import java.util.Iterator JavaDoc;
54 import java.util.List JavaDoc;
55 import java.util.Locale JavaDoc;
56
57 import javax.servlet.jsp.JspException JavaDoc;
58 import javax.servlet.jsp.PageContext JavaDoc;
59 import javax.servlet.jsp.tagext.BodyTagSupport JavaDoc;
60 import javax.servlet.jsp.tagext.Tag JavaDoc;
61
62 /**
63  * Implementation of the <code>&lt;cms:contentload/&gt;</code> tag,
64  * used to access and display XML content item information from the VFS.<p>
65  *
66  * @author Alexander Kandzior
67  *
68  * @version $Revision: 1.33 $
69  *
70  * @since 6.0.0
71  */

72 public class CmsJspTagContentLoad extends BodyTagSupport JavaDoc implements I_CmsXmlContentContainer {
73
74     /** Serial version UID required for safe serialization. */
75     private static final long serialVersionUID = 981176995635225294L;
76
77     /** The CmsObject for the current user. */
78     private CmsObject m_cms;
79
80     /** The name of the collector to use for list building. */
81     private String JavaDoc m_collector;
82
83     /** The name of the content collector used. */
84     private String JavaDoc m_collectorName;
85
86     /** The parameters of the content collector uses. */
87     private String JavaDoc m_collectorParam;
88
89     /** The list of collected content items. */
90     private List JavaDoc m_collectorResult;
91
92     /** Reference to the last loaded content element. */
93     private I_CmsXmlDocument m_content;
94
95     /** The bean to store information required to make the result list browsable. */
96     private CmsContentInfoBean m_contentInfoBean;
97
98     /**
99      * The locale to use for displaying the current content.<p>
100      *
101      * Initially, this is equal to the locale set using <code>{@link #setLocale(String)}</code>.
102      * However, the content locale may change in case a loaded XML content does not have the selected locale available.
103      * In this case the next default locale that is available in the content will be used as content locale.<p>
104      */

105     private Locale JavaDoc m_contentLocale;
106
107     /** The FlexController for the current request. */
108     private CmsFlexController m_controller;
109
110     /** The "direct edit" button selection to use for the 2nd to the last element. */
111     private CmsDirectEditButtonSelection m_directEditFollowButtons;
112
113     /** The link for creation of a new element, specified by the selected collector. */
114     private String JavaDoc m_directEditLinkForNew;
115
116     /** The editable mode. */
117     private CmsDirectEditMode m_directEditMode;
118
119     /** Indicates if the last element was direct editable. */
120     private boolean m_directEditOpen;
121
122     /** Indicates if this is the first content iteration loop. */
123     private boolean m_isFirstLoop;
124
125     /** Refenence to the currently selected locale. */
126     private Locale JavaDoc m_locale;
127
128     /** The index of the current page that gets displayed. */
129     private String JavaDoc m_pageIndex;
130
131     /** The number of page links in the Google-like page navigation. */
132     private String JavaDoc m_pageNavLength;
133
134     /** The size of a page to be displayed. */
135     private String JavaDoc m_pageSize;
136
137     /** Paramter used for the collector. */
138     private String JavaDoc m_param;
139
140     /** Indicates if the collector results should be preloaded. */
141     private boolean m_preload;
142
143     /** The (optional) property to extend the parameter with. */
144     private String JavaDoc m_property;
145
146     /** The file name to load the current content value from. */
147     private String JavaDoc m_resourceName;
148
149     /**
150      * Empty constructor, required for JSP tags.<p>
151      */

152     public CmsJspTagContentLoad() {
153
154         super();
155     }
156
157     /**
158      * Constructor used when using <code>contentload</code> from scriptlet code.<p>
159      *
160      * @param container the parent content container (could be a preloader)
161      * @param context the JSP page context
162      * @param collectorName the collector name to use
163      * @param collectorParam the collector param to use
164      * @param locale the locale to use
165      * @param editable indicates if "direct edit" support is wanted
166      *
167      * @throws JspException in case something goes wrong
168      */

169     public CmsJspTagContentLoad(
170         I_CmsXmlContentContainer container,
171         PageContext JavaDoc context,
172         String JavaDoc collectorName,
173         String JavaDoc collectorParam,
174         Locale JavaDoc locale,
175         boolean editable)
176     throws JspException JavaDoc {
177
178         this(container, context, collectorName, collectorParam, null, null, locale, editable);
179     }
180
181     /**
182      * Constructor used when using <code>contentload</code> from scriptlet code.<p>
183      *
184      * @param container the parent content container (could be a preloader)
185      * @param context the JSP page context
186      * @param collectorName the collector name to use
187      * @param collectorParam the collector param to use
188      * @param pageIndex the display page index (may contain macros)
189      * @param pageSize the display page size (may contain macros)
190      * @param locale the locale to use
191      * @param editable indicates if "direct edit" support is wanted
192      *
193      * @throws JspException in case something goes wrong
194      */

195     public CmsJspTagContentLoad(
196         I_CmsXmlContentContainer container,
197         PageContext JavaDoc context,
198         String JavaDoc collectorName,
199         String JavaDoc collectorParam,
200         String JavaDoc pageIndex,
201         String JavaDoc pageSize,
202         Locale JavaDoc locale,
203         boolean editable)
204     throws JspException JavaDoc {
205
206         this(
207             container,
208             context,
209             collectorName,
210             collectorParam,
211             pageIndex,
212             pageSize,
213             locale,
214             CmsDirectEditMode.valueOf(editable));
215     }
216
217     /**
218      * Constructor used when using <code>contentload</code> from scriptlet code.<p>
219      *
220      * @param container the parent content container (could be a preloader)
221      * @param context the JSP page context
222      * @param collectorName the collector name to use
223      * @param collectorParam the collector param to use
224      * @param pageIndex the display page index (may contain macros)
225      * @param pageSize the display page size (may contain macros)
226      * @param locale the locale to use
227      * @param editMode indicates which "direct edit" mode is wanted
228      *
229      * @throws JspException in case something goes wrong
230      */

231     public CmsJspTagContentLoad(
232         I_CmsXmlContentContainer container,
233         PageContext JavaDoc context,
234         String JavaDoc collectorName,
235         String JavaDoc collectorParam,
236         String JavaDoc pageIndex,
237         String JavaDoc pageSize,
238         Locale JavaDoc locale,
239         CmsDirectEditMode editMode)
240     throws JspException JavaDoc {
241
242         setCollector(collectorName);
243         setParam(collectorParam);
244         setPageIndex(pageIndex);
245         setPageSize(pageSize);
246         m_locale = locale;
247         m_contentLocale = locale;
248         m_directEditMode = editMode;
249         m_preload = false;
250
251         setPageContext(context);
252         init(container);
253     }
254
255     /**
256      * Returns the resource name currently processed.<p>
257      *
258      * @param cms the current OpenCms user context
259      * @param contentContainer the current content container
260      *
261      * @return the resource name currently processed
262      */

263     protected static String JavaDoc getResourceName(CmsObject cms, I_CmsXmlContentContainer contentContainer) {
264
265         if ((contentContainer != null) && (contentContainer.getResourceName() != null)) {
266             return contentContainer.getResourceName();
267         } else if (cms != null) {
268             return cms.getRequestContext().getUri();
269         } else {
270             return null;
271         }
272     }
273
274     /**
275      * Limits the collector's result list to the size of a page to be displayed in a JSP.<p>
276      *
277      * @param contentInfoBean the info bean of the collector
278      * @param collectorResult the result list of the collector
279      *
280      * @return a limited collector's result list
281      */

282     private static List JavaDoc limitCollectorResult(CmsContentInfoBean contentInfoBean, List JavaDoc collectorResult) {
283
284         List JavaDoc result = null;
285         int pageCount = -1;
286
287         if (contentInfoBean.getPageSize() > 0) {
288
289             pageCount = collectorResult.size() / contentInfoBean.getPageSize();
290             if ((collectorResult.size() % contentInfoBean.getPageSize()) != 0) {
291                 pageCount++;
292             }
293
294             contentInfoBean.setPageCount(pageCount);
295
296             int startIndex = (contentInfoBean.getPageIndex() - 1) * contentInfoBean.getPageSize();
297             int endIndex = contentInfoBean.getPageIndex() * contentInfoBean.getPageSize();
298             if (endIndex > collectorResult.size()) {
299                 endIndex = collectorResult.size();
300             }
301
302             result = collectorResult.subList(startIndex, endIndex);
303         } else {
304
305             result = collectorResult;
306             if (collectorResult.size() > 0) {
307                 contentInfoBean.setPageCount(1);
308             }
309         }
310
311         return result;
312     }
313
314     /**
315      * @see javax.servlet.jsp.tagext.BodyTagSupport#doAfterBody()
316      */

317     public int doAfterBody() throws JspException JavaDoc {
318
319         // close open direct edit first
320
if (hasMoreContent()) {
321             // another loop is required
322
return EVAL_BODY_AGAIN;
323         }
324         // need to release manually, JSP container may not call release as required (happens with Tomcat)
325
release();
326         // no more files are available, so skip the body and finish the loop
327
return SKIP_BODY;
328     }
329
330     /**
331      * @see javax.servlet.jsp.tagext.Tag#doEndTag()
332      */

333     public int doEndTag() {
334
335         // need to release manually, JSP container may not call release as required (happens with Tomcat)
336
release();
337         return EVAL_PAGE;
338     }
339
340     /**
341      * @see javax.servlet.jsp.tagext.Tag#doStartTag()
342      */

343     public int doStartTag() throws JspException JavaDoc, CmsIllegalArgumentException {
344
345         // get a reference to the parent "content container" class (if available)
346
Tag JavaDoc ancestor = findAncestorWithClass(this, I_CmsXmlContentContainer.class);
347         I_CmsXmlContentContainer container = null;
348         if (ancestor != null) {
349             // parent content container available, use preloaded values from this container
350
container = (I_CmsXmlContentContainer)ancestor;
351             // check if container really is a preloader
352
if (!container.isPreloader()) {
353                 // don't use ancestor if not a preloader
354
container = null;
355             }
356         }
357
358         // initialize the content load tag
359
init(container);
360
361         hasMoreContent();
362
363         return EVAL_BODY_INCLUDE;
364     }
365
366     /**
367      * Returns the collector.<p>
368      *
369      * @return the collector
370      */

371     public String JavaDoc getCollector() {
372
373         return m_collector;
374     }
375
376     /**
377      * @see org.opencms.jsp.I_CmsXmlContentContainer#getCollectorName()
378      */

379     public String JavaDoc getCollectorName() {
380
381         return m_collectorName;
382     }
383
384     /**
385      * @see org.opencms.jsp.I_CmsXmlContentContainer#getCollectorParam()
386      */

387     public String JavaDoc getCollectorParam() {
388
389         return m_collectorParam;
390     }
391
392     /**
393      * @see org.opencms.jsp.I_CmsXmlContentContainer#getCollectorResult()
394      */

395     public List JavaDoc getCollectorResult() {
396
397         return m_collectorResult;
398     }
399
400     /**
401      * Returns the editable flag.<p>
402      *
403      * @return the editable flag
404      */

405     public String JavaDoc getEditable() {
406
407         return m_directEditMode != null ? m_directEditMode.toString() : "";
408     }
409
410     /**
411      * Returns the locale.<p>
412      *
413      * @return the locale
414      */

415     public String JavaDoc getLocale() {
416
417         return (m_locale != null) ? m_locale.toString() : "";
418     }
419
420     /**
421      * Returns the index of the page to be displayed.<p>
422      *
423      * @return the index of the page to be displayed
424      */

425     public String JavaDoc getPageIndex() {
426
427         return m_pageIndex;
428     }
429
430     /**
431      * Returns the number of page links in the Google-like page navigation.<p>
432      *
433      * @return the number of page links in the Google-like page navigation
434      */

435     public String JavaDoc getPageNavLength() {
436
437         return m_pageNavLength;
438     }
439
440     /**
441      * Returns the size of a single page to be displayed.<p>
442      *
443      * @return the size of a single page to be displayed
444      */

445     public String JavaDoc getPageSize() {
446
447         return m_pageSize;
448     }
449
450     /**
451      * Returns the collector parameter.<p>
452      *
453      * @return the collector parameter
454      */

455     public String JavaDoc getParam() {
456
457         return m_param;
458     }
459
460     /**
461      * Returns <code>"true"</code> if this content load tag should only preload the values from the collector.<p>
462      *
463      * @return <code>"true"</code> if this content load tag should only preload the values from the collector
464      */

465     public String JavaDoc getPreload() {
466
467         return String.valueOf(m_preload);
468     }
469
470     /**
471      * Returns the property.<p>
472      *
473      * @return the property
474      */

475     public String JavaDoc getProperty() {
476
477         return m_property;
478     }
479
480     /**
481      * @see org.opencms.jsp.I_CmsXmlContentContainer#getResourceName()
482      */

483     public String JavaDoc getResourceName() {
484
485         return m_resourceName;
486     }
487
488     /**
489      * @see org.opencms.jsp.I_CmsXmlContentContainer#getXmlDocument()
490      */

491     public I_CmsXmlDocument getXmlDocument() {
492
493         return m_content;
494     }
495
496     /**
497      * @see org.opencms.jsp.I_CmsXmlContentContainer#getXmlDocumentElement()
498      */

499     public String JavaDoc getXmlDocumentElement() {
500
501         // value must be set in "loop" or "show" class
502
return null;
503     }
504
505     /**
506      * @see org.opencms.jsp.I_CmsXmlContentContainer#getXmlDocumentLocale()
507      */

508     public Locale JavaDoc getXmlDocumentLocale() {
509
510         return m_contentLocale;
511     }
512
513     /**
514      * @see org.opencms.jsp.I_CmsXmlContentContainer#hasMoreContent()
515      */

516     public boolean hasMoreContent() throws JspException JavaDoc {
517
518         if (m_isFirstLoop) {
519             m_isFirstLoop = false;
520         } else {
521             if (m_directEditOpen) {
522                 // last element was direct editable, close it
523
CmsJspTagEditable.endDirectEdit(pageContext);
524                 m_directEditOpen = false;
525             }
526         }
527
528         if (m_preload) {
529             // if in preload mode, no result is required
530
return false;
531         }
532
533         // check if there are more files to iterate
534
boolean hasMoreContent = m_collectorResult.size() > 0;
535         if (hasMoreContent) {
536             // there are more results available...
537
try {
538                 doLoadNextFile();
539             } catch (CmsException e) {
540                 m_controller.setThrowable(e, m_resourceName);
541                 throw new JspException JavaDoc(e);
542             }
543
544             // check "direct edit" support
545
if (m_directEditMode.isEnabled() && (m_resourceName != null)) {
546
547                 // check options for first element
548
CmsDirectEditButtonSelection directEditButtons;
549                 if (m_directEditFollowButtons == null) {
550                     // this is the first call, calculate the options
551
if (m_directEditLinkForNew == null) {
552                         // if create link is null, show only "edit" button for first element
553
directEditButtons = CmsDirectEditButtonSelection.EDIT;
554                         // also show only the "edit" button for 2nd to last element
555
m_directEditFollowButtons = directEditButtons;
556                     } else {
557                         // if create link is not null, show "edit", "delete" and "new" button for first element
558
directEditButtons = CmsDirectEditButtonSelection.EDIT_DELETE_NEW;
559                         // show "edit" and "delete" button for 2nd to last element
560
m_directEditFollowButtons = CmsDirectEditButtonSelection.EDIT_DELETE;
561                     }
562                 } else {
563                     // re-use pre calculated options
564
directEditButtons = m_directEditFollowButtons;
565                 }
566
567                 m_directEditOpen = CmsJspTagEditable.startDirectEdit(pageContext, new CmsDirectEditParams(
568                     m_resourceName,
569                     directEditButtons,
570                     m_directEditMode,
571                     m_directEditLinkForNew));
572             }
573
574         } else {
575             // no more results in the collector, reset locale (just to make sure...)
576
m_locale = null;
577         }
578
579         return hasMoreContent;
580     }
581
582     /**
583      * @see org.opencms.jsp.I_CmsXmlContentContainer#isPreloader()
584      */

585     public boolean isPreloader() {
586
587         return m_preload;
588     }
589
590     /**
591      * @see javax.servlet.jsp.tagext.Tag#release()
592      */

593     public void release() {
594
595         m_cms = null;
596         m_collector = null;
597         m_collectorName = null;
598         m_collectorParam = null;
599         m_collectorResult = null;
600         m_content = null;
601         m_contentInfoBean = null;
602         m_contentLocale = null;
603         m_controller = null;
604         m_directEditLinkForNew = null;
605         m_directEditFollowButtons = null;
606         m_directEditOpen = false;
607         m_directEditMode = null;
608         m_isFirstLoop = false;
609         m_locale = null;
610         m_pageIndex = null;
611         m_pageNavLength = null;
612         m_pageSize = null;
613         m_param = null;
614         m_preload = false;
615         m_property = null;
616         m_resourceName = null;
617         super.release();
618     }
619
620     /**
621      * Sets the collector.<p>
622      *
623      * @param collector the collector to set
624      */

625     public void setCollector(String JavaDoc collector) {
626
627         m_collector = collector;
628     }
629
630     /**
631      * Sets the editable mode.<p>
632      *
633      * @param mode the mode to set
634      */

635     public void setEditable(String JavaDoc mode) {
636
637         m_directEditMode = CmsDirectEditMode.valueOf(mode);
638     }
639
640     /**
641      * Sets the locale.<p>
642      *
643      * @param locale the locale to set
644      */

645     public void setLocale(String JavaDoc locale) {
646
647         if (CmsStringUtil.isEmpty(locale)) {
648             m_locale = null;
649             m_contentLocale = null;
650         } else {
651             m_locale = CmsLocaleManager.getLocale(locale);
652             m_contentLocale = m_locale;
653         }
654     }
655
656     /**
657      * Sets the index of the page to be displayed.<p>
658      *
659      * @param pageIndex the index of the page to be displayed
660      */

661     public void setPageIndex(String JavaDoc pageIndex) {
662
663         m_pageIndex = pageIndex;
664     }
665
666     /**
667      * Sets the number of page links in the Google-like page navigation.<p>
668      *
669      * @param pageNavLength the number of page links in the Google-like page navigation
670      */

671     public void setPageNavLength(String JavaDoc pageNavLength) {
672
673         m_pageNavLength = pageNavLength;
674     }
675
676     /**
677      * Sets the size of a single page to be displayed.<p>
678      *
679      * @param pageSize the size of a single page to be displayed
680      */

681     public void setPageSize(String JavaDoc pageSize) {
682
683         m_pageSize = pageSize;
684     }
685
686     /**
687      * Sets the collector parameter.<p>
688      *
689      * @param param the collector parameter to set
690      */

691     public void setParam(String JavaDoc param) {
692
693         m_param = param;
694     }
695
696     /**
697      * Sets the preload flag for this content load tag.<p>
698      *
699      * If this is set to <code>true</code>, then the collector result will only
700      * be preloaded, but not iterated.<p>
701      *
702      * @param preload the preload flag to set
703      */

704     public void setPreload(String JavaDoc preload) {
705
706         m_preload = Boolean.valueOf(preload).booleanValue();
707     }
708
709     /**
710      * Sets the property.<p>
711      *
712      * @param property the property to set
713      */

714     public void setProperty(String JavaDoc property) {
715
716         m_property = property;
717     }
718
719     /**
720      * Load the next file name from the initialized list of file names.<p>
721      *
722      * @throws CmsException if something goes wrong
723      */

724     protected void doLoadNextFile() throws CmsException {
725
726         // get the next resource from the collector
727
CmsResource resource = getNextResource();
728         if (resource == null) {
729             m_resourceName = null;
730             m_content = null;
731             return;
732         }
733
734         // set the resource name
735
m_resourceName = m_cms.getSitePath(resource);
736
737         // upgrade the resource to a file
738
// the static method CmsFile.upgrade(...) is not used for performance reasons
739
CmsFile file = null;
740         if (resource instanceof CmsFile) {
741             // check the resource contents
742
file = (CmsFile)resource;
743             if ((file.getContents() == null) || (file.getContents().length <= 0)) {
744                 // file has no contents available, force re-read
745
file = null;
746             }
747         }
748         if (file == null) {
749             // use ALL filter since the list itself should have filtered out all unwanted resources already
750
file = m_cms.readFile(m_resourceName, CmsResourceFilter.ALL);
751         }
752
753         // unmarshal the XML content from the resource
754
m_content = CmsXmlContentFactory.unmarshal(m_cms, file);
755
756         // check if locale is available
757
m_contentLocale = m_locale;
758         if (!m_content.hasLocale(m_contentLocale)) {
759             Iterator JavaDoc it = OpenCms.getLocaleManager().getDefaultLocales().iterator();
760             while (it.hasNext()) {
761                 Locale JavaDoc locale = (Locale JavaDoc)it.next();
762                 if (m_content.hasLocale(locale)) {
763                     // found a matching locale
764
m_contentLocale = locale;
765                     break;
766                 }
767             }
768         }
769     }
770
771     /**
772      * Returns the content info bean.<p>
773      *
774      * @return the content info bean
775      */

776     protected CmsContentInfoBean getContentInfoBean() {
777
778         return m_contentInfoBean;
779     }
780
781     /**
782      * Initializes this content load tag.<p>
783      *
784      * @param container the parent container (could be a preloader)
785      *
786      * @throws JspException in case something goes wrong
787      */

788     protected void init(I_CmsXmlContentContainer container) throws JspException JavaDoc {
789
790         // check if the tag contains a pageSize, pageIndex and pageNavLength attribute, or none of them
791
int pageAttribCount = 0;
792         pageAttribCount += CmsStringUtil.isNotEmpty(m_pageSize) ? 1 : 0;
793         pageAttribCount += CmsStringUtil.isNotEmpty(m_pageIndex) ? 1 : 0;
794
795         if ((pageAttribCount > 0) && (pageAttribCount < 2)) {
796             throw new CmsIllegalArgumentException(Messages.get().container(Messages.ERR_TAG_CONTENTLOAD_INDEX_SIZE_0));
797         }
798
799         I_CmsXmlContentContainer usedContainer;
800         if (container == null) {
801             // no preloading ancestor has been found
802
usedContainer = this;
803             if (CmsStringUtil.isEmpty(m_collector)) {
804                 // check if the tag contains a collector attribute
805
throw new CmsIllegalArgumentException(Messages.get().container(
806                     Messages.ERR_TAG_CONTENTLOAD_MISSING_COLLECTOR_0));
807             }
808             if (CmsStringUtil.isEmpty(m_param)) {
809                 // check if the tag contains a param attribute
810
throw new CmsIllegalArgumentException(Messages.get().container(
811                     Messages.ERR_TAG_CONTENTLOAD_MISSING_PARAM_0));
812             }
813         } else {
814             // use provided container (preloading ancestor)
815
usedContainer = container;
816         }
817
818         if (m_preload) {
819             // always deactivate direct edit for prelaod
820
m_directEditMode = CmsDirectEditMode.FALSE;
821         } else if (m_directEditMode == null) {
822             // direct edit mode must not be null
823
m_directEditMode = CmsDirectEditMode.FALSE;
824         }
825
826         // initialize OpenCms access objects
827
m_controller = CmsFlexController.getController(pageContext.getRequest());
828         m_cms = m_controller.getCmsObject();
829
830         // get the resource name from the selected container
831
String JavaDoc resourcename = getResourceName(m_cms, usedContainer);
832
833         // initialize a string mapper to resolve EL like strings in tag attributes
834
CmsMacroResolver resolver = CmsMacroResolver.newInstance().setCmsObject(m_cms).setJspPageContext(pageContext).setResourceName(
835             resourcename).setKeepEmptyMacros(true);
836
837         // resolve the collector name
838
if (container == null) {
839             // no preload parent container, initialize new values
840
m_collectorName = resolver.resolveMacros(getCollector());
841             // resolve the parameter
842
m_collectorParam = resolver.resolveMacros(getParam());
843             m_collectorResult = null;
844         } else {
845             // preload parent content container available, use values from this container
846
m_collectorName = usedContainer.getCollectorName();
847             m_collectorParam = usedContainer.getCollectorParam();
848             m_collectorResult = usedContainer.getCollectorResult();
849             if (m_locale == null) {
850                 // use locale from ancestor if available
851
m_locale = usedContainer.getXmlDocumentLocale();
852             }
853         }
854
855         if (m_locale == null) {
856             // no locale set, use locale from users request context
857
m_locale = m_cms.getRequestContext().getLocale();
858         }
859
860         try {
861             // now collect the resources
862
I_CmsResourceCollector collector = OpenCms.getResourceManager().getContentCollector(m_collectorName);
863             if (collector == null) {
864                 throw new CmsException(Messages.get().container(Messages.ERR_COLLECTOR_NOT_FOUND_1, m_collectorName));
865             }
866             // execute the collector if not already done in parent tag
867
if (m_collectorResult == null) {
868                 m_collectorResult = collector.getResults(m_cms, m_collectorName, m_collectorParam);
869             }
870
871             m_contentInfoBean = new CmsContentInfoBean();
872             m_contentInfoBean.setPageSizeAsString(resolver.resolveMacros(m_pageSize));
873             m_contentInfoBean.setPageIndexAsString(resolver.resolveMacros(m_pageIndex));
874             m_contentInfoBean.setPageNavLengthAsString(resolver.resolveMacros(m_pageNavLength));
875             m_contentInfoBean.setResultSize(m_collectorResult.size());
876             m_contentInfoBean.setLocale(m_locale.toString());
877             m_contentInfoBean.initResultIndex();
878
879             if (!m_preload) {
880                 // not required when only preloading
881

882                 m_collectorResult = CmsJspTagContentLoad.limitCollectorResult(m_contentInfoBean, m_collectorResult);
883                 m_contentInfoBean.initPageNavIndexes();
884
885                 String JavaDoc createParam = collector.getCreateParam(m_cms, m_collectorName, m_collectorParam);
886                 if (createParam != null) {
887                     // use "create link" only if collector supports it
888
m_directEditLinkForNew = CmsEncoder.encode(m_collectorName + "|" + createParam);
889                 }
890             }
891
892         } catch (CmsException e) {
893             m_controller.setThrowable(e, m_cms.getRequestContext().getUri());
894             throw new JspException JavaDoc(e);
895         }
896
897         // reset the direct edit options (required becaue of re-used tags)
898
m_directEditOpen = false;
899         m_directEditFollowButtons = null;
900
901         // the next loop is the first loop
902
m_isFirstLoop = true;
903     }
904
905     /**
906      * Returns the next resource from the collector.<p>
907      *
908      * @return the next resource from the collector
909      */

910     private CmsResource getNextResource() {
911
912         if ((m_collectorResult != null) && (m_collectorResult.size() > 0)) {
913
914             m_contentInfoBean.incResultIndex();
915             return (CmsResource)m_collectorResult.remove(0);
916         }
917
918         return null;
919     }
920 }
Popular Tags