cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From anathan...@apache.org
Subject svn commit: r234111 - in /cocoon/branches/BRANCH_2_1_X: src/blocks/xsp/java/org/apache/cocoon/components/language/markup/xsp/java/xsp.xsl src/blocks/xsp/samples/java/escaping.xsp src/blocks/xsp/samples/samples.xml status.xml tools/src/blocks-build.xsl
Date Sat, 20 Aug 2005 19:06:28 GMT
Author: anathaniel
Date: Sat Aug 20 12:06:19 2005
New Revision: 234111

URL: http://svn.apache.org/viewcvs?rev=234111&view=rev
Log:
XSP block: Add xsp:expr and various other contexts where text must be
passed through XSLTExtension:escape in order to preserve non-ASCII
characters in Java string constants independently of the XSP source file
and compiler expected encodings.

Added:
    cocoon/branches/BRANCH_2_1_X/src/blocks/xsp/samples/java/escaping.xsp   (with props)
Modified:
    cocoon/branches/BRANCH_2_1_X/src/blocks/xsp/java/org/apache/cocoon/components/language/markup/xsp/java/xsp.xsl
    cocoon/branches/BRANCH_2_1_X/src/blocks/xsp/samples/samples.xml
    cocoon/branches/BRANCH_2_1_X/status.xml
    cocoon/branches/BRANCH_2_1_X/tools/src/blocks-build.xsl

Modified: cocoon/branches/BRANCH_2_1_X/src/blocks/xsp/java/org/apache/cocoon/components/language/markup/xsp/java/xsp.xsl
URL: http://svn.apache.org/viewcvs/cocoon/branches/BRANCH_2_1_X/src/blocks/xsp/java/org/apache/cocoon/components/language/markup/xsp/java/xsp.xsl?rev=234111&r1=234110&r2=234111&view=diff
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/src/blocks/xsp/java/org/apache/cocoon/components/language/markup/xsp/java/xsp.xsl
(original)
+++ cocoon/branches/BRANCH_2_1_X/src/blocks/xsp/java/org/apache/cocoon/components/language/markup/xsp/java/xsp.xsl
Sat Aug 20 12:06:19 2005
@@ -134,7 +134,7 @@
         public void generate() throws SAXException, IOException, ProcessingException {
             <!-- Do any user-defined necessary initializations -->
             <xsl:for-each select="xsp:init-page">
-              <xsl:copy-of select="."/>
+              <xsl:value-of select="XSLTExtension:escape($extension,.)"/>
             </xsl:for-each>
 
             this.contentHandler.startDocument();
@@ -152,7 +152,7 @@
 
             <!-- Do any user-defined necessary clean-ups -->
             <xsl:for-each select="xsp:exit-page">
-              <xsl:copy-of select="."/>
+              <xsl:value-of select="XSLTExtension:escape($extension,.)"/>
             </xsl:for-each>
         }
     }
@@ -357,9 +357,9 @@
         <xsl:if test="position() &gt; 1"> + </xsl:if>
         <xsl:choose>
           <xsl:when test="namespace-uri(.) = $xsp-uri and local-name(.) = 'expr'">
-            String.valueOf(<xsl:value-of select="."/>)
+            String.valueOf(<xsl:value-of select="XSLTExtension:escape($extension,.)"/>)
           </xsl:when>
-          <xsl:otherwise> "<xsl:value-of select="XSLTExtension:escape($extension,.)"/>"
</xsl:otherwise>
+          <xsl:otherwise> "<xsl:value-of select="XSLTExtension:escapeJava($extension,.)"/>"
</xsl:otherwise>
         </xsl:choose>
       </xsl:for-each>
       <xsl:if test="not(text()|xsp:expr|xsp:text)"> "" </xsl:if>
@@ -381,14 +381,14 @@
              Expression is nested inside another XSP tag:
              preserve its Java type
         -->
-        (<xsl:value-of select="."/>)
+        (<xsl:value-of select="XSLTExtension:escape($extension,.)"/>)
       </xsl:when>
       <xsl:when test="string-length(.) = 0">
         <!-- Do nothing -->
       </xsl:when>
       <xsl:otherwise>
         <!-- Output the value as elements or character data depending on its type -->
-        XSPObjectHelper.xspExpr(contentHandler, <xsl:value-of select="."/>);
+        XSPObjectHelper.xspExpr(contentHandler, <xsl:value-of select="XSLTExtension:escape($extension,.)"/>);
       </xsl:otherwise>
     </xsl:choose>
   </xsl:template>
@@ -490,7 +490,7 @@
       "<xsl:value-of select="local-name(.)"/>",
       "<xsl:value-of select="name(.)"/>",
       "CDATA",
-      "<xsl:value-of select="XSLTExtension:escape($extension,.)"/>"
+      "<xsl:value-of select="XSLTExtension:escapeJava($extension,.)"/>"
     );
     </xsl:if>
   </xsl:template>
