Trying to use <util:get-file-contents> on Cocoon2.1-dev (cvs updated today),
I noticed three problems :
- You must specify the encoding attribute, or go to hell
- You must catch the java.io.IOException, or apply the patch I made for
util.xsl
- You must use absolute path for the name of the file

Since I'm a beginner with java and xsp, don't yell at me. If you find this
patch is crap, please tell me why and suggest some better solution. And by
the way, do you known why relative paths won't work ?

--- src/org/apache/cocoon/components/language/markup/xsp/java/util.xsl
2001/07/12 11:03:21     1.5
+++ src/org/apache/cocoon/components/language/markup/xsp/java/util.xsl
2001/07/18 15:08:59
@@ -240,14 +240,20 @@
       </xsl:choose>
     </xsl:variable>

-    <xsp:expr>
-      XSPUtil.getFileContents(
-    XSPUtil.relativeFilename(
-          String.valueOf(<xsl:copy-of select="$name"/>),
-      this.objectModel
-    ), "<xsl:value-of select="@encoding"/>"
-      )
-    </xsp:expr>
+    <xsp:logic>
+      String result = "";
+      try {
+        result = XSPUtil.getFileContents(
+      XSPUtil.relativeFilename(
+            String.valueOf(<xsl:copy-of select="$name"/>),
+        this.objectModel
+      ), "<xsl:value-of select="@encoding"/>"
+        );
+      } catch (Exception e) {
+        getLogger().error("Could not include page", e);
+      }
+    </xsp:logic>
+    <xsp:expr>result</xsp:expr>
   </xsl:template>


Here is my XSP page (it works for me) :
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsp:page
          language="java"
          xmlns:xsp="http://apache.org/xsp";
          xmlns:util="http://apache.org/xsp/util/2.0";
>
 <page>
  <util:get-file-contents name="/tmp/data.txt" encoding="iso-8859-1"/>
 </page>
</xsp:page>

-- 
Arnaud Bienvenu
http://www.generasound.com/

---------------------------------------------------------------------
Please check that your question has not already been answered in the
FAQ before posting. <http://xml.apache.org/cocoon/faqs.html>

To unsubscribe, e-mail: <[EMAIL PROTECTED]>
For additional commands, e-mail: <[EMAIL PROTECTED]>

Reply via email to