details:   /erp/devel/pi/rev/33315a869d2f
changeset: 8220:33315a869d2f
user:      Adrián Romero <adrianromero <at> openbravo.com>
date:      Tue Aug 24 12:21:18 2010 +0200
summary:   Issue 14202: Product Movements Report appears in spanish when it is 
executed in english
XmlDocument.translateDataValue: Refactor:
- Simplify loops
- Reduce nesting level with an early return-
- Check if translations exist out of the loop
- Reduce casting using generics
- Extract translation of XmlVectorTemplate into helper function
- Inline only used once variable

details:   /erp/devel/pi/rev/dfeacf18d718
changeset: 8221:dfeacf18d718
user:      Adrián Romero <adrianromero <at> openbravo.com>
date:      Tue Aug 24 12:48:19 2010 +0200
summary:   Fixes issue 14202: Product Movements Report appears in spanish when 
it is executed in english
Translate the current xmlDocument values and not the (cached) template

details:   /erp/devel/pi/rev/8badd5d23b59
changeset: 8222:8badd5d23b59
user:      Adrián Romero <adrianromero <at> openbravo.com>
date:      Tue Aug 24 14:30:21 2010 +0200
summary:   Issue 14202: Product Movements Report appears in spanish when it is 
executed in english
Removing not needed castings

details:   /erp/devel/pi/rev/24f60c5e9ff5
changeset: 8223:24f60c5e9ff5
user:      Adrián Romero <adrianromero <at> openbravo.com>
date:      Wed Aug 25 13:14:06 2010 +0200
summary:   merging changes

diffstat:

 src-core/src/org/openbravo/xmlEngine/DataTemplate.java                    |   
4 +-
 src-core/src/org/openbravo/xmlEngine/DataValue.java                       |  
21 +-
 src-core/src/org/openbravo/xmlEngine/SectionValue.java                    |   
6 +-
 src-core/src/org/openbravo/xmlEngine/XmlDocument.java                     |  
89 ++++----
 src-db/database/sourcedata/AD_ELEMENT.xml                                 |  
13 +-
 src-db/database/sourcedata/AD_FIELD.xml                                   |  
10 +-
 src-db/database/sourcedata/AD_REF_LIST.xml                                |   
6 +-
 src-test/org/openbravo/test/dal/IssuesTest.java                           |  
57 +++++
 src-test/org/openbravo/test/security/AllDataAllowedOrganizationsTest.java |  
99 ++++++++++
 src/org/openbravo/dal/core/DalRequestFilter.java                          |   
2 +
 src/org/openbravo/dal/core/OBInterceptor.java                             |  
16 +
 src/org/openbravo/erpCommon/ad_forms/ModuleManagement.java                |  
56 ++++-
 src/org/openbravo/erpCommon/ad_reports/ReportNotPosted_data.xsql          |  
25 ++-
 src/org/openbravo/erpCommon/security/Login_F1.html                        |   
2 +-
 web/js/appStatus.js                                                       |   
2 +-
 web/js/utils.js                                                           |   
4 +-
 16 files changed, 314 insertions(+), 98 deletions(-)

diffs (truncated from 763 to 300 lines):

