pier 2004/04/30 12:34:46
Modified:
src/blocks/serializers/java/org/apache/cocoon/components/serializers
HTMLSerializer.java XMLSerializer.java
src/blocks/serializers/java/org/apache/cocoon/components/serializers/encoding
CharsetFactory.java
src/blocks/serializers/java/org/apache/cocoon/components/serializers/util
DocType.java
Added:
src/blocks/serializers/java/org/apache/cocoon/components/serializers/util
SGMLDocType.java
Log:
Providing a "compatible" SGML doctype to avoid stupid browser differences
notified at VNU Publications when a SYSTEM identifier is present together
with its PUBLIC identifier.
Basically a SGML doctype allows a PUBLIC without a SYSTEM and is used only
in SGML. Documents processed this way are still 100% valid using the W3C
validator serivce at http://validator.w3.org/ as HTML 4.01 Transitional,
but cross-browser compatibility (and rendering on the pages) is much
more improved.
Thank you to Ben Eveling <[EMAIL PROTECTED]> and Jeremy for spending
hours and getting blind on looking at how (and why) pixels are rendered
in one way or another in different browsers.
Revision Changes Path
1.3 +10 -6
cocoon-2.1/src/blocks/serializers/java/org/apache/cocoon/components/serializers/HTMLSerializer.java
Index: HTMLSerializer.java
===================================================================
RCS file:
/home/cvs/cocoon-2.1/src/blocks/serializers/java/org/apache/cocoon/components/serializers/HTMLSerializer.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- HTMLSerializer.java 27 Apr 2004 18:35:21 -0000 1.2
+++ HTMLSerializer.java 30 Apr 2004 19:34:46 -0000 1.3
@@ -17,29 +17,33 @@
import org.apache.cocoon.components.serializers.encoding.HTMLEncoder;
import org.apache.cocoon.components.serializers.util.DocType;
+import org.apache.cocoon.components.serializers.util.SGMLDocType;
import org.xml.sax.SAXException;
/**
*
- *
* @author <a href="mailto:[EMAIL PROTECTED]">Pier Fumagalli</a>, February
2003
* @version CVS $Id$
*/
public class HTMLSerializer extends XHTMLSerializer {
+ /** A cross-browser compatible very simple document type declaration. */
+ public static final DocType HTML401_DOCTYPE_COMPATIBLE = new SGMLDocType(
+ "HTML", "-//W3C//DTD HTML 4.01 Transitional//EN", null);
+
/** A representation of the HTML 4.01 strict document type. */
- public static final DocType HTML401_DOCTYPE_STRICT = new DocType(
+ public static final DocType HTML401_DOCTYPE_STRICT = new SGMLDocType(
"HTML", "-//W3C//DTD HTML 4.01//EN",
"http://www.w3.org/TR/html4/strict.dtd");
/** A representation of the HTML 4.01 transitional document type. */
- public static final DocType HTML401_DOCTYPE_TRANSITIONAL = new DocType(
+ public static final DocType HTML401_DOCTYPE_TRANSITIONAL = new
SGMLDocType(
"HTML", "-//W3C//DTD HTML 4.01 Transitional//EN",
"http://www.w3.org/TR/html4/loose.dtd");
/** A representation of the HTML 4.01 frameset document type. */
- public static final DocType HTML401_DOCTYPE_FRAMESET = new DocType(
+ public static final DocType HTML401_DOCTYPE_FRAMESET = new SGMLDocType(
"HTML", "-//W3C//DTD HTML 4.01 Frameset//EN",
"http://www.w3.org/TR/html4/frameset.dtd");
@@ -96,7 +100,7 @@
}
if (this.doctype == null) {
- this.doctype = HTML401_DOCTYPE_TRANSITIONAL;
+ this.doctype = HTML401_DOCTYPE_COMPATIBLE;
} else if (XHTML1_DOCTYPE_STRICT.equals(this.doctype)) {
this.doctype = HTML401_DOCTYPE_STRICT;
} else if (XHTML1_DOCTYPE_TRANSITIONAL.equals(this.doctype)) {
1.3 +6 -3
cocoon-2.1/src/blocks/serializers/java/org/apache/cocoon/components/serializers/XMLSerializer.java
Index: XMLSerializer.java
===================================================================
RCS file:
/home/cvs/cocoon-2.1/src/blocks/serializers/java/org/apache/cocoon/components/serializers/XMLSerializer.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- XMLSerializer.java 27 Apr 2004 18:35:21 -0000 1.2
+++ XMLSerializer.java 30 Apr 2004 19:34:46 -0000 1.3
@@ -211,8 +211,11 @@
if (public_id != null) {
this.write(S_DOCTYPE_2); // [ PUBLIC "]
this.write(public_id);
- this.write(S_DOCTYPE_3); // [" "]
- this.write(system_id);
+ /* This is wring in XML, but not in SGML/HTML */
+ if (system_id != null) {
+ this.write(S_DOCTYPE_3); // [" "]
+ this.write(system_id);
+ }
this.write(S_DOCTYPE_5); // [">]
} else if (system_id != null) {
this.write(S_DOCTYPE_4); // [ SYSTEM "]
1.2 +7 -4
cocoon-2.1/src/blocks/serializers/java/org/apache/cocoon/components/serializers/encoding/CharsetFactory.java
Index: CharsetFactory.java
===================================================================
RCS file:
/home/cvs/cocoon-2.1/src/blocks/serializers/java/org/apache/cocoon/components/serializers/encoding/CharsetFactory.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- CharsetFactory.java 21 Apr 2004 09:33:22 -0000 1.1
+++ CharsetFactory.java 30 Apr 2004 19:34:46 -0000 1.2
@@ -36,6 +36,10 @@
*/
public final class CharsetFactory {
+ /** The lookup class name for the encodings. */
+ private static final String CHARSET_LOOKUP_CLASS =
+
"org/apache/cocoon/components/serializers/encoding/cs_US_ASCII.class";
+
/** Our private instance. */
private static CharsetFactory instance = new CharsetFactory();
@@ -55,9 +59,8 @@
super();
this.unknownCharset = new UnknownCharset();
- ClassLoader loader = this.getClass().getClassLoader();
- String file = this.getClass().getName().replace('.','/') + ".class";
- URL url = loader.getResource(file);
+ ClassLoader loader = Thread.currentThread().getContextClassLoader();
+ URL url = loader.getResource(CHARSET_LOOKUP_CLASS);
if ("jar".equals(url.getProtocol())) {
this.loadCharsetsFromJar(url);
1.2 +22 -12
cocoon-2.1/src/blocks/serializers/java/org/apache/cocoon/components/serializers/util/DocType.java
Index: DocType.java
===================================================================
RCS file:
/home/cvs/cocoon-2.1/src/blocks/serializers/java/org/apache/cocoon/components/serializers/util/DocType.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- DocType.java 21 Apr 2004 09:33:26 -0000 1.1
+++ DocType.java 30 Apr 2004 19:34:46 -0000 1.2
@@ -24,16 +24,25 @@
*/
public class DocType {
/** The name of the root element. */
- private String root_name = null;
+ protected String root_name = null;
/** The configured system identifier. */
- private String public_id = null;
+ protected String public_id = null;
/** The configured public identifier. */
- private String system_id = null;
+ protected String system_id = null;
/**
* Create a new <code>DocType</code> instance.
*
* @param root_name The document root element name.
+ */
+ public DocType(String root_name) {
+ this(root_name, null, null);
+ }
+
+ /**
+ * Create a new <code>DocType</code> instance.
+ *
+ * @param root_name The document root element name.
* @param system_id The document type system identifier.
*/
public DocType(String root_name, String system_id) {
@@ -94,15 +103,16 @@
if (!(object instanceof DocType)) return(false);
DocType doctype = (DocType)object;
- if (this.public_id != null) {
- return(this.public_id.equals(doctype.public_id) &&
- this.system_id.equals(doctype.system_id) &&
- this.root_name.equals(doctype.root_name));
+ if (this.public_id == null) {
+ if (doctype.public_id != null) return(false);
+ } else {
+ if (!this.public_id.equals(doctype.public_id)) return(false);
}
-
- if (this.system_id != null) {
- return(this.system_id.equals(doctype.system_id) &&
- this.root_name.equals(doctype.root_name));
+
+ if (this.system_id == null) {
+ if (doctype.system_id != null) return(false);
+ } else {
+ if (!this.system_id.equals(doctype.system_id)) return(false);
}
return(this.root_name.equals(doctype.root_name));
1.1
cocoon-2.1/src/blocks/serializers/java/org/apache/cocoon/components/serializers/util/SGMLDocType.java
Index: SGMLDocType.java
===================================================================
/*
* Copyright 1999-2004 The Apache Software Foundation.
*
* 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.
*/
package org.apache.cocoon.components.serializers.util;
/**
* The <code>SGMLDocType</code> class encapsulates informations regarding
* the document type public and system IDs and root element name for SGML
* (like HTML) documents.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Pier Fumagalli</a>, February
2003
* @version CVS $Id: SGMLDocType.java,v 1.1 2004/04/30 19:34:46 pier Exp $
*/
public class SGMLDocType extends DocType {
/**
* Create a new <code>SGMLDocType</code> instance.
*
* @param root_name The document root element name.
*/
public SGMLDocType(String root_name) {
this(root_name, null, null);
}
/**
* Create a new <code>SGMLDocType</code> instance.
*
* @param root_name The document root element name.
* @param public_id The document type public identifier.
* @param system_id The document type system identifier.
*/
public SGMLDocType(String root_name, String public_id, String system_id) {
super(root_name);
this.public_id = public_id;
this.system_id = system_id;
}
}