vgritsenko 02/02/09 15:28:05 Modified: src/java/org/apache/cocoon/transformation I18nTransformer.java Log: Patch from Piroumian, Konstantin [[EMAIL PROTECTED]] Revision Changes Path 1.12 +56 -28 xml-cocoon2/src/java/org/apache/cocoon/transformation/I18nTransformer.java Index: I18nTransformer.java =================================================================== RCS file: /home/cvs/xml-cocoon2/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 7 Feb 2002 14:23:15 -0000 1.11 +++ I18nTransformer.java 9 Feb 2002 23:28:05 -0000 1.12 @@ -229,7 +229,7 @@ * @author <a href="mailto:[EMAIL PROTECTED]">Marcus Crafter</a> * @author <a href="mailto:[EMAIL PROTECTED]">Michael Enke</a> * @author <a href="mailto:[EMAIL PROTECTED]">Lassi Immonen</a> - * @version CVS $Id: I18nTransformer.java,v 1.11 2002/02/07 14:23:15 vgritsenko Exp $ + * @version CVS $Id: I18nTransformer.java,v 1.12 2002/02/09 23:28:05 vgritsenko Exp $ * * @todo Move all formatting/parsing routines to I18nUtils */ @@ -588,9 +588,6 @@ // Date pattern types map: short, medium, long, full private static final Map datePatterns; - - // String buffer - private StringBuffer strBuffer; static { // initialize date types set @@ -629,6 +626,9 @@ // elements. private int prev_state; + // Character data buffer, used to concat chunked character data + private StringBuffer strBuffer; + // The i18n:key attribute is stored for the current element. // If no translation found for the key then the character data of element is // used as default value. @@ -864,6 +864,10 @@ if (I18N_NAMESPACE_URI.equals(uri)) { debug("Starting i18n element: " + name); + if (strBuffer != null) { + i18nCharacters(strBuffer.toString()); + strBuffer = null; + } startI18NElement(name, attr); return; } @@ -876,6 +880,10 @@ throws SAXException { if (I18N_NAMESPACE_URI.equals(uri)) { + if (strBuffer != null) { + i18nCharacters(strBuffer.toString()); + strBuffer = null; + } endI18NElement(name); return; } @@ -886,7 +894,12 @@ public void characters(char[] ch, int start, int len) throws SAXException { if (current_state != STATE_OUTSIDE) { - i18nCharacters(ch, start, len); + // Perform buffering to prevent chunked character data + if (strBuffer == null) { + strBuffer = new StringBuffer(); + } + strBuffer.append(ch, start, len); + return; } @@ -902,8 +915,6 @@ throws SAXException { debug("Start i18n element: " + name); - //initialize the string buffer - strBuffer = new StringBuffer(); if (I18N_TEXT_ELEMENT.equals(name)) { if (current_state != STATE_OUTSIDE @@ -1033,11 +1044,40 @@ private void endI18NElement(String name) throws SAXException { debug("End i18n element: " + name); - - if (strBuffer.length() == 0) { + switch (current_state) { + case STATE_INSIDE_TEXT: + endTextElement(); + break; + + case STATE_INSIDE_TRANSLATE: + endTranslateElement(); + break; + + case STATE_INSIDE_PARAM: + endParamElement(); + break; + + case STATE_INSIDE_DATE: + case STATE_INSIDE_DATE_TIME: + case STATE_INSIDE_TIME: + endDate_TimeElement(); + break; + + case STATE_INSIDE_NUMBER: + endNumberElement(); + break; + } + } + + private void i18nCharacters(String textValue) + throws SAXException { + + textValue = textValue.trim(); + if (textValue == null || textValue.length() == 0) { return; } - debug( "i18n message text = '" + strBuffer.toString() + "'" ); + + debug( "i18n message text = '" + textValue + "'" ); switch (current_state) { case STATE_INSIDE_TEXT: @@ -1046,46 +1086,40 @@ // If no translation found and untranslated param is null if (translated_text == null) { - translated_text = strBuffer.toString(); // use the key + translated_text = textValue; // use the key } // reset the key holding variable current_key = null; } else { // use text value as dictionary key - translated_text = getString(strBuffer.toString(), - (untranslated == null) ? strBuffer.toString(): untranslated); + translated_text = getString(textValue, (untranslated == null) + ? textValue : untranslated); } - endTextElement(); break; case STATE_INSIDE_TRANSLATE: // Store text for param substitution (do not translate) if (substitute_text == null) { - substitute_text = strBuffer.toString(); + substitute_text = textValue; } - endTranslateElement(); break; case STATE_INSIDE_PARAM: // Store translation for param substitution if (param_value == null) { - param_value = strBuffer.toString(); + param_value = textValue; } - endParamElement(); break; case STATE_INSIDE_DATE: case STATE_INSIDE_DATE_TIME: case STATE_INSIDE_TIME: - endDate_TimeElement(); - break; case STATE_INSIDE_NUMBER: if (formattingParams.get(I18N_VALUE_ATTRIBUTE) == null) { - formattingParams.put(I18N_VALUE_ATTRIBUTE, strBuffer.toString()); + formattingParams.put(I18N_VALUE_ATTRIBUTE, textValue); } else { ; // ignore the text inside of date element } - endNumberElement(); break; default: @@ -1095,12 +1129,6 @@ } } - private void i18nCharacters(char[] ch, int start, int len) - throws SAXException { - - strBuffer.append(new String(ch, start, len).trim()); - } - // Translate all attributes that are listed in i18n:attr attribute private Attributes translateAttributes(String name, Attributes attr) throws SAXException { @@ -1508,7 +1536,6 @@ factory.release(dictionary); dictionary = null; - strBuffer = null; } public void dispose() { @@ -1548,3 +1575,4 @@ } */ } +
---------------------------------------------------------------------- In case of troubles, e-mail: [EMAIL PROTECTED] To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]