Author: sylvain Date: Thu Mar 24 10:13:22 2005 New Revision: 158930 URL: http://svn.apache.org/viewcvs?view=rev&rev=158930 Log: stronger checks that classpath is a directory
Modified: cocoon/trunk/src/java/org/apache/cocoon/components/classloader/DefaultClassLoaderFactory.java Modified: cocoon/trunk/src/java/org/apache/cocoon/components/classloader/DefaultClassLoaderFactory.java URL: http://svn.apache.org/viewcvs/cocoon/trunk/src/java/org/apache/cocoon/components/classloader/DefaultClassLoaderFactory.java?view=diff&r1=158929&r2=158930 ============================================================================== --- cocoon/trunk/src/java/org/apache/cocoon/components/classloader/DefaultClassLoaderFactory.java (original) +++ cocoon/trunk/src/java/org/apache/cocoon/components/classloader/DefaultClassLoaderFactory.java Thu Mar 24 10:13:22 2005 @@ -61,6 +61,14 @@ this.resolver = (SourceResolver)manager.lookup(SourceResolver.ROLE); } + private void ensureIsDirectory(Source src, String location) throws ConfigurationException { + if (!src.exists()) { + throw new ConfigurationException(src.getURI() + " doesn't exist, at " + location); + } else if (!(src instanceof TraversableSource) || !((TraversableSource)src).isCollection()) { + throw new ConfigurationException(src.getURI() + " is not a directory, at " + location); + } + } + private URL[] parseConfiguration(Configuration config) throws ConfigurationException { List urlList = new ArrayList(); Configuration[] children = config.getChildren(); @@ -72,22 +80,20 @@ src = resolver.resolveURI(child.getAttribute("src")); // A class dir: simply add its URL if ("class-dir".equals(name)) { + ensureIsDirectory(src, child.getLocation()); urlList.add(new URL(src.getURI())); // A lib dir: scan for all jar and zip it contains } else if ("lib-dir".equals(name)) { - if (src instanceof TraversableSource) { - Iterator iter = ((TraversableSource)src).getChildren().iterator(); - while (iter.hasNext()) { - Source childSrc = (Source)iter.next(); - String childURI = childSrc.getURI(); - resolver.release(childSrc); - if (childURI.endsWith(".jar") || childURI.endsWith(".zip")) { - urlList.add(new URL(childURI)); - } + ensureIsDirectory(src, child.getLocation()); + Iterator iter = ((TraversableSource)src).getChildren().iterator(); + while (iter.hasNext()) { + Source childSrc = (Source)iter.next(); + String childURI = childSrc.getURI(); + resolver.release(childSrc); + if (childURI.endsWith(".jar") || childURI.endsWith(".zip")) { + urlList.add(new URL(childURI)); } - } else { - throw new ConfigurationException(src.getURI() + " is not a directory, at " + child.getLocation()); } } else { throw new ConfigurationException("Unexpected element " + name + " at " + child.getLocation());