]> granicus.if.org Git - docbook-dsssl/commitdiff
Added Saxon support for encoding attribute on textdata. Added new parameter textdata...
authorJirka Kosek <jirka@kosek.cz>
Wed, 24 Mar 2004 09:10:17 +0000 (09:10 +0000)
committerJirka Kosek <jirka@kosek.cz>
Wed, 24 Mar 2004 09:10:17 +0000 (09:10 +0000)
xsl/extensions/saxon643/com/nwalsh/saxon/Text.java
xsl/fo/graphics.xsl
xsl/fo/param.ent
xsl/fo/param.xweb
xsl/html/Makefile.param
xsl/html/graphics.xsl
xsl/html/param.ent
xsl/html/param.xweb
xsl/params/textdata.default.encoding.xml [new file with mode: 0755]

index 1b76fff9a3a8b33104bac292f52a737ed7e805f3..b6d3fe1c911aa430d4182d1b8c4a302c6ab0c0ae 100644 (file)
@@ -94,6 +94,9 @@ public class Text extends StyleElement {
    *
    * <p>Processing this element inserts the contents of the URL named
    * by the href attribute into the result tree as plain text.</p>
+   * 
+   * <p>Optional encoding attribute can specify encoding of resource.
+   * If not specified default system encoding is used.</p>
    *
    */
   public void process( Context context ) throws TransformerException {
@@ -102,21 +105,31 @@ public class Text extends StyleElement {
     String hrefAtt = getAttribute("href");
     Expression hrefExpr = makeAttributeValueTemplate(hrefAtt);
     String href = hrefExpr.evaluateAsString(context);
+    
+    String encodingAtt = getAttribute("encoding");
+    Expression encodingExpr = makeAttributeValueTemplate(encodingAtt);
+    String encoding = encodingExpr.evaluateAsString(context);
+    
     URL fileURL = null;
 
     try {
       try {
-       fileURL = new URL(href);
+        fileURL = new URL(href);
       } catch (MalformedURLException e1) {
-       try {
-         fileURL = new URL("file:" + href);
-       } catch (MalformedURLException e2) {
-         System.out.println("Cannot open " + href);
-         return;
-       }
+        try {
+          fileURL = new URL("file:" + href);
+        } catch (MalformedURLException e2) {
+          System.out.println("Cannot open " + href);
+          return;
+        }
       }
 
-      InputStreamReader isr = new InputStreamReader(fileURL.openStream());
+      InputStreamReader isr = null;
+      if (encoding.equals("") == true)
+        isr = new InputStreamReader(fileURL.openStream());
+      else
+        isr = new InputStreamReader(fileURL.openStream(), encoding);
+                  
       BufferedReader is = new BufferedReader(isr);
 
       final int BUFFER_SIZE = 4096;
@@ -128,42 +141,42 @@ public class Text extends StyleElement {
 
       while ((len = is.read(chars)) > 0) 
       {
-       // various new lines are normalized to LF to prevent blank lines between lines
-       int nlen = 0;
-       for (i=0; i<len; i++)
-       {
-         // is current char CR?
-         if (chars[i] == '\r')
-         {
-           if (i < (len - 1))
-           {
-                     // skip it if next char is LF
-             if (chars[i+1] == '\n') continue;
+        // various new lines are normalized to LF to prevent blank lines between lines
+        int nlen = 0;
+        for (i=0; i<len; i++)
+        {
+          // is current char CR?
+          if (chars[i] == '\r')
+          {
+            if (i < (len - 1))
+            {
+              // skip it if next char is LF
+              if (chars[i+1] == '\n') continue;
               // single CR -> LF to normalize MAC line endings
               nchars[nlen] = '\n';
-             nlen++;
+              nlen++;
               continue;
-           }
-           else
-           {
-             // if CR is last char of buffer we must look ahead
-             carry = is.read();
+            }
+            else
+            {
+              // if CR is last char of buffer we must look ahead
+              carry = is.read();
               nchars[nlen] = '\n';
               nlen++;
-             if (carry == '\n')
-             {
+              if (carry == '\n')
+              {
                 carry = -1;
               }
               break;
-           }
-         }
-         nchars[nlen] = chars[i];
-         nlen++;
-       }
-       out.writeContent(nchars, 0, nlen);
+            }
+          }
+          nchars[nlen] = chars[i];
+          nlen++;
+        }
+        out.writeContent(nchars, 0, nlen);
         // handle look aheaded character
-       if (carry != -1) out.writeContent(String.valueOf((char)carry));
-       carry = -1;
+        if (carry != -1) out.writeContent(String.valueOf((char)carry));
+        carry = -1;
       }
       is.close();
     } catch (Exception e) {
index 74d71b671066b3aec1e14dbffce4ece899cd2de4..dc193db2791b55634c9b88d46a3e5757d90a14df 100644 (file)
     </xsl:choose>
   </xsl:variable>
 
+  <xsl:variable name="encoding">
+    <xsl:choose>
+      <xsl:when test="@encoding">
+        <xsl:value-of select="@encoding"/>
+      </xsl:when>
+      <xsl:otherwise>
+        <xsl:value-of select="$textdata.default.encoding"/>
+      </xsl:otherwise>
+    </xsl:choose>
+  </xsl:variable>
+
   <xsl:choose>
     <xsl:when test="$use.extensions != '0'
                     and $textinsert.extension != '0'">
       <xsl:choose>
         <xsl:when test="element-available('stext:insertfile')">
-          <stext:insertfile href="{$filename}"/>
+          <stext:insertfile href="{$filename}" encoding="{$encoding}"/>
         </xsl:when>
         <xsl:when test="element-available('xtext:insertfile')">
           <xtext:insertfile href="{$filename}"/>
index 92a192ed4dbd307050234957c6c31232b65700a8..b104bd519097992aa74b6595e98f7db083b25131 100644 (file)
 <!ENTITY table.frame.border.color SYSTEM "../params/table.frame.border.color.xml">
 <!ENTITY table.frame.border.style SYSTEM "../params/table.frame.border.style.xml">
 <!ENTITY table.frame.border.thickness SYSTEM "../params/table.frame.border.thickness.xml">
+<!ENTITY textdata.default.encoding SYSTEM "../params/textdata.default.encoding.xml">
 <!ENTITY header.content.properties SYSTEM "../params/header.content.properties.xml">
 <!ENTITY footer.content.properties SYSTEM "../params/footer.content.properties.xml">
 <!ENTITY ignore.image.scaling SYSTEM "../params/ignore.image.scaling.xml">
index be5ac4b5246e14a8ed2fc96b0d952788d1ea5c51..22acc016dc6f8ae533f97629edd9d1a692d24452 100644 (file)
@@ -123,6 +123,7 @@ generate.section.toc.level;
 &linenumbering.width;
 &tablecolumns.extension;
 &textinsert.extension;
+&textdata.default.encoding;
 &use.extensions;
 </reference>
 
@@ -691,6 +692,7 @@ around all these parameters.</para>
 <src:fragref linkend="tablecolumns.extension.frag"/>
 <src:fragref linkend="table.table.properties.frag"/>
 <src:fragref linkend="target.database.document.frag"/>
+<src:fragref linkend="textdata.default.encoding.frag"/>
 <src:fragref linkend="tex.math.delims.frag"/>
 <src:fragref linkend="tex.math.in.alt.frag"/>
 <src:fragref linkend="textinsert.extension.frag"/>
index f29a1331de62d91e3d5a5fa0d861205478bb0b7f..12b0952b9fb2e4d8325976a44ccb801c7e62e4b5 100644 (file)
@@ -234,6 +234,7 @@ PARAMS=../params/admon.graphics.xml \
        ../params/table.frame.border.color.xml \
        ../params/table.frame.border.style.xml \
        ../params/table.frame.border.thickness.xml \
+       ../params/textdata.default.encoding.xml \
        ../params/ignore.image.scaling.xml \
        ../params/footnote.number.format.xml \
        ../params/table.footnote.number.format.xml \
index 276bc1e799156bc03a0154f2b4ea6667a677e0a6..2b53f90b4bfb794733bd17e95846dd8ea8c36d79 100644 (file)
@@ -1101,12 +1101,23 @@ valign: <xsl:value-of select="@valign"/></xsl:message>
     </xsl:choose>
   </xsl:variable>
 
+  <xsl:variable name="encoding">
+    <xsl:choose>
+      <xsl:when test="@encoding">
+        <xsl:value-of select="@encoding"/>
+      </xsl:when>
+      <xsl:otherwise>
+        <xsl:value-of select="$textdata.default.encoding"/>
+      </xsl:otherwise>
+    </xsl:choose>
+  </xsl:variable>
+
   <xsl:choose>
     <xsl:when test="$use.extensions != '0'
                     and $textinsert.extension != '0'">
       <xsl:choose>
         <xsl:when test="element-available('stext:insertfile')">
-          <stext:insertfile href="{$filename}"/>
+          <stext:insertfile href="{$filename}" encoding="{$encoding}"/>
         </xsl:when>
         <xsl:when test="element-available('xtext:insertfile')">
           <xtext:insertfile href="{$filename}"/>
index 282451f57bd91b16882fb05e2e58026058bc4453..df60c891d4f62106c007379739dd0b55ff52d823 100644 (file)
 <!ENTITY table.frame.border.color SYSTEM "../params/table.frame.border.color.xml">
 <!ENTITY table.frame.border.style SYSTEM "../params/table.frame.border.style.xml">
 <!ENTITY table.frame.border.thickness SYSTEM "../params/table.frame.border.thickness.xml">
+<!ENTITY textdata.default.encoding SYSTEM "../params/textdata.default.encoding.xml">
 <!ENTITY ignore.image.scaling SYSTEM "../params/ignore.image.scaling.xml">
 <!ENTITY footnote.number.format SYSTEM "../params/footnote.number.format.xml">
 <!ENTITY table.footnote.number.format SYSTEM "../params/table.footnote.number.format.xml">
index a66fe5732faf070ff82b72f4ea65da6eda504d78..21b49bc6ac75cb486c3130e93228a038e82477e6 100644 (file)
@@ -110,6 +110,7 @@ to be incomplete. Don't forget to read the source, too :-)</para>
 &linenumbering.width;
 &tablecolumns.extension;
 &textinsert.extension;
+&textdata.default.encoding;
 &graphicsize.extension;
 &use.extensions;
 </reference>
@@ -637,6 +638,7 @@ around all these parameters.</para>
 <src:fragref linkend="tablecolumns.extension.frag"/>
 <src:fragref linkend="target.database.document.frag"/>
 <src:fragref linkend="targets.filename.frag"/>
+<src:fragref linkend="textdata.default.encoding.frag"/>
 <src:fragref linkend="tex.math.delims.frag"/>
 <src:fragref linkend="tex.math.file.frag"/>
 <src:fragref linkend="tex.math.in.alt.frag"/>
diff --git a/xsl/params/textdata.default.encoding.xml b/xsl/params/textdata.default.encoding.xml
new file mode 100755 (executable)
index 0000000..5e124e7
--- /dev/null
@@ -0,0 +1,27 @@
+<refentry id="textdata.default.encoding">
+<refmeta>
+<refentrytitle>textdata.default.encoding</refentrytitle>
+<refmiscinfo role="type">string</refmiscinfo>
+</refmeta>
+<refnamediv>
+<refname>textdata.default.encoding</refname>
+<refpurpose>Default encoding of external text files which are included
+using textdata element</refpurpose>
+</refnamediv>
+
+<refsynopsisdiv>
+<src:fragment id='textdata.default.encoding.frag'>
+<xsl:param name="textdata.default.encoding" select="''"/>
+</src:fragment>
+</refsynopsisdiv>
+
+<refsect1><title>Description</title>
+
+<para>Default encoding of external text files which are included using
+textdata element. This value is used only when you do not specify
+encoding by appropriate attribute directly on textdata. Default
+encoding (empty string) is interpreted as system default
+encoding.</para>
+
+</refsect1>
+</refentry>