You are viewing a plain text version of this content. The canonical link for it is here.
Posted to j-users@xalan.apache.org by Bennett <be...@glengroup.com> on 2003/10/03 23:14:34 UTC

check for file existence

Hi All,

	Does anyone have any examples of the best approach to checking for the 
existence of a local and remote file (like images for example) from 
within  a stylesheet?

  I'd like to be able to make a decision in the stylesheet that is 
dependent upon whether a file exists or not.
I've tried a number of different ways.

The closest I've come, so far, is by creating an extension using rhino 
1.5R4_1 (js.jar), and doing an importClass(java.io.File).

The problem with this is that I want to be able to check remote files 
via HTTP, too. When I try to importClass(java.net.URL) using rhino 1.5, 
I get:

XSLT Error (javax.xml.transform.TransformerException): Could not create 
extension: fileExists because of: 
java.lang.reflect.InvocationTargetException


I've also tried to write an extension in Java and use it within the 
stylesheet but, when I tried calling the class (trying to follow the 
idea behind the example "Formatting a Date" on  
http://xml.apache.org/xalan-j/extensions.html ), the error I got was:

java.lang.NoSuchMethodException: For extension function, could not find 
method java.lang.String.URLExists([ExpressionContext,] ).

(it really weird to me that something would be trying to tie the custom 
class URLExists as an extension of java.lang.String)

Please let me know if you would like me post code.

If you have any suggested resources or code samples, too that would be 
great.

TIA,
Bennett


Re: check for file existence

Posted by Santiago Pericas-Geertsen <Sa...@sun.com>.
On Fri, 2003-10-03 at 17:14, Bennett wrote:
> 
> I've also tried to write an extension in Java and use it within the 
> stylesheet 
>

 It should be easy to do this way. Can you post 1. declaration of Java
extension URL, 2. definition of Java function (is it static?) and 3.
method invocation.

-- Santiago