* If the file is not already in URL format, tries to locate it by resolving
* as a URL.
*
- * @param file
+ * @param f
* @return
*/
- String addProtocol(final String file)
+ String addProtocol(final String f)
{
- if (file.indexOf("://") == -1)
+ if (f.indexOf("://") != -1)
{
- /*
- * Try relative to document base
- */
- String url = applet.resolveUrlForLocalOrAbsolute(file,
- getDocumentBase());
- if (urlExists(url))
- {
- if (debug)
- {
- System.err.println("Prepended document base for resource: '"
- + file + "'");
- }
- return url;
- }
+ // already has URL format
+ return f;
+ }
- /*
- * Try relative to codebase
- */
- url = applet.resolveUrlForLocalOrAbsolute(file, getCodeBase());
- if (urlExists(url))
+ /*
+ * Try relative to document base
+ */
+ URL documentBase = getDocumentBase();
+ String url = applet.resolveUrlForLocalOrAbsolute(f, documentBase);
+ if (urlExists(url))
+ {
+ if (debug)
{
- if (debug)
- {
- System.err.println("Prepended codebase for resource: '" + file
- + "'");
- }
- return url;
+ System.err.println("Prepended document base '" + documentBase
+ + "' to make: '" + url
+ + "'");
}
+ return url;
}
/*
- * Not resolved, leave unchanged
+ * Try relative to codebase
*/
- return file;
+ URL codeBase = getCodeBase();
+ url = applet.resolveUrlForLocalOrAbsolute(f, codeBase);
+ if (urlExists(url))
+ {
+ if (debug)
+ {
+ System.err.println("Prepended codebase '" + codeBase
+ + "' to make: '" + url + "'");
+ }
+ return url;
+ }
+
+ return f;
}
/**
*/
public String[] separatorListToArray(String list, String separator)
{
- // note separator local variable intentionally masks object field
int seplen = separator.length();
if (list == null || list.equals("") || list.equals(separator))
{
String codebase = localref.toString();
if (url.indexOf("/") == 0)
{
+ String localfile = localref.getFile();
url = codebase.substring(0, codebase.length()
- - localref.getFile().length())
+ - localfile.length())
+ url;
}
else
{
url = localref + url;
}
+ if (debug)
+ {
+ System.err.println("URL: " + localref.toString());
+ System.err.println("URL.getFile: " + localref.getFile());
+ System.err.println("URL.getPath: " + localref.getPath());
+ System.err.println("URL.getQuery: " + localref.getQuery());
+ System.err.println("returning " + url);
+ }
return url;
}