KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * File : $Source: /usr/local/cvs/opencms/src/org/opencms/jsp/CmsJspActionElement.java,v $
3  * Date : $Date: 2006/10/26 12:25:35 $
4  * Version: $Revision: 1.27 $
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.CmsProperty;
36 import org.opencms.flex.CmsFlexController;
37 import org.opencms.i18n.CmsMessageContainer;
38 import org.opencms.i18n.CmsMessages;
39 import org.opencms.loader.CmsImageScaler;
40 import org.opencms.loader.I_CmsResourceLoader;
41 import org.opencms.main.CmsException;
42 import org.opencms.main.OpenCms;
43 import org.opencms.security.CmsSecurityException;
44 import org.opencms.staticexport.CmsLinkManager;
45 import org.opencms.util.CmsStringUtil;
46 import org.opencms.workplace.editors.directedit.CmsDirectEditJspIncludeProvider;
47 import org.opencms.workplace.editors.directedit.CmsDirectEditMode;
48 import org.opencms.workplace.editors.directedit.I_CmsDirectEditProvider;
49
50 import java.io.UnsupportedEncodingException JavaDoc;
51 import java.util.HashMap JavaDoc;
52 import java.util.Iterator JavaDoc;
53 import java.util.Locale JavaDoc;
54 import java.util.Map JavaDoc;
55
56 import javax.servlet.http.HttpServletRequest JavaDoc;
57 import javax.servlet.http.HttpServletResponse JavaDoc;
58 import javax.servlet.jsp.JspException JavaDoc;
59 import javax.servlet.jsp.PageContext JavaDoc;
60
61 /**
62  * Bean to be used in JSP scriptlet code that provides direct
63  * access to the functionality offered by the opencms taglib.<p>
64  *
65  * By instanciating a bean of this type and accessing the methods provided by
66  * the instance, all functionality of the OpenCms JSP taglib can be easily
67  * used from within JSP scriplet code.<p>
68  *
69  * Initialize this bean at the beginning of your JSP like this:
70  * <pre>
71  * &lt;jsp:useBean id="cms" class="org.opencms.jsp.CmsJspActionElement"&gt;
72  * &lt% cms.init(pageContext, request, response); %&gt;
73  * &lt;/jsp:useBean&gt;
74  * </pre>
75  *
76  * You can also access the current users <code>{@link org.opencms.file.CmsObject}</code>
77  * by using <code>{@link org.opencms.jsp.CmsJspBean#getCmsObject()}</code>.<p>
78  *
79  * All exceptions that occur when calling any method of this class are catched
80  * and written to the log output only, so that a template still has a chance of
81  * working at least in some elements.<p>
82  *
83  * @author Alexander Kandzior
84  *
85  * @version $Revision: 1.27 $
86  *
87  * @since 6.0.0
88  */

