KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jahia > deprecated > taglibs > button > DisplayLanguageCodeTag


1 // ____.
2
// __/\ ______| |__/\. _______
3
// __ .____| | \ | +----+ \
4
// _______| /--| | | - \ _ | : - \_________
5
// \\______: :---| : : | : | \________>
6
// |__\---\_____________:______: :____|____:_____\
7
// /_____|
8
//
9
// . . . i n j a h i a w e t r u s t . . .
10
//
11
/*
12  * ----- BEGIN LICENSE BLOCK -----
13  * Version: JCSL 1.0
14  *
15  * The contents of this file are subject to the Jahia Community Source License
16  * 1.0 or later (the "License"); you may not use this file except in
17  * compliance with the License. You may obtain a copy of the License at
18  * http://www.jahia.org/license
19  *
20  * Software distributed under the License is distributed on an "AS IS" basis,
21  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
22  * for the rights, obligations and limitations governing use of the contents
23  * of the file. The Original and Upgraded Code is the Jahia CMS and Portal
24  * Server. The developer of the Original and Upgraded Code is JAHIA Ltd. JAHIA
25  * Ltd. owns the copyrights in the portions it created. All Rights Reserved.
26  *
27  * The Shared Modifications are Jahia button taglibs.
28  *
29  * The Developer of the Shared Modifications is Jahia Solution Sàrl.
30  * Portions created by the Initial Developer are Copyright (C) 2002 by the
31  * Initial Developer. All Rights Reserved.
32  *
33  * Contributor(s):
34  * Sep 24 2002 Jahia Solutions Sàrl: MAP Initial release.
35  *
36  * ----- END LICENSE BLOCK -----
37  */

38
39 package org.jahia.deprecated.taglibs.button;
40
41 import java.io.IOException JavaDoc;
42 import java.util.Locale JavaDoc;
43
44 import javax.servlet.jsp.JspException JavaDoc;
45 import javax.servlet.jsp.JspWriter JavaDoc;
46 import javax.servlet.jsp.tagext.BodyTagSupport JavaDoc;
47
48 import org.jahia.utils.LanguageCodeConverters;
49 import org.jahia.utils.TextHtml;
50
51 /**
52  * <p>Title: Jahia Tag Lib</p>
53  * <p>Description:
54  * Display a language in the country language format.<br>
55  * Synopsis : < jahia:displayLanguageFlag code="'iso639'[_'iso3166']"<br>
56  * [href="'anchor href'"] [style="className"]<br>
57  * <br>
58  * The language is a composition of these both paramters :<br>
59  * <li>'iso639' : is the iso 639 language code. If this code is incorrect then the
60  * code name is displayed as is.<br>
61  * <li>'iso3166' : Optional parameter that represent the iso 3166 country code.<br>
62  * examples : code="en_UK" ; will display : English<br>
63  * code="fr" ; will display : français<br>
64  * code="fr_CH" ; will display : français<br>
65  * code="ar_AS" ; will display : ??????? (arabic chars)<br>
66  * </p>
67  * <p>Copyright: MAP (Jahia Solutions Sàrl 2002)</p>
68  * <p>Company: Jahia Solutions Sàrl</p>
69  * @author MAP
70  * @version 1.0
71  */

72 public class DisplayLanguageCodeTag extends BodyTagSupport JavaDoc {
73
74     /**
75      * @param code The language code coresponding to the iso 639 language code
76      * list.
77      */

78     public void setCode(String JavaDoc code) {
79         _code = code;
80     }
81
82     /**
83      * @param href The anchor href parameter.
84      */

85     public void setHref(String JavaDoc href) {
86         _href = href;
87     }
88
89     /**
90      *
91      * @param style The class CSS defined in the view interface.
92      */

93     public void setStyle(String JavaDoc style) {
94         _style = style;
95     }
96
97     public int doStartTag() {
98
99         // Produce the HTML code
100
try {
101             JspWriter JavaDoc out = pageContext.getOut();
102             StringBuffer JavaDoc str = new StringBuffer JavaDoc("");
103             if (debug) {
104                 str.append("\n<!-- ======================================================================= -->\n");
105                 str.append("<!-- The following HTML code is generated by 'DisplayLanguageCodeTag' taglib -->\n");
106                 str.append("<!----------------------------------------------------------------------------->\n");
107             }
108             if (!"".equals(_href)) {
109                 str.append("<a ");
110                 if (!"".equals(_style)) {
111                     str.append("class=\"");
112                     str.append(_style);
113                     str.append("\" ");
114                 }
115                 str.append("href=\"");
116                 str.append(_href);
117                 str.append("\">");
118             }
119             Locale JavaDoc localeLangToDisplay = LanguageCodeConverters.languageCodeToLocale(_code);
120             str.append(TextHtml.text2html(localeLangToDisplay.getDisplayLanguage(localeLangToDisplay)));
121             if (!"".equals(_href)) {
122                 str.append("</a>");
123             }
124             if (debug) {
125                 str.append("\n<!-- ======================================================================= -->\n");
126             }
127             out.print(str.toString());
128         } catch (IOException JavaDoc ioe) {
129             logger.debug(ioe.toString());
130         }
131         return SKIP_BODY;
132     }
133
134     public int doEndTag() throws JspException JavaDoc {
135         // let's reinitialize the tag variables to allow tag object reuse in
136
// pooling.
137
_code = "";
138         _href = "";
139         _style = "";
140         return EVAL_PAGE;
141     }
142
143     // Taglib parameters
144
private String JavaDoc _code = "";
145     private String JavaDoc _href = "";
146     private String JavaDoc _style = "";
147
148     // Display debug information
149
/** @todo FIXME : change harcoded debug information */
150     private boolean debug = false;
151     private static long imgID = 0;
152
153     private static org.apache.log4j.Logger logger =
154             org.apache.log4j.Logger.getLogger(DisplayLanguageCodeTag.class);
155
156 }
Popular Tags