536 |
Resource getResource(String name) |
Resource getResource(String name) |
537 |
{ |
{ |
538 |
File file = new File(dir, name); |
File file = new File(dir, name); |
539 |
if (file.exists() && ! file.isDirectory()) |
if (file.exists()) |
540 |
return new FileResource(this, name, file); |
return new FileResource(this, name, file); |
541 |
return null; |
return null; |
542 |
} |
} |
554 |
|
|
555 |
InputStream getInputStream() throws IOException |
InputStream getInputStream() throws IOException |
556 |
{ |
{ |
557 |
|
// Delegate to the URL content handler mechanism to retrieve an |
558 |
|
// HTML representation of the directory listing if a directory |
559 |
|
if (file.isDirectory()) |
560 |
|
{ |
561 |
|
URL url = getURL(); |
562 |
|
return url.openStream(); |
563 |
|
} |
564 |
|
// Otherwise simply return a FileInputStream |
565 |
return new FileInputStream(file); |
return new FileInputStream(file); |
566 |
} |
} |
567 |
|
|
568 |
public int getLength() |
public int getLength() |
569 |
{ |
{ |
570 |
|
// Delegate to the URL content handler mechanism to retrieve the |
571 |
|
// length of the HTML representation of the directory listing if |
572 |
|
// a directory, or -1 if an exception occurs opening the directory. |
573 |
|
if (file.isDirectory()) |
574 |
|
{ |
575 |
|
URL url = getURL(); |
576 |
|
try |
577 |
|
{ |
578 |
|
URLConnection connection = url.openConnection(); |
579 |
|
return connection.getContentLength(); |
580 |
|
} |
581 |
|
catch (IOException e) |
582 |
|
{ |
583 |
|
return -1; |
584 |
|
} |
585 |
|
} |
586 |
|
// Otherwise simply return the file length |
587 |
return (int) file.length(); |
return (int) file.length(); |
588 |
} |
} |
589 |
|
|
731 |
if (newUrl == null) |
if (newUrl == null) |
732 |
return; // Silently ignore... |
return; // Silently ignore... |
733 |
|
|
734 |
|
// Reset the toString() value. |
735 |
|
thisString = null; |
736 |
|
|
737 |
// Check global cache to see if there're already url loader |
// Check global cache to see if there're already url loader |
738 |
// for this url. |
// for this url. |
739 |
URLLoader loader = (URLLoader) urlloaders.get(newUrl); |
URLLoader loader = (URLLoader) urlloaders.get(newUrl); |
947 |
*/ |
*/ |
948 |
public String toString() |
public String toString() |
949 |
{ |
{ |
950 |
if (thisString == null) |
synchronized (urlloaders) |
951 |
{ |
{ |
952 |
StringBuffer sb = new StringBuffer(); |
if (thisString == null) |
|
sb.append(this.getClass().getName()); |
|
|
sb.append("{urls=[" ); |
|
|
URL[] thisURLs = getURLs(); |
|
|
for (int i = 0; i < thisURLs.length; i++) |
|
953 |
{ |
{ |
954 |
sb.append(thisURLs[i]); |
StringBuffer sb = new StringBuffer(); |
955 |
if (i < thisURLs.length - 1) |
sb.append(this.getClass().getName()); |
956 |
sb.append(','); |
sb.append("{urls=[" ); |
957 |
|
URL[] thisURLs = getURLs(); |
958 |
|
for (int i = 0; i < thisURLs.length; i++) |
959 |
|
{ |
960 |
|
sb.append(thisURLs[i]); |
961 |
|
if (i < thisURLs.length - 1) |
962 |
|
sb.append(','); |
963 |
|
} |
964 |
|
sb.append(']'); |
965 |
|
sb.append(", parent="); |
966 |
|
sb.append(getParent()); |
967 |
|
sb.append('}'); |
968 |
|
thisString = sb.toString(); |
969 |
} |
} |
970 |
sb.append(']'); |
return thisString; |
|
sb.append(", parent="); |
|
|
sb.append(getParent()); |
|
|
sb.append('}'); |
|
|
thisString = sb.toString(); |
|
971 |
} |
} |
|
return thisString; |
|
972 |
} |
} |
973 |
|
|
974 |
/** |
/** |