I do not see a need to support this. A simple test shows that a URLClassLoader loading jar files does not support this, although it seems to work for URLs to a directory. The javadoc for ClassLoader.getResource also makes no mention that the resource name can have relative resource path segments (e.g. '.' or '..') and that the classloader must normalize the resource path when searching. The Bundle.getResource is pretty much an equivalent to ClassLoader.getResource() method.
If you want to get a resource from a bundle which is relative to another resource then you could use an initial URL as a context for a relative URL like this: URL initialResource = bundle.getResource("test/dir1/resource1.txt"); URL relativeResource = new URL(initialResource, "../dir2/resource2.txt"); FWIW the equinox framwork does not support '.' or '..' segments in resource names for Bundle.getResource either. Tom "Karl Pauls" <[EMAIL PROTECTED] com> To dev@felix.apache.org 09/17/2007 03:46 cc PM Subject Re: A bug in Please respond to Bundle.getResource(String)? [EMAIL PROTECTED] org Hi Stefano, please create a JIRA issue and attach your patch there. I'm currently busy preparing the 1.0.1 release and this will have to wait until we have it out of the door. regards, Karl > Hi All, > > I've found a odd behavior in the method Bundle.getResource(String), the > method is not able to resolve the resource if the reource path contains: > '.' or '..' directory. > > I have already patched the: > org.apache.felix.framework.searchpolicy.ContentLoaderImpl.getResource(String) > in order to accept the '..' and '.' path (see attchment). > > Can I commit the patch? > > > Ciao, > Stefano "Kismet" Lenzi > > P.S.: As you can see from my patch I do not consider the case when the > URL is encoded. > > P.P.S.: Should I report a issue on JIRA? > > > > Index: src/main/java/org/apache/felix/framework/searchpolicy/ContentLoaderImpl.java > =================================================================== > --- src/main/java/org/apache/felix/framework/searchpolicy/ContentLoaderImpl.java (revision 576472) > +++ src/main/java/org/apache/felix/framework/searchpolicy/ContentLoaderImpl.java (working copy) > @@ -22,12 +22,18 @@ > import java.io.InputStream; > import java.net.URL; > import java.security.ProtectionDomain; > +import java.util.ArrayList; > import java.util.Enumeration; > +import java.util.Iterator; > +import java.util.StringTokenizer; > import java.util.Vector; > > import org.apache.felix.framework.Logger; > import org.apache.felix.framework.util.SecureAction; > -import org.apache.felix.moduleloader.*; > +import org.apache.felix.moduleloader.IContent; > +import org.apache.felix.moduleloader.IContentLoader; > +import org.apache.felix.moduleloader.ISearchPolicy; > +import org.apache.felix.moduleloader.IURLPolicy; > > public class ContentLoaderImpl implements IContentLoader > { > @@ -129,13 +135,49 @@ > public URL getResource(String name) > { > URL url = null; > - > + > + //TODO Handling encoded URL > + > // Remove leading slash, if present. > if (name.startsWith("/")) > { > name = name.substring(1); > - } > - > + } > + > + /* > + * NORMALIZING PATH: > + * 1 - Removing /./ path > + * 2 - Resolving /../ path > + */ > + StringTokenizer tokenizer = new StringTokenizer(name,"/"); > + ArrayList parts = new ArrayList(); > + while(tokenizer.hasMoreTokens()) > + { > + String namePart = tokenizer.nextToken(); > + if(namePart.equals(".")) > + { > + continue; > + } > + else if(namePart.equals("..") && parts.size()>=1) > + { > + //XXX Should we launch an exception if there are too many parent directory?!?!? > + parts.remove(parts.size()-1); > + } > + else > + { > + parts.add(namePart); > + } > + } > + > + //Rebuilding the path from parts > + name = ""; > + for (Iterator i = parts.iterator(); i.hasNext();) > + { > + String p = (String) i.next(); > + name += "/" + p; > + } > + name = name.substring(1); > + > // Check the module class path. > for (int i = 0; > (url == null) && > > -- Karl Pauls [EMAIL PROTECTED]