You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@clerezza.apache.org by re...@apache.org on 2010/02/09 11:35:55 UTC

svn commit: r907995 - in /incubator/clerezza: issues/CLEREZZA-69/ trunk/org.apache.clerezza.parent/org.apache.clerezza.platform.xhtml2html/ trunk/org.apache.clerezza.parent/org.apache.clerezza.platform.xhtml2html/src/main/java/org/apache/clerezza/platf...

Author: reto
Date: Tue Feb  9 10:35:54 2010
New Revision: 907995

URL: http://svn.apache.org/viewvc?rev=907995&view=rev
Log:
CLEREZZA-69: merged down, closed branch

Added:
    incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.platform.xhtml2html/src/main/java/org/apache/clerezza/platform/xhtml2html/ContentLengthSettingByteChannel.java
      - copied unchanged from r907977, incubator/clerezza/issues/CLEREZZA-69/org.apache.clerezza.platform.xhtml2html/src/main/java/org/apache/clerezza/platform/xhtml2html/ContentLengthSettingByteChannel.java
    incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.platform.xhtml2html/src/main/java/org/apache/clerezza/platform/xhtml2html/DocTypeFilteringByteChannel.java
      - copied unchanged from r907977, incubator/clerezza/issues/CLEREZZA-69/org.apache.clerezza.platform.xhtml2html/src/main/java/org/apache/clerezza/platform/xhtml2html/DocTypeFilteringByteChannel.java
    incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.platform.xhtml2html/src/main/java/org/apache/clerezza/platform/xhtml2html/SelfClosing2ClosingTagsByteChannel.java
      - copied unchanged from r907977, incubator/clerezza/issues/CLEREZZA-69/org.apache.clerezza.platform.xhtml2html/src/main/java/org/apache/clerezza/platform/xhtml2html/SelfClosing2ClosingTagsByteChannel.java
    incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.platform.xhtml2html/src/main/java/org/apache/clerezza/platform/xhtml2html/Xhtml2HtmlConvertingBody.java
      - copied unchanged from r907977, incubator/clerezza/issues/CLEREZZA-69/org.apache.clerezza.platform.xhtml2html/src/main/java/org/apache/clerezza/platform/xhtml2html/Xhtml2HtmlConvertingBody.java
    incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.platform.xhtml2html/src/test/java/org/apache/clerezza/platform/xhtml2html/SelfClosing2ClosingTagsByteChannelTest.java
      - copied unchanged from r907977, incubator/clerezza/issues/CLEREZZA-69/org.apache.clerezza.platform.xhtml2html/src/test/java/org/apache/clerezza/platform/xhtml2html/SelfClosing2ClosingTagsByteChannelTest.java
Removed:
    incubator/clerezza/issues/CLEREZZA-69/
    incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.platform.xhtml2html/src/main/java/org/apache/clerezza/platform/xhtml2html/DocTypeSettingBody.java
    incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.platform.xhtml2html/src/main/java/org/apache/clerezza/platform/xhtml2html/DocTypeSettingByteChannel.java
Modified:
    incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.platform.xhtml2html/   (props changed)
    incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.platform.xhtml2html/src/main/java/org/apache/clerezza/platform/xhtml2html/ResponseStatusInfo.java
    incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.platform.xhtml2html/src/main/java/org/apache/clerezza/platform/xhtml2html/WrappedRequest.java
    incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.platform.xhtml2html/src/main/java/org/apache/clerezza/platform/xhtml2html/WrappedResponse.java
    incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.platform.xhtml2html/src/test/java/org/apache/clerezza/platform/xhtml2html/DocTypeSettingByteChannelTest.java

Propchange: incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.platform.xhtml2html/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Tue Feb  9 10:35:54 2010
@@ -1 +1,2 @@
 /incubator/clerezza/issues/CLEREZZA-39/org.apache.clerezza.platform.xhtml2html:895979-897874
+/incubator/clerezza/issues/CLEREZZA-69/org.apache.clerezza.platform.xhtml2html:898291-907977

Modified: incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.platform.xhtml2html/src/main/java/org/apache/clerezza/platform/xhtml2html/ResponseStatusInfo.java
URL: http://svn.apache.org/viewvc/incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.platform.xhtml2html/src/main/java/org/apache/clerezza/platform/xhtml2html/ResponseStatusInfo.java?rev=907995&r1=907994&r2=907995&view=diff
==============================================================================
--- incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.platform.xhtml2html/src/main/java/org/apache/clerezza/platform/xhtml2html/ResponseStatusInfo.java (original)
+++ incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.platform.xhtml2html/src/main/java/org/apache/clerezza/platform/xhtml2html/ResponseStatusInfo.java Tue Feb  9 10:35:54 2010
@@ -1,32 +1,34 @@
 /*
- *  Copyright 2010 reto.
- * 
- *  Licensed 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.
- *  See the License for the specific language governing permissions and
- *  limitations under the License.
- *  under the License.
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  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.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
  */
