You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@cocoon.apache.org by an...@apache.org on 2008/02/17 07:48:23 UTC
svn commit: r628434 - in
/cocoon/trunk/core/cocoon-pipeline/cocoon-pipeline-impl/src:
main/java/org/apache/cocoon/components/sax/ test/java/org/apache/cocoon/xml/
Author: antonio
Date: Sat Feb 16 22:48:17 2008
New Revision: 628434
URL: http://svn.apache.org/viewvc?rev=628434&view=rev
Log:
<action dev="AG" type="fix" fixes-bug="COCOON-2158">
Core: XMLByteStreamCompiler hard-coded limits of 0xffff Strings prevents large XML documents
from being handled in Cocoon.
</action>
Modified:
cocoon/trunk/core/cocoon-pipeline/cocoon-pipeline-impl/src/main/java/org/apache/cocoon/components/sax/AbstractXMLByteStreamCompiler.java
cocoon/trunk/core/cocoon-pipeline/cocoon-pipeline-impl/src/main/java/org/apache/cocoon/components/sax/AbstractXMLByteStreamInterpreter.java
cocoon/trunk/core/cocoon-pipeline/cocoon-pipeline-impl/src/test/java/org/apache/cocoon/xml/AbstractXMLTestCase.java
Modified: cocoon/trunk/core/cocoon-pipeline/cocoon-pipeline-impl/src/main/java/org/apache/cocoon/components/sax/AbstractXMLByteStreamCompiler.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-pipeline/cocoon-pipeline-impl/src/main/java/org/apache/cocoon/components/sax/AbstractXMLByteStreamCompiler.java?rev=628434&r1=628433&r2=628434&view=diff
==============================================================================
--- cocoon/trunk/core/cocoon-pipeline/cocoon-pipeline-impl/src/main/java/org/apache/cocoon/components/sax/AbstractXMLByteStreamCompiler.java (original)
+++ cocoon/trunk/core/cocoon-pipeline/cocoon-pipeline-impl/src/main/java/org/apache/cocoon/components/sax/AbstractXMLByteStreamCompiler.java Sat Feb 16 22:48:17 2008
@@ -5,9 +5,9 @@
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -183,7 +183,6 @@
this.writeEvent(END_CDATA);
}
-
/**
* SAX Event Handling: LexicalHandler
*/
@@ -212,14 +211,23 @@
map.put(str, new Integer(mapCount++));
int length = str.length();
this.writeChars(str.toCharArray(), 0, length);
- }
- else {
+ } else {
int i = index.intValue();
- if (i > 0xFFFF) throw new SAXException("Index too large");
-
- this.write(((i >>> 8) & 0xFF) | 0x80);
- this.write((i >>> 0) & 0xFF);
+ if (i <= 0x7FFF) {
+ // write index value in 16-bits
+ this.write(((i >>> 8) & 0xFF) | 0x80);
+ this.write((i >>> 0) & 0xFF);
+ } else {
+ // write escape code (Short.MAX_VALUE) to write a full 32-bit value
+ write((byte)0x7F);
+ write((byte)0xFF);
+ // write index value in 32-bit
+ write((byte) ((i >>> 24) & 0xFF) | 0x80);
+ write((byte) ((i >>> 16) & 0xFF));
+ write((byte) ((i >>> 8) & 0xFF));
+ write((byte) ((i >>> 0) & 0xFF));
+ }
}
}
@@ -268,70 +276,11 @@
write((byte) (0x80 | ((c >> 0) & 0x3F)));
}
}
-
-
-/*
- if (length == 0) return;
-
- assure( (int) (buf.length + length * utfRatioAverage) );
-
- int utflentotal = 0;
-
- bufCount += 2;
- int bufStart = bufCount;
-
- for (int i = 0; i < length; i++) {
- int c = ch[i + start];
- int l = bufCount-bufStart;
-
- if (l+3 >= 0x7FFF) {
- buf[bufStart-2] = (byte) ((l >>> 8) & 0xFF);
- buf[bufStart-1] = (byte) ((l >>> 0) & 0xFF);
- utflentotal += l;
- bufCount += 2;
- bufStart = bufCount;
- }
-
- if ((c >= 0x0001) && (c <= 0x007F)) {
- assure(bufCount+1);
- buf[bufCount++] = (byte)c;
- }
- else if (c > 0x07FF) {
- assure(bufCount+3);
- buf[bufCount++] = (byte) (0xE0 | ((c >> 12) & 0x0F));
- buf[bufCount++] = (byte) (0x80 | ((c >> 6) & 0x3F));
- buf[bufCount++] = (byte) (0x80 | ((c >> 0) & 0x3F));
- }
- else {
- assure(bufCount+2);
- buf[bufCount++] = (byte) (0xC0 | ((c >> 6) & 0x1F));
- buf[bufCount++] = (byte) (0x80 | ((c >> 0) & 0x3F));
- }
- }
-
- int l = bufCount-bufStart;
- buf[bufStart-2] = (byte) ((l >>> 8) & 0xFF);
- buf[bufStart-1] = (byte) ((l >>> 0) & 0xFF);
- utflentotal += l;
-
- utfRatioAverage = (utfRatioAverage + (utflentotal / length) / 2);
-*/
}
-/* JH (2003-11-20): seems to be never used
-
- private void write( final byte[] b ) {
- int newcount = this.bufCount + b.length;
- assure(newcount);
- System.arraycopy(b, 0, this.buf, this.bufCount, b.length);
- this.bufCount = newcount;
- }
-*/
-
abstract protected void write( final int b ) throws SAXException;
- private void writeProlog() throws SAXException
- {
+ private void writeProlog() throws SAXException {
write((byte)'C');
write((byte)'X');
write((byte)'M');
@@ -341,4 +290,3 @@
hasProlog = true;
}
}
-
Modified: cocoon/trunk/core/cocoon-pipeline/cocoon-pipeline-impl/src/main/java/org/apache/cocoon/components/sax/AbstractXMLByteStreamInterpreter.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-pipeline/cocoon-pipeline-impl/src/main/java/org/apache/cocoon/components/sax/AbstractXMLByteStreamInterpreter.java?rev=628434&r1=628433&r2=628434&view=diff
==============================================================================
--- cocoon/trunk/core/cocoon-pipeline/cocoon-pipeline-impl/src/main/java/org/apache/cocoon/components/sax/AbstractXMLByteStreamInterpreter.java (original)
+++ cocoon/trunk/core/cocoon-pipeline/cocoon-pipeline-impl/src/main/java/org/apache/cocoon/components/sax/AbstractXMLByteStreamInterpreter.java Sat Feb 16 22:48:17 2008
@@ -5,9 +5,9 @@
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -85,7 +85,7 @@
/**
* This method needs to be used by sub classes to start the parsing of the byte stream
- *
+ *
* @throws SAXException
*/
protected void parse() throws SAXException {
@@ -155,8 +155,8 @@
}
break;
case START_DTD:
- lexicalHandler.startDTD(this.readString(),
- this.readString(),
+ lexicalHandler.startDTD(this.readString(),
+ this.readString(),
this.readString());
break;
case END_DTD:
@@ -199,13 +199,19 @@
private String readString() throws SAXException {
int length = this.readWord();
- int index = length & 0x00007FFF;
+ int index;
if (length >= 0x00008000) {
+ // index value in 16-bits format
+ index = length & 0x00007FFF;
return (String) list.get(index);
- }
- else {
+ } else {
if (length == 0x00007FFF) {
length = this.readLong();
+ if (length >= 0x80000000) {
+ // index value in 32-bits format
+ index = length & 0x7fffffff;
+ return (String) list.get(index);
+ }
}
char[] chars = this.readChars(length);
int len = chars.length;
Modified: cocoon/trunk/core/cocoon-pipeline/cocoon-pipeline-impl/src/test/java/org/apache/cocoon/xml/AbstractXMLTestCase.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-pipeline/cocoon-pipeline-impl/src/test/java/org/apache/cocoon/xml/AbstractXMLTestCase.java?rev=628434&r1=628433&r2=628434&view=diff
==============================================================================
--- cocoon/trunk/core/cocoon-pipeline/cocoon-pipeline-impl/src/test/java/org/apache/cocoon/xml/AbstractXMLTestCase.java (original)
+++ cocoon/trunk/core/cocoon-pipeline/cocoon-pipeline-impl/src/test/java/org/apache/cocoon/xml/AbstractXMLTestCase.java Sat Feb 16 22:48:17 2008
@@ -5,9 +5,9 @@
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -44,14 +44,19 @@
protected void generateLargeSAX( ContentHandler consumer ) throws SAXException {
AttributesImpl atts = new AttributesImpl();
- final int size = 65000;
+ final int size = 66000;
char[] large = new char[size];
for(int i=0;i<size;i++) {
- large[i] = 'x';
+ large[i] = '\uffff';
}
consumer.startDocument();
consumer.startElement("", "root", "root", atts);
+ for (int i=0; i<0x10000; ++i) {
+ final String uniqueString = "f_" + i;
+ consumer.startElement("", uniqueString, uniqueString, atts);
+ consumer.endElement("", uniqueString, uniqueString);
+ }
consumer.characters(large,0,size);
consumer.endElement("", "root", "root");
consumer.endDocument();
@@ -81,4 +86,3 @@
return bos.toByteArray();
}
}
-