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/03/15 14:47:24 UTC
svn commit: r923225 -
/incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.platform.xhtml2html/src/main/java/org/apache/clerezza/platform/xhtml2html/Xhtml2HtmlFilter.java
Author: reto
Date: Mon Mar 15 13:47:24 2010
New Revision: 923225
URL: http://svn.apache.org/viewvc?rev=923225&view=rev
Log:
CLEREZZA-160: concerting to html when html preferred
Modified:
incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.platform.xhtml2html/src/main/java/org/apache/clerezza/platform/xhtml2html/Xhtml2HtmlFilter.java
Modified: incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.platform.xhtml2html/src/main/java/org/apache/clerezza/platform/xhtml2html/Xhtml2HtmlFilter.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/Xhtml2HtmlFilter.java?rev=923225&r1=923224&r2=923225&view=diff
==============================================================================
--- incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.platform.xhtml2html/src/main/java/org/apache/clerezza/platform/xhtml2html/Xhtml2HtmlFilter.java (original)
+++ incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.platform.xhtml2html/src/main/java/org/apache/clerezza/platform/xhtml2html/Xhtml2HtmlFilter.java Mon Mar 15 13:47:24 2010
@@ -18,7 +18,10 @@
*/
package org.apache.clerezza.platform.xhtml2html;
+import java.util.Iterator;
import java.util.regex.Pattern;
+import javax.activation.MimeType;
+import javax.activation.MimeTypeParseException;
import org.osgi.service.component.ComponentContext;
import org.wymiwyg.wrhapi.Handler;
import org.wymiwyg.wrhapi.HandlerException;
@@ -26,6 +29,8 @@ import org.wymiwyg.wrhapi.HeaderName;
import org.wymiwyg.wrhapi.Request;
import org.wymiwyg.wrhapi.Response;
import org.wymiwyg.wrhapi.filter.Filter;
+import org.wymiwyg.wrhapi.util.AcceptHeaderEntry;
+import org.wymiwyg.wrhapi.util.EnhancedRequest;
/**
* This Filter acts on client agents matching a pattern defined by the
@@ -44,6 +49,16 @@ import org.wymiwyg.wrhapi.filter.Filter;
public class Xhtml2HtmlFilter implements Filter {
private Pattern[] patterns;
+ final MimeType xhtmlMimeType;
+ final MimeType htmlMimeType;
+ {
+ try {
+ xhtmlMimeType = new MimeType("application", "xhtml+xml");
+ htmlMimeType = new MimeType("text", "html");
+ } catch (MimeTypeParseException ex) {
+ throw new RuntimeException(ex);
+ }
+ }
@Override
public void handle(Request request, Response response, Handler handler)
@@ -56,6 +71,9 @@ public class Xhtml2HtmlFilter implements
}
private boolean isApplicable(final Request request) throws HandlerException {
+ if (htmlPreferredInAccept(request)) {
+ return true;
+ }
final String[] userAgentStrings = request.getHeaderValues(HeaderName.USER_AGENT);
for (final String userAgentString : userAgentStrings) {
for (final Pattern pattern : patterns) {
@@ -67,6 +85,21 @@ public class Xhtml2HtmlFilter implements
return false;
}
+ private boolean htmlPreferredInAccept(Request request) throws HandlerException {
+ EnhancedRequest ehRequest = new EnhancedRequest(request);
+ Iterator<AcceptHeaderEntry> iter = ehRequest.getAccept();
+ while (iter.hasNext()) {
+ AcceptHeaderEntry entry = iter.next();
+ if (entry.getRange().match(xhtmlMimeType)) {
+ return false;
+ }
+ if (entry.getRange().match(htmlMimeType)) {
+ return true;
+ }
+ }
+ return false;
+ }
+
protected void activate(ComponentContext context) throws Exception {
final String[] patternStrings = (String[]) context.getProperties().
get("pattern");
@@ -76,4 +109,6 @@ public class Xhtml2HtmlFilter implements
}
}
+
+
}