Chinmay,

Can you test (and may be bugfix) attached patch?


Vadim


ch ku wrote:

Thanks Vadim

chinmay
--- Vadim Gritsenko <[EMAIL PROTECTED]>
wrote:

ch ku wrote:


Hi All

Has somebody came across any exception like this ?


No.



How Can I deal with Strings having length more

than 32k ? in xsp ??


You can patch XMLByteStreamCompiler.writeChars() /
characters() and split up larchge chunks on smaller ones to fit UTF
limitation.

Or, you can think of redesigning your software.


Vadim

...

Index: XMLByteStreamCompiler.java
===================================================================
RCS file: 
/home/cvspublic/xml-cocoon2/src/java/org/apache/cocoon/components/sax/XMLByteStreamCompiler.java,v
retrieving revision 1.5.2.1
diff -u -r1.5.2.1 XMLByteStreamCompiler.java
--- XMLByteStreamCompiler.java  26 Aug 2002 11:13:36 -0000      1.5.2.1
+++ XMLByteStreamCompiler.java  22 Oct 2002 13:52:35 -0000
@@ -51,7 +51,6 @@
 package org.apache.cocoon.components.sax;
 
 import org.apache.avalon.excalibur.pool.Recyclable;
-import org.apache.avalon.framework.component.Component;
 import org.xml.sax.Attributes;
 import org.xml.sax.Locator;
 import org.xml.sax.SAXException;
@@ -173,14 +172,13 @@
 
     public void characters(char[] ch, int start, int length)
     throws SAXException {
-        this.writeEvent(CHARACTERS);
-        this.writeChars(ch, start, length);
+        this.writeEventAndChars(CHARACTERS, ch, start, length);
     }
 
     public void ignorableWhitespace(char[] ch, int start, int length)
     throws SAXException {
         this.writeEvent(IGNORABLE_WHITESPACE);
-        this.writeChars(ch, start, length);
+        this.writeEventAndChars(IGNORABLE_WHITESPACE, ch, start, length);
     }
 
     public void processingInstruction(String target, String data)
@@ -212,7 +210,7 @@
     /**
      * SAX Event Handling: LexicalHandler
      */
-    public void startDTD(String name, String publicId, String systemId) 
+    public void startDTD(String name, String publicId, String systemId)
     throws SAXException {
         this.writeEvent(START_DTD);
         this.writeString(name);
@@ -261,11 +259,10 @@
     /**
      * SAX Event Handling: LexicalHandler
      */
-    public void comment(char ary[], int start, int length)
+    public void comment(char ch[], int start, int length)
     throws SAXException {
         try {
-            this.writeEvent(COMMENT);
-            this.writeChars(ary, start, length);
+            this.writeEventAndChars(COMMENT, ch, start, length);
        } catch (Exception e) {
             throw new SAXException(e);
        }
@@ -293,10 +290,41 @@
         }
     }
 
+    public final void writeEventAndChars(int event, char[] ch, int start, int length)
+    throws SAXException {
+        int utflen = 0;
+        int c = 0;
+
+        for (int i = 0; i < length; i++) {
+            c = ch[i + start];
+            if ((c >= 0x0001) && (c <= 0x007F)) {
+                utflen++;
+            } else if (c > 0x07FF) {
+                utflen += 3;
+            } else {
+                utflen += 2;
+            }
+
+            if (utflen == 0x00007FFF) {
+                writeEvent(event);
+                writeChars0(utflen, ch, start, i);
+                start += i;
+                length -= i;
+                i = 0;
+                utflen = 0;
+            }
+        }
+
+        if (utflen > 0) {
+            writeEvent(event);
+            writeChars0(utflen, ch, start, length);
+        }
+    }
+
     public final void writeChars(char[] ch, int start, int length)
     throws SAXException {
         int utflen = 0;
-        int c, count = 0;
+        int c = 0;
 
         for (int i = 0; i < length; i++) {
             c = ch[i + start];
@@ -308,6 +336,13 @@
                 utflen += 2;
             }
         }
+
+        writeChars0(utflen, ch, start, length);
+    }
+
+    private final void writeChars0(int utflen, char[] ch, int start, int length)
+    throws SAXException {
+        int c, count = 0;
 
         if (utflen > 0x00007FFF)
             throw new SAXException("UTFDataFormatException: String cannot be longer 
than 32k.");

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, email: [EMAIL PROTECTED]

Reply via email to