Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: com/opencms/flex/jsp/CmsJspActionElement.java


1   /*
2    * File   : $Source: /usr/local/cvs/opencms/src/com/opencms/flex/jsp/CmsJspActionElement.java,v $
3    * Date   : $Date: 2003/05/13 13:18:20 $
4    * Version: $Revision: 1.24.2.1 $
5    *
6    * This library is part of OpenCms -
7    * the Open Source Content Mananagement System
8    *
9    * Copyright (C) 2002 - 2003 Alkacon Software (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, 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 com.opencms.flex.jsp;
33  
34  import com.opencms.boot.I_CmsLogChannels;
35  import com.opencms.core.A_OpenCms;
36  import com.opencms.core.CmsException;
37  import com.opencms.file.CmsFile;
38  import com.opencms.file.CmsObject;
39  import com.opencms.file.CmsRequestContext;
40  import com.opencms.file.CmsResource;
41  import com.opencms.flex.CmsJspLoader;
42  import com.opencms.flex.CmsJspTemplate;
43  import com.opencms.flex.cache.CmsFlexController;
44  import com.opencms.flex.util.CmsMessages;
45  import com.opencms.launcher.CmsDumpLauncher;
46  import com.opencms.launcher.CmsLinkLauncher;
47  import com.opencms.launcher.CmsXmlLauncher;
48  import com.opencms.launcher.I_CmsLauncher;
49  import com.opencms.template.CmsXmlTemplate;
50  import com.opencms.util.Utils;
51  
52  import java.io.UnsupportedEncodingException;
53  import java.util.HashMap;
54  import java.util.Iterator;
55  import java.util.Map;
56  
57  import javax.servlet.http.HttpServletRequest;
58  import javax.servlet.http.HttpServletResponse;
59  import javax.servlet.jsp.JspException;
60  import javax.servlet.jsp.PageContext;
61  
62  /**
63   * Bean to be used in JSP scriptlet code that provides direct 
64   * access to the functionality offered by the opencms taglib.<p>
65   * 
66   * By instanciating a bean of this type and accessing the methods provided by 
67   * the instance, all functionality of the OpenCms JSP taglib can be easily 
68   * used from within JSP scriplet code,<p>
69   * 
70   * Initialize this bean at the beginning of your JSP like this:
71   * <pre>
72   * &lt;jsp:useBean id="cms" class="com.opencms.flex.jsp.CmsJspActionElement"&gt;
73   * &lt% cms.init(pageContext, request, response); %&gt;
74   * &lt;/jsp:useBean&gt;
75   * </pre>
76   * 
77   * All exceptions that occur when calling any method of this class are catched 
78   * and written to the log output only, so that a template still has a chance of
79   * working at last in some elements.<p>
80   *
81   * @author  Alexander Kandzior (a.kandzior@alkacon.com)
82   * @version $Revision: 1.24.2.1 $
83   * 
84   * @since 5.0 beta 2
85   */
86  public class CmsJspActionElement {
87  
88      /** OpenCms JSP request */
89      private HttpServletRequest m_request;
90  
91      /** OpenCms JSP response */
92      private HttpServletResponse m_response;
93      
94      /** OpenCms core CmsObject */
95      private CmsFlexController m_controller;
96  
97      /** JSP page context */
98      private PageContext m_context;    
99      
100     /** JSP navigation builder */
101     private CmsJspNavBuilder m_navigation = null;    
102     
103     /** Flag to indicate that this bean was properly initialized */
104     private boolean m_notInitialized;
105     
106     /** Flag to indicate if we want default or custom Exception handling */
107     private boolean m_handleExceptions = true;
108         
109     /** Error message in case bean was not properly initialized */
110     public final static String C_NOT_INITIALIZED = "+++ CmsJspActionElement not initialized +++";
111 
112     /** DEBUG flag */
113     private static final int DEBUG = 0;
114     
115     /**
116      * Empty constructor, required for every JavaBean.
117      */
118     public CmsJspActionElement() {
119         m_notInitialized = true;
120     }
121     
122     /**
123      * Constructor, with parameters.
124      * 
125      * @param content the JSP page context object
126      * @param req the JSP request 
127      * @param res the JSP response 
128      */
129     public CmsJspActionElement(PageContext context, HttpServletRequest req, HttpServletResponse res) {
130         m_notInitialized = true;
131         init(context, req, res);
132     }    
133     
134     /**
135      * Initialize the bean with the current page context, request and response.<p>
136      * 
137      * It is required to call one of the init() methods before you can use the 
138      * instance of this bean.
139      * 
140      * @param content the JSP page context object
141      * @param req the JSP request 
142      * @param res the JSP response 
143      */
144     public void init(PageContext context, HttpServletRequest req, HttpServletResponse res) {
145         m_controller = (CmsFlexController)req.getAttribute(CmsFlexController.ATTRIBUTE_NAME);
146         if (m_controller == null) {
147             // controller not found - this request was not initialized properly
148             
149         }
150         m_context = context;
151         m_request = req;
152         m_response = res;
153         m_notInitialized = false;
154     }    
155     
156     /**
157      * Returns <code>true</code> if Exceptions are handled by the class instace, or
158      * <code>false</code> if they will be thrown and have to be handled by the calling class.<p>
159      * 
160      * The default is <code>true</code>.
161      * If set to <code>false</code> Exceptions that occur internally will be wrapped into
162      * a RuntimeException and thrown to the calling class instance.<p>
163      * 
164      * <b>Important:</b> Exceptions that occur during a call to {@link #includeSilent(String, String, Map)}
165      * will NOT be handled.
166      * 
167      * @return <code>true</code> if Exceptions are handled by the class instace, or
168      *      <code>false</code> if they will be thrown and have to be handled by the calling class
169      */
170     public boolean getHandleExceptions() {
171         return m_handleExceptions;
172     }
173 
174     /**
175      * Controls if Exceptions that occur in methods of this class are supressed (true)
176      * or not (false).<p>
177      * 
178      * The default is <code>true</code>.
179      * If set to <code>false</code> all Exceptions that occur internally will be wrapped into
180      * a RuntimeException and thrown to the calling class instance.<p>
181      * 
182      * <b>Important:</b> Exceptions that occur during a call to {@link #includeSilent(String, String, Map)}
183      * will NOT be handled.
184      * 
185      * @param the value to set the Exception handing to
186      */
187     public void setHandleExceptions(boolean value) {
188         m_handleExceptions = value;
189     }    
190     
191     /**
192      * Returns the request wrapped by the element.<p>
193      * 
194      * @return the request wrapped by the element
195      */
196     public HttpServletRequest getRequest() {
197         if (m_notInitialized) return null;
198         return m_request;        
199     }
200     
201     /**
202      * Returns the reponse wrapped by this element.<p>
203      * 
204      * @return the reponse wrapped by this element
205      */
206     public HttpServletResponse getResponse() {
207         if (m_notInitialized) return null;
208         return m_response;        
209     }    
210     
211     /**
212      * Returns the JSP page context wrapped by this element.<p>
213      * 
214      * @return the JSP page context wrapped by this element
215      */    
216     public PageContext getPageContext() {
217         if (m_notInitialized) return null;
218         return m_context;           
219     }
220 
221     /**
222      * Returns the CmsObject from the wrapped request.<p>
223      *
224      * This is a convenience method in case you need access to
225      * the CmsObject in your JSP scriplets.
226      *
227      * @return the CmsObject from the wrapped request
228      */
229     public CmsObject getCmsObject() {
230         if (m_notInitialized) return null;
231         try { 
232             return m_controller.getCmsObject();
233         } catch (Throwable t) {
234             handleException(t);
235         }      
236         return null;            
237     }
238     
239     /**
240      * Include a sub-element without paramters from the OpenCms VFS, same as
241      * using the <code>&lt;cms:include file="..." /&gt;</code> tag.
242      * 
243      * @param target the target uri of the file in the OpenCms VFS (can be relative or absolute)
244      * @throws JspException in case there were problems including the target
245      *
246      * @see com.opencms.flex.jsp.CmsJspTagInclude
247      */
248     public void include(String target) throws JspException {
249         this.include(target, null, null);
250     }
251     
252     /**
253      * Include a named sub-element without paramters from the OpenCms VFS, same as
254      * using the <code>&lt;cms:include file="..." element="..." /&gt;</code> tag.
255      * 
256      * @param target the target uri of the file in the OpenCms VFS (can be relative or absolute)
257      * @param element the element (template selector) to display from the target
258      * @throws JspException in case there were problems including the target
259      *
260      * @see com.opencms.flex.jsp.CmsJspTagInclude
261      */    
262     public void include(String target, String element) throws JspException {
263         this.include(target, element, null);
264     }
265 
266     /**
267      * Include a named sub-element with paramters from the OpenCms VFS, same as
268      * using the <code>&lt;cms:include file="..." element="..." /&gt;</code> tag
269      * with parameters in the tag body.<p>
270      * 
271      * The parameter map should be a map where the keys are Strings 
272      * (the parameter names) and the values are of type String[].
273      * However, as a convenience feature,
274      * in case you provide just a String for the parameter value, 
275      * it will automatically be translated to a String[1].<p>
276      * 
277      * The handling of the <code>element</code> parameter depends on the 
278      * included file type. Most often it is used as template selector.<p>
279      * 
280      * <b>Important:</b> Exceptions that occur in the include process are NOT
281      * handled even if {@link #setHandleExceptions(boolean)} was set to <code>true</code>.
282      * 
283      * @param target the target uri of the file in the OpenCms VFS (can be relative or absolute)
284      * @param element the element (template selector) to display from the target
285      * @param parameterMap a map of the request parameters
286      * @throws JspException in case there were problems including the target
287      * 
288      * @see com.opencms.flex.jsp.CmsJspTagInclude
289      */
290     public void include(String target, String element, Map parameterMap) throws JspException {
291         if (m_notInitialized) return;
292         if (parameterMap != null) {
293             try {
294                 HashMap modParameterMap = new HashMap(parameterMap.size());
295                 // ensure parameters are always of type String[] not just String
296                 Iterator i = parameterMap.keySet().iterator();
297                 while (i.hasNext()) {
298                     String key = (String)i.next();
299                     Object value = parameterMap.get(key);
300                     if (value instanceof String[]) {
301                         modParameterMap.put(key, value);
302                     } else {
303                         if (value == null)
304                             value = "null";
305                         String[] newValue = new String[] { value.toString()};
306                         modParameterMap.put(key, newValue);
307                     }
308                 }
309                 parameterMap = modParameterMap;
310             } catch (UnsupportedOperationException e) {
311                 // parameter map is immutable, just use it "as is"
312             }
313         }
314         CmsJspTagInclude.includeTagAction(m_context, target, element, parameterMap, m_request, m_response);
315     }
316     
317     /**
318      * Includes a named sub-element supressing all Exceptions that occur during the include,
319      * otherwise the same as using {@link #include(String, String, Map null)}.<p>
320      * 
321      * This is a convenience method that allows to include elements on a page without checking 
322      * if they exist or not. If the target element does not exist, nothing is printed to 
323      * the JSP output.<p>
324      * 
325      * @param target the target uri of the file in the OpenCms VFS (can be relative or absolute)
326      * @param element the element (template selector) to display from the target
327      */
328     public void includeSilent(String target, String element) {
329         try {
330             include(target, element, null);
331         } catch (Throwable t) {
332         }
333     }  
334         
335     /**
336      * Includes a named sub-element supressing all Exceptions that occur during the include,
337      * otherwise the same as using {@link #include(String, String, Map)}.<p>
338      * 
339      * This is a convenience method that allows to include elements on a page without checking 
340      * if they exist or not. If the target element does not exist, nothing is printed to 
341      * the JSP output.<p>
342      * 
343      * @param target the target uri of the file in the OpenCms VFS (can be relative or absolute)
344      * @param element the element (template selector) to display from the target
345      * @param parameterMap a map of the request parameters
346      */
347     public void includeSilent(String target, String element, Map parameterMap) {
348         try {
349             include(target, element, parameterMap);
350         } catch (Throwable t) {
351         }
352     }    
353     
354     /**
355      * Converts a relative URI in the OpenCms VFS to an absolute one based on 
356      * the location of the currently processed OpenCms URI.
357      * 
358      * @param target the relative URI to convert
359      * @return the target URI converted to an absolute one
360      */
361     public String toAbsolute(String target) {
362         if (m_notInitialized) return C_NOT_INITIALIZED;
363         return m_controller.getCurrentRequest().toAbsolute(target);
364     }
365             
366     /**
367      * Calculate a link with the OpenCms link management,
368      * same as using the <code>&lt;cms:link&gt;...&lt;/cms:link&gt;</code> tag.<p>
369      * 
370      * This is important to get the right link for exported resources, 
371      * e.g. for images in the online project.
372      * 
373      * @param link the uri in the OpenCms to link to
374      * @return the translated link
375      * 
376      * @see com.opencms.flex.jsp.CmsJspTagLink
377      */
378     public String link(String link) {
379         if (m_notInitialized) return C_NOT_INITIALIZED;
380         try {        
381             return CmsJspTagLink.linkTagAction(link, m_request);
382         } catch (Throwable t) {
383             handleException(t);
384         }  
385         return "+++ error generating link to '" + link + "' +++";             
386     }
387     
388     /**
389      * Returns a selected user property, i.e. information about the currently
390      * logged in user, same as using 
391      * the <code>&lt;cms:user property="..." /&gt;</code> tag.<p>
392      * 
393      * @param property the user property to display, please see the tag documentation for valid options
394      * @return the value of the selected user property
395      * 
396      * @see com.opencms.flex.jsp.CmsJspTagUser
397      */
398     public String user(String property) {
399         if (m_notInitialized) return C_NOT_INITIALIZED;
400         try {
401             return CmsJspTagUser.userTagAction(property, m_request);
402         } catch (Throwable t) {
403             handleException(t);
404         }  
405         return "+++ error reading user property '" + property + "' +++";            
406     }
407     
408     /**
409      * Returns a selected file property value, same as using 
410      * the <code>&lt;cms:property name="..." /&gt;</code> tag or
411      * calling {@link #property(String name, String null, String null, boolean false)}.<p>
412      * 
413      * @param name the name of the property to look for
414      * @return the value of the property found, or null if the property could not be found
415      * 
416      * @see #property(String, String, String, boolean)
417      * @see com.opencms.flex.jsp.CmsJspTagProperty
418      */
419     public String property(String name) {
420         return this.property(name, null, null, false);       
421     }
422         
423     /**
424      * Returns a selected file property value, same as using 
425      * the <code>&lt;cms:property name="..." file="..." /&gt;</code> tag or
426      * calling {@link #property(String name, String file, String null, boolean false)}.<p>
427      * 
428      * @param name the name of the property to look for
429      * @param file the file (or folder) to look at for the property
430      * @return the value of the property found, or null if the property could not be found
431      * 
432      * @see #property(String, String, String, boolean)
433      * @see com.opencms.flex.jsp.CmsJspTagProperty
434      */
435     public String property(String name, String file) {
436         return this.property(name, file, null, false);       
437     }
438 
439     /**
440      * Returns a selected file property value, same as using
441      * the <code>&lt;cms:property name="..." file="..." default="..." /&gt;</code> tag or
442      * calling {@link #property(String name, String file, String defaultValue, boolean false)}.<p>
443      *
444      * @param name the name of the property to look for
445      * @param file the file (or folder) to look at for the property
446      * @param defaultValue a default value in case the property was not found
447      * @return the value of the property found, or the value of defaultValue
448      *     if the property could not be found
449      *
450      * @see #property(String, String, String, boolean)
451      * @see com.opencms.flex.jsp.CmsJspTagProperty
452      */
453     public String property(String name, String file, String defaultValue) {
454         return this.property(name, file, defaultValue, false);
455     }
456             
457     /**
458      * Returns a selected file property value with optional HTML escaping, same as using 
459      * the <code>&lt;cms:property name="..." file="..." default="..." /&gt;</code> tag.<p>
460      * 
461      * Please see the description of the class {@link com.opencms.flex.jsp.CmsJspTagProperty} for
462      * valid options of the <code>file</code> parameter.<p>
463      * 
464      * @param name the name of the property to look for
465      * @param file the file (or folder) to look at for the property
466      * @param defaultValue a default value in case the property was not found
467      * @param escapeHtml if <code>true</code>, special HTML characters in the return value
468      *     are escaped with their number representations (e.g. &amp; becomes &amp;#38;)
469      * @return the value of the property found, or the value of defaultValue 
470      *     if the property could not be found
471      *
472      * @see com.opencms.flex.jsp.CmsJspTagProperty
473      */
474     public String property(String name, String file, String defaultValue, boolean escapeHtml) {
475         if (m_notInitialized) return C_NOT_INITIALIZED;
476         try {
477             if (file == null) file = m_controller.getCmsObject().getRequestContext().getUri();
478             return CmsJspTagProperty.propertyTagAction(name, file, defaultValue, escapeHtml, m_request);
479         } catch (Throwable t) {
480             handleException(t);
481         }   
482         if (defaultValue == null) {
483             return "+++ error reading file property '" + name + "' on '" + file + "' +++";
484         } else {
485             return defaultValue;
486         }
487     }
488 
489     /**
490      * Returns all properites of the current file.<p>
491      * 
492      * @return Map all properties of the current file
493      */
494     public Map properties() {
495         return this.properties(null);
496     }
497        
498     /**
499      * Returns all properites of the selected file.<p>
500      * 
501      * Please see the description of the class {@link com.opencms.flex.jsp.CmsJspTagProperty} for
502      * valid options of the <code>file</code> parameter.<p>
503      * 
504      * @param file the file (or folder) to look at for the properties
505      * @return Map all properties of the current file 
506      *     (and optional of the folders containing the file)
507      * 
508      * @see com.opencms.flex.jsp.CmsJspTagProperty
509      */
510     public Map properties(String file) {
511         if (m_notInitialized) return new HashMap();
512         Map value = new HashMap();        
513         try {
514             if (file == null) file = CmsJspTagProperty.USE_URI;   
515             switch (CmsJspTagProperty.m_actionValue.indexOf(file)) {      
516                 case 0: // USE_URI
517                 case 1: // USE_PARENT
518                     value = getCmsObject().readProperties(getRequestContext().getUri(), false);
519                     break;
520                 case 2: // USE_SEARCH
521                 case 3: // USE_SEARCH_URI
522                 case 4: // USE_SEARCH_PARENT 
523                     value = getCmsObject().readProperties(getRequestContext().getUri(), true);                        
524                     break;                
525                 case 5: // USE_ELEMENT_URI
526                 case 6: // USE_THIS
527                     // Read properties of this file            
528                     value = getCmsObject().readProperties(m_controller.getCurrentRequest().getElementUri(), false);
529                     break;
530                 case 7: // USE_SEARCH_ELEMENT_URI
531                 case 8: // USE_SEARCH_THIS
532                     // Try to find property on this file and all parent folders
533                     value = getCmsObject().readProperties(m_controller.getCurrentRequest().getElementUri(), true);
534                     break;
535                 default:
536                     // Read properties of the file named in the attribute            
537                     value = getCmsObject().readProperties(toAbsolute(file), false);
538             }            
539         } catch (Throwable t) {
540             handleException(t);
541         }
542         return value;          
543     }
544     
545     /**
546      * Returns an OpenCms or JVM system info property value, same as using
547      * the <code>&lt;cms:info property="..." /&gt;</code> tag.<p>
548      * 
549      * See the description of the class {@link CmsJspTagInfo} for a detailed list 
550      * of available options for the property value.<p>
551      *  
552      * @param property the property to look up
553      * @return String the value of the system property
554      * @see com.opencms.flex.jsp.CmsJspTagInfo
555      */
556     public String info(String property) {
557         try {        
558             return CmsJspTagInfo.infoTagAction(property, m_request);   
559         } catch (Throwable t) {
560             handleException(t);
561         }  
562         return "+++ error reading info property '" + property + "' +++";
563     }
564     
565     /**
566      * Returns an OpenCms workplace label.<p>
567      * 
568      * You should consider using a standard 
569      * {@link java.util.ResourceBundle java.util.ResourceBundle} instead of the 
570      * OpenCms workplace language files.
571      * 
572      * @param label the label to look up
573      * @return label the value of the label
574      * 
575      * @see com.opencms.flex.jsp.CmsJspTagLabel
576      */
577     public String label(String label) {
578         if (m_notInitialized) return C_NOT_INITIALIZED;
579         try {
580             return CmsJspTagLabel.wpLabelTagAction(label, m_request);
581         } catch (Throwable t) {
582             handleException(t);
583         }  
584         return "+++ error reading workplace label '" + label + "' +++";
585     }    
586     
587     /**
588      * Checks if a template part should be used or not, same as using 
589      * the <code>&lt;cms:template element="..." /&gt;</code> tag.<p>
590      * 
591      * @param part the template element to check 
592      * @return <code>true</code> if the element is active, <code>false</code> otherwise
593      * 
594      * @see com.opencms.flex.jsp.CmsJspTagUser
595      */
596     public boolean template(String element) {
597         if (m_notInitialized) return true;        
598         try {
599             return CmsJspTagTemplate.templateTagAction(element, m_request);
600         } catch (Throwable t) {
601             handleException(t);
602         }
603         return true;
604     }
605     
606     /** 
607      * Returns the current request context from the internal CmsObject.
608      * 
609      * @return the current request context from the internal CmsObject
610      */
611     public CmsRequestContext getRequestContext() {
612         if (m_notInitialized) return null;
613         try {
614             return m_controller.getCmsObject().getRequestContext();
615         } catch (Throwable t) {
616             handleException(t);
617         }
618         return null;
619     }
620     
621     /**
622      * Returns an initialized {@link CmsJspNavBuilder} instance.<p>
623      *  
624      * @return CmsJspNavBuilder an initialized <code>CmsJspNavBuilder</code>
625      * 
626      * @see com.opencms.flex.jsp.CmsJspNavBuilder
627      */
628     public CmsJspNavBuilder getNavigation() {
629         if (m_notInitialized) return null;
630         try {
631             if (m_navigation == null) {
632                 m_navigation = new CmsJspNavBuilder(m_controller.getCmsObject());
633             }
634             return m_navigation;
635         } catch (Throwable t) {
636             handleException(t);
637         }
638         return null;            
639     }
640     
641     /**
642      * Generates an initialized instance of {@link com.opencms.flex.util.CmsMessages} for 
643      * convenient access to localized resource bundles.<p>
644      * 
645      * @param bundleName the name of the ResourceBundle to use
646      * @param language language indentificator for the locale of the bundle
647      * @return CmsMessages a message bundle initialized with the provided values
648      */       
649     public CmsMessages getMessages(String bundleName, String language) {
650         return getMessages(bundleName, language, "", "", null);
651     }
652     
653     /**
654      * Generates an initialized instance of {@link com.opencms.flex.util.CmsMessages} for 
655      * convenient access to localized resource bundles.<p>
656      * 
657      * @param bundleName the name of the ResourceBundle to use
658      * @param language language indentificator for the locale of the bundle
659      * @param defaultLanguage default for the language, will be used 
660      *         if language is null or empty String "", and defaultLanguage is not null
661      * @return CmsMessages a message bundle initialized with the provided values
662      */    
663     public CmsMessages getMessages(String bundleName, String language, String defaultLanguage) {
664         return getMessages(bundleName, language, "", "", defaultLanguage);
665     }
666     
667     /**
668      * Generates an initialized instance of {@link com.opencms.flex.util.CmsMessages} for 
669      * convenient access to localized resource bundles.<p>
670      * 
671      * @param bundleName the name of the ResourceBundle to use
672      * @param language language indentificator for the locale of the bundle
673      * @param country 2 letter country code for the locale of the bundle 
674      * @param variant a vendor or browser-specific variant code
675      * @param defaultLanguage default for the language, will be used 
676      *         if language is null or empty String "", and defaultLanguage is not null
677      * @return CmsMessages a message bundle initialized with the provided values
678      * 
679      * @see java.util.ResourceBundle
680      * @see com.opencms.flex.util.CmsMessages
681      */
682     public CmsMessages getMessages(String bundleName, String language, String country, String variant, String defaultLanguage) {
683         try {
684             if ((defaultLanguage != null) && ((language == null) || ("".equals(language)))) {
685                 language = defaultLanguage;
686             }
687             if (language == null) language = "";
688             if (country == null) country = "";
689             if (variant == null) variant = "";
690             return new CmsMessages(bundleName, language, country, variant);
691         } catch (Throwable t) {
692             handleException(t);
693         }
694         return null;
695     }    
696     
697     /**
698      * Returns the processed output of an OpenCms resource in a String.<p>
699      * 
700      * @param target the target to process
701      * @return the processed output of an OpenCms resource in a String
702      */
703     public String getContent(String target) {
704         try {
705             I_CmsLauncher launcher = null;
706             target = toAbsolute(target);
707             try {
708                 CmsResource resource = getCmsObject().readFileHeader(target);
709                 launcher = getCmsObject().getLauncherManager().getLauncher(resource.getLauncherType());
710             } catch (java.lang.ClassCastException e) {
711                 // no loader omplementation found
712                 return "??? " + e.getMessage() + " ???";
713             } catch (com.opencms.core.CmsException e) {
714                 // file might not exist or no read permissions
715                 return "??? " + e.getMessage() + " ???";
716             }
717             try {
718                 if (launcher instanceof CmsJspLoader) {
719                     // jsp page
720                     CmsJspTemplate template = new CmsJspTemplate();
721                     byte[] res = template.getContent(getCmsObject(), target, null, null);
722                     return new String(res, getRequestContext().getEncoding());
723                 } else if (launcher instanceof CmsXmlLauncher) {
724                     // XmlTemplate page (will not work if file does not use the standard XmlTemplate class)
725                     CmsXmlTemplate template = new CmsXmlTemplate();
726                     byte[] res = template.getContent(getCmsObject(), target, null, null);
727                     return new String(res, getRequestContext().getEncoding());
728                 } else if (launcher instanceof CmsDumpLauncher) {
729                     // static page
730                     CmsFile file = getCmsObject().readFile(target);
731                     return new String(file.getContents(), getRequestContext().getEncoding());
732                 } else if (launcher instanceof CmsLinkLauncher) {
733                     // link
734                     CmsFile file = getCmsObject().readFile(target);
735                     return new String(file.getContents());
736                 }
737             } catch (CmsException ce) {
738                 return "??? " + ce.getMessage() + " ???";
739             } catch (UnsupportedEncodingException uee) {
740                 return "??? " + uee.getMessage() + " ???";
741             }
742         } catch (Throwable t) {
743             handleException(t);
744             return "??? " + t.getMessage() + " ???";
745         }
746         return "";
747     }
748 
749     /**
750      * Handles any exception that might occur in the context of this element to 
751      * ensure that templates are not disturbed.<p>
752      * 
753      * @param e the exception that was catched
754      */
755     private void handleException(Throwable t) {
756         if (I_CmsLogChannels.C_LOGGING && A_OpenCms.isLogging(I_CmsLogChannels.C_FLEX_LOADER)) {
757             A_OpenCms.log(I_CmsLogChannels.C_FLEX_LOADER, Utils.getStackTrace(t));
758         } 
759         if (! (m_handleExceptions || getRequestContext().currentProject().isOnlineProject())) {    
760             if (DEBUG > 0) {        
761                 System.err.println("Exception in " + this.getClass().getName() + ":");
762                 if (DEBUG > 1) t.printStackTrace(System.err);
763             }
764             throw new RuntimeException("Exception in " + this.getClass().getName(), t);
765         }
766     }
767 }