[Yanel-commits] rev 49909 - public/yanel/trunk/src/core/java/org/wyona/yanel/core/transformation

michi at wyona.com michi at wyona.com
Wed May 26 14:32:10 CEST 2010


Author: michi
Date: 2010-05-26 14:32:09 +0200 (Wed, 26 May 2010)
New Revision: 49909

Modified:
   public/yanel/trunk/src/core/java/org/wyona/yanel/core/transformation/I18nTransformer3.java
Log:
l10n attribute fixed

Modified: public/yanel/trunk/src/core/java/org/wyona/yanel/core/transformation/I18nTransformer3.java
===================================================================
--- public/yanel/trunk/src/core/java/org/wyona/yanel/core/transformation/I18nTransformer3.java	2010-05-26 12:08:44 UTC (rev 49908)
+++ public/yanel/trunk/src/core/java/org/wyona/yanel/core/transformation/I18nTransformer3.java	2010-05-26 12:32:09 UTC (rev 49909)
@@ -159,7 +159,7 @@
     }
 
     /**
-     *
+     * @deprecated Use getMessage(String, Locale) instead
      */
     protected String getMessage(String key) {
         String value = this.messageManager.getText(key, this.locale);
@@ -170,6 +170,17 @@
     }
 
     /**
+     *
+     */
+    private String getMessage(String key, Locale locale) {
+        String value = this.messageManager.getText(key, locale);
+        if (value == null) {
+            log.error("Cannot find message for key: " + key);
+        }
+        return value;
+    }
+
+    /**
      * @deprecated Use getMessage(String, List, Locale) instead
      */
     protected String getMessage(String key, List parameters) {
@@ -257,6 +268,8 @@
                 this.key = attrs.getValue("key");
             } else if (isI18nParamElement(namespaceURI, localName, qName)) {
                 this.textBuffer = new StringBuffer(); 
+            } else if (isL10nParamElement(namespaceURI, localName, qName)) {
+                this.textBuffer = new StringBuffer(); 
             } else {
                 log.error("invalid element inside of i18n:translate: " + qName);
             }
@@ -277,10 +290,10 @@
             } else {
                 // no i18n element -> translate attributes:
                 
-                int index = attrs.getIndex(NS_URI, "attr");
-                
-                if (index != -1) {
-                    List i18nAttrs = Arrays.asList(attrs.getValue(index).split(" "));
+                int indexI18nAttr = attrs.getIndex(NS_URI, "attr");
+                int indexL10nAttr = attrs.getIndex(NS_UI_URI, "attr");
+                if (indexI18nAttr != -1) {
+                    List i18nAttrs = Arrays.asList(attrs.getValue(indexI18nAttr).split(" "));
                     AttributesImpl newAttrs = new AttributesImpl();
                     
                     for(int i = 0; i < attrs.getLength(); i++) {
@@ -304,6 +317,32 @@
                     }
                     super.startElement(namespaceURI, localName, qName, newAttrs);
                     
+              } else if (indexL10nAttr != -1) {
+                  //log.debug("l10n attribute found!");
+                  List l10nAttrs = Arrays.asList(attrs.getValue(indexL10nAttr).split(" "));
+                  AttributesImpl newAttrs = new AttributesImpl();
+                    
+                  for(int i = 0; i < attrs.getLength(); i++) {
+                      String attrUri = attrs.getURI(i);
+                      String attrLocalName = attrs.getLocalName(i);
+                      String attrQName = attrs.getQName(i);
+                      String attrValue = attrs.getValue(i);
+                      String attrType = attrs.getType(i);
+                        
+                      if (!attrLocalName.equals("attr") || !attrUri.equals(NS_UI_URI)) {
+                          if (l10nAttrs.contains(attrQName)) {
+                              String l10nValue = getMessage(attrValue, this.userLocale);
+                              if (l10nValue == null) {
+                                  l10nValue = attrValue;
+                              }
+                              newAttrs.addAttribute(attrUri, attrLocalName, attrQName, attrType, l10nValue);
+                          } else {
+                              newAttrs.addAttribute(attrUri, attrLocalName, attrQName, attrType, attrValue);
+                          }
+                      }
+                  }
+                  super.startElement(namespaceURI, localName, qName, newAttrs);
+                    
                 } else {
                     
                     // support old i18n attribute syntax for compatibility reasons: 
@@ -359,6 +398,10 @@
                 String param = this.textBuffer.toString();
                 this.parameters.add(param);
                 
+            } else if (isL10nParamElement(namespaceURI, localName, qName)) {
+                String param = this.textBuffer.toString();
+                this.parameters.add(param);
+                
             } else if (isI18nTranslateElement(namespaceURI, localName, qName)) {
                 String message = getMessage(this.key, this.defaultText, this.parameters, this.locale);
                 state = STATE_OUTSIDE;
@@ -418,6 +461,9 @@
         return false;
     }
 
+    /**
+     *
+     */
     protected boolean isI18nParamElement(String namespaceURI, String localName, String qName) {
         if (namespaceURI.equals(NS_URI) && localName.equals("param")) {
             return true;
@@ -425,6 +471,16 @@
         return false;
     }
 
+    /**
+     *
+     */
+    protected boolean isL10nParamElement(String namespaceURI, String localName, String qName) {
+        if (namespaceURI.equals(NS_UI_URI) && localName.equals("param")) {
+            return true;
+        }
+        return false;
+    }
+
     public void characters(char[] buf, int offset, int len) throws SAXException {
         if (this.state == STATE_INSIDE_TEXT || state == STATE_INSIDE_TRANSLATE || state == STATE_INSIDE_TEXT_UI) {
             this.textBuffer.append(buf, offset, len);



More information about the Yanel-commits mailing list