@@ -510,12 +510,6 @@
         this.characters("<xsl:value-of select="XSLTExtension:escapeJava($extension, .)"/>");
       </xsl:otherwise>
     </xsl:choose>
-  </xsl:template>
-
-  <!-- FIXME: there seems to be no apply-templates with that mode,
-              i.e. can this template be removed? -->
-  <xsl:template match="text()" mode="value">
-    <xsl:value-of select="."/>
   </xsl:template>
 
   <xsl:template match="processing-instruction()">

Added: cocoon/branches/BRANCH_2_1_X/src/blocks/xsp/samples/java/escaping.xsp
URL: http://svn.apache.org/viewcvs/cocoon/branches/BRANCH_2_1_X/src/blocks/xsp/samples/java/escaping.xsp?rev=234111&view=auto
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/src/blocks/xsp/samples/java/escaping.xsp (added)
+++ cocoon/branches/BRANCH_2_1_X/src/blocks/xsp/samples/java/escaping.xsp Sat Aug 20 12:06:19
2005
@@ -0,0 +1,155 @@
+<?xml version="1.0" encoding="iso-8859-1"?>
+<!-- Important to be encoding="iso-8859-1" -->
+<!--
+  Copyright 2005 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.
+-->
+
+<!-- SVN $Id$ -->
+
+<xsp:page
+  language="java"
+  xmlns:xsp-interpolation="http://apache.org/xsp/interpolation/1.0"
+  xmlns:xsp="http://apache.org/xsp">
+
+  <!-- 
+       Check that LATIN1 characters are properly propagated
+       by applying XSLTExtension:escape in xsp.xsl.
+       The string constant contain also a quote (") in order to
+       verify that XSLTExtension:escapeJava is used where required.
+   -->
+
+  <xsp:logic>
+    String logicHeader = "Héllô \"wörld\"! 1";
+  </xsp:logic>
+
+  <xsp:init-page>
+    String initPage = "Héllô \"wörld\"! 2";
+  </xsp:init-page>
+
+  <xsp:init-page>
+    String exprInit = <xsp:expr>"Héllô \"wörld\"! 3"</xsp:expr>;
+  </xsp:init-page>
+
+  <xsp:logic>
+    // Use static to check exit-page logic the second time the page is called.
+    static String exitPage = "Reload page please";
+    static String exprExit = "Reload page please";
+  </xsp:logic>
+  <xsp:exit-page>
+    exitPage = "Héllô \"wörld\"! 4";
+    exprExit = <xsp:expr>"Héllô \"wörld\"! 5"</xsp:expr>;
+  </xsp:exit-page>
+
+  <xsp:logicsheet location="logicsheets/interpolation.xsl"/>
+
+  <page>
+    <title>Escaping of non-ASCII characters</title>
+    <content>
+      <xsp:logic>
+        String logicContent = "Héllô \"wörld\"! 6";
+      </xsp:logic>
+
+      <xsp:logic>
+        String exprLogic = <xsp:expr>"Héllô \"wörld\"! 7"</xsp:expr>;
+      </xsp:logic>
+
+      <p>
+        For the various Java compilers which have been interfaced to Cocoon
+        there is no unified method to tell the compiler the encoding of the
+        Java source.
+        Some compilers always assume UTF-8, others deduce it from the
+        systems locale settings.
+      </p>
+
+      <p>
+        If there is a mismatch in the encodings, umlauts, accents,
+        and other international characters will be mutilated in the output.
+        In order to avoid this problem, XSP preprocesses all Java code and
+        converts all non-ASCII characters to their \u1234 equivalent.
+        Thus the Java compiler sees only ASCII characters, and the encoding
+        becomes irrelevant (at least for character sets such as ISO-8859-1
+        which coincide which ASCII in the lower 128 characters).
+      </p>
+
+      <p>
+        Older Cocoon versions omitted to do the \u1234 conversion in some of
+        the XSP contexts where Java string constants could be used.
+      </p>
+
+      <p>
+        In Cocoon 2.1.8 this is now fixed, as this test is supposed to show:
+      </p>
+      <table border="1">
+        <tr>
+          <th>Context</th>
+          <th>Result</th>
+        </tr>
+        <tr>
+          <td>xsp:page/xsp:logic</td>
+          <td><xsp:expr>logicHeader</xsp:expr></td>
+        </tr>
+        <tr>
+          <td>xsp:page/xsp:init-page</td>
+          <td><xsp:expr>initPage</xsp:expr></td>
+        </tr>
+        <tr>
+          <td>xsp:init-page/xsp:expr</td>
+          <td><xsp:expr>exprInit</xsp:expr></td>
+        </tr>
+        <tr>
+          <td>xsp:page/xsp:exit-page</td>
+          <td><xsp:expr>exitPage</xsp:expr></td>
+        </tr>
+        <tr>
+          <td>xsp:exit-page/xsp:expr</td>
+          <td><xsp:expr>exprExit</xsp:expr></td>
+        </tr>
+        <tr>
+          <td>xsp:logic</td>
+          <td><xsp:expr>logicContent</xsp:expr></td>
+        </tr>
+        <tr>
+          <td>xsp:logic/xsp:expr</td>
+          <td><xsp:expr>exprLogic</xsp:expr></td>
+        </tr>
+        <tr>
+          <td>xsp:content/xsp:expr</td>
+          <td><xsp:content><xsp:expr>"Héllô \"wörld\"! 8"</xsp:expr></xsp:content></td>
+        </tr>
+        <tr>
+          <td>xsp:expr</td>
+          <td><xsp:expr>"Héllô \"wörld\"! 9"</xsp:expr></td>
+        </tr>
+        <tr>
+          <td>text()</td>
+          <td>Héllô "wörld"! 10</td>
+        </tr>
+        <tr>
+          <td>attribute</td>
+          <td><img src=".gif" alt='Héllô "wörld"! 11'/></td>
+        </tr>
+        <tr>
+          <td>xsp:attribute/text()</td>
+          <td><img src=".gif"><xsp:attribute name="alt">Héllô "wörld"!
12</xsp:attribute></img></td>
+        </tr>
+        <tr>
+          <td>xsp:attribute/xsp:expr</td>
+          <td><img src=".gif"><xsp:attribute name="alt"><xsp:expr>"Héllô
\"wörld\"! 13"</xsp:expr></xsp:attribute></img></td>
+        </tr>
+      </table>
+    </content>
+  </page>
+
+</xsp:page>

Propchange: cocoon/branches/BRANCH_2_1_X/src/blocks/xsp/samples/java/escaping.xsp
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cocoon/branches/BRANCH_2_1_X/src/blocks/xsp/samples/java/escaping.xsp
------------------------------------------------------------------------------
    svn:keywords = Id

Modified: cocoon/branches/BRANCH_2_1_X/src/blocks/xsp/samples/samples.xml
URL: http://svn.apache.org/viewcvs/cocoon/branches/BRANCH_2_1_X/src/blocks/xsp/samples/samples.xml?rev=234111&r1=234110&r2=234111&view=diff
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/src/blocks/xsp/samples/samples.xml (original)
+++ cocoon/branches/BRANCH_2_1_X/src/blocks/xsp/samples/samples.xml Sat Aug 20 12:06:19 2005
@@ -67,6 +67,9 @@
    <sample name="Util" href="java/resolver" xlink:role="dynamic">
     Util logicsheet tests.
    </sample>
+   <sample name="Escaping" href="java/escaping" xlink:role="dynamic">
+    Escaping of non-ASCII characters.
+   </sample>
   </group>
 
   <group name="eXtensible Server Pages in Javascript">

Modified: cocoon/branches/BRANCH_2_1_X/status.xml
URL: http://svn.apache.org/viewcvs/cocoon/branches/BRANCH_2_1_X/status.xml?rev=234111&r1=234110&r2=234111&view=diff
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/status.xml (original)
+++ cocoon/branches/BRANCH_2_1_X/status.xml Sat Aug 20 12:06:19 2005
@@ -196,6 +196,12 @@
 
   <changes>
   <release version="@version@" date="@date@">
+    <action dev="AN" type="fix">
+      XSP block: Add xsp:expr and various other contexts where text must be
+      passed through XSLTExtension:escape in order to preserve non-ASCII
+      characters in Java string constants independently of the XSP source file
+      and compiler expected encodings.
+    </action>
     <action dev="VG" type="update">
       Faces block: Updated MyFaces libraries to the SVN r233484, get rid of patched
       version.

Modified: cocoon/branches/BRANCH_2_1_X/tools/src/blocks-build.xsl
URL: http://svn.apache.org/viewcvs/cocoon/branches/BRANCH_2_1_X/tools/src/blocks-build.xsl?rev=234111&r1=234110&r2=234111&view=diff
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/tools/src/blocks-build.xsl (original)
+++ cocoon/branches/BRANCH_2_1_X/tools/src/blocks-build.xsl Sat Aug 20 12:06:19 2005
@@ -314,7 +314,18 @@
           <if>
             <available file="@{{dir}}/samples/sitemap.xmap"/>
             <then>
-              <copy filtering="on" todir="${{build.webapp}}/samples/blocks/@{{name}}">
+              <!-- Important to use here encoding="iso-8859-1" to avoid
+                   mutilating LATIN-1 characters in the copy operation.
+                   If these were read assuming UTF-8 encoding, umlauts
+                   are invalid byte sequences and get replaced by '?'.
+              
+                   On the other hand, reading UTF-8 files using LATIN-1
+                   encoding is not a problem in this context since every
+                   UTF-8 byte sequence maps to one or more LATIN-1 characters.
+                   We only need to assume that the tokens to be replaced
+                   by the filtering option are written in ASCII only.
+               -->
+              <copy filtering="on" todir="${{build.webapp}}/samples/blocks/@{{name}}"
encoding="iso-8859-1">
                 <fileset dir="@{{dir}}/samples">
                   <exclude name="**/*.gif"/>
                   <exclude name="**/*.jpg"/>



Mime
View raw message