516 |
*/ |
*/ |
517 |
public URL getResource(String name) |
public URL getResource(String name) |
518 |
{ |
{ |
|
name = normalize(name); |
|
519 |
URL result; |
URL result; |
520 |
|
|
521 |
if (parent == null) |
if (parent == null) |
550 |
*/ |
*/ |
551 |
public final Enumeration getResources(String name) throws IOException |
public final Enumeration getResources(String name) throws IOException |
552 |
{ |
{ |
|
name = normalize(name); |
|
553 |
Enumeration parentResources; |
Enumeration parentResources; |
554 |
if (parent == null) |
if (parent == null) |
555 |
parentResources = VMClassLoader.getResources(name); |
parentResources = VMClassLoader.getResources(name); |
559 |
} |
} |
560 |
|
|
561 |
/** |
/** |
|
* Normalizes a resource path name. This removes all ./ from the start and |
|
|
* all further '//', "/../" and "/./" from the given name. |
|
|
*/ |
|
|
private static String normalize(String resource) |
|
|
{ |
|
|
while (resource.startsWith("./")) |
|
|
resource = resource.substring(2); |
|
|
|
|
|
int index = resource.indexOf("//"); |
|
|
while (index != -1) |
|
|
{ |
|
|
resource = resource.substring(0, index) + resource.substring(index+1); |
|
|
index = resource.indexOf("//"); |
|
|
} |
|
|
|
|
|
index = resource.indexOf("/../"); |
|
|
while (index != -1) |
|
|
{ |
|
|
int last = resource.lastIndexOf('/', index-1); |
|
|
if (last != -1) |
|
|
resource = resource.substring(0, last+1) |
|
|
+ resource.substring(index+4); |
|
|
else |
|
|
resource = resource.substring(index+4); |
|
|
index = resource.indexOf("/../"); |
|
|
} |
|
|
|
|
|
index = resource.indexOf("/./"); |
|
|
while (index != -1) |
|
|
{ |
|
|
resource = resource.substring(0, index) + resource.substring(index+2); |
|
|
index = resource.indexOf("/./"); |
|
|
} |
|
|
|
|
|
return resource; |
|
|
} |
|
|
|
|
|
/** |
|
562 |
* Called whenever all locations of a named resource are needed. |
* Called whenever all locations of a named resource are needed. |
563 |
* It is called by <code>getResources()</code> after it has called |
* It is called by <code>getResources()</code> after it has called |
564 |
* <code>parent.getResources()</code>. The results are combined by |
* <code>parent.getResources()</code>. The results are combined by |