Hi,
I've slightly modified org.apache.fop.app.InputHandler.fileInputSource 
so that it works with UNC names under Windows, such 
as "//host/resource/file".
The problem is caused by the use of java.net.URL.
Consider this example:
   new java.net.URL("file", null, "//host/resource/file").toString()
that returns the string "file://host/resource/file" instead of
the right one: "file:////host/resource/file".

I've attached the patched InputHandler.java, from FOP 0.20.3.

Regards,
   Alberto.


/*
 * $Id: InputHandler.java,v 1.5 2001/08/14 08:50:47 keiron Exp $
 * Copyright (C) 2001 The Apache Software Foundation. All rights reserved.
 * For details on use and redistribution please refer to the
 * LICENSE file included with these sources.
 */

package org.apache.fop.apps;

// SAX
import org.xml.sax.InputSource;
import org.xml.sax.XMLReader;

// Java
import java.net.URL;
import java.io.File;

// FOP
import org.apache.fop.messaging.MessageHandler;
import org.apache.fop.configuration.Configuration;


abstract public class InputHandler {


    abstract public InputSource getInputSource();
    abstract public XMLReader getParser() throws FOPException;


    static public InputSource urlInputSource(URL url) {
        return new InputSource(url.toString());
    }

    /**
     * create an InputSource from a File
     *
     * @param file the File
     * @return the InputSource created
     */
    static public InputSource fileInputSource(File file) {
        /* this code adapted from James Clark's in XT */
        boolean isUNC = false;
        String path = file.getAbsolutePath();
        String fSep = System.getProperty("file.separator");
        
        if (fSep != null && fSep.length() == 1) {
            path = path.replace(fSep.charAt(0), '/');
            isUNC = path.startsWith("//");
        }
        if (path.length() > 0 && path.charAt(0) != '/')
            path = '/' + path;
        try {
                   path = new URL("file", null, path).toString();
        } catch (java.net.MalformedURLException e) {
            throw new Error("unexpected MalformedURLException");
        }

        if (isUNC)
            path = "file://" + path.substring(5, path.length());

        return new InputSource(path);
    }

    /**
     * creates a SAX parser, using the value of org.xml.sax.parser
     * defaulting to org.apache.xerces.parsers.SAXParser
     *
     * @return the created SAX parser
     */
    protected static XMLReader createParser() throws FOPException {
        String parserClassName = Driver.getParserClassName();
        MessageHandler.logln("using SAX parser " + parserClassName);

        try {
            return (XMLReader)Class.forName(parserClassName).newInstance();
        } catch (ClassNotFoundException e) {
            throw new FOPException(e);
        } catch (InstantiationException e) {
            throw new FOPException("Could not instantiate "
                                   + parserClassName, e);
        } catch (IllegalAccessException e) {
            throw new FOPException("Could not access " + parserClassName, e);
        } catch (ClassCastException e) {
            throw new FOPException(parserClassName + " is not a SAX driver",
                                   e);
        }
    }

}

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

Reply via email to