89 public class CmsJspActionElement extends CmsJspBean {
90
91     /** Error message in case bean was not properly initialized. */
92     // cannot use a string: At class-loading time the
93
// user request context for localization is not at hand.
94
public static final CmsMessageContainer NOT_INITIALIZED = Messages.get().container(
95         Messages.GUI_ERR_ACTIONELEM_NOT_INIT_0);
96
97     /** JSP navigation builder. */
98     private CmsJspNavBuilder m_navigation;
99
100     /**
101      * Empty constructor, required for every JavaBean.
102      */

103     public CmsJspActionElement() {
104
105         super();
106     }
107
108     /**
109      * Constructor, with parameters.
110      *
111      * @param context the JSP page context object
112      * @param req the JSP request
113      * @param res the JSP response
114      */

115     public CmsJspActionElement(PageContext JavaDoc context, HttpServletRequest JavaDoc req, HttpServletResponse JavaDoc res) {
116
117         super();
118         init(context, req, res);
119     }
120
121     /**
122      * Includes direct edit scriptlets, same as
123      * using the <code>&lt;cms:editable /&gt;</code> tag.<p>
124      *
125      * The configured default direct edit provider is used.<p>
126      *
127      * @param isEditable include scriptlets only if true
128      *
129      * @throws JspException if something goes wrong
130      */

131     public void editable(boolean isEditable) throws JspException JavaDoc {
132
133         if (isEditable) {
134             CmsJspTagEditable.editableTagAction(getJspContext(), null, CmsDirectEditMode.AUTO, null);
135         }
136     }
137
138     /**
139      * Includes direct edit scriptlets, same as
140      * using the <code>&lt;cms:editable file="..." /&gt;</code>tag.<p>
141      *
142      * For backward compatibilty, this always uses the JSP include based direct edit provider<p>.
143      *
144      * @param isEditable include scriptlets only if true
145      * @param filename file with scriptlets
146      *
147      * @throws JspException if something goes wrong
148      */

149     public void editable(boolean isEditable, String JavaDoc filename) throws JspException JavaDoc {
150
151         if (isEditable) {
152             CmsJspTagEditable.editableTagAction(
153                 getJspContext(),
154                 CmsDirectEditJspIncludeProvider.class.getName(),
155                 CmsDirectEditMode.AUTO,
156                 filename);
157         }
158     }
159
160     /**
161      * Includes direct edit scriptlets, same as
162      * using the <code>&lt;cms:editable provider="..." mode="..." file="..." /&gt;</code>tag.<p>
163      *
164      * @param provider the direct edit provider class name
165      * @param mode the direct edit mode to use
166      * @param filename file with scriptlets (may be <code>null</code>)
167      *
168      * @throws JspException if something goes wrong
169      */

170     public void editable(String JavaDoc provider, String JavaDoc mode, String JavaDoc filename) throws JspException JavaDoc {
171
172         CmsJspTagEditable.editableTagAction(getJspContext(), provider, CmsDirectEditMode.valueOf(mode), filename);
173     }
174
175     /**
176      * Insert the end HTML for the direct edit buttons in manual mode (if required).<p>
177      *
178      * Same as closing the <code>&lt;/cms:editable</code> tag after opening one in manual mode.<p>
179      *
180      * @param needsClose result of {@link #editableManualOpen()} should be the value for this parameter
181      *
182      * @throws JspException if something goes wrong
183      */

184     public void editableManualClose(boolean needsClose) throws JspException JavaDoc {
185
186         if (needsClose) {
187             CmsJspTagEditable.editableTagAction(getJspContext(), null, CmsDirectEditMode.MANUAL, null);
188         }
189     }
190
191     /**
192      * Insert the start HTML for the direct edit buttons in manual mode.<p>
193      *
194      * Same as opening the <code>&lt;cms:editable mode="manual"&gt;</code> tag.<p>
195      *
196      * @return <code>true</code> if HTML was inserted that needs to be closed
197      *
198      * @throws JspException if something goes wrong
199      */

200     public boolean editableManualOpen() throws JspException JavaDoc {
201
202         boolean result = false;
203         if (!CmsFlexController.isCmsOnlineRequest(getJspContext().getRequest())) {
204             // all this does NOT apply to the "online" project
205
I_CmsDirectEditProvider eb = CmsJspTagEditable.getDirectEditProvider(getJspContext());
206             if ((eb != null)) {
207                 // check if the provider support manual placement of buttons
208
if (eb.isManual(CmsDirectEditMode.MANUAL)) {
209                     // the provider supports manual placement of buttons
210
result = true;
211                     CmsJspTagEditable.editableTagAction(getJspContext(), null, CmsDirectEditMode.MANUAL, null);
212                 }
213             }
214         }
215         return result;
216     }
217
218     /**
219      * Returns the processed output of an OpenCms resource in a String.<p>
220      *
221      * @param target the target to process
222      * @return the processed output of an OpenCms resource in a String
223      */

224     public String JavaDoc getContent(String JavaDoc target) {
225
226         return getContent(target, null, null);
227     }
228
229     /**
230      * Returns the processed output of an element within an OpenCms resource.<p>
231      *
232      * @param target the target to process
233      * @param element name of the element
234      * @param locale locale of the element
235      * @return the processed output
236      */

237     public String JavaDoc getContent(String JavaDoc target, String JavaDoc element, Locale JavaDoc locale) {
238
239         I_CmsResourceLoader loader;
240         CmsFile file;
241         target = toAbsolute(target);
242
243         try {
244             file = getCmsObject().readFile(target);
245             loader = OpenCms.getResourceManager().getLoader(file);
246         } catch (ClassCastException JavaDoc e) {
247             // no loader implementation found
248
return CmsMessages.formatUnknownKey(e.getMessage());
249         } catch (CmsException e) {
250             // file might not exist or no read permissions
251
return CmsMessages.formatUnknownKey(e.getMessage());
252         }
253
254         try {
255             byte[] result = loader.dump(getCmsObject(), file, element, locale, getRequest(), getResponse());
256             return new String JavaDoc(result, getRequestContext().getEncoding());
257         } catch (UnsupportedEncodingException JavaDoc uee) {
258             // encoding unsupported
259
return CmsMessages.formatUnknownKey(uee.getMessage());
260         } catch (Throwable JavaDoc t) {
261             // any other exception, check for hidden root cause first
262
Throwable JavaDoc cause = CmsFlexController.getThrowable(getRequest());
263             if (cause == null) {
264                 cause = t;
265             }
266             handleException(cause);
267             return CmsMessages.formatUnknownKey(cause.getMessage());
268         }
269     }
270
271     /**
272      * Generates an initialized instance of {@link CmsMessages} for
273      * convenient access to localized resource bundles.<p>
274      *
275      * @param bundleName the name of the ResourceBundle to use
276      * @param locale the locale to use for localization
277      *
278      * @return CmsMessages a message bundle initialized with the provided values
279      */

280     public CmsMessages getMessages(String JavaDoc bundleName, Locale JavaDoc locale) {
281
282         return new CmsMessages(bundleName, locale);
283     }
284
285     /**
286      * Generates an initialized instance of {@link CmsMessages} for
287      * convenient access to localized resource bundles.<p>
288      *
289      * @param bundleName the name of the ResourceBundle to use
290      * @param language language indentificator for the locale of the bundle
291      * @return CmsMessages a message bundle initialized with the provided values
292      */

293     public CmsMessages getMessages(String JavaDoc bundleName, String JavaDoc language) {
294
295         return getMessages(bundleName, language, "", "", null);
296     }
297
298     /**
299      * Generates an initialized instance of {@link CmsMessages} for
300      * convenient access to localized resource bundles.<p>
301      *
302      * @param bundleName the name of the ResourceBundle to use
303      * @param language language indentificator for the locale of the bundle
304      * @param defaultLanguage default for the language, will be used
305      * if language is null or empty String "", and defaultLanguage is not null
306      * @return CmsMessages a message bundle initialized with the provided values
307      */

308     public CmsMessages getMessages(String JavaDoc bundleName, String JavaDoc language, String JavaDoc defaultLanguage) {
309
310         return getMessages(bundleName, language, "", "", defaultLanguage);
311     }
312
313     /**
314      * Generates an initialized instance of {@link CmsMessages} for
315      * convenient access to localized resource bundles.<p>
316      *
317      * @param bundleName the name of the ResourceBundle to use
318      * @param language language indentificator for the locale of the bundle
319      * @param country 2 letter country code for the locale of the bundle
320      * @param variant a vendor or browser-specific variant code
321      * @param defaultLanguage default for the language, will be used
322      * if language is null or empty String "", and defaultLanguage is not null
323      * @return CmsMessages a message bundle initialized with the provided values
324      *
325      * @see java.util.ResourceBundle
326      * @see org.opencms.i18n.CmsMessages
327      */

328     public CmsMessages getMessages(
329         String JavaDoc bundleName,
330         String JavaDoc language,
331         String JavaDoc country,
332         String JavaDoc variant,
333         String JavaDoc defaultLanguage) {
334
335         try {
336             if ((defaultLanguage != null) && CmsStringUtil.isEmpty(language)) {
337                 language = defaultLanguage;
338             }
339             if (language == null) {
340                 language = "";
341             }
342             if (country == null) {
343                 country = "";
344             }
345             if (variant == null) {
346                 variant = "";
347             }
348             return getMessages(bundleName, new Locale JavaDoc(language, country, variant));
349         } catch (Throwable JavaDoc t) {
350             handleException(t);
351         }
352         return null;
353     }
354
355     /**
356      * Returns an initialized {@link CmsJspNavBuilder} instance.<p>
357      *
358      * @return CmsJspNavBuilder an initialized <code>CmsJspNavBuilder</code>
359      *
360      * @see org.opencms.jsp.CmsJspNavBuilder
361      */

362     public CmsJspNavBuilder getNavigation() {
363
364         if (isNotInitialized()) {
365             return null;
366         }
367         if (m_navigation == null) {
368             m_navigation = new CmsJspNavBuilder(getController().getCmsObject());
369         }
370         return m_navigation;
371     }
372
373     /**
374      * Returns the HTML for an <code>&lt;img SRC="..." /&gt;</code> tag that includes the given image scaling parameters.<p>
375      *
376      * @param target the target uri of the file in the OpenCms VFS
377      * @param scaler the image scaler to use for scaling the image
378      * @param attributes a map of additional HTML attributes that are added to the output
379      *
380      * @return the HTML for an <code>&lt;img src&gt;</code> tag that includes the given image scaling parameters
381      */

382     public String JavaDoc img(String JavaDoc target, CmsImageScaler scaler, Map JavaDoc attributes) {
383
384         return img(target, scaler, attributes, false);
385     }
386
387     /**
388      * Returns the HTML for an <code>&lt;img SRC="..." /&gt;</code> tag that includes the given image scaling parameters.<p>
389      *
390      * @param target the target uri of the file in the OpenCms VFS
391      * @param scaler the image scaler to use for scaling the image
392      * @param attributes a map of additional HTML attributes that are added to the output
393      * @param partialTag if <code>true</code>, the opening <code>&lt;img</code> and closing <code> /&gt;</code> is omitted
394      *
395      * @return the HTML for an <code>&lt;img src&gt;</code> tag that includes the given image scaling parameters
396      */

397     public String JavaDoc img(String JavaDoc target, CmsImageScaler scaler, Map JavaDoc attributes, boolean partialTag) {
398
399         try {
400             return CmsJspTagImage.imageTagAction(target, scaler, attributes, partialTag, getRequest());
401         } catch (Throwable JavaDoc t) {
402             handleException(t);
403         }
404         CmsMessageContainer msgContainer = Messages.get().container(
405             Messages.GUI_ERR_IMG_SCALE_2,
406             target,
407             scaler == null ? "null" : scaler.toString());
408         return getMessage(msgContainer);
409     }
410
411     /**
412      * Include a sub-element without paramters from the OpenCms VFS, same as
413      * using the <code>&lt;cms:include file="***" /&gt;</code> tag.<p>
414      *
415      * @param target the target uri of the file in the OpenCms VFS (can be relative or absolute)
416      * @throws JspException in case there were problems including the target
417      *
418      * @see org.opencms.jsp.CmsJspTagInclude
419      */

420     public void include(String JavaDoc target) throws JspException JavaDoc {
421
422         include(target, null, null);
423     }
424
425     /**
426      * Include a named sub-element without paramters from the OpenCms VFS, same as
427      * using the <code>&lt;cms:include file="***" element="***" /&gt;</code> tag.<p>
428      *
429      * @param target the target uri of the file in the OpenCms VFS (can be relative or absolute)
430      * @param element the element (template selector) to display from the target
431      * @throws JspException in case there were problems including the target
432      *
433      * @see org.opencms.jsp.CmsJspTagInclude
434      */

435     public void include(String JavaDoc target, String JavaDoc element) throws JspException JavaDoc {
436
437         include(target, element, null);
438     }
439
440     /**
441      * Include a named sub-element without paramters from the OpenCms VFS, same as
442      * using the <code>&lt;cms:include file="***" element="***" /&gt;</code> tag.<p>
443      *
444      * @param target the target uri of the file in the OpenCms VFS (can be relative or absolute)
445      * @param element the element (template selector) to display from the target
446      * @param editable flag to indicate if element is editable
447      * @throws JspException in case there were problems including the target
448      *
449      * @see org.opencms.jsp.CmsJspTagInclude
450      */

451     public void include(String JavaDoc target, String JavaDoc element, boolean editable) throws JspException JavaDoc {
452
453         include(target, element, editable, null);
454     }
455
456     /**
457      * Include a named sub-element with paramters from the OpenCms VFS, same as
458      * using the <code>&lt;cms:include file="***" element="***" /&gt;</code> tag
459      * with parameters in the tag body.<p>
460      *
461      * The parameter map should be a map where the keys are Strings
462      * (the parameter names) and the values are of type String[].
463      * However, as a convenience feature,
464      * in case you provide just a String for the parameter value,
465      * it will automatically be translated to a String[1].<p>
466      *
467      * The handling of the <code>element</code> parameter depends on the
468      * included file type. Most often it is used as template selector.<p>
469      *
470      * <b>Important:</b> Exceptions that occur in the include process are NOT
471      * handled even if {@link #setSupressingExceptions(boolean)} was set to <code>true</code>.
472      *
473      * @param target the target uri of the file in the OpenCms VFS (can be relative or absolute)
474      * @param element the element (template selector) to display from the target
475      * @param editable flag to indicate if element is editable
476      * @param parameterMap a map of the request parameters
477      * @throws JspException in case there were problems including the target
478      *
479      * @see org.opencms.jsp.CmsJspTagInclude
480      */

481     public void include(String JavaDoc target, String JavaDoc element, boolean editable, Map JavaDoc parameterMap) throws JspException JavaDoc {
482
483         if (isNotInitialized()) {
484             return;
485         }
486         if (parameterMap != null) {
487             try {
488                 HashMap JavaDoc modParameterMap = new HashMap JavaDoc(parameterMap.size());
489                 // ensure parameters are always of type String[] not just String
490
Iterator JavaDoc i = parameterMap.entrySet().iterator();
491                 while (i.hasNext()) {
492                     Map.Entry JavaDoc entry = (Map.Entry JavaDoc)i.next();
493                     String JavaDoc key = (String JavaDoc)entry.getKey();
494                     Object JavaDoc value = entry.getValue();
495                     if (value instanceof String JavaDoc[]) {
496                         modParameterMap.put(key, value);
497                     } else {
498                         if (value == null) {
499                             value = "null";
500                         }
501                         String JavaDoc[] newValue = new String JavaDoc[] {value.toString()};
502                         modParameterMap.put(key, newValue);
503                     }
504                 }
505                 parameterMap = modParameterMap;
506             } catch (UnsupportedOperationException JavaDoc e) {
507                 // parameter map is immutable, just use it "as is"
508
}
509         }
510         CmsJspTagInclude.includeTagAction(
511             getJspContext(),
512             target,
513             element,
514             editable,
515             parameterMap,
516             getRequest(),
517             getResponse());
518     }
519
520     /**
521      * Include a named sub-element with paramters from the OpenCms VFS, same as
522      * using the <code>&lt;cms:include file="***" element="***" /&gt;</code> tag
523      * with parameters in the tag body.<p>
524      *
525      * @param target the target uri of the file in the OpenCms VFS (can be relative or absolute)
526      * @param element the element (template selector) to display from the target
527      * @param parameterMap a map of the request parameters
528      * @throws JspException in case there were problems including the target
529      *
530      * @see org.opencms.jsp.CmsJspTagInclude
531      */

532     public void include(String JavaDoc target, String JavaDoc element, Map JavaDoc parameterMap) throws JspException JavaDoc {
533
534         include(target, element, false, parameterMap);
535     }
536
537     /**
538      * Includes a named sub-element supressing all Exceptions that occur during the include,
539      * otherwise the same as using {@link #include(String, String, Map)}.<p>
540      *
541      * This is a convenience method that allows to include elements on a page without checking
542      * if they exist or not. If the target element does not exist, nothing is printed to
543      * the JSP output.<p>
544      *
545      * @param target the target uri of the file in the OpenCms VFS (can be relative or absolute)
546      * @param element the element (template selector) to display from the target
547      */

548     public void includeSilent(String JavaDoc target, String JavaDoc element) {
549
550         try {
551             include(target, element, null);
552         } catch (Throwable JavaDoc t) {
553             // ignore
554
}
555     }
556
557     /**
558      * Includes a named sub-element supressing all Exceptions that occur during the include,
559      * otherwise the same as using {@link #include(String, String, Map)}.<p>
560      *
561      * This is a convenience method that allows to include elements on a page without checking
562      * if they exist or not. If the target element does not exist, nothing is printed to
563      * the JSP output.<p>
564      *
565      * @param target the target uri of the file in the OpenCms VFS (can be relative or absolute)
566      * @param element the element (template selector) to display from the target
567      * @param editable flag to indicate if element is editable
568      */

569     public void includeSilent(String JavaDoc target, String JavaDoc element, boolean editable) {
570
571         try {
572             include(target, element, editable, null);
573         } catch (Throwable JavaDoc t) {
574             // ignore
575
}
576     }
577
578     /**
579      * Includes a named sub-element supressing all Exceptions that occur during the include,
580      * otherwise the same as using {@link #include(String, String, Map)}.<p>
581      *
582      * This is a convenience method that allows to include elements on a page without checking
583      * if they exist or not. If the target element does not exist, nothing is printed to
584      * the JSP output.<p>
585      *
586      * @param target the target uri of the file in the OpenCms VFS (can be relative or absolute)
587      * @param element the element (template selector) to display from the target
588      * @param editable flag to indicate if element is editable
589      * @param parameterMap a map of the request parameters
590      */

591     public void includeSilent(String JavaDoc target, String JavaDoc element, boolean editable, Map JavaDoc parameterMap) {
592
593         try {
594             include(target, element, editable, parameterMap);
595         } catch (Throwable JavaDoc t) {
596             // ignore
597
}
598     }
599
600     /**
601      * Includes a named sub-element supressing all Exceptions that occur during the include,
602      * otherwise the same as using {@link #include(String, String, Map)}.<p>
603      *
604      * This is a convenience method that allows to include elements on a page without checking
605      * if they exist or not. If the target element does not exist, nothing is printed to
606      * the JSP output.<p>
607      *
608      * @param target the target uri of the file in the OpenCms VFS (can be relative or absolute)
609      * @param element the element (template selector) to display from the target
610      * @param parameterMap a map of the request parameters
611      */

612     public void includeSilent(String JavaDoc target, String JavaDoc element, Map JavaDoc parameterMap) {
613
614         try {
615             include(target, element, parameterMap);
616         } catch (Throwable JavaDoc t) {
617             // ignore
618
}
619     }
620
621     /**
622      * Returns an OpenCms or JVM system info property value, same as using
623      * the <code>&lt;cms:info property="***" /&gt;</code> tag.<p>
624      *
625      * See the description of the class {@link CmsJspTagInfo} for a detailed list
626      * of available options for the property value.<p>
627      *
628      * @param property the property to look up
629      * @return String the value of the system property
630      * @see org.opencms.jsp.CmsJspTagInfo
631      */

632     public String JavaDoc info(String JavaDoc property) {
633
634         try {
635             return CmsJspTagInfo.infoTagAction(property, getRequest());
636         } catch (Throwable JavaDoc t) {
637             handleException(t);
638         }
639         CmsMessageContainer msgContainer = Messages.get().container(Messages.GUI_ERR_INFO_PROP_READ_1, property);
640         return getMessage(msgContainer);
641     }
642
643     /**
644      * Returns an OpenCms workplace label.<p>
645      *
646      * You should consider using a standard
647      * {@link java.util.ResourceBundle java.util.ResourceBundle} instead of the
648      * OpenCms workplace language files.
649      *
650      * @param label the label to look up
651      * @return label the value of the label
652      *
653      * @see org.opencms.jsp.CmsJspTagLabel
654      */

655     public String JavaDoc label(String JavaDoc label) {
656
657         if (isNotInitialized()) {
658             return getMessage(NOT_INITIALIZED);
659         }
660         try {
661             return CmsJspTagLabel.wpLabelTagAction(label, getRequest());
662         } catch (Throwable JavaDoc t) {
663             handleException(t);
664         }
665         CmsMessageContainer msgContainer = Messages.get().container(Messages.GUI_ERR_WORKPL_LABEL_READ_1, label);
666         return getMessage(msgContainer);
667     }
668
669     /**
670      * Calculate a link with the OpenCms link management,
671      * same as using the <code>&lt;cms:link&gt;***&lt;/cms:link&gt;</code> tag.<p>
672      *
673      * This is important to get the right link for exported resources,
674      * e.g. for images in the online project.
675      *
676      * @param link the uri in the OpenCms to link to
677      * @return the translated link
678      *
679      * @see org.opencms.jsp.CmsJspTagLink
680      */

681     public String JavaDoc link(String JavaDoc link) {
682
683         if (isNotInitialized()) {
684             return getMessage(NOT_INITIALIZED);
685         }
686         try {
687             return CmsJspTagLink.linkTagAction(link, getRequest());
688         } catch (Throwable JavaDoc t) {
689             handleException(t);
690         }
691         CmsMessageContainer msgContainer = Messages.get().container(Messages.GUI_ERR_GEN_LINK_1, link);
692         return getMessage(msgContainer);
693     }
694
695     /**
696      * Returns all properites of the current file.<p>
697      *
698      * @return Map all properties of the current file
699      */

700     public Map JavaDoc properties() {
701
702         return properties(null);
703     }
704
705     /**
706      * Returns all properites of the selected file.<p>
707      *
708      * Please see the description of the class {@link org.opencms.jsp.CmsJspTagProperty} for
709      * valid options of the <code>file</code> parameter.<p>
710      *
711      * @param file the file (or folder) to look at for the properties
712      * @return Map all properties of the current file
713      * (and optional of the folders containing the file)
714      *
715      * @see org.opencms.jsp.CmsJspTagProperty
716      */

717     public Map JavaDoc properties(String JavaDoc file) {
718
719         if (isNotInitialized()) {
720             return new HashMap JavaDoc();
721         }
722         Map JavaDoc value = new HashMap JavaDoc();
723         try {
724             if (file == null) {
725                 file = CmsJspTagProperty.USE_URI;
726             }
727             switch (CmsJspTagProperty.ACTION_VALUES_LIST.indexOf(file)) {
728                 case 0: // USE_URI
729
case 1: // USE_PARENT
730
value = CmsProperty.toMap(getCmsObject().readPropertyObjects(getRequestContext().getUri(), false));
731                     break;
732                 case 2: // USE_SEARCH
733
case 3: // USE_SEARCH_URI
734
case 4: // USE_SEARCH_PARENT
735
value = CmsProperty.toMap(getCmsObject().readPropertyObjects(getRequestContext().getUri(), true));
736                     break;
737                 case 5: // USE_ELEMENT_URI
738
case 6: // USE_THIS
739
// Read properties of this file
740
value = CmsProperty.toMap(getCmsObject().readPropertyObjects(
741                         getController().getCurrentRequest().getElementUri(),
742                         false));
743                     break;
744                 case 7: // USE_SEARCH_ELEMENT_URI
745
case 8: // USE_SEARCH_THIS
746
// Try to find property on this file and all parent folders
747
value = CmsProperty.toMap(getCmsObject().readPropertyObjects(
748                         getController().getCurrentRequest().getElementUri(),
749                         true));
750                     break;
751                 default:
752                     // Read properties of the file named in the attribute
753
value = CmsProperty.toMap(getCmsObject().readPropertyObjects(toAbsolute(file), false));
754             }
755         } catch (Throwable JavaDoc t) {
756             handleException(t);
757         }
758         return value;
759     }
760
761     /**
762      * Returns a selected file property value, same as using
763      * the <code>&lt;cms:property name="***" /&gt;</code> tag or
764      * calling {@link #property(String, String, String, boolean)}.<p>
765      *
766      * @param name the name of the property to look for
767      * @return the value of the property found, or null if the property could not be found
768      *
769      * @see #property(String, String, String, boolean)
770      * @see org.opencms.jsp.CmsJspTagProperty
771      */

772     public String JavaDoc property(String JavaDoc name) {
773
774         return property(name, null, null, false);
775     }
776
777     /**
778      * Returns a selected file property value, same as using
779      * the <code>&lt;cms:property name="***" file="***" /&gt;</code> tag or
780      * calling {@link #property(String, String, String, boolean)}.<p>
781      *
782      * @param name the name of the property to look for
783      * @param file the file (or folder) to look at for the property
784      * @return the value of the property found, or null if the property could not be found
785      *
786      * @see #property(String, String, String, boolean)
787      * @see org.opencms.jsp.CmsJspTagProperty
788      */

789     public String JavaDoc property(String JavaDoc name, String JavaDoc file) {
790
791         return property(name, file, null, false);
792     }
793
794     /**
795      * Returns a selected file property value, same as using
796      * the <code>&lt;cms:property name="***" file="***" default="***" /&gt;</code> tag or
797      * calling {@link #property(String, String, String, boolean)}.<p>
798      *
799      * @param name the name of the property to look for
800      * @param file the file (or folder) to look at for the property
801      * @param defaultValue a default value in case the property was not found
802      * @return the value of the property found, or the value of defaultValue
803      * if the property could not be found
804      *
805      * @see #property(String, String, String, boolean)
806      * @see org.opencms.jsp.CmsJspTagProperty
807      */

808     public String JavaDoc property(String JavaDoc name, String JavaDoc file, String JavaDoc defaultValue) {
809
810         return property(name, file, defaultValue, false);
811     }
812
813     /**
814      * Returns a selected file property value with optional HTML escaping, same as using
815      * the <code>&lt;cms:property name="***" file="***" default="***" /&gt;</code> tag.<p>
816      *
817      * Please see the description of the class {@link org.opencms.jsp.CmsJspTagProperty} for
818      * valid options of the <code>file</code> parameter.<p>
819      *
820      * @param name the name of the property to look for
821      * @param file the file (or folder) to look at for the property
822      * @param defaultValue a default value in case the property was not found
823      * @param escapeHtml if <code>true</code>, special HTML characters in the return value
824      * are escaped with their number representations (e.g. &amp; becomes &amp;#38;)
825      * @return the value of the property found, or the value of defaultValue
826      * if the property could not be found
827      *
828      * @see org.opencms.jsp.CmsJspTagProperty
829      */

830     public String JavaDoc property(String JavaDoc name, String JavaDoc file, String JavaDoc defaultValue, boolean escapeHtml) {
831
832         if (isNotInitialized()) {
833             return getMessage(NOT_INITIALIZED);
834         }
835         try {
836             if (file == null) {
837                 file = getController().getCmsObject().getRequestContext().getUri();
838             }
839             return CmsJspTagProperty.propertyTagAction(name, file, defaultValue, escapeHtml, getRequest());
840         } catch (CmsSecurityException e) {
841             if (defaultValue == null) {
842                 handleException(e);
843             }
844         } catch (Throwable JavaDoc t) {
845             handleException(t);
846         }
847         if (defaultValue == null) {
848             CmsMessageContainer msgContainer = Messages.get().container(
849                 Messages.GUI_ERR_FILE_PROP_MISSING_2,
850                 name,
851                 file);
852             return getMessage(msgContainer);
853         } else {
854             return defaultValue;
855         }
856     }
857
858     /**
859      * Checks if a template part should be used or not, same as using
860      * the <code>&lt;cms:template element="***" /&gt;</code> tag.<p>
861      *
862      * @param element the template element to check
863      * @return <code>true</code> if the element is active, <code>false</code> otherwise
864      *
865      * @see org.opencms.jsp.CmsJspTagUser
866      */

867     public boolean template(String JavaDoc element) {
868
869         return template(element, null, false);
870     }
871
872     /**
873      * Checks if a template part should be used or not, same as using
874      * the <code>&lt;cms:template ifexists="***" /&gt;</code> tag.<p>
875      *
876      * @param elementlist the list of elements to check
877      * @param checkall <code>true</code> if all elements in the list should be checked
878      * @return <code>true</code> if the elements available, <code>false</code> otherwise
879      *
880      * @see org.opencms.jsp.CmsJspTagUser
881      */

882     public boolean template(String JavaDoc elementlist, boolean checkall) {
883
884         return template(null, elementlist, checkall);
885     }
886
887     /**
888      * Checks if a template part should be used or not, same as using
889      * the <code>&lt;cms:template element="***" ifexists="***" /&gt;</code> tag.<p>
890      *
891      * @param element the template element to check
892      * @param elementlist the list of elements to check
893      * @param checkall <code>true</code> if all elements in the list should be checked
894      * @return <code>true</code> if the element is active, <code>false</code> otherwise
895      *
896      * @see org.opencms.jsp.CmsJspTagUser
897      */

898     public boolean template(String JavaDoc element, String JavaDoc elementlist, boolean checkall) {
899
900         if (isNotInitialized()) {
901             return true;
902         }
903         try {
904             return CmsJspTagTemplate.templateTagAction(element, elementlist, checkall, false, getRequest());
905         } catch (Throwable JavaDoc t) {
906             handleException(t);
907         }
908         return true;
909     }
910
911     /**
912      * Converts a relative URI in the OpenCms VFS to an absolute one based on
913      * the location of the currently processed OpenCms URI.<p>
914      *
915      * @param target the relative URI to convert
916      * @return the target URI converted to an absolute one
917      */

918     public String JavaDoc toAbsolute(String JavaDoc target) {
919
920         if (isNotInitialized()) {
921             return getMessage(NOT_INITIALIZED);
922         }
923         return CmsLinkManager.getAbsoluteUri(target, getController().getCurrentRequest().getElementUri());
924     }
925
926     /**
927      * Returns a selected user property, i.e. information about the currently
928      * logged in user, same as using
929      * the <code>&lt;cms:user property="***" /&gt;</code> tag.<p>
930      *
931      * @param property the user property to display, please see the tag documentation for valid options
932      * @return the value of the selected user property
933      *
934      * @see org.opencms.jsp.CmsJspTagUser
935      */

936     public String JavaDoc user(String JavaDoc property) {
937
938         if (isNotInitialized()) {
939             return getMessage(NOT_INITIALIZED);
940         }
941         try {
942             return CmsJspTagUser.userTagAction(property, getRequest());
943         } catch (Throwable JavaDoc t) {
944             handleException(t);
945         }
946         CmsMessageContainer msgContainer = Messages.get().container(Messages.GUI_ERR_USER_PROP_READ_1, property);
947         return getMessage(msgContainer);
948     }
949 }
Popular Tags