📄 filemanager.java
字号:
/*
* Copyright 2007 JavaAtWork All rights reserved.
* Use is subject to license terms.
*/
package com.javaatwork.mydownloader;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.StringTokenizer;
import java.util.Vector;
import com.javaatwork.mydownloader.utils.Logger;
import com.javaatwork.mydownloader.utils.Parameters;
import com.javaatwork.mydownloader.utils.Version;
/**
* Class for retrieving the download files out of the
* the applet parameter 'files'.
*
* @author Johannes Postma
*/
public class FileManager {
/**
* Returns the initial files to download.
*
* @param codeBase The codebase of the applet.
* @return The initial files to download.
*/
public static DownloadFile [] getFilesToDownload(URL codeBase) {
String list = Parameters.getParameter(Parameters.FILES, null);
Vector fileList = new Vector();
// check if demo version
if (Version.DEMO_EDITION) {
try {
fileList.addElement(new DownloadFile(new URL("http://www.javaatwork.com/java-download-applet/files/mydownloader.doc")));
fileList.addElement(new DownloadFile(new URL("http://www.javaatwork.com/java-download-applet/files/mydownloader.xls")));
fileList.addElement(new DownloadFile(new URL("http://www.javaatwork.com/java-download-applet/files/castle.jpg")));
fileList.addElement(new DownloadFile(new URL("http://www.javaatwork.com/java-download-applet/files/kid.jpg")));
} catch (MalformedURLException e) {
// do nothing
DownloadFile [] files = new DownloadFile[0];
return files;
}
} else {
if (list == null) {
DownloadFile [] files = new DownloadFile[0];
return files;
} else {
StringTokenizer tokens = new StringTokenizer(list, ";");
while (tokens.hasMoreTokens()) {
String file = tokens.nextToken();
String part [] = file.split("#:#");
URL url = null;
try {
if (!part[0].startsWith("http")) {
url = new URL(codeBase, part[0]);
} else {
url = new URL(part[0]);
}
if (part.length == 2) {
fileList.addElement(new DownloadFile(url, part[1]));
} else {
fileList.addElement(new DownloadFile(url));
}
} catch (MalformedURLException e) {
Logger.log("FileManager", "getFilesToDownload", part[0] + " is not a valid url.");
}
}
}
}
return (DownloadFile[])fileList.toArray(new DownloadFile[fileList.size()]);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -