sylvain 2003/08/13 10:12:25
Modified: . status.xml
src/java/org/apache/cocoon/transformation
I18nTransformer.java
Log:
Ensure legacy behaviour of the I18nTransformer
Revision Changes Path
1.119 +6 -1 cocoon-2.1/status.xml
Index: status.xml
===================================================================
RCS file: /home/cvs/cocoon-2.1/status.xml,v
retrieving revision 1.118
retrieving revision 1.119
diff -u -r1.118 -r1.119
--- status.xml 13 Aug 2003 08:54:44 -0000 1.118
+++ status.xml 13 Aug 2003 17:12:25 -0000 1.119
@@ -202,6 +202,11 @@
<changes>
<release version="@version@" date="@date@">
+ <action dev="SW" type="fix">
+ Update the I18nTransformer so that it also accepts the 2.0 namespace. This
ensures backwards compatibility
+ for 2.0 applications. Additionally, attributes on "i18n:" elements can now be
in the default namespace (meaning
+ we can now write <i8n:text key="foo"> instead of <i18n:text
i18n:key="foo">)
+ </action>
<action dev="BRD" type="fix">
Fix in the SVG serializer: if setDocumentLocator wasn't called on the
serializer (which can happen if you have e.g. an XSLT transformer in the
1.12 +41 -13
cocoon-2.1/src/java/org/apache/cocoon/transformation/I18nTransformer.java
Index: I18nTransformer.java
===================================================================
RCS file:
/home/cvs/cocoon-2.1/src/java/org/apache/cocoon/transformation/I18nTransformer.java,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -r1.11 -r1.12
--- I18nTransformer.java 6 Aug 2003 14:50:11 -0000 1.11
+++ I18nTransformer.java 13 Aug 2003 17:12:25 -0000 1.12
@@ -252,6 +252,12 @@
public static final String I18N_OLD_NAMESPACE_URI =
"http://apache.org/cocoon/i18n/2.0";
+ /**
+ * Did we already encountered a old namespace ? This is static to ensure that
+ * the associated message will be logged only once.
+ */
+ private static boolean deprecationFound = false;
+
//
// i18n elements
//
@@ -1127,15 +1133,19 @@
strBuffer = null;
}
+ // Process start element event
if (I18N_OLD_NAMESPACE_URI.equals(uri)) {
- this.getLogger().error("The namespace "
- + I18N_OLD_NAMESPACE_URI
- + " for i18n is not supported any more, use: "
- + I18N_NAMESPACE_URI);
- }
+ if (!deprecationFound) {
+ deprecationFound = true;
+ this.getLogger().warn("The namespace '"
+ + I18N_OLD_NAMESPACE_URI
+ + "' for i18n is not supported any more, use:
'"
+ + I18N_NAMESPACE_URI + "'");
+ }
+ debug("Starting deprecated i18n element: " + name);
+ startI18NElement(name, attr);
- // Process start element event
- if (I18N_NAMESPACE_URI.equals(uri)) {
+ } else if (I18N_NAMESPACE_URI.equals(uri)) {
debug("Starting i18n element: " + name);
startI18NElement(name, attr);
} else { // We have a non i18n element event
@@ -1164,7 +1174,7 @@
strBuffer = null;
}
- if (I18N_NAMESPACE_URI.equals(uri)) {
+ if (I18N_NAMESPACE_URI.equals(uri) || I18N_OLD_NAMESPACE_URI.equals(uri)) {
endI18NElement(name);
} else if (current_state == STATE_INSIDE_PARAM) {
param_recorder.endElement(uri, name, raw);
@@ -1221,8 +1231,22 @@
prev_state = current_state;
current_state = STATE_INSIDE_TEXT;
- current_key = attr.getValue(I18N_NAMESPACE_URI, I18N_KEY_ATTRIBUTE);
- currentCatalogueId = attr.getValue(I18N_NAMESPACE_URI,
I18N_CATALOGUE_ATTRIBUTE);
+
+ current_key = attr.getValue("", I18N_KEY_ATTRIBUTE);
+ if (current_key == null) {
+ // Try the namespaced attribute
+ current_key = attr.getValue(I18N_NAMESPACE_URI, I18N_KEY_ATTRIBUTE);
+ if (current_key == null) {
+ // Try the old namespace
+ current_key = attr.getValue(I18N_OLD_NAMESPACE_URI,
I18N_KEY_ATTRIBUTE);
+ }
+ }
+
+ currentCatalogueId = attr.getValue("", I18N_CATALOGUE_ATTRIBUTE);
+ if (currentCatalogueId == null) {
+ // Try the namespaced attribute
+ currentCatalogueId = attr.getValue(I18N_NAMESPACE_URI,
I18N_CATALOGUE_ATTRIBUTE);
+ }
if (prev_state != STATE_INSIDE_PARAM)
tr_text_recorder = null;
@@ -1540,8 +1564,12 @@
// Translate all attributes from i18n:attr="name1 name2 ..."
// using their values as keys
- int i18n_attr_index =
- temp_attr.getIndex(I18N_NAMESPACE_URI,I18N_ATTR_ATTRIBUTE);
+ int i18n_attr_index =
temp_attr.getIndex(I18N_NAMESPACE_URI,I18N_ATTR_ATTRIBUTE);
+
+ if (i18n_attr_index == -1) {
+ // Try the old namespace
+ i18n_attr_index =
temp_attr.getIndex(I18N_OLD_NAMESPACE_URI,I18N_ATTR_ATTRIBUTE);
+ }
if (i18n_attr_index != -1) {
StringTokenizer st =