KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * File : $Source: /usr/local/cvs/opencms/src/org/opencms/jsp/CmsJspTagLabel.java,v $
3  * Date : $Date: 2006/03/27 14:52:19 $
4  * Version: $Revision: 1.19 $
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.CmsObject;
35 import org.opencms.flex.CmsFlexController;
36 import org.opencms.i18n.CmsMessages;
37 import org.opencms.main.CmsLog;
38 import org.opencms.main.OpenCms;
39
40 import javax.servlet.ServletRequest JavaDoc;
41 import javax.servlet.jsp.JspException JavaDoc;
42 import javax.servlet.jsp.tagext.BodyContent JavaDoc;
43 import javax.servlet.jsp.tagext.BodyTagSupport JavaDoc;
44
45 import org.apache.commons.logging.Log;
46
47 /**
48  * Provides access to the labels stored in the
49  * language files of the OpenCms workplace.<p>
50  *
51  * Instead of using the XML based workplace tags one should
52  * consider using standard Java resource bundles to provide language independent
53  * implementations.<p>
54  *
55  * @author Alexander Kandzior
56  *
57  * @version $Revision: 1.19 $
58  *
59  * @since 6.0.0
60  */

61 public class CmsJspTagLabel extends BodyTagSupport JavaDoc {
62
63     /** The log object for this class. */
64     private static final Log LOG = CmsLog.getLog(CmsJspTagLabel.class);
65
66     /** Serial version UID required for safe serialization. */
67     private static final long serialVersionUID = 5720473164730803034L;
68
69     /**
70      * Internal action method.<p>
71      *
72      * @param label the label to look up
73      * @param req the current request
74      * @return String the value of the selected label
75      */

76     public static String JavaDoc wpLabelTagAction(String JavaDoc label, ServletRequest JavaDoc req) {
77
78         CmsObject cms = CmsFlexController.getCmsObject(req);
79         CmsMessages messages = OpenCms.getWorkplaceManager().getMessages(cms.getRequestContext().getLocale());
80         return messages.key(label);
81     }
82
83     /**
84      * @see javax.servlet.jsp.tagext.IterationTag#doAfterBody()
85      */

86     public int doAfterBody() throws JspException JavaDoc {
87
88         ServletRequest JavaDoc req = pageContext.getRequest();
89
90         // This will always be true if the page is called through OpenCms
91
if (CmsFlexController.isCmsRequest(req)) {
92             try {
93
94                 // Get label string from the body and reset body
95
BodyContent JavaDoc body = this.getBodyContent();
96                 String JavaDoc label = body.getString();
97                 body.clearBody();
98
99                 // Get the result...
100
String JavaDoc result = wpLabelTagAction(label, req);
101                 this.getPreviousOut().print(result);
102
103             } catch (Exception JavaDoc ex) {
104                 if (LOG.isErrorEnabled()) {
105                     LOG.error(Messages.get().getBundle().key(Messages.ERR_PROCESS_TAG_1, "label"), ex);
106                 }
107                 throw new javax.servlet.jsp.JspException JavaDoc(ex);
108             }
109         }
110         return SKIP_BODY;
111     }
112
113 }
114
Popular Tags