You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@clerezza.apache.org by mi...@apache.org on 2010/01/11 14:15:54 UTC

svn commit: r897852 - in /incubator/clerezza/issues/CLEREZZA-39/org.apache.clerezza.platform.xhtml2html/src: main/java/org/apache/clerezza/platform/xhtml2html/ test/java/org/apache/clerezza/platform/xhtml2html/

Author: mir
Date: Mon Jan 11 13:15:54 2010
New Revision: 897852

URL: http://svn.apache.org/viewvc?rev=897852&view=rev
Log:
CLEREZZA-39: returns now the difference between the byte remaining in the buffer before and after the call.

Modified:
    incubator/clerezza/issues/CLEREZZA-39/org.apache.clerezza.platform.xhtml2html/src/main/java/org/apache/clerezza/platform/xhtml2html/DocTypeSettingByteChannel.java
    incubator/clerezza/issues/CLEREZZA-39/org.apache.clerezza.platform.xhtml2html/src/main/java/org/apache/clerezza/platform/xhtml2html/WrappedResponse.java
    incubator/clerezza/issues/CLEREZZA-39/org.apache.clerezza.platform.xhtml2html/src/test/java/org/apache/clerezza/platform/xhtml2html/DocTypeSettingByteChannelTest.java

Modified: incubator/clerezza/issues/CLEREZZA-39/org.apache.clerezza.platform.xhtml2html/src/main/java/org/apache/clerezza/platform/xhtml2html/DocTypeSettingByteChannel.java
URL: http://svn.apache.org/viewvc/incubator/clerezza/issues/CLEREZZA-39/org.apache.clerezza.platform.xhtml2html/src/main/java/org/apache/clerezza/platform/xhtml2html/DocTypeSettingByteChannel.java?rev=897852&r1=897851&r2=897852&view=diff
==============================================================================
--- incubator/clerezza/issues/CLEREZZA-39/org.apache.clerezza.platform.xhtml2html/src/main/java/org/apache/clerezza/platform/xhtml2html/DocTypeSettingByteChannel.java (original)
+++ incubator/clerezza/issues/CLEREZZA-39/org.apache.clerezza.platform.xhtml2html/src/main/java/org/apache/clerezza/platform/xhtml2html/DocTypeSettingByteChannel.java Mon Jan 11 13:15:54 2010
@@ -54,8 +54,7 @@
 	@Override
 	public int write(ByteBuffer byteBuffer) throws IOException {
 		if (!doctypeWritten && wrappedResponse.isHtml()) {
-			int writtenBytes = byteBuffer.remaining();
-			System.out.println(writtenBytes);
+			int initialRemaining = byteBuffer.remaining();
 			while (byteBuffer.remaining() > 0) {
 				byte b = byteBuffer.get();
 				cachedBytes.write(b);
@@ -65,11 +64,10 @@
 				}
 				if (arrayPosition == (DOCTYPE_TAG_BYTES.length - 1) &&
 						DOCTYPE_TAG_BYTES[arrayPosition] == b) {
-					byte[] cachedBytesArray = cachedBytes.toByteArray();
-					writeToWrappedChannel(cachedBytesArray);
-					int rest = wrappedByteChannel.write(byteBuffer);
+					writeToWrappedChannel(cachedBytes.toByteArray());
+					wrappedByteChannel.write(byteBuffer);
 					doctypeWritten = true;
-					return cachedBytesArray.length + rest;
+					break;
 				}
 				if (arrayPosition < XML_DECLARATION_BYTES.length
 						&& XML_DECLARATION_BYTES[arrayPosition] != b) {
@@ -86,17 +84,16 @@
 				if (DOCTYPE_TAG_BYTES[arrayPosition] != b || isNotADoctypeDef) {
 					isNotADoctypeDef = true;
 					if (!isXmlDeclaration) {
-						writeToWrappedChannel(DOCTYPE_DEF_BYTES);
-						byte[] cachedBytesArray = cachedBytes.toByteArray();
-						writeToWrappedChannel(cachedBytesArray);
-						int rest = wrappedByteChannel.write(byteBuffer);
+						writeToWrappedChannel(DOCTYPE_DEF_BYTES);						
+						writeToWrappedChannel(cachedBytes.toByteArray());
+						wrappedByteChannel.write(byteBuffer);
 						doctypeWritten = true;
-						return DOCTYPE_DEF_BYTES.length + cachedBytesArray.length + rest;
+						break;
 					}
 				}
 				arrayPosition++;
 			}
-			return 0;
+			return initialRemaining  - byteBuffer.remaining();
 		} else {
 			return wrappedByteChannel.write(byteBuffer);
 		}

Modified: incubator/clerezza/issues/CLEREZZA-39/org.apache.clerezza.platform.xhtml2html/src/main/java/org/apache/clerezza/platform/xhtml2html/WrappedResponse.java
URL: http://svn.apache.org/viewvc/incubator/clerezza/issues/CLEREZZA-39/org.apache.clerezza.platform.xhtml2html/src/main/java/org/apache/clerezza/platform/xhtml2html/WrappedResponse.java?rev=897852&r1=897851&r2=897852&view=diff
==============================================================================
--- incubator/clerezza/issues/CLEREZZA-39/org.apache.clerezza.platform.xhtml2html/src/main/java/org/apache/clerezza/platform/xhtml2html/WrappedResponse.java (original)
+++ incubator/clerezza/issues/CLEREZZA-39/org.apache.clerezza.platform.xhtml2html/src/main/java/org/apache/clerezza/platform/xhtml2html/WrappedResponse.java Mon Jan 11 13:15:54 2010
@@ -41,9 +41,13 @@
 
 	@Override
 	public void addHeader(HeaderName headerName, Object value) throws HandlerException {
+		if (headerName.equals(HeaderName.CONTENT_LENGTH) && isHtml) {
+			return;
+		}
 		if (headerName.equals(HeaderName.CONTENT_TYPE) && XHTML_TYPE.equals(value)) {
 			super.addHeader(headerName, HTML_TYPE);
 			isHtml = true;
+			super.setHeader(HeaderName.CONTENT_LENGTH, null);
 		} else {
 			super.addHeader(headerName, value);
 		}
@@ -51,9 +55,13 @@
 
 	@Override
 	public void setHeader(HeaderName headerName, Object value) throws HandlerException {
+		if (headerName.equals(HeaderName.CONTENT_LENGTH) && isHtml) {
+			return;
+		}
 		if (headerName.equals(HeaderName.CONTENT_TYPE) && XHTML_TYPE.equals(value)) {
 			super.setHeader(headerName, HTML_TYPE);
 			isHtml = true;
+			super.setHeader(HeaderName.CONTENT_LENGTH, null);
 		} else {
 			super.setHeader(headerName, value);
 		}

Modified: incubator/clerezza/issues/CLEREZZA-39/org.apache.clerezza.platform.xhtml2html/src/test/java/org/apache/clerezza/platform/xhtml2html/DocTypeSettingByteChannelTest.java
URL: http://svn.apache.org/viewvc/incubator/clerezza/issues/CLEREZZA-39/org.apache.clerezza.platform.xhtml2html/src/test/java/org/apache/clerezza/platform/xhtml2html/DocTypeSettingByteChannelTest.java?rev=897852&r1=897851&r2=897852&view=diff
==============================================================================
--- incubator/clerezza/issues/CLEREZZA-39/org.apache.clerezza.platform.xhtml2html/src/test/java/org/apache/clerezza/platform/xhtml2html/DocTypeSettingByteChannelTest.java (original)
+++ incubator/clerezza/issues/CLEREZZA-39/org.apache.clerezza.platform.xhtml2html/src/test/java/org/apache/clerezza/platform/xhtml2html/DocTypeSettingByteChannelTest.java Mon Jan 11 13:15:54 2010
@@ -71,13 +71,12 @@
 			public boolean isHtml() {
 				return true;
 			}
-
 		});
 		int bytesWritten = channel.write(ByteBuffer.wrap(someHtml.substring(0, 20).getBytes(UTF8)));
 		bytesWritten += channel.write(ByteBuffer.wrap(someHtml.substring(20).getBytes(UTF8)));
 		final String resultString = new String(baos.toByteArray(), UTF8);
 		System.out.println(resultString);
-		Assert.assertEquals(resultString.length(), bytesWritten);
+		Assert.assertEquals(someHtml.length(), bytesWritten);
 		Assert.assertTrue(resultString.contains("<!DOCTYPE"));
 		/* The test fails iff the ?xml is at another position than 0, not
 		 * if its removed*/
@@ -103,7 +102,6 @@
 			public boolean isHtml() {
 				return true;
 			}
-
 		});
 		channel.write(ByteBuffer.wrap(someHtml.getBytes(UTF8)));
 		final String resultString = new String(baos.toByteArray(), UTF8);