commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Poppe, Troy" <Troy.Po...@eia.doe.gov>
Subject [io/configuration] file:// URL problem
Date Thu, 09 Jun 2005 19:46:00 GMT

I'm running on a 1.4.2 JVM, commons-io 1.0, commons-configuration 1.1.

I've got a set of FileObjects, and on each I call getURL(), they return URLs that
point to valid files and look like the following:

file://c:/projects/IPDB/conf/input/oecdde.xml

Now, if I try to open these with Windows directly, this works fine.  However, if
I try to pass each of these URLs to the XMLConfiguration constructor, an
exception like the following is thrown:

org.apache.commons.configuration.ConfigurationException: Cannot locate
configuration source oecdde.xml
	at
org.apache.commons.configuration.AbstractFileConfiguration.load(AbstractFileConfi
guration.java:183)
	at
org.apache.commons.configuration.AbstractFileConfiguration.load(AbstractFileConfi
guration.java:166)
	at
org.apache.commons.configuration.XMLConfiguration.load(XMLConfiguration.java:348)
	at
org.apache.commons.configuration.XMLConfiguration.<init>(XMLConfiguration.java:13
4)
	at URLBuster.main(URLBuster.java:56)
Exception in thread "main" 

It appears that the problem originates from AbstractFileConfiguration.java:180:
            URL url = ConfigurationUtils.locate(basePath, fileName);


In locate(String base, String name), it attempts to construct a URL to the file
by constructing a baseURL, and then using this as a 'context' onto which the
fileName is to be added.  The problem crops up here:

                URL baseURL = new URL(base);
                url = new URL(baseURL, name);

Prior to this point, the URLs that had been used did not refer to a 'host', and
were local to the JVM's execution.  At this point, baseURL refers to a host named
'c'!

Any fixes for this?


Troy


Here's the sample code:

import java.io.File;

import org.apache.commons.configuration.Configuration;
import org.apache.commons.configuration.XMLConfiguration;
import org.apache.commons.vfs.FileFilter;
import org.apache.commons.vfs.FileFilterSelector;
import org.apache.commons.vfs.FileObject;
import org.apache.commons.vfs.FileSelectInfo;
import org.apache.commons.vfs.FileSystemManager;
import org.apache.commons.vfs.VFS;

public class URLBuster
{

    public static void main(String[] args)
    	throws Exception
    {
        
        FileSystemManager fsManager = VFS.getManager();
        FileObject inputDir = fsManager.resolveFile( new File("."),
"conf/input/" );
        
        FileFilterSelector ffs = new FileFilterSelector(new FileFilter()
        {
            public boolean accept(FileSelectInfo fsi)
            {
                if ( "xml".equals(fsi.getFile().getName().getExtension()) )
                {
                    return true;
                }
                else
                {
                    return false;
                }
            }
        });
        
        FileObject[] children = inputDir.findFiles(ffs);

        for ( int i = 0 ; i < children.length ; ++i )
        {
            FileObject fo = children[i];
            System.out.println(fo);
            Configuration config = config = new XMLConfiguration(fo.getURL());
        }

    }
}


---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org


Mime
View raw message