dgraham 2003/07/10 21:22:15
Modified: doc/userGuide struts-html.xml
src/share/org/apache/struts/taglib/html HtmlTag.java
Log:
Added lang attribute and deprecated locale attribute for PR# 18000.
Revision Changes Path
1.56 +17 -0 jakarta-struts/doc/userGuide/struts-html.xml
Index: struts-html.xml
===================================================================
RCS file: /home/cvs/jakarta-struts/doc/userGuide/struts-html.xml,v
retrieving revision 1.55
retrieving revision 1.56
diff -u -r1.55 -r1.56
--- struts-html.xml 8 Jul 2003 00:05:10 -0000 1.55
+++ struts-html.xml 11 Jul 2003 04:22:15 -0000 1.56
@@ -2291,6 +2291,19 @@
object, if there is one.</p>
</info>
+ <attribute>
+ <name>lang</name>
+ <required>false</required>
+ <rtexprvalue>true</rtexprvalue>
+ <info>
+ Renders a lang attribute with the locale stored in the user's
session. If not
+ found in the session, the language from the
<code>Accept-Language</code>
+ HTTP header is used. If still not found, the default language for
the server
+ is used.
+ </info>
+ <since>Struts 1.2</since>
+ </attribute>
+
<attribute>
<name>locale</name>
<required>false</required>
@@ -2302,6 +2315,10 @@
if one does not already exist. The lang attribute is rendered with
the
appropriate language code.</p>
</info>
+ <deprecated>
+ Creating a session is undesirable for apps that don't support them.
Use the lang
+ attribute to acheive the same functionality without creating a
session.
+ </deprecated>
</attribute>
<attribute>
1.14 +54 -19
jakarta-struts/src/share/org/apache/struts/taglib/html/HtmlTag.java
Index: HtmlTag.java
===================================================================
RCS file:
/home/cvs/jakarta-struts/src/share/org/apache/struts/taglib/html/HtmlTag.java,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -r1.13 -r1.14
--- HtmlTag.java 10 Jul 2003 04:10:05 -0000 1.13
+++ HtmlTag.java 11 Jul 2003 04:22:15 -0000 1.14
@@ -97,34 +97,58 @@
/**
* Should we set the current Locale for this user if needed?
+ * @deprecated This will be removed after Struts 1.2.
*/
protected boolean locale = false;
+ /**
+ * @deprecated This will be removed after Struts 1.2.
+ */
public boolean getLocale() {
return (locale);
}
+ /**
+ * @deprecated This will be removed after Struts 1.2.
+ */
public void setLocale(boolean locale) {
this.locale = locale;
}
-
/**
* Are we rendering an xhtml page?
*/
protected boolean xhtml = false;
+
+ /**
+ * Are we rendering a lang attribute?
+ * @since Struts 1.2
+ */
+ protected boolean lang = false;
public boolean getXhtml() {
- return (xhtml);
+ return this.xhtml;
}
public void setXhtml(boolean xhtml) {
this.xhtml = xhtml;
}
+
+ /**
+ * Returns true if the tag should render a lang attribute.
+ * @since Struts 1.2
+ */
+ public boolean getLang() {
+ return this.lang;
+ }
-
- // --------------------------------------------------------- Public Methods
-
+ /**
+ * Sets whether the tag should render a lang attribute.
+ * @since Struts 1.2
+ */
+ public void setLang(boolean lang) {
+ this.lang = lang;
+ }
/**
* Process the start of this tag.
@@ -146,29 +170,38 @@
StringBuffer sb = new StringBuffer("<html");
// Use the current Locale to set our language preferences
- Locale currentLocale = this.getCurrentLocale();
- String lang = currentLocale.getLanguage();
+ String language = null;
+ if (this.locale) {
+ // provided for 1.1 backward compatibility, remove after 1.2
+ language = this.getCurrentLocale().getLanguage();
+ } else {
+ language =
+ RequestUtils
+ .retrieveUserLocale(pageContext, Globals.LOCALE_KEY)
+ .getLanguage();
+ }
// Does the locale have a language?
- boolean validLanguage = ((lang != null) && (lang.length() > 0));
+ boolean validLanguage = ((language != null) && (language.length() > 0));
if (this.xhtml) {
this.pageContext.setAttribute(
Globals.XHTML_KEY,
"true",
PageContext.PAGE_SCOPE);
+
sb.append(" xmlns=\"http://www.w3.org/1999/xhtml\"");
}
- if ((this.locale || this.xhtml) && validLanguage) {
+ if ((this.lang || this.locale || this.xhtml) && validLanguage) {
sb.append(" lang=\"");
- sb.append(lang);
+ sb.append(language);
sb.append("\"");
}
if (this.xhtml && validLanguage) {
sb.append(" xml:lang=\"");
- sb.append(lang);
+ sb.append(language);
sb.append("\"");
}
@@ -196,10 +229,9 @@
* Release any acquired resources.
*/
public void release() {
-
- locale = false;
- xhtml = false;
-
+ this.locale = false;
+ this.xhtml = false;
+ this.lang=false;
}
@@ -212,6 +244,7 @@
* client's Accept-Language header or the server's default locale and store it
in the
* session. This will always return a Locale and never null.
* @since Struts 1.1
+ * @deprecated This will be removed after Struts 1.2.
*/
protected Locale getCurrentLocale() {
@@ -225,5 +258,7 @@
return userLocale;
}
+
+
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]