diff -r 64d6d6da854d -r 24f60c5e9ff5 
src-core/src/org/openbravo/xmlEngine/DataTemplate.java
--- a/src-core/src/org/openbravo/xmlEngine/DataTemplate.java    Tue Aug 24 
09:53:37 2010 +0200
+++ b/src-core/src/org/openbravo/xmlEngine/DataTemplate.java    Wed Aug 25 
13:14:06 2010 +0200
@@ -23,7 +23,7 @@
 class DataTemplate implements XmlComponentTemplate {
   String strName; // the name should be initialized
 
-  Vector<Object> vecSectionTemplate;
+  Vector<SectionTemplate> vecSectionTemplate;
   XmlVectorTemplate vecDetailTemplate; // vector of XmlComponents
   Vector<Object> vecFieldTemplate; // vector of FieldComponent's
   Vector<Object> vecParameterTemplate; // vector of ParameterTemplates for the
@@ -46,7 +46,7 @@
   public DataTemplate() {
     intTotalLevels = -1;
     log4jDataTemplate.debug("Initial value: " + intTotalLevels);
-    vecSectionTemplate = new Vector<Object>();
+    vecSectionTemplate = new Vector<SectionTemplate>();
     vecDetailTemplate = new XmlVectorTemplate();
     vecFieldTemplate = new Vector<Object>();
     vecParameterTemplate = new Vector<Object>();
diff -r 64d6d6da854d -r 24f60c5e9ff5 
src-core/src/org/openbravo/xmlEngine/DataValue.java
--- a/src-core/src/org/openbravo/xmlEngine/DataValue.java       Tue Aug 24 
09:53:37 2010 +0200
+++ b/src-core/src/org/openbravo/xmlEngine/DataValue.java       Wed Aug 25 
13:14:06 2010 +0200
@@ -36,7 +36,7 @@
   PreparedStatement preparedStatement;
   ResultSet result;
 
-  Vector<Object> vecSectionValue;
+  Vector<SectionValue> vecSectionValue;
   XmlVectorValue vecDetailValue; // vector of XmlComponentValues
   Vector<Object> vecFieldValue; // vector of FieldValues
   Vector<Object> vecParameterValue; // vector of ParameterValues for the query
@@ -94,8 +94,8 @@
 
     // vector of Sections
     log4jDataValue.debug("vector of Sections");
-    vecSectionValue = new Vector<Object>();
-    for (Enumeration<Object> e1 = dataTemplate.vecSectionTemplate.elements(); 
e1.hasMoreElements();) {
+    vecSectionValue = new Vector<SectionValue>();
+    for (Enumeration<SectionTemplate> e1 = 
dataTemplate.vecSectionTemplate.elements(); e1.hasMoreElements();) {
       SectionTemplate sectionTemplate = (SectionTemplate) e1.nextElement();
       SectionValue sectionValue = 
sectionTemplate.createSectionValue(xmlDocument, this);
       vecSectionValue.addElement(sectionValue);
@@ -356,8 +356,7 @@
   private void init() {
     if (log4jDataValue.isDebugEnabled())
       log4jDataValue.debug("DataValue: init");
-    for (Enumeration<Object> e = vecSectionValue.elements(); 
e.hasMoreElements();) {
-      SectionValue section = (SectionValue) e.nextElement();
+    for (SectionValue section : vecSectionValue) {
       log4jDataValue.debug("DataValue: init, section:" + 
section.sectionTemplate.name);
       section.init();
     }
@@ -372,8 +371,7 @@
   }
 
   private void firstValues() {
-    for (Enumeration<Object> e = vecSectionValue.elements(); 
e.hasMoreElements();) {
-      SectionValue sectionValue = (SectionValue) e.nextElement();
+    for (SectionValue sectionValue : vecSectionValue) {
       if (sectionValue.breakFieldValue != null) {
         sectionValue.breakFieldValue.savePrevious();
       }
@@ -387,12 +385,10 @@
   }
 
   private void check() {
-    boolean checked = true;
-    for (Enumeration<Object> e = vecSectionValue.elements(); 
e.hasMoreElements() && checked;) {
-      SectionValue sectionValue = (SectionValue) e.nextElement();
+    for (SectionValue sectionValue : vecSectionValue) {
       if (!sectionValue.check()) {
-        checked = false;
         sectionValue.close();
+        return;
       }
     }
   }
@@ -428,8 +424,7 @@
   }
 
   public void acumulate() {
-    for (Enumeration<Object> e = vecSectionValue.elements(); 
e.hasMoreElements();) {
-      SectionValue sectionValue = (SectionValue) e.nextElement();
+    for (SectionValue sectionValue : vecSectionValue) {
       sectionValue.acumulate();
     }
 
diff -r 64d6d6da854d -r 24f60c5e9ff5 
src-core/src/org/openbravo/xmlEngine/SectionValue.java
--- a/src-core/src/org/openbravo/xmlEngine/SectionValue.java    Tue Aug 24 
09:53:37 2010 +0200
+++ b/src-core/src/org/openbravo/xmlEngine/SectionValue.java    Wed Aug 25 
13:14:06 2010 +0200
@@ -63,7 +63,7 @@
       functionInstance.init();
     }
     if (sectionTemplate.intLevel != 
sectionTemplate.dataTemplate.intTotalLevels) {
-      SectionValue section = (SectionValue) dataValue.vecSectionValue
+      SectionValue section = dataValue.vecSectionValue
           .elementAt(sectionTemplate.intLevel + 1);
       section.strSection = new StringBuffer();
     } else {
@@ -75,7 +75,7 @@
     log4jSectionValue.debug("(Close) Levels:" + 
sectionTemplate.dataTemplate.intTotalLevels
         + " actual level: " + sectionTemplate.intLevel);
     if (sectionTemplate.intLevel != 
sectionTemplate.dataTemplate.intTotalLevels) {
-      SectionValue section = (SectionValue) dataValue.vecSectionValue
+      SectionValue section = dataValue.vecSectionValue
           .elementAt(sectionTemplate.intLevel + 1);
       section.close();
     }
@@ -84,7 +84,7 @@
 
     // add next section
     if (sectionTemplate.intLevel != 
sectionTemplate.dataTemplate.intTotalLevels) {
-      SectionValue section = (SectionValue) dataValue.vecSectionValue
+      SectionValue section = dataValue.vecSectionValue
           .elementAt(sectionTemplate.intLevel + 1);
       strSection.append(section.strSection);
     } else {
diff -r 64d6d6da854d -r 24f60c5e9ff5 
src-core/src/org/openbravo/xmlEngine/XmlDocument.java
--- a/src-core/src/org/openbravo/xmlEngine/XmlDocument.java     Tue Aug 24 
09:53:37 2010 +0200
+++ b/src-core/src/org/openbravo/xmlEngine/XmlDocument.java     Wed Aug 25 
13:14:06 2010 +0200
@@ -13,7 +13,6 @@
 
 import java.util.Enumeration;
 import java.util.Hashtable;
-import java.util.Iterator;
 import java.util.Vector;
 
 import org.apache.log4j.Logger;
@@ -305,58 +304,52 @@
    *          DataValue object that might contain sections to be translated
    */
   private void translateDataValue(DataValue elementDataValue) {
-    if (elementDataValue.dataTemplate != null) {
-      DataTemplate dataTemplate = elementDataValue.dataTemplate;
-      if (dataTemplate.vecSectionTemplate != null) {
-        Vector<Object> vecSectionTemplate = dataTemplate.vecSectionTemplate;
-        for (Iterator<?> iterator = vecSectionTemplate.iterator(); 
iterator.hasNext();) {
-          SectionTemplate sectionTemplate = (SectionTemplate) iterator.next();
-          if (sectionTemplate.vecHeadTemplate != null) {
-            XmlVectorTemplate template = sectionTemplate.vecHeadTemplate;
-            for (Iterator<?> iterator2 = template.iterator(); 
iterator2.hasNext();) {
-              Object componentTemplate = (Object) iterator2.next();
-              if (CharacterComponent.class.isInstance(componentTemplate)) {
-                CharacterComponent charComponent = (CharacterComponent) 
componentTemplate;
-                if (charComponent.character != null && 
!charComponent.equals("")) {
-                  String original = charComponent.character.trim();
-                  if (xmlVectorValue != null && xmlVectorValue.getTextMap() != 
null) {
-                    String trl = xmlVectorValue.getTextMap().get(original);
 
-                    if (trl != null && !trl.equals(""))
-                      charComponent.character = trl;
-                  }
-                }
-                componentTemplate = charComponent;
-              }
-            }
-            sectionTemplate.vecHeadTemplate = template;
-          }
+    if (xmlVectorValue == null || xmlVectorValue.getTextMap() == null) {
+      return;
+    }
 
-          if (sectionTemplate.vecFootTemplate != null) {
-            XmlVectorTemplate xmlFootTemplate = 
sectionTemplate.vecFootTemplate;
-            for (Iterator<?> iterator2 = xmlFootTemplate.iterator(); 
iterator2.hasNext();) {
-              Object componentTemplate = (Object) iterator2.next();
-              if (CharacterComponent.class.isInstance(componentTemplate)) {
-                CharacterComponent charComponent = (CharacterComponent) 
componentTemplate;
-                if (charComponent.character != null && 
!charComponent.equals("")) {
-                  String original = charComponent.character.trim();
-                  if (xmlVectorValue.getTextMap() != null) {
-                    String trl = xmlVectorValue.getTextMap().get(original);
-                    if (trl != null && !trl.equals(""))
-                      charComponent.character = trl;
-                  }
-                }
-                componentTemplate = charComponent;
-              }
-            }
-            sectionTemplate.vecFootTemplate = xmlFootTemplate;
+    if (elementDataValue.vecSectionValue == null) {
+      return;
+    }
+
+    for (SectionValue sectionValue : elementDataValue.vecSectionValue) {
+      translateXmlVectorTemplate(sectionValue.vecHeadValue);
+      translateXmlVectorTemplate(sectionValue.vecFootValue);
+    }
+  }
+
+  /**
+   * Utility method to translate all CharacterComponents contained in the 
passed XmlVectorTemplate.
+   */
+  private void translateXmlVectorTemplate(XmlVectorValue vecXmlVectorValue) {
+
+    if (vecXmlVectorValue == null) {
+      return;
+    }
+
+    for (int i = 0; i < vecXmlVectorValue.size(); i++) {
+      Object componentTemplate = vecXmlVectorValue.get(i);
+      if (CharacterComponent.class.isInstance(componentTemplate)) {
+        CharacterComponent charComponent = (CharacterComponent) 
componentTemplate;
+        if (charComponent.character != null && 
!charComponent.character.equals("")) {
+          String original = charComponent.character.trim();
+          String trl = xmlVectorValue.getTextMap().get(original);
+          if (trl != null && !trl.equals("")) {
+            /*
+             * Need to create a new instance here, instead of just modifying 
the attribute of the
+             * existing instance, as SectionTemplate and SectionValue do share 
the same
+             * CharacterComponent instances and do not copy them. Without the 
new instance here we
+             * would silently modify the templates' text also and effectively 
translating the
+             * (cached) template.
+             */
+            charComponent = new CharacterComponent(trl);
+            vecXmlVectorValue.set(i, charComponent);
           }
         }
-        dataTemplate.vecSectionTemplate = vecSectionTemplate;
+        componentTemplate = charComponent;
       }
-      elementDataValue.dataTemplate = dataTemplate;
     }
-
   }
 
   public String printPrevious() {
@@ -376,5 +369,5 @@
       elementDataValue.connect();
     }
   }
-
+  
 }
diff -r 64d6d6da854d -r 24f60c5e9ff5 src-db/database/sourcedata/AD_ELEMENT.xml
--- a/src-db/database/sourcedata/AD_ELEMENT.xml Tue Aug 24 09:53:37 2010 +0200
+++ b/src-db/database/sourcedata/AD_ELEMENT.xml Wed Aug 25 13:14:06 2010 +0200
@@ -25280,8 +25280,10 @@
 <!--7890366979722CEFE040007F01013334-->  <AD_ORG_ID><![CDATA[0]]></AD_ORG_ID>
 <!--7890366979722CEFE040007F01013334-->  <ISACTIVE><![CDATA[Y]]></ISACTIVE>
 <!--7890366979722CEFE040007F01013334-->  
<COLUMNNAME><![CDATA[Paidamt]]></COLUMNNAME>
-<!--7890366979722CEFE040007F01013334-->  <NAME><![CDATA[Paid Amount]]></NAME>
-<!--7890366979722CEFE040007F01013334-->  
<PRINTNAME><![CDATA[Paidamt]]></PRINTNAME>
+<!--7890366979722CEFE040007F01013334-->  <NAME><![CDATA[Received 
Amount]]></NAME>
+<!--7890366979722CEFE040007F01013334-->  <PRINTNAME><![CDATA[Received 
Amount]]></PRINTNAME>
+<!--7890366979722CEFE040007F01013334-->  <PO_NAME><![CDATA[Paid 
Amount]]></PO_NAME>
+<!--7890366979722CEFE040007F01013334-->  <PO_PRINTNAME><![CDATA[Paid 
Amount]]></PO_PRINTNAME>
 <!--7890366979722CEFE040007F01013334-->  
<AD_MODULE_ID><![CDATA[0]]></AD_MODULE_ID>
 <!--7890366979722CEFE040007F01013334--></AD_ELEMENT>
 
@@ -25418,8 +25420,11 @@
 <!--78B98ED04532560FE040007F0101777C-->  <AD_ORG_ID><![CDATA[0]]></AD_ORG_ID>
 <!--78B98ED04532560FE040007F0101777C-->  <ISACTIVE><![CDATA[Y]]></ISACTIVE>
 <!--78B98ED04532560FE040007F0101777C-->  
<COLUMNNAME><![CDATA[Lastpayment]]></COLUMNNAME>
-<!--78B98ED04532560FE040007F0101777C-->  <NAME><![CDATA[Last Payment]]></NAME>
-<!--78B98ED04532560FE040007F0101777C-->  
<PRINTNAME><![CDATA[Lastpayment]]></PRINTNAME>
+<!--78B98ED04532560FE040007F0101777C-->  <NAME><![CDATA[Last Payment 
Date]]></NAME>
+<!--78B98ED04532560FE040007F0101777C-->  <PRINTNAME><![CDATA[Last Payment 
Date]]></PRINTNAME>
+<!--78B98ED04532560FE040007F0101777C-->  <PO_NAME><![CDATA[Last Payment 
Date]]></PO_NAME>
+<!--78B98ED04532560FE040007F0101777C-->  <PO_PRINTNAME><![CDATA[Last Payment 
Date]]></PO_PRINTNAME>
+<!--78B98ED04532560FE040007F0101777C-->  <PO_DESCRIPTION><![CDATA[Last Payment 
Date]]></PO_DESCRIPTION>
 <!--78B98ED04532560FE040007F0101777C-->  
<AD_MODULE_ID><![CDATA[0]]></AD_MODULE_ID>
 <!--78B98ED04532560FE040007F0101777C--></AD_ELEMENT>
 
diff -r 64d6d6da854d -r 24f60c5e9ff5 src-db/database/sourcedata/AD_FIELD.xml
--- a/src-db/database/sourcedata/AD_FIELD.xml   Tue Aug 24 09:53:37 2010 +0200
+++ b/src-db/database/sourcedata/AD_FIELD.xml   Wed Aug 25 13:14:06 2010 +0200
@@ -181827,7 +181827,7 @@
 <!--133B82E6E63D42A8BF22920E72A3A5EA-->  
<AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
 <!--133B82E6E63D42A8BF22920E72A3A5EA-->  <AD_ORG_ID><![CDATA[0]]></AD_ORG_ID>
 <!--133B82E6E63D42A8BF22920E72A3A5EA-->  <ISACTIVE><![CDATA[Y]]></ISACTIVE>
-<!--133B82E6E63D42A8BF22920E72A3A5EA-->  <NAME><![CDATA[Paying from]]></NAME>
+<!--133B82E6E63D42A8BF22920E72A3A5EA-->  <NAME><![CDATA[Paying From]]></NAME>
 <!--133B82E6E63D42A8BF22920E72A3A5EA-->  <HELP><![CDATA[Financial account 
where the payment amount is deposited.]]></HELP>
 <!--133B82E6E63D42A8BF22920E72A3A5EA-->  
<ISCENTRALLYMAINTAINED><![CDATA[N]]></ISCENTRALLYMAINTAINED>
 <!--133B82E6E63D42A8BF22920E72A3A5EA-->  
<AD_TAB_ID><![CDATA[F7A52FDAAA0346EFA07D53C125B40404]]></AD_TAB_ID>
@@ -195094,7 +195094,7 @@
 <!--7C541AC0C75AFDD7E040007F01016B4D-->  
<AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
 <!--7C541AC0C75AFDD7E040007F01016B4D-->  <AD_ORG_ID><![CDATA[0]]></AD_ORG_ID>
 <!--7C541AC0C75AFDD7E040007F01016B4D-->  <ISACTIVE><![CDATA[Y]]></ISACTIVE>
-<!--7C541AC0C75AFDD7E040007F01016B4D-->  <NAME><![CDATA[Deposit to]]></NAME>
+<!--7C541AC0C75AFDD7E040007F01016B4D-->  <NAME><![CDATA[Deposit To]]></NAME>
 <!--7C541AC0C75AFDD7E040007F01016B4D-->  <HELP><![CDATA[Financial account 
where the payment amount is deposited.]]></HELP>
 <!--7C541AC0C75AFDD7E040007F01016B4D-->  
<ISCENTRALLYMAINTAINED><![CDATA[N]]></ISCENTRALLYMAINTAINED>
 <!--7C541AC0C75AFDD7E040007F01016B4D-->  
<AD_TAB_ID><![CDATA[C4B6506838E14A349D6717D6856F1B56]]></AD_TAB_ID>
@@ -195138,7 +195138,7 @@
 <!--7C541AC0C75CFDD7E040007F01016B4D-->  
<AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
 <!--7C541AC0C75CFDD7E040007F01016B4D-->  <AD_ORG_ID><![CDATA[0]]></AD_ORG_ID>
 <!--7C541AC0C75CFDD7E040007F01016B4D-->  <ISACTIVE><![CDATA[Y]]></ISACTIVE>
-<!--7C541AC0C75CFDD7E040007F01016B4D-->  <NAME><![CDATA[Received from]]></NAME>
+<!--7C541AC0C75CFDD7E040007F01016B4D-->  <NAME><![CDATA[Received From]]></NAME>
 <!--7C541AC0C75CFDD7E040007F01016B4D-->  <HELP><![CDATA[The Business Partner 
the payment is receipt from.]]></HELP>
 <!--7C541AC0C75CFDD7E040007F01016B4D-->  
<ISCENTRALLYMAINTAINED><![CDATA[N]]></ISCENTRALLYMAINTAINED>
 <!--7C541AC0C75CFDD7E040007F01016B4D-->  
<AD_TAB_ID><![CDATA[C4B6506838E14A349D6717D6856F1B56]]></AD_TAB_ID>
@@ -197666,7 +197666,7 @@
 <!--7FF223474904844FE040007F01003861-->  
<AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
 <!--7FF223474904844FE040007F01003861-->  <AD_ORG_ID><![CDATA[0]]></AD_ORG_ID>
 <!--7FF223474904844FE040007F01003861-->  <ISACTIVE><![CDATA[Y]]></ISACTIVE>

------------------------------------------------------------------------------
Sell apps to millions through the Intel(R) Atom(Tm) Developer Program
Be part of this innovative community and reach millions of netbook users 
worldwide. Take advantage of special opportunities to increase revenue and 
speed time-to-market. Join now, and jumpstart your future.
http://p.sf.net/sfu/intel-atom-d2d
_______________________________________________
Openbravo-commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/openbravo-commits

Reply via email to