cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From andr...@apache.org
Subject svn commit: r737005 - in /cocoon/trunk/blocks/cocoon-serializers/cocoon-serializers-charsets/src/main/java/org/apache/cocoon/components/serializers/util: HTMLSerializer.java XHTMLSerializer.java
Date Fri, 23 Jan 2009 11:14:39 GMT
Author: andreas
Date: Fri Jan 23 03:14:38 2009
New Revision: 737005

URL: http://svn.apache.org/viewvc?rev=737005&view=rev
Log:
XHTMLSerializer: Don't encode characters in <script> and <style> elements to avoid
JavaScript parsing errors. This behaviour has been pulled up from the HTMLSerializer. Fixes
https://issues.apache.org/jira/browse/COCOON-2249.

Modified:
    cocoon/trunk/blocks/cocoon-serializers/cocoon-serializers-charsets/src/main/java/org/apache/cocoon/components/serializers/util/HTMLSerializer.java
    cocoon/trunk/blocks/cocoon-serializers/cocoon-serializers-charsets/src/main/java/org/apache/cocoon/components/serializers/util/XHTMLSerializer.java

Modified: cocoon/trunk/blocks/cocoon-serializers/cocoon-serializers-charsets/src/main/java/org/apache/cocoon/components/serializers/util/HTMLSerializer.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/blocks/cocoon-serializers/cocoon-serializers-charsets/src/main/java/org/apache/cocoon/components/serializers/util/HTMLSerializer.java?rev=737005&r1=737004&r2=737005&view=diff
==============================================================================
--- cocoon/trunk/blocks/cocoon-serializers/cocoon-serializers-charsets/src/main/java/org/apache/cocoon/components/serializers/util/HTMLSerializer.java
(original)
+++ cocoon/trunk/blocks/cocoon-serializers/cocoon-serializers-charsets/src/main/java/org/apache/cocoon/components/serializers/util/HTMLSerializer.java
Fri Jan 23 03:14:38 2009
@@ -70,8 +70,6 @@
 
     private static final HTMLEncoder HTML_ENCODER = new HTMLEncoder();
 
-    protected boolean encodeCharacters = true;
-
     /**
      * Create a new instance of this <code>HTMLSerializer</code>
      */
@@ -185,10 +183,6 @@
             length++;
         }
 
-        // script and style are CDATA sections by default, so no encoding
-        if ( "SCRIPT".equals(name) || "STYLE".equals(name) ) {
-            this.encodeCharacters = false;
-        }
         super.startElementImpl(XHTML1_NAMESPACE, name, name, NAMESPACES, at);
     }
 
@@ -220,22 +214,7 @@
         if (name.equals("META")) return;
         if (name.equals("PARAM")) return;
 
-        // script and style are CDATA sections by default, so no encoding
-        if ( "SCRIPT".equals(name) || "STYLE".equals(name) ) {
-            this.encodeCharacters = true;
-        }
         super.endElementImpl(XHTML1_NAMESPACE, name, name);
     }
 
-    /**
-     * Encode and write a specific part of an array of characters.
-     */
-    protected void encode(char data[], int start, int length)
-    throws SAXException {
-        if ( !this.encodeCharacters ) {
-            this.write(data, start, length);
-            return;
-        }
-        super.encode(data, start, length);
-    }
 }

Modified: cocoon/trunk/blocks/cocoon-serializers/cocoon-serializers-charsets/src/main/java/org/apache/cocoon/components/serializers/util/XHTMLSerializer.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/blocks/cocoon-serializers/cocoon-serializers-charsets/src/main/java/org/apache/cocoon/components/serializers/util/XHTMLSerializer.java?rev=737005&r1=737004&r2=737005&view=diff
==============================================================================
--- cocoon/trunk/blocks/cocoon-serializers/cocoon-serializers-charsets/src/main/java/org/apache/cocoon/components/serializers/util/XHTMLSerializer.java
(original)
+++ cocoon/trunk/blocks/cocoon-serializers/cocoon-serializers-charsets/src/main/java/org/apache/cocoon/components/serializers/util/XHTMLSerializer.java
Fri Jan 23 03:14:38 2009
@@ -75,6 +75,8 @@
 
     private static final XHTMLEncoder XHTML_ENCODER = new XHTMLEncoder();
 
+    protected boolean encodeCharacters = true;
+
     /* ====================================================================== */
 
     /** The <code>DocType</code> instance representing the document. */
@@ -173,6 +175,9 @@
                                  String namespaces[][], String attributes[][])
     throws SAXException {
         if (uri.length() == 0) uri = XHTML1_NAMESPACE;
+        if (isCdataElement(local)) {
+            this.encodeCharacters = false;
+        }
         super.startElementImpl(uri, local, qual, namespaces, attributes);
     }
 
@@ -209,7 +214,34 @@
                 this.endElementImpl(XHTML1_NAMESPACE, loc, qua);
             }
         }
+        
+        if (isCdataElement(local)) {
+            this.encodeCharacters = true;
+        }
+
         super.endElementImpl(uri, local, qual);
     }
 
+    /**
+     * script and style are CDATA sections by default, so no encoding
+     * @param localName The local name of the element.
+     * @return If the element should be serialized without encoding.
+     */
+    protected boolean isCdataElement(String localName) {
+        String upperCase = localName.toUpperCase();
+        return "SCRIPT".equals(upperCase) || "STYLE".equals(upperCase);
+    }
+        
+
+    /**
+     * Encode and write a specific part of an array of characters.
+     */
+    protected void encode(char data[], int start, int length)
+    throws SAXException {
+        if (this.encodeCharacters) {
+            super.encode(data, start, length);
+        } else {
+            this.write(data, start, length);
+        }
+    }
 }



Mime
View raw message