*
* <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 {
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;
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) {
</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}"/>
<!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">
&linenumbering.width;
&tablecolumns.extension;
&textinsert.extension;
+&textdata.default.encoding;
&use.extensions;
</reference>
<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"/>
../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 \
</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}"/>
<!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">
&linenumbering.width;
&tablecolumns.extension;
&textinsert.extension;
+&textdata.default.encoding;
&graphicsize.extension;
&use.extensions;
</reference>
<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"/>
--- /dev/null
+<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>