You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@cocoon.apache.org by gi...@apache.org on 2006/09/01 13:49:43 UTC
svn commit: r439278 - in
/cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/components/sax:
AbstractXMLByteStreamCompiler.java AbstractXMLByteStreamInterpreter.java
XMLByteStreamCompiler.java
Author: giacomo
Date: Fri Sep 1 04:49:43 2006
New Revision: 439278
URL: http://svn.apache.org/viewvc?rev=439278&view=rev
Log:
stream prolog is abstraction affair
Modified:
cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/components/sax/AbstractXMLByteStreamCompiler.java
cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/components/sax/AbstractXMLByteStreamInterpreter.java
cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/components/sax/XMLByteStreamCompiler.java
Modified: cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/components/sax/AbstractXMLByteStreamCompiler.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/components/sax/AbstractXMLByteStreamCompiler.java?rev=439278&r1=439277&r2=439278&view=diff
==============================================================================
--- cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/components/sax/AbstractXMLByteStreamCompiler.java (original)
+++ cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/components/sax/AbstractXMLByteStreamCompiler.java Fri Sep 1 04:49:43 2006
@@ -33,15 +33,17 @@
private HashMap map;
private int mapCount;
+ private boolean hasProlog = false;
protected AbstractXMLByteStreamCompiler() {
this.map = new HashMap();
this.initOutput();
}
- protected void initOutput() {
+ private void initOutput() {
this.mapCount = 0;
this.map.clear();
+ this.hasProlog = false;
}
public void recycle() {
@@ -49,6 +51,8 @@
}
public void startDocument() throws SAXException {
+ if(!hasProlog)
+ writeProlog();
this.writeEvent(START_DOCUMENT);
}
@@ -57,6 +61,8 @@
}
public void startPrefixMapping(java.lang.String prefix, java.lang.String uri) throws SAXException {
+ if(!hasProlog)
+ writeProlog();
this.writeEvent(START_PREFIX_MAPPING);
this.writeString(prefix);
this.writeString(uri);
@@ -318,5 +324,16 @@
*/
abstract protected void write( final int b );
+
+ private void writeProlog()
+ {
+ write((byte)'C');
+ write((byte)'X');
+ write((byte)'M');
+ write((byte)'L');
+ write((byte)1);
+ write((byte)0);
+ hasProlog = true;
+ }
}
Modified: cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/components/sax/AbstractXMLByteStreamInterpreter.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/components/sax/AbstractXMLByteStreamInterpreter.java?rev=439278&r1=439277&r2=439278&view=diff
==============================================================================
--- cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/components/sax/AbstractXMLByteStreamInterpreter.java (original)
+++ cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/components/sax/AbstractXMLByteStreamInterpreter.java Fri Sep 1 04:49:43 2006
@@ -187,17 +187,6 @@
}
}
- private void checkProlog() throws SAXException {
- int valid = 0;
- if (this.read() == 'C') valid++;
- if (this.read() == 'X') valid++;
- if (this.read() == 'M') valid++;
- if (this.read() == 'L') valid++;
- if (this.read() == 1) valid++;
- if (this.read() == 0) valid++;
- if (valid != 6) throw new SAXException("Unrecognized file format.");
- }
-
protected int readEvent() throws SAXException {
return this.read();
}
@@ -311,5 +300,16 @@
int ch3 = this.read();
int ch4 = this.read();
return ((ch1 << 24) + (ch2 << 16) + (ch3 << 8) + (ch4 << 0));
+ }
+
+ private void checkProlog() throws SAXException {
+ int valid = 0;
+ if (this.read() == 'C') valid++;
+ if (this.read() == 'X') valid++;
+ if (this.read() == 'M') valid++;
+ if (this.read() == 'L') valid++;
+ if (this.read() == 1) valid++;
+ if (this.read() == 0) valid++;
+ if (valid != 6) throw new SAXException("Unrecognized file format.");
}
}
Modified: cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/components/sax/XMLByteStreamCompiler.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/components/sax/XMLByteStreamCompiler.java?rev=439278&r1=439277&r2=439278&view=diff
==============================================================================
--- cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/components/sax/XMLByteStreamCompiler.java (original)
+++ cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/components/sax/XMLByteStreamCompiler.java Fri Sep 1 04:49:43 2006
@@ -40,26 +40,19 @@
this.initOutput();
}
- protected void initOutput() {
- super.initOutput();
+ private void initOutput() {
this.buf = new byte[bufCountAverage];
- this.buf[0] = (byte)'C';
- this.buf[1] = (byte)'X';
- this.buf[2] = (byte)'M';
- this.buf[3] = (byte)'L';
- this.buf[4] = (byte)1;
- this.buf[5] = (byte)0;
- this.bufCount = 6;
}
public void recycle() {
bufCountAverage = (bufCountAverage + bufCount) / 2;
+ initOutput();
super.recycle();
}
public Object getSAXFragment() {
- if (this.bufCount == 6) { // no event arrived yet
+ if (this.bufCount == 0) { // no event arrived yet
return null;
}
byte newbuf[] = new byte[this.bufCount];