515 |
*/ |
*/ |
516 |
public URL getResource(String name) |
public URL getResource(String name) |
517 |
{ |
{ |
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 |
{ |
{ |
553 |
|
name = normalize(name); |
554 |
Enumeration parentResources; |
Enumeration parentResources; |
555 |
if (parent == null) |
if (parent == null) |
556 |
parentResources = VMClassLoader.getResources(name); |
parentResources = VMClassLoader.getResources(name); |
560 |
} |
} |
561 |
|
|
562 |
/** |
/** |
563 |
|
* Normalizes a resource path name. This removes all ./ from the start and |
564 |
|
* all further '//', "/../" and "/./" from the given name. |
565 |
|
*/ |
566 |
|
private static String normalize(String resource) |
567 |
|
{ |
568 |
|
while (resource.startsWith("./")) |
569 |
|
resource = resource.substring(2); |
570 |
|
|
571 |
|
int index = resource.indexOf("//"); |
572 |
|
while (index != -1) |
573 |
|
{ |
574 |
|
resource = resource.substring(0, index) + resource.substring(index+1); |
575 |
|
index = resource.indexOf("//"); |
576 |
|
} |
577 |
|
|
578 |
|
index = resource.indexOf("/../"); |
579 |
|
while (index != -1) |
580 |
|
{ |
581 |
|
int last = resource.lastIndexOf('/', index-1); |
582 |
|
if (last != -1) |
583 |
|
resource = resource.substring(0, last+1) |
584 |
|
+ resource.substring(index+4); |
585 |
|
else |
586 |
|
resource = resource.substring(index+4); |
587 |
|
index = resource.indexOf("/../"); |
588 |
|
} |
589 |
|
|
590 |
|
index = resource.indexOf("/./"); |
591 |
|
while (index != -1) |
592 |
|
{ |
593 |
|
resource = resource.substring(0, index) + resource.substring(index+2); |
594 |
|
index = resource.indexOf("/./"); |
595 |
|
} |
596 |
|
|
597 |
|
return resource; |
598 |
|
} |
599 |
|
|
600 |
|
/** |
601 |
* Called whenever all locations of a named resource are needed. |
* Called whenever all locations of a named resource are needed. |
602 |
* It is called by <code>getResources()</code> after it has called |
* It is called by <code>getResources()</code> after it has called |
603 |
* <code>parent.getResources()</code>. The results are combined by |
* <code>parent.getResources()</code>. The results are combined by |