-
 package org.apache.clerezza.platform.xhtml2html;
 
 /**
  *
- * @author reto
+ * @author reto, mir
  */
 interface ResponseStatusInfo {
 
 	/**
 	 *
-	 * @return true if the response is known to be (x)html, false otherwise
+	 * @return true if the content of the response has to be converted from
+	 *		xhtml to html, false otherwise
 	 */
-	boolean isHtml();
+	boolean convertXhtml2Html();
 
 }

Modified: incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.platform.xhtml2html/src/main/java/org/apache/clerezza/platform/xhtml2html/WrappedRequest.java
URL: http://svn.apache.org/viewvc/incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.platform.xhtml2html/src/main/java/org/apache/clerezza/platform/xhtml2html/WrappedRequest.java?rev=907995&r1=907994&r2=907995&view=diff
==============================================================================
--- incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.platform.xhtml2html/src/main/java/org/apache/clerezza/platform/xhtml2html/WrappedRequest.java (original)
+++ incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.platform.xhtml2html/src/main/java/org/apache/clerezza/platform/xhtml2html/WrappedRequest.java Tue Feb  9 10:35:54 2010
@@ -19,13 +19,10 @@
 package org.apache.clerezza.platform.xhtml2html;
 
 import java.util.ArrayList;
-import java.util.Arrays;
 import java.util.List;
 import org.wymiwyg.wrhapi.HandlerException;
 import org.wymiwyg.wrhapi.HeaderName;
 import org.wymiwyg.wrhapi.Request;
-import org.wymiwyg.wrhapi.util.AcceptHeaderEntry;
-import org.wymiwyg.wrhapi.util.AcceptHeaderIterator;
 import org.wymiwyg.wrhapi.util.RequestWrapper;
 
 /**

Modified: incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.platform.xhtml2html/src/main/java/org/apache/clerezza/platform/xhtml2html/WrappedResponse.java
URL: http://svn.apache.org/viewvc/incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.platform.xhtml2html/src/main/java/org/apache/clerezza/platform/xhtml2html/WrappedResponse.java?rev=907995&r1=907994&r2=907995&view=diff
==============================================================================
--- incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.platform.xhtml2html/src/main/java/org/apache/clerezza/platform/xhtml2html/WrappedResponse.java (original)
+++ incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.platform.xhtml2html/src/main/java/org/apache/clerezza/platform/xhtml2html/WrappedResponse.java Tue Feb  9 10:35:54 2010
@@ -18,6 +18,8 @@
  */
 package org.apache.clerezza.platform.xhtml2html;
 
+import java.util.ArrayList;
+import java.util.List;
 import org.wymiwyg.wrhapi.HandlerException;
 import org.wymiwyg.wrhapi.HeaderName;
 import org.wymiwyg.wrhapi.MessageBody;
@@ -31,23 +33,26 @@
 class WrappedResponse extends ResponseWrapper implements ResponseStatusInfo {
 	private String XHTML_TYPE = "application/xhtml+xml";
 	private String HTML_TYPE = "text/html";
-	private boolean isHtml = false;
+	private boolean convertXhtml2Html = false;
+	private List<Object> contentLengths = new ArrayList<Object>();
 
 	public WrappedResponse(Response response) {
 		super(response);
 	}
 
-
-
 	@Override
 	public void addHeader(HeaderName headerName, Object value) throws HandlerException {
-		if (headerName.equals(HeaderName.CONTENT_LENGTH) && isHtml) {
+		if (headerName.equals(HeaderName.CONTENT_LENGTH)) {
+			if (convertXhtml2Html) {
+				// do nothing
+			} else {
+				contentLengths.add(value);
+			}
 			return;
 		}
 		if (headerName.equals(HeaderName.CONTENT_TYPE) && XHTML_TYPE.equals(value)) {
 			super.addHeader(headerName, HTML_TYPE);
-			isHtml = true;
-			super.setHeader(HeaderName.CONTENT_LENGTH, null);
+			convertXhtml2Html = true;
 		} else {
 			super.addHeader(headerName, value);
 		}
@@ -55,13 +60,18 @@
 
 	@Override
 	public void setHeader(HeaderName headerName, Object value) throws HandlerException {
-		if (headerName.equals(HeaderName.CONTENT_LENGTH) && isHtml) {
+		if (headerName.equals(HeaderName.CONTENT_LENGTH)) {
+			if (convertXhtml2Html) {
+				// do nothing
+			} else {
+				contentLengths.clear();
+				contentLengths.add(value);
+			}
 			return;
 		}
 		if (headerName.equals(HeaderName.CONTENT_TYPE) && XHTML_TYPE.equals(value)) {
 			super.setHeader(headerName, HTML_TYPE);
-			isHtml = true;
-			super.setHeader(HeaderName.CONTENT_LENGTH, null);
+			convertXhtml2Html = true;
 		} else {
 			super.setHeader(headerName, value);
 		}
@@ -69,11 +79,17 @@
 
 	@Override
 	public void setBody(MessageBody body) throws HandlerException {
-		super.setBody(new DocTypeSettingBody(body, this));
+		super.setBody(new Xhtml2HtmlConvertingBody(body, this));
 	}
 
 	@Override
-	public boolean isHtml() {
-		return isHtml;
+	public boolean convertXhtml2Html() {
+		return convertXhtml2Html;
+	}
+
+	void setContentLengthIfNoConversion() throws HandlerException {
+		if (contentLengths.size() > 0 && !convertXhtml2Html) {
+			super.setHeader(HeaderName.CONTENT_LENGTH, contentLengths.toArray());
+		}
 	}
 }

Modified: incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.platform.xhtml2html/src/test/java/org/apache/clerezza/platform/xhtml2html/DocTypeSettingByteChannelTest.java
URL: http://svn.apache.org/viewvc/incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.platform.xhtml2html/src/test/java/org/apache/clerezza/platform/xhtml2html/DocTypeSettingByteChannelTest.java?rev=907995&r1=907994&r2=907995&view=diff
==============================================================================
--- incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.platform.xhtml2html/src/test/java/org/apache/clerezza/platform/xhtml2html/DocTypeSettingByteChannelTest.java (original)
+++ incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.platform.xhtml2html/src/test/java/org/apache/clerezza/platform/xhtml2html/DocTypeSettingByteChannelTest.java Tue Feb  9 10:35:54 2010
@@ -38,11 +38,11 @@
 				"</body>\n" +
 				"</html>";
 		final ByteArrayOutputStream baos = new ByteArrayOutputStream();
-		final WritableByteChannel channel = new DocTypeSettingByteChannel(Channels.newChannel(baos),
+		final WritableByteChannel channel = new DocTypeFilteringByteChannel(Channels.newChannel(baos),
 				new ResponseStatusInfo() {
 
 			@Override
-			public boolean isHtml() {
+			public boolean convertXhtml2Html() {
 				return true;
 			}
 
@@ -64,11 +64,11 @@
 				"</body>\n" +
 				"</html>";
 		final ByteArrayOutputStream baos = new ByteArrayOutputStream();
-		final WritableByteChannel channel = new DocTypeSettingByteChannel(Channels.newChannel(baos),
+		final WritableByteChannel channel = new DocTypeFilteringByteChannel(Channels.newChannel(baos),
 				new ResponseStatusInfo() {
 
 			@Override
-			public boolean isHtml() {
+			public boolean convertXhtml2Html() {
 				return true;
 			}
 		});
@@ -95,11 +95,11 @@
 				"</body>\n" +
 				"</html>";
 		final ByteArrayOutputStream baos = new ByteArrayOutputStream();
-		final WritableByteChannel channel = new DocTypeSettingByteChannel(Channels.newChannel(baos),
+		final WritableByteChannel channel = new DocTypeFilteringByteChannel(Channels.newChannel(baos),
 				new ResponseStatusInfo() {
 
 			@Override
-			public boolean isHtml() {
+			public boolean convertXhtml2Html() {
 				return true;
 			}
 		});
@@ -124,11 +124,11 @@
 				"</body>\n" +
 				"</html>";
 		final ByteArrayOutputStream baos = new ByteArrayOutputStream();
-		final WritableByteChannel channel = new DocTypeSettingByteChannel(Channels.newChannel(baos),
+		final WritableByteChannel channel = new DocTypeFilteringByteChannel(Channels.newChannel(baos),
 				new ResponseStatusInfo() {
 
 			@Override
-			public boolean isHtml() {
+			public boolean convertXhtml2Html() {
 				return true;
 			}
 
@@ -148,11 +148,11 @@
 				"</body>\n" +
 				"</html>";
 		final ByteArrayOutputStream baos = new ByteArrayOutputStream();
-		final WritableByteChannel channel = new DocTypeSettingByteChannel(Channels.newChannel(baos),
+		final WritableByteChannel channel = new DocTypeFilteringByteChannel(Channels.newChannel(baos),
 				new ResponseStatusInfo() {
 
 			@Override
-			public boolean isHtml() {
+			public boolean convertXhtml2Html() {
 				return true;
 			}