You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xmlbeans.apache.org by ce...@apache.org on 2007/04/05 16:16:13 UTC

svn commit: r525831 - in /xmlbeans/trunk/src: store/org/apache/xmlbeans/impl/store/Saver.java typeimpl/org/apache/xmlbeans/impl/util/XsTypeConverter.java xmlpublic/org/apache/xmlbeans/GDurationBuilder.java

Author: cezar
Date: Thu Apr  5 07:16:12 2007
New Revision: 525831

URL: http://svn.apache.org/viewvc?view=rev&rev=525831
Log:
Fixing the all text is CDATA scenario.

checkintests pass


Modified:
    xmlbeans/trunk/src/store/org/apache/xmlbeans/impl/store/Saver.java
    xmlbeans/trunk/src/typeimpl/org/apache/xmlbeans/impl/util/XsTypeConverter.java
    xmlbeans/trunk/src/xmlpublic/org/apache/xmlbeans/GDurationBuilder.java

Modified: xmlbeans/trunk/src/store/org/apache/xmlbeans/impl/store/Saver.java
URL: http://svn.apache.org/viewvc/xmlbeans/trunk/src/store/org/apache/xmlbeans/impl/store/Saver.java?view=diff&rev=525831&r1=525830&r2=525831
==============================================================================
--- xmlbeans/trunk/src/store/org/apache/xmlbeans/impl/store/Saver.java (original)
+++ xmlbeans/trunk/src/store/org/apache/xmlbeans/impl/store/Saver.java Thu Apr  5 07:16:12 2007
@@ -1277,7 +1277,7 @@
                 prevChar = ch;
             }
 
-            if (count == 0 && !hasCharToBeReplaced)
+            if (count == 0 && !hasCharToBeReplaced && count<_cdataEntityCountThreshold)
                 return;
 
             i = _lastEmitIn;

Modified: xmlbeans/trunk/src/typeimpl/org/apache/xmlbeans/impl/util/XsTypeConverter.java
URL: http://svn.apache.org/viewvc/xmlbeans/trunk/src/typeimpl/org/apache/xmlbeans/impl/util/XsTypeConverter.java?view=diff&rev=525831&r1=525830&r2=525831
==============================================================================
--- xmlbeans/trunk/src/typeimpl/org/apache/xmlbeans/impl/util/XsTypeConverter.java (original)
+++ xmlbeans/trunk/src/typeimpl/org/apache/xmlbeans/impl/util/XsTypeConverter.java Thu Apr  5 07:16:12 2007
@@ -603,7 +603,8 @@
     private static String trimTrailingZeros(String xsd_decimal)
     {
         final int last_char_idx = xsd_decimal.length() - 1;
-        if (xsd_decimal.charAt(last_char_idx) == '0') {
+        if (xsd_decimal.charAt(last_char_idx) == '0')
+        {
             final int last_point = xsd_decimal.lastIndexOf('.');
             if (last_point >= 0) {
                 //find last trailing zero

Modified: xmlbeans/trunk/src/xmlpublic/org/apache/xmlbeans/GDurationBuilder.java
URL: http://svn.apache.org/viewvc/xmlbeans/trunk/src/xmlpublic/org/apache/xmlbeans/GDurationBuilder.java?view=diff&rev=525831&r1=525830&r2=525831
==============================================================================
--- xmlbeans/trunk/src/xmlpublic/org/apache/xmlbeans/GDurationBuilder.java (original)
+++ xmlbeans/trunk/src/xmlpublic/org/apache/xmlbeans/GDurationBuilder.java Thu Apr  5 07:16:12 2007
@@ -16,6 +16,7 @@
 package org.apache.xmlbeans;
 
 import java.math.BigDecimal;
+import java.math.BigInteger;
 
 /**
  * Used to build {@link GDuration GDurations}.
@@ -580,7 +581,7 @@
             if (duration.getSecond() != 0)
                 s = s.add(BigDecimal.valueOf(duration.getSecond()));
             // todo when upgrade to 1.5  message.append(s.stripTrailingZeros().toPlainString());
-            message.append(s.stripTrailingZeros());
+            message.append(stripTrailingZeros(toPlainString(s)));
             message.append('S');
         }
         else if (duration.getSecond() != 0)
@@ -593,5 +594,75 @@
             message.append("T0S");
 
         return message.toString();
+    }
+
+    public static String toPlainString(BigDecimal bd)
+    {
+        BigInteger intVal = bd.unscaledValue();
+        int scale = bd.scale();
+        String intValStr = intVal.toString();
+        if (scale == 0)
+            return intValStr;
+
+        boolean isNegative = (intValStr.charAt(0) == '-');
+
+        int point = intValStr.length() - scale - (isNegative ? 1 : 0);
+
+        StringBuffer sb = new StringBuffer(intValStr.length() + 2 + (point <= 0 ? (-point + 1) : 0));
+        if (point <= 0)
+        {
+            // prepend zeros and a decimal point.
+            if (isNegative) sb.append('-');
+            sb.append('0').append('.');
+            while (point < 0)
+            {
+                sb.append('0');
+                point++;
+            }
+            sb.append(intValStr.substring(isNegative ? 1 : 0));
+        }
+        else if (point < intValStr.length())
+        {
+            // No zeros needed
+            sb.append(intValStr);
+            sb.insert(point + (isNegative ? 1 : 0), '.');
+        }
+        else
+        {
+            // append zeros if not 0
+            sb.append(intValStr);
+            if (!intVal.equals(BigInteger.ZERO))
+                for (int i = intValStr.length(); i < point; i++)
+                    sb.append('0');
+        }
+        return sb.toString();
+    }
+
+    public static String stripTrailingZeros(String s)
+    {
+        boolean seenDot = false;
+        int i = s.length() - 1;
+        int zeroIndex = i;
+
+        while(i>=0)
+        {
+            if (s.charAt(i)!='0')
+                break;
+            i--;
+            zeroIndex--;
+        }
+        while(i>=0)
+        {
+            if (s.charAt(i)=='E')
+                return s;
+            if (s.charAt(i)=='.')
+            {
+                seenDot = true;
+                break;
+            }
+            i--;
+        }
+        
+        return seenDot? s.substring(0, zeroIndex+1) : s;
     }
 }



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@xmlbeans.apache.org
For additional commands, e-mail: commits-help@xmlbeans.apache.org