KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > ofbiz > webapp > taglib > I18nBundleTag


1 /*
2  * $Id: I18nBundleTag.java 5462 2005-08-05 18:35:48Z jonesde $
3  *
4  * Copyright (c) 2002-2003 The Open For Business Project - www.ofbiz.org
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a
7  * copy of this software and associated documentation files (the "Software"),
8  * to deal in the Software without restriction, including without limitation
9  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10  * and/or sell copies of the Software, and to permit persons to whom the
11  * Software is furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be included
14  * in all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
17  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19  * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
20  * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT
21  * OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR
22  * THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23  *
24  */

25 package org.ofbiz.webapp.taglib;
26
27 import java.util.ResourceBundle JavaDoc;
28 import javax.servlet.http.HttpServletRequest JavaDoc;
29 import javax.servlet.jsp.JspException JavaDoc;
30 import javax.servlet.jsp.tagext.TagSupport JavaDoc;
31
32 import org.ofbiz.base.util.Debug;
33 import org.ofbiz.base.util.UtilHttp;
34 import org.ofbiz.base.util.UtilJ2eeCompat;
35 import org.ofbiz.base.util.UtilProperties;
36
37 /**
38  * I18nBundleTag - JSP tag that the MessageTags will use when retrieving keys
39  * for this page.
40  *
41  * @author <a HREF="mailto:k3ysss@yahoo.com">Jian He</a>
42  * @author <a HREF="mailto:">Quake Wang</a>
43  * @author <a HREF="mailto:jonesde@ofbiz.org">David E. Jones</a>
44  * @version $Rev: 5462 $
45  * @since 2.0
46  */

47 public class I18nBundleTag extends TagSupport JavaDoc {
48     
49     public static final String JavaDoc module = I18nBundleTag.class.getName();
50
51     private String JavaDoc baseName = null;
52
53     private ResourceBundle JavaDoc bundle = null;
54
55     public void setBaseName(String JavaDoc baseName) {
56         this.baseName = baseName;
57     }
58
59     public String JavaDoc getBaseName() {
60         return this.baseName;
61     }
62
63     public void setBundle(ResourceBundle JavaDoc bundle) {
64         this.bundle = bundle;
65     }
66
67     public ResourceBundle JavaDoc getBundle() {
68         return this.bundle;
69     }
70
71     public int doStartTag() throws JspException JavaDoc {
72         try {
73             this.bundle = UtilProperties.getResourceBundle(this.baseName, UtilHttp.getLocale((HttpServletRequest JavaDoc) pageContext.getRequest()));
74
75             if (this.getId() != null) {
76                 pageContext.setAttribute(this.getId(), this.bundle);
77             }
78         } catch (Exception JavaDoc e) {
79             if (UtilJ2eeCompat.useNestedJspException(pageContext.getServletContext())) {
80                 throw new JspException JavaDoc(e.getMessage(), e);
81             } else {
82                 Debug.logError(e, "Server does not support nested exceptions, here is the exception", module);
83                 throw new JspException JavaDoc(e.toString());
84             }
85         }
86
87         return EVAL_BODY_INCLUDE;
88     }
89
90     public int doEndTag() throws JspException JavaDoc {
91         return EVAL_PAGE;
92     }
93 }
94
Popular Tags