Source code: com/opencms/flex/jsp/CmsJspTagLabel.java
1 /*
2 * File : $Source: /usr/local/cvs/opencms/src/com/opencms/flex/jsp/Attic/CmsJspTagLabel.java,v $
3 * Date : $Date: 2003/05/13 13:18:20 $
4 * Version: $Revision: 1.3.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.core.CmsException;
35 import com.opencms.flex.cache.CmsFlexController;
36 import com.opencms.workplace.CmsXmlLanguageFile;
37 import com.opencms.workplace.CmsXmlWpLabelDefFile;
38 import com.opencms.workplace.I_CmsWpConstants;
39
40 import javax.servlet.ServletRequest;
41 import javax.servlet.jsp.JspException;
42 import javax.servlet.jsp.tagext.BodyContent;
43 import javax.servlet.jsp.tagext.BodyTagSupport;
44
45 /**
46 * Provides access to the labels stored in the
47 * language files of the OpenCms workplace.<p>
48 *
49 * Instead of using the XML based workplace tags one should
50 * consider using standard Java resource bundles to provide language independent
51 * implementations.
52 *
53 * @author Alexander Kandzior (a.kandzior@alkacon.com)
54 * @version $Revision: 1.3.2.1 $
55 */
56 public class CmsJspTagLabel extends BodyTagSupport {
57
58 /**
59 * @see javax.servlet.jsp.tagext.IterationTag#doAfterBody()
60 */
61 public int doAfterBody() throws JspException {
62
63 ServletRequest req = pageContext.getRequest();
64
65 // This will always be true if the page is called through OpenCms
66 if (CmsFlexController.isCmsRequest(req)) {
67 try {
68
69 // Get label string from the body and reset body
70 BodyContent body = this.getBodyContent();
71 String label = body.getString();
72 body.clearBody();
73
74 // Get the result...
75 String result = wpLabelTagAction(label, req);
76 this.getPreviousOut().print(result);
77
78 } catch (Exception ex) {
79 System.err.println("Error in Jsp 'label' tag processing: " + ex);
80 System.err.println(com.opencms.util.Utils.getStackTrace(ex));
81 throw new javax.servlet.jsp.JspException(ex);
82 }
83 }
84 return SKIP_BODY;
85 }
86
87 /**
88 * Internal action method.<p>
89 *
90 * @param label the label to look up
91 * @param req the current request
92 * @return String the value of the selected lable
93 * @throws CmsException in case something goes wrong
94 */
95 public static String wpLabelTagAction(String label, ServletRequest req)
96 throws CmsException {
97 CmsXmlWpLabelDefFile labeldeffile;
98 CmsXmlLanguageFile langfile;
99
100 CmsFlexController controller = (CmsFlexController)req.getAttribute(CmsFlexController.ATTRIBUTE_NAME);
101
102 labeldeffile = new CmsXmlWpLabelDefFile(controller.getCmsObject(), I_CmsWpConstants.C_VFS_PATH_WORKPLACE + I_CmsWpConstants.C_VFS_DIR_TEMPLATES + I_CmsWpConstants.C_LABELTEMPLATE);
103 langfile = new CmsXmlLanguageFile(controller.getCmsObject());
104
105 return labeldeffile.getLabel(langfile.getLanguageValue(label));
106 }
107
108 }