Author: scottbw
Date: Sat Feb 12 19:35:12 2011
New Revision: 1070138
URL: http://svn.apache.org/viewvc?rev=1070138&view=rev
Log:
Changed the implementation of charset overrides for widget start pages. Setting
the response type for a GET has no effect on the server at all and it will use
the default setting (UTF-8 on Tomcat; ISO on Jetty). So instead I've changed
the StartPageProcessor to inject a <meta http-equiv="Content-Type"> tag into
the <head> of the start page with the encoding and type overrides from the
Widget's <content> element. This addresses issue WOOKIE-93.
Removed:
incubator/wookie/trunk/src/org/apache/wookie/server/CharSetFilter.java
Modified:
incubator/wookie/trunk/WebContent/WEB-INF/web.xml
incubator/wookie/trunk/parser/java/src/org/apache/wookie/w3c/IStartPageProcessor.java
incubator/wookie/trunk/parser/java/src/org/apache/wookie/w3c/W3CWidgetFactory.java
incubator/wookie/trunk/src/org/apache/wookie/util/html/HtmlCleaner.java
incubator/wookie/trunk/src/org/apache/wookie/util/html/IHtmlProcessor.java
incubator/wookie/trunk/src/org/apache/wookie/util/html/StartPageProcessor.java
Modified: incubator/wookie/trunk/WebContent/WEB-INF/web.xml
URL:
http://svn.apache.org/viewvc/incubator/wookie/trunk/WebContent/WEB-INF/web.xml?rev=1070138&r1=1070137&r2=1070138&view=diff
==============================================================================
--- incubator/wookie/trunk/WebContent/WEB-INF/web.xml (original)
+++ incubator/wookie/trunk/WebContent/WEB-INF/web.xml Sat Feb 12 19:35:12 2011
@@ -59,15 +59,6 @@
<filter-name>MainFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
-
- <filter>
- <filter-name>CharSet Filter</filter-name>
- <filter-class>org.apache.wookie.server.CharSetFilter</filter-class>
- </filter>
- <filter-mapping>
- <filter-name>CharSet Filter</filter-name>
- <url-pattern>/*</url-pattern>
- </filter-mapping>
<filter>
<filter-name>Localized Resource Filter</filter-name>
Modified:
incubator/wookie/trunk/parser/java/src/org/apache/wookie/w3c/IStartPageProcessor.java
URL:
http://svn.apache.org/viewvc/incubator/wookie/trunk/parser/java/src/org/apache/wookie/w3c/IStartPageProcessor.java?rev=1070138&r1=1070137&r2=1070138&view=diff
==============================================================================
---
incubator/wookie/trunk/parser/java/src/org/apache/wookie/w3c/IStartPageProcessor.java
(original)
+++
incubator/wookie/trunk/parser/java/src/org/apache/wookie/w3c/IStartPageProcessor.java
Sat Feb 12 19:35:12 2011
@@ -28,7 +28,7 @@ public interface IStartPageProcessor {
* @throws IOException if there is a problem reading or writing to the
start file, or if the start file cannot be parsed
* with the HTML processor used
*/
- public abstract void processStartFile(File startFile, W3CWidget model)
+ public abstract void processStartFile(File startFile, W3CWidget model,
IContentEntity content)
throws Exception;
}
\ No newline at end of file
Modified:
incubator/wookie/trunk/parser/java/src/org/apache/wookie/w3c/W3CWidgetFactory.java
URL:
http://svn.apache.org/viewvc/incubator/wookie/trunk/parser/java/src/org/apache/wookie/w3c/W3CWidgetFactory.java?rev=1070138&r1=1070137&r2=1070138&view=diff
==============================================================================
---
incubator/wookie/trunk/parser/java/src/org/apache/wookie/w3c/W3CWidgetFactory.java
(original)
+++
incubator/wookie/trunk/parser/java/src/org/apache/wookie/w3c/W3CWidgetFactory.java
Sat Feb 12 19:35:12 2011
@@ -93,7 +93,7 @@ public class W3CWidgetFactory {
this.outputDirectory = null;
this.encodings = new String[]{"UTF-8"};
this.startPageProcessor = new IStartPageProcessor(){
- public void processStartFile(File startFile, W3CWidget
model)
+ public void processStartFile(File startFile, W3CWidget
model,IContentEntity content)
throws Exception {
}
@@ -251,7 +251,7 @@ public class W3CWidgetFactory {
String relativestartUrl =
(WidgetPackageUtils.getURLForWidget(localPath, manifestIdentifier,
content.getSrc()));
content.setSrc(relativestartUrl);
if(startFile.exists() &&
startPageProcessor != null){
-
startPageProcessor.processStartFile(startFile, widgetModel);
+
startPageProcessor.processStartFile(startFile, widgetModel, content);
}
}
if (widgetModel.getContentList().isEmpty()){
Modified:
incubator/wookie/trunk/src/org/apache/wookie/util/html/HtmlCleaner.java
URL:
http://svn.apache.org/viewvc/incubator/wookie/trunk/src/org/apache/wookie/util/html/HtmlCleaner.java?rev=1070138&r1=1070137&r2=1070138&view=diff
==============================================================================
--- incubator/wookie/trunk/src/org/apache/wookie/util/html/HtmlCleaner.java
(original)
+++ incubator/wookie/trunk/src/org/apache/wookie/util/html/HtmlCleaner.java Sat
Feb 12 19:35:12 2011
@@ -47,7 +47,7 @@ public class HtmlCleaner implements IHtm
cleaner = new org.htmlcleaner.HtmlCleaner();
// set cleaner properties
properties = cleaner.getProperties();
- properties.setOmitDoctypeDeclaration(false);
+ properties.setOmitDoctypeDeclaration(true);
properties.setOmitXmlDeclaration(true);
properties.setUseCdataForScriptAndStyle(true);
properties.setUseEmptyElementTags(false);
@@ -90,8 +90,13 @@ public class HtmlCleaner implements IHtm
/* (non-Javadoc)
* @see
org.apache.wookie.util.html.IHtmlProcessor#setCharset(java.lang.String)
*/
- public void setCharset(String charset) {
- // TODO Auto-generated method stub
+ public void setTypeAndCharset(String type, String charset) {
+ // This overrides any existing encoding information in the HTML
file.
+ TagNode meta = new TagNode(META_TAG);
+ meta.addAttribute("http-equiv", "Content-Type");
+ if (charset.equals("UTF-8")) charset="utf-8";
+ meta.addAttribute("content", type+";charset="+charset);
+ headNode.getChildren().add(0, meta);
}
/* (non-Javadoc)
Modified:
incubator/wookie/trunk/src/org/apache/wookie/util/html/IHtmlProcessor.java
URL:
http://svn.apache.org/viewvc/incubator/wookie/trunk/src/org/apache/wookie/util/html/IHtmlProcessor.java?rev=1070138&r1=1070137&r2=1070138&view=diff
==============================================================================
--- incubator/wookie/trunk/src/org/apache/wookie/util/html/IHtmlProcessor.java
(original)
+++ incubator/wookie/trunk/src/org/apache/wookie/util/html/IHtmlProcessor.java
Sat Feb 12 19:35:12 2011
@@ -34,6 +34,7 @@ public interface IHtmlProcessor {
final String HEAD_TAG = "head";
final String SCRIPT_TAG = "script";
final String LINK_TAG = "link";
+ final String META_TAG = "meta";
final String TYPE_ATTRIBUTE = "type";
final String TYPE_ATTRIBUTE_VALUE = "text/javascript";
final String CSS_TYPE_ATTRIBUTE_VALUE = "text/css";
@@ -62,10 +63,11 @@ public interface IHtmlProcessor {
public void injectStylesheet(String href);
/**
- * Sets the charset of the HTML document
+ * Sets the type and charset of the HTML document
+ * @param type
* @param charset
*/
- public void setCharset(String charset);
+ public void setTypeAndCharset(String type, String charset);
/**
* Processes the HTML and writes the output to the specified writer
Modified:
incubator/wookie/trunk/src/org/apache/wookie/util/html/StartPageProcessor.java
URL:
http://svn.apache.org/viewvc/incubator/wookie/trunk/src/org/apache/wookie/util/html/StartPageProcessor.java?rev=1070138&r1=1070137&r2=1070138&view=diff
==============================================================================
---
incubator/wookie/trunk/src/org/apache/wookie/util/html/StartPageProcessor.java
(original)
+++
incubator/wookie/trunk/src/org/apache/wookie/util/html/StartPageProcessor.java
Sat Feb 12 19:35:12 2011
@@ -21,6 +21,7 @@ import org.apache.wookie.beans.IServerFe
import org.apache.wookie.beans.util.IPersistenceManager;
import org.apache.wookie.beans.util.PersistenceManagerFactory;
import org.apache.wookie.feature.IFeature;
+import org.apache.wookie.w3c.IContentEntity;
import org.apache.wookie.w3c.IFeatureEntity;
import org.apache.wookie.w3c.W3CWidget;
import org.apache.wookie.w3c.IStartPageProcessor;
@@ -38,7 +39,7 @@ public class StartPageProcessor implemen
/* (non-Javadoc)
* @see
org.apache.wookie.util.html.IStartPageProcessor#processStartFile(java.io.File,
org.apache.wookie.w3c.IManifestModel)
*/
- public void processStartFile(File startFile, W3CWidget model) throws
Exception{
+ public void processStartFile(File startFile, W3CWidget model,
IContentEntity content) throws Exception{
if (startFile == null) throw new Exception("Start file cannot
be processed: file is null");
if (!startFile.exists()) throw new Exception("Start file cannot
be processed: file does not exist");
if (!(startFile.canWrite()&&startFile.canRead())) throw new
Exception("Start file cannot be processed: read or write permissions missing");
@@ -47,10 +48,15 @@ public class StartPageProcessor implemen
engine.setReader(new FileReader(startFile));
addDefaultScripts(engine);
addFeatures(engine, model);
+ setContentType(engine, content);
FileWriter writer = new FileWriter(startFile);
engine.process(writer);
}
+ private void setContentType(IHtmlProcessor engine, IContentEntity
content){
+ engine.setTypeAndCharset(content.getType(),
content.getCharSet());
+ }
+
/**
* Injects default wrapper and utilities
* @param engine