535 |
/** get resource with the name "name" in the file url */ |
/** get resource with the name "name" in the file url */ |
536 |
Resource getResource(String name) |
Resource getResource(String name) |
537 |
{ |
{ |
538 |
File file = new File(dir, name); |
try |
539 |
if (file.exists() && !file.isDirectory()) |
{ |
540 |
return new FileResource(this, name, file); |
File file = new File(dir, name).getCanonicalFile(); |
541 |
|
if (file.exists() && !file.isDirectory()) |
542 |
|
return new FileResource(this, file.getPath(), file); |
543 |
|
} |
544 |
|
catch (IOException e) |
545 |
|
{ |
546 |
|
// Fall through... |
547 |
|
} |
548 |
return null; |
return null; |
549 |
} |
} |
550 |
} |
} |
708 |
|
|
709 |
private void addURLImpl(URL newUrl) |
private void addURLImpl(URL newUrl) |
710 |
{ |
{ |
711 |
synchronized (urlloaders) |
synchronized (this) |
712 |
{ |
{ |
713 |
if (newUrl == null) |
if (newUrl == null) |
714 |
return; // Silently ignore... |
return; // Silently ignore... |
765 |
} |
} |
766 |
|
|
767 |
/** |
/** |
768 |
|
* Look in both Attributes for a given value. The first Attributes |
769 |
|
* object, if not null, has precedence. |
770 |
|
*/ |
771 |
|
private String getAttributeValue(Attributes.Name name, Attributes first, |
772 |
|
Attributes second) |
773 |
|
{ |
774 |
|
String result = null; |
775 |
|
if (first != null) |
776 |
|
result = first.getValue(name); |
777 |
|
if (result == null) |
778 |
|
result = second.getValue(name); |
779 |
|
return result; |
780 |
|
} |
781 |
|
|
782 |
|
/** |
783 |
* Defines a Package based on the given name and the supplied manifest |
* Defines a Package based on the given name and the supplied manifest |
784 |
* information. The manifest indicates the tile, version and |
* information. The manifest indicates the title, version and |
785 |
* vendor information of the specification and implementation and wheter the |
* vendor information of the specification and implementation and whether the |
786 |
* package is sealed. If the Manifest indicates that the package is sealed |
* package is sealed. If the Manifest indicates that the package is sealed |
787 |
* then the Package will be sealed with respect to the supplied URL. |
* then the Package will be sealed with respect to the supplied URL. |
788 |
* |
* |
789 |
|
* @exception IllegalArgumentException If this package name already exists |
790 |
|
* in this class loader |
791 |
* @param name The name of the package |
* @param name The name of the package |
792 |
* @param manifest The manifest describing the specification, |
* @param manifest The manifest describing the specification, |
793 |
* implementation and sealing details of the package |
* implementation and sealing details of the package |
794 |
* @param url the code source url to seal the package |
* @param url the code source url to seal the package |
|
* @exception IllegalArgumentException If this package name already exists |
|
|
* in this class loader |
|
795 |
* @return the defined Package |
* @return the defined Package |
796 |
*/ |
*/ |
797 |
protected Package definePackage(String name, Manifest manifest, URL url) |
protected Package definePackage(String name, Manifest manifest, URL url) |
798 |
throws IllegalArgumentException |
throws IllegalArgumentException |
799 |
{ |
{ |
800 |
|
// Compute the name of the package as it may appear in the |
801 |
|
// Manifest. |
802 |
|
StringBuffer xform = new StringBuffer(name); |
803 |
|
for (int i = xform.length () - 1; i >= 0; --i) |
804 |
|
if (xform.charAt(i) == '.') |
805 |
|
xform.setCharAt(i, '/'); |
806 |
|
xform.append('/'); |
807 |
|
String xformName = xform.toString(); |
808 |
|
|
809 |
|
Attributes entryAttr = manifest.getAttributes(xformName); |
810 |
Attributes attr = manifest.getMainAttributes(); |
Attributes attr = manifest.getMainAttributes(); |
811 |
String specTitle = attr.getValue(Attributes.Name.SPECIFICATION_TITLE); |
|
812 |
String specVersion = attr.getValue(Attributes.Name.SPECIFICATION_VERSION); |
String specTitle |
813 |
String specVendor = attr.getValue(Attributes.Name.SPECIFICATION_VENDOR); |
= getAttributeValue(Attributes.Name.SPECIFICATION_TITLE, |
814 |
String implTitle = attr.getValue(Attributes.Name.IMPLEMENTATION_TITLE); |
entryAttr, attr); |
815 |
String implVersion = attr.getValue(Attributes.Name.IMPLEMENTATION_VERSION); |
String specVersion |
816 |
String implVendor = attr.getValue(Attributes.Name.IMPLEMENTATION_VENDOR); |
= getAttributeValue(Attributes.Name.SPECIFICATION_VERSION, |
817 |
|
entryAttr, attr); |
818 |
|
String specVendor |
819 |
|
= getAttributeValue(Attributes.Name.SPECIFICATION_VENDOR, |
820 |
|
entryAttr, attr); |
821 |
|
String implTitle |
822 |
|
= getAttributeValue(Attributes.Name.IMPLEMENTATION_TITLE, |
823 |
|
entryAttr, attr); |
824 |
|
String implVersion |
825 |
|
= getAttributeValue(Attributes.Name.IMPLEMENTATION_VERSION, |
826 |
|
entryAttr, attr); |
827 |
|
String implVendor |
828 |
|
= getAttributeValue(Attributes.Name.IMPLEMENTATION_VENDOR, |
829 |
|
entryAttr, attr); |
830 |
|
|
831 |
// Look if the Manifest indicates that this package is sealed |
// Look if the Manifest indicates that this package is sealed |
832 |
// XXX - most likely not completely correct! |
// XXX - most likely not completely correct! |
838 |
// make sure that the URL is null so the package is not sealed |
// make sure that the URL is null so the package is not sealed |
839 |
url = null; |
url = null; |
840 |
|
|
841 |
return definePackage(name, specTitle, specVersion, specVendor, implTitle, |
return definePackage(name, |
842 |
implVersion, implVendor, url); |
specTitle, specVendor, specVersion, |
843 |
|
implTitle, implVendor, implVersion, |
844 |
|
url); |
845 |
} |
} |
846 |
|
|
847 |
/** |
/** |
973 |
*/ |
*/ |
974 |
public String toString() |
public String toString() |
975 |
{ |
{ |
976 |
synchronized (urlloaders) |
synchronized (this) |
977 |
{ |
{ |
978 |
if (thisString == null) |
if (thisString == null) |
979 |
{ |
{ |