diff --git a/.svn/entries b/.svn/entries deleted file mode 100644 index 3cacc0b..0000000 --- a/.svn/entries +++ /dev/null @@ -1 +0,0 @@ -12 \ No newline at end of file diff --git a/.svn/format b/.svn/format deleted file mode 100644 index 3cacc0b..0000000 --- a/.svn/format +++ /dev/null @@ -1 +0,0 @@ -12 \ No newline at end of file diff --git a/.svn/pristine/00/005a95f1c60b39cf4a64a1ec41aff33bc0649789.svn-base b/.svn/pristine/00/005a95f1c60b39cf4a64a1ec41aff33bc0649789.svn-base deleted file mode 100644 index ac8d1c6..0000000 Binary files a/.svn/pristine/00/005a95f1c60b39cf4a64a1ec41aff33bc0649789.svn-base and /dev/null differ diff --git a/.svn/pristine/00/006af0660ae56e2862b649bc8053c892fa9dd5fd.svn-base b/.svn/pristine/00/006af0660ae56e2862b649bc8053c892fa9dd5fd.svn-base deleted file mode 100644 index 9a50b1f..0000000 --- a/.svn/pristine/00/006af0660ae56e2862b649bc8053c892fa9dd5fd.svn-base +++ /dev/null @@ -1,36 +0,0 @@ -/** - * - */ -package com.zhazhapan.qiniu.model; - -/** - * @author pantao - * - */ -public class Key { - - private String accessKey; - - private String secretKey; - - public Key(String accessKey, String secretKey) { - this.accessKey = accessKey; - this.secretKey = secretKey; - } - - public String getAccessKey() { - return accessKey; - } - - public void setAccessKey(String accessKey) { - this.accessKey = accessKey; - } - - public String getSecretKey() { - return secretKey; - } - - public void setSecretKey(String secretKey) { - this.secretKey = secretKey; - } -} diff --git a/.svn/pristine/02/0202245c029a442c5bbb0c56e48a969e021b037a.svn-base b/.svn/pristine/02/0202245c029a442c5bbb0c56e48a969e021b037a.svn-base deleted file mode 100644 index 65a4201..0000000 --- a/.svn/pristine/02/0202245c029a442c5bbb0c56e48a969e021b037a.svn-base +++ /dev/null @@ -1,201 +0,0 @@ -/** - * - */ -package com.zhazhapan.qiniu.config; - -import java.io.BufferedReader; -import java.io.BufferedWriter; -import java.io.File; -import java.io.FileReader; -import java.io.FileWriter; -import java.io.IOException; -import java.util.Map; - -import org.apache.log4j.Logger; - -import com.google.gson.Gson; -import com.google.gson.JsonArray; -import com.google.gson.JsonElement; -import com.google.gson.JsonObject; -import com.google.gson.JsonParser; -import com.zhazhapan.qiniu.QiniuApplication; -import com.zhazhapan.qiniu.controller.MainWindowController; -import com.zhazhapan.qiniu.model.Key; -import com.zhazhapan.qiniu.modules.constant.Values; -import com.zhazhapan.qiniu.util.Checker; -import com.zhazhapan.qiniu.util.Formatter; -import com.zhazhapan.qiniu.view.Dialogs; - -import javafx.application.Platform; - -/** - * @author pantao - * - */ -public class ConfigLoader { - - private static Logger logger = Logger.getLogger(ConfigLoader.class); - - public static String configPath = null; - - /* - * 加载配置文件 - */ - public static void loadConfig() { - logger.info("start to load configuration"); - File config = new File(configPath); - if (config.exists()) { - // 读取配置文件内容 - JsonObject json = readConfig(); - if (Checker.isNull(json)) { - showInputKeyDialog(); - } else { - // 读取Key - try { - String ak = json.get("accesskey").getAsString(); - String sk = json.get("secretkey").getAsString(); - QiniuApplication.key = new Key(ak, sk); - new QConfig().createAuth(ak, sk); - } catch (Exception e) { - logger.error("read key from configuration failed, message: " + e.getMessage()); - Dialogs.showException(Values.LOAD_CONFIG_ERROR, e); - showInputKeyDialog(); - } - // 读取Bucket - JsonElement buckets = json.get("buckets"); - if (Checker.isNotNull(buckets)) { - logger.info("load buckets into memory"); - JsonArray array = buckets.getAsJsonArray(); - boolean setvalue = true; - for (JsonElement element : array) { - JsonObject obj = (JsonObject) element; - String bucket = obj.get("bucket").getAsString(); - JsonElement url = obj.get("url"); - String zone = obj.get("zone").getAsString(); - String zones = zone + " " + (Checker.isNull(url) ? "" : url.getAsString()); - QiniuApplication.buckets.put(bucket, zones); - Platform.runLater(() -> MainWindowController.getInstance().addItem(bucket)); - if (setvalue) { - Platform.runLater(() -> { - MainWindowController.getInstance().bucketChoiceCombo.setValue(bucket); - MainWindowController.getInstance().zoneText.setText(zone); - }); - setvalue = false; - } - } - } - // 读取文件前缀 - JsonElement prefix = json.get("prefix"); - if (Checker.isNotNull(prefix)) { - JsonArray array = prefix.getAsJsonArray(); - Platform.runLater(() -> { - for (JsonElement element : array) { - String string = element.getAsString(); - QiniuApplication.prefix.add(string); - MainWindowController.getInstance().filePrefixCombo.getItems().add(string); - } - }); - } - } - } else { - logger.info("there is no configuration file, starting to create"); - checkWorkPath(); - // 创建配置文件 - try { - config.createNewFile(); - logger.info("create file 'qiniu.conf' success"); - } catch (IOException e) { - logger.error("create configuration file failed, messages: " + e.getMessage()); - Dialogs.showFatalError(Values.LOAD_CONFIG_ERROR, e); - } - showInputKeyDialog(); - } - // 如果Key是Null则退出程序 - if (Checker.isNull(QiniuApplication.key)) { - System.exit(0); - } - } - - /* - * 检测工作文件夹是否存在 - */ - public static void checkWorkPath() { - File dir = new File(QiniuApplication.workDir); - if (!dir.exists()) { - dir.mkdirs(); - logger.info("mkdir '/tmp/qiniu/tool' success"); - } - } - - /* - * 初始状态时要求用户输入AccessKey和SecretKey,否则退出程序 - */ - public static void showInputKeyDialog() { - logger.info("show dialog to require user input key"); - new Dialogs().showInputKeyDialog(); - } - - public static void writeKey(String accessKey, String secretKey) { - QiniuApplication.key = new Key(accessKey, secretKey); - writeConfig(); - } - - public static JsonObject readConfig() { - StringBuilder config = new StringBuilder(); - JsonObject jsonObject = null; - try { - logger.info("load configuration into memory"); - BufferedReader reader = new BufferedReader(new FileReader(configPath)); - String line; - while ((line = reader.readLine()) != null) { - config.append(line); - } - reader.close(); - jsonObject = new JsonParser().parse(config.toString()).getAsJsonObject(); - } catch (IOException e) { - logger.error("load configuration error, messages: " + e.getMessage()); - Dialogs.showFatalError(Values.LOAD_CONFIG_ERROR, e); - } catch (Exception e) { - logger.error("convert json string to json object failed, app'll reset"); - Dialogs.showException(Values.JSON_TO_OBJECT_ERROR, e); - } - return jsonObject; - } - - public static void writeConfig() { - JsonObject config = new JsonObject(); - // Key - config.addProperty("accesskey", QiniuApplication.key.getAccessKey()); - config.addProperty("secretkey", QiniuApplication.key.getSecretKey()); - JsonArray buckets = new JsonArray(); - // Bucket - for (Map.Entry entry : QiniuApplication.buckets.entrySet()) { - JsonObject json = new JsonObject(); - json.addProperty("bucket", entry.getKey()); - String[] zones = entry.getValue().split(" "); - json.addProperty("zone", zones[0]); - json.addProperty("url", zones.length > 1 ? zones[1] : ""); - buckets.add(json); - } - config.add("buckets", buckets); - // Prefix - JsonArray prefix = new JsonArray(); - for (String string : QiniuApplication.prefix) { - prefix.add(string); - } - config.add("prefix", prefix); - writeConfig(new Gson().toJson(config)); - } - - public static void writeConfig(String configJson) { - try { - BufferedWriter out = new BufferedWriter(new FileWriter(configPath, false)); - out.write(Formatter.jsonFormat(configJson)); - out.close(); - logger.info("rewrite configuration success"); - } catch (IOException e) { - logger.error("rewrite configuration file failed, messages: " + e.getMessage()); - Dialogs.showFatalError(Values.LOAD_CONFIG_ERROR, e); - } - } -} diff --git a/.svn/pristine/06/0689b8dbd58ae2fff58685f1c243f8f046035c1d.svn-base b/.svn/pristine/06/0689b8dbd58ae2fff58685f1c243f8f046035c1d.svn-base deleted file mode 100644 index e8fa429..0000000 --- a/.svn/pristine/06/0689b8dbd58ae2fff58685f1c243f8f046035c1d.svn-base +++ /dev/null @@ -1,405 +0,0 @@ -/** - * - */ -package com.zhazhapan.qiniu.controller; - -import java.awt.Desktop; -import java.io.File; -import java.io.IOException; -import java.util.ArrayList; -import java.util.Date; -import java.util.HashMap; -import java.util.List; -import java.util.Optional; -import java.util.regex.Pattern; - -import org.apache.log4j.Logger; - -import com.qiniu.common.QiniuException; -import com.zhazhapan.qiniu.FileExecutor; -import com.zhazhapan.qiniu.QManager; -import com.zhazhapan.qiniu.QiniuApplication; -import com.zhazhapan.qiniu.config.ConfigLoader; -import com.zhazhapan.qiniu.config.QConfig; -import com.zhazhapan.qiniu.model.FileInfo; -import com.zhazhapan.qiniu.modules.constant.Values; -import com.zhazhapan.qiniu.util.Checker; -import com.zhazhapan.qiniu.util.Formatter; -import com.zhazhapan.qiniu.util.Utils; -import com.zhazhapan.qiniu.view.Dialogs; - -import javafx.application.Platform; -import javafx.collections.FXCollections; -import javafx.collections.ObservableList; -import javafx.event.ActionEvent; -import javafx.fxml.FXML; -import javafx.scene.control.Button; -import javafx.scene.control.ButtonType; -import javafx.scene.control.ComboBox; -import javafx.scene.control.SelectionMode; -import javafx.scene.control.TableColumn; -import javafx.scene.control.TableView; -import javafx.scene.control.TextArea; -import javafx.scene.control.TextField; -import javafx.scene.control.cell.PropertyValueFactory; -import javafx.scene.control.cell.TextFieldTableCell; -import javafx.scene.input.KeyEvent; -import javafx.stage.FileChooser; - -/** - * @author pantao - * - */ -public class MainWindowController { - - private Logger logger = Logger.getLogger(MainWindowController.class); - - @FXML - public ComboBox bucketChoiceCombo; - - @FXML - public TextField zoneText; - - @FXML - private Button bucketAddableButton; - - @FXML - private Button resetKeyButton; - - @FXML - public TextArea uploadStatusTextArea; - - @FXML - private TextArea selectedFileTextArea; - - @FXML - public ComboBox filePrefixCombo; - - @FXML - private TextField bucketDomainTextField; - - @FXML - public TableView resTable; - - @FXML - public TextField searchTextField; - - @FXML - private TableColumn nameCol; - - @FXML - private TableColumn typeCol; - - @FXML - private TableColumn sizeCol; - - @FXML - private TableColumn timeCol; - - private static MainWindowController mainWindowController = null; - - private String status = ""; - - public static MainWindowController getInstance() { - return mainWindowController; - } - - /* - * 初始化 - */ - @FXML - private void initialize() { - mainWindowController = this; - nameCol.setCellValueFactory(new PropertyValueFactory<>("name")); - // 文件名可编辑 - nameCol.setCellFactory(TextFieldTableCell.forTableColumn()); - nameCol.setOnEditCommit(v -> { - String name = ""; - if (new QManager().renameFile(bucketChoiceCombo.getValue(), v.getOldValue(), v.getNewValue())) { - name = v.getNewValue(); - } else { - name = v.getOldValue(); - } - v.getTableView().getItems().get(v.getTablePosition().getRow()).setName(name); - }); - typeCol.setCellValueFactory(new PropertyValueFactory<>("type")); - // 文件类型可编辑 - typeCol.setCellFactory(TextFieldTableCell.forTableColumn()); - typeCol.setOnEditCommit(v -> { - FileInfo fileInfo = v.getTableView().getItems().get(v.getTablePosition().getRow()); - if (new QManager().changeType(fileInfo.getName(), v.getNewValue(), bucketChoiceCombo.getValue())) { - fileInfo.setType(v.getNewValue()); - } else { - fileInfo.setType(v.getOldValue()); - } - }); - sizeCol.setCellValueFactory(new PropertyValueFactory<>("size")); - timeCol.setCellValueFactory(new PropertyValueFactory<>("time")); - resTable.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE); - // BucketChoiceComboBox改变事件,改变后并配置新的上传环境 - bucketChoiceCombo.getSelectionModel().selectedItemProperty().addListener((observable, oldValue, newValue) -> { - String[] zones = QiniuApplication.buckets.get(newValue).split(" "); - zoneText.setText(zones[0]); - searchTextField.clear(); - if (Checker.isHyperLink(zones[1])) { - bucketDomainTextField.setText(zones[1]); - } else { - logger.warn("has doesn't config the domain of bucket correctly yet"); - bucketDomainTextField.setText(Values.DOMAIN_CONFIG_ERROR); - } - new Thread(() -> { - if (new QConfig().configUploadEnv(zones[0], newValue)) { - // 加载文件列表 - setResTableData(); - } - }).start(); - }); - } - - /* - * 批量移动文件 - */ - public void moveFiles() { - - } - - /* - * 显示移动或复制文件的窗口 - */ - public void showFileMovableDialog() { - boolean bool = new Dialogs().showFileMovableDialog(); - // 是否更新数据源 - if (bool) { - - } - } - - /* - * 删除文件 - */ - public void deleteFiles() { - ObservableList fileInfos = resTable.getSelectionModel().getSelectedItems(); - new QManager().deleteFiles(fileInfos, bucketChoiceCombo.getValue()); - } - - /* - * 复制链接 - */ - public void copyLink() { - ObservableList fileInfos = resTable.getSelectionModel().getSelectedItems(); - if (Checker.isNotEmpty(fileInfos)) { - // 只复制选中的第一个文件的链接 - String link = "http://" + bucketDomainTextField.getText() + "/" + fileInfos.get(0).getName(); - Utils.copyToClipboard(link); - logger.info("copy link: " + link); - } - } - - /* - * 搜索资源文件,忽略大小写 - */ - public void searchFile(KeyEvent event) { - ArrayList files = new ArrayList(); - String search = Checker.checkNull(searchTextField.getText()); - logger.info("search file: " + search); - try { - // 正则匹配查询 - Pattern pattern = Pattern.compile(search, Pattern.CASE_INSENSITIVE); - for (FileInfo file : QiniuApplication.data) { - if (pattern.matcher(file.getName()).find()) { - files.add(file); - } - } - } catch (Exception e) { - logger.warn("pattern '" + search + "' compile error, message: " + e.getMessage()); - } - resTable.setItems(FXCollections.observableArrayList(files)); - } - - /* - * 刷新资源列表 - */ - public void refreshResTable() { - if (!new QConfig().checkNet()) { - Dialogs.showWarning(Values.NET_ERROR); - return; - } - setResTableData(); - Dialogs.showInformation(Values.REFRESH_SUCCESS); - } - - /* - * 将从存储空间获取的文件列表映射到Table - */ - public void setResTableData() { - new Thread(() -> { - new QManager().listFileOfBucket(); - Platform.runLater(() -> resTable.setItems(QiniuApplication.data)); - }).start(); - } - - /* - * 添加bucket到ComboBox - */ - public void addItem(String bucket) { - if (!bucketChoiceCombo.getItems().contains(bucket)) { - bucketChoiceCombo.getItems().add(bucket); - } - } - - /* - * 保存文件的上传状态 - */ - public void saveUploadStatus() { - FileChooser chooser = new FileChooser(); - chooser.setTitle(Values.FILE_CHOOSER_TITLE); - chooser.setInitialDirectory(new File(System.getProperty("user.home"))); - File file = chooser.showSaveDialog(QiniuApplication.stage); - new FileExecutor().saveFile(file, uploadStatusTextArea.getText()); - } - - /* - * 复制上传状态到剪贴板 - */ - public void copyUploadStatus() { - Utils.copyToClipboard(uploadStatusTextArea.getText()); - } - - /* - * 清空文件的上传状态 - */ - public void clearUploadStatus() { - uploadStatusTextArea.clear(); - } - - /* - * 选择要上传的文件 - */ - public void selectFile() { - logger.info("show file chooser dialog"); - FileChooser chooser = new FileChooser(); - chooser.setTitle(Values.FILE_CHOOSER_TITLE); - chooser.setInitialDirectory(new File(System.getProperty("user.home"))); - List files = chooser.showOpenMultipleDialog(QiniuApplication.stage); - if (Checker.isNotEmpty(files)) { - for (File file : files) { - selectedFileTextArea.insertText(0, file.getAbsolutePath() + "\r\n"); - } - } - } - - /* - * 上传选择的文件 - */ - public void uploadFile() { - if (Checker.isNullOrEmpty(zoneText.getText()) || Checker.isNullOrEmpty(selectedFileTextArea.getText())) { - // 没有选择存储空间或文件,不能上传文件 - Dialogs.showWarning(Values.NEED_SCHOOSE_BUCKET_OR_FILE); - return; - } - // 新建一个上传文件的线程 - new Thread(() -> { - Platform.runLater(() -> uploadStatusTextArea.insertText(0, Values.CONFIGING_UPLOAD_ENVIRONMENT)); - String bucket = bucketChoiceCombo.getValue(); - // 默认不指定key的情况下,以文件内容的hash值作为文件名 - String key = Checker.checkNull(filePrefixCombo.getValue()); - String[] paths = selectedFileTextArea.getText().split("\n"); - int end = Values.UPLOADING.length() - 2;// 去掉\r\n的长度 - Platform.runLater( - () -> uploadStatusTextArea.deleteText(0, Values.CONFIGING_UPLOAD_ENVIRONMENT.length() - 1)); - for (String path : paths) { - if (Checker.isNotEmpty(path)) { - Platform.runLater(() -> uploadStatusTextArea.insertText(0, Values.UPLOADING)); - try { - logger.info("start to upload file: " + path); - File file = new File(path); - String filename = "undefined"; - String url = "http://" + QiniuApplication.buckets.get(bucket).split(" ")[1] + "/"; - // 判断文件是否存在 - if (file.exists()) { - filename = key + file.getName(); - QiniuApplication.uploadManager.put(path, filename, QiniuApplication.upToken); - status = Formatter.datetimeToString(new Date()) + "\tsuccess\t" + url + filename + "\t" - + path; - logger.info("upload file '" + path + "' to bucket '" + bucket + "' success"); - } else if (Checker.isHyperLink(path)) { - // 抓取网络文件到空间中 - logger.info(path + " is a hyper link"); - filename = key + Formatter.getFileName(path); - QiniuApplication.bucketManager.fetch(path, bucket, filename); - status = Formatter.datetimeToString(new Date()) + "\tsuccess\t" + url + filename + "\t" - + path; - logger.info("fetch remote file '" + path + "' to bucket '" + bucket + "' success"); - } else { - // 文件不存在 - logger.info("file '" + path + "' not exists"); - status = Formatter.datetimeToString(new Date()) + "\tfailed\t" + path; - } - } catch (QiniuException e) { - status = Formatter.datetimeToString(new Date()) + "\terror\t" + path; - logger.error("upload error, message: " + e.getMessage()); - Platform.runLater(() -> Dialogs.showException(Values.UPLOAD_ERROR, e)); - } - Platform.runLater(() -> { - uploadStatusTextArea.deleteText(0, end); - uploadStatusTextArea.insertText(0, status); - }); - } - Platform.runLater(() -> selectedFileTextArea.deleteText(0, path.length() + (paths.length > 1 ? 1 : 0))); - } - Platform.runLater(() -> { - // 将光标移到最前面 - uploadStatusTextArea.positionCaret(0); - // 清空待上传的文件列表 - selectedFileTextArea.clear(); - }); - // 添加文件前缀到配置文件 - if (Checker.isNotEmpty(key) && !QiniuApplication.prefix.contains(key)) { - Platform.runLater(() -> filePrefixCombo.getItems().add(key)); - QiniuApplication.prefix.add(key); - ConfigLoader.writeConfig(); - } - setResTableData(); - }).start(); - } - - /* - * 打开配置文件 - */ - public void openConfigFile() { - try { - Desktop.getDesktop().open(new File(ConfigLoader.configPath)); - logger.info("open config file"); - Optional result = Dialogs.showConfirmation(Values.RELOAD_CONFIG); - if (result.get() == ButtonType.OK) { - // 重新载入配置文件 - QiniuApplication.buckets = new HashMap(); - QiniuApplication.prefix = new ArrayList(); - bucketChoiceCombo.getItems().clear(); - filePrefixCombo.getItems().clear(); - ConfigLoader.loadConfig(); - } - } catch (IOException e) { - logger.error("open config file error, message: " + e.getMessage()); - Dialogs.showException(Values.OPEN_FILE_ERROR, e); - } catch (Exception e) { - logger.error("can't open config file, message: " + e.getMessage()); - Dialogs.showException(Values.OPEN_FILE_ERROR, e); - } - } - - /* - * 重置Key - */ - public void resetKey() { - ConfigLoader.showInputKeyDialog(); - } - - /* - * 添加存储空间 - */ - public void showBucketAddableDialog(ActionEvent event) { - logger.info("show bucket addable dialog"); - new Dialogs().showBucketAddableDialog(); - } -} diff --git a/.svn/pristine/06/06a9f39b594d58f50532e5629a923ebdf273b6c1.svn-base b/.svn/pristine/06/06a9f39b594d58f50532e5629a923ebdf273b6c1.svn-base deleted file mode 100644 index 26d9273..0000000 --- a/.svn/pristine/06/06a9f39b594d58f50532e5629a923ebdf273b6c1.svn-base +++ /dev/null @@ -1,58 +0,0 @@ -/** - * - */ -package com.zhazhapan.qiniu.util; - -import java.util.List; -import java.util.regex.Pattern; - -/** - * @author pantao - * - */ -public class Checker { - - public static final Pattern HYPER_LINK_PATTERN = Pattern.compile("^(https*://)?([a-z0-9]+\\.)+[a-z0-9]+(/[^\\s])*$", - Pattern.CASE_INSENSITIVE); - - public static final Pattern NUMBER_PATTERN = Pattern.compile("^[0-9]+$"); - - public static boolean isNumber(String string) { - return isNull(string) ? false : NUMBER_PATTERN.matcher(string).matches(); - } - - public static boolean isNull(Object object) { - return object == null ? true : false; - } - - public static boolean isNotNull(Object object) { - return !isNull(object); - } - - public static boolean isNullOrEmpty(String string) { - return isNull(string) ? true : string.isEmpty(); - } - - public static boolean isNotEmpty(String string) { - return !isNullOrEmpty(string); - } - - public static String checkNull(String string) { - return isNull(string) ? "" : string; - } - - public static boolean isNotEmpty(List list) { - return !isEmpty(list); - } - - public static boolean isEmpty(List list) { - return isNull(list) ? true : list.isEmpty(); - } - - public static boolean isHyperLink(String string) { - if (isNotEmpty(string)) { - return HYPER_LINK_PATTERN.matcher(string).matches(); - } - return false; - } -} diff --git a/.svn/pristine/07/07cb8779c200d6837a011b3685342c15d7804294.svn-base b/.svn/pristine/07/07cb8779c200d6837a011b3685342c15d7804294.svn-base deleted file mode 100644 index 3756a9f..0000000 --- a/.svn/pristine/07/07cb8779c200d6837a011b3685342c15d7804294.svn-base +++ /dev/null @@ -1,103 +0,0 @@ -/** - * - */ -package com.zhazhapan.qiniu.modules.constant; - -/** - * @author pantao - * - */ -public class Values { - - public static final String MAIN_TITLE = "七牛云管理工具"; - - public static final String INIT_APP_ERROR_HEADER = "初始化错误,无法继续运行"; - - public static final String APP_PATH_OF_WINDOWS = "C:/program files/Qiniu Tool"; - - public static final String APP_PATH_OF_UNIX = "/tmp/qiniu/tool"; - - public static final String CONFIG_PATH = "/config.json"; - - public static final String FORMAT_JSON_ERROR = "将字符串格式化为JSON失败"; - - public static final String FATAL_UNKNOW_ERROR = "发生了一些严重的未知错误,程序即将退出"; - - public static final String LOAD_CONFIG_ERROR = "加载配置失败,无法继续运行"; - - public static final String OK = "确的"; - - public static final String CANCEL = "取消"; - - public static final String JSON_TO_OBJECT_ERROR = "将JSON字符串转换成JSON对象失败"; - - public static final String BUCKET_NAME = "空间名称"; - - public static final String BUCKET_ZONE_NAME = "存储区域"; - - public static final String BUCKET_URL = "空间域名"; - - public static final String[] BUCKET_NAME_ARRAY = { "华东", "华北", "华南", "北美" }; - - public static final String FILE_CHOOSER_TITLE = "选择需要上传的文件"; - - public static final String OPEN_FILE_ERROR = "打开文件失败"; - - public static final String UPLOAD_ERROR = "上传文件失败"; - - public static final String UPLOAD_SUCCESS = "上传文件成功"; - - public static final String UPLOADING = "文件上传中。。。。。。\r\n"; - - public static final String NEED_SCHOOSE_BUCKET_OR_FILE = "请先选择一个存储空间或文件"; - - public static final String CONFIGING_UPLOAD_ENVIRONMENT = "正在配置文件上传环境,请耐心等待。。。。。。\r\n"; - - public static final String RELOAD_CONFIG = "是否重新载入配置文件?"; - - public static final String SAVE_FILE_ERROR = "保存文件失败"; - - public static final String DOMAIN_CONFIG_ERROR = "您还没有正确地配置空间域名"; - - public static final int BUCKET_LIST_LIMIT_SIZE = 1000; - - public static final long KB = 1024; - - public static final long MB = KB * 1024; - - public static final long GB = MB * 1024; - - public static final long TB = GB * 1024; - - public static final String REFRESH_SUCCESS = "刷新资源列表成功"; - - public static final String LIST_FILE_ERROR = "获取资源列表失败"; - - public static final String NET_ERROR = "没有连接到网络,无法运行程序"; - - public static final String DELETE_ERROR = "删除文件时发生异常"; - - public static final String CHANGE_FILE_TYPE_ERROR = "删除文件发生异常"; - - public static final String MOVE_OR_RENAME_ERROR = "移动或重命名文件失败"; - - public static final String WINDOW_OS = "window"; - - public static final String FILE_NAME = "文件名"; - - public static final String COPY_AS = "保存文件副本"; - - public static final String FILE_LIFE = "文件生存时间(天)"; - - public static final String UPDATE_ERROR = "更新镜像源失败"; - - public static final String GENERATE_URL_ERROR = "生成下载链接失败"; - - public static final String DEFAULT_FILE_LIFE = "365"; - - public static final String CONFIG_DOWNLOAD_PATH = "配置文件下载路径"; - - public static final String DOWNLOAD_FILE_ERROR = "下载文件错误"; - - public static final String OPEN_LINK_ERROR = "打开链接失败"; -} diff --git a/.svn/pristine/07/07e14f70fd8970337170510d36caa79dafe9f947.svn-base b/.svn/pristine/07/07e14f70fd8970337170510d36caa79dafe9f947.svn-base deleted file mode 100644 index 4d53ddf..0000000 --- a/.svn/pristine/07/07e14f70fd8970337170510d36caa79dafe9f947.svn-base +++ /dev/null @@ -1,416 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - - -
diff --git a/.svn/pristine/0a/0a1dc92fdf4cd24f37b0193aa26af721d9c54154.svn-base b/.svn/pristine/0a/0a1dc92fdf4cd24f37b0193aa26af721d9c54154.svn-base deleted file mode 100644 index 467f940..0000000 --- a/.svn/pristine/0a/0a1dc92fdf4cd24f37b0193aa26af721d9c54154.svn-base +++ /dev/null @@ -1,90 +0,0 @@ -package com.zhazhapan.qiniu; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.Map; - -import org.apache.log4j.Logger; -import org.springframework.boot.autoconfigure.SpringBootApplication; - -import com.qiniu.common.Zone; -import com.qiniu.storage.BucketManager; -import com.qiniu.storage.Configuration; -import com.qiniu.storage.UploadManager; -import com.qiniu.util.Auth; -import com.zhazhapan.qiniu.config.ConfigLoader; -import com.zhazhapan.qiniu.model.FileInfo; -import com.zhazhapan.qiniu.model.Key; -import com.zhazhapan.qiniu.modules.constant.Values; -import com.zhazhapan.qiniu.view.MainWindow; - -import javafx.application.Application; -import javafx.collections.ObservableList; -import javafx.stage.Stage; - -@SpringBootApplication -public class QiniuApplication extends Application { - - public static MainWindow mainWindow = null; - - public static Key key = null; - - public static Map zone = new HashMap(); - - // Value包括存储空间和空间域名,用英文空格分隔 - public static Map buckets = new HashMap(); - - private static Logger logger = Logger.getLogger(QiniuApplication.class); - - public static Stage stage = null; - - public static ArrayList prefix = new ArrayList(); - - public static String workDir = null; - - public static Auth auth = null; - - public static UploadManager uploadManager = null; - - public static String upToken = null; - - public static Configuration configuration = null; - - public static BucketManager bucketManager = null; - - public static ObservableList data = null; - - public static StringBuilder deleteLog = new StringBuilder(); - - /* - * 主程序入口 - */ - public static void main(String[] args) { - logger.info("start to run application"); - String osname = System.getProperties().getProperty("os.name").toLowerCase(); - logger.info("current operation system: " + osname); - if (osname.contains("window")) { - workDir = Values.APP_PATH_OF_WINDOWS; - } else { - workDir = Values.APP_PATH_OF_UNIX; - } - ConfigLoader.configPath = workDir + Values.CONFIG_PATH; - mainWindow = new MainWindow(); - launch(args); - } - - @Override - public void start(Stage stage) throws Exception { - ConfigLoader.loadConfig(); - mainWindow.init(stage); - mainWindow.show(); - initZone(); - } - - public void initZone() { - zone.put(Values.BUCKET_NAME_ARRAY[0], Zone.zone0()); - zone.put(Values.BUCKET_NAME_ARRAY[1], Zone.zone1()); - zone.put(Values.BUCKET_NAME_ARRAY[2], Zone.zone2()); - zone.put(Values.BUCKET_NAME_ARRAY[3], Zone.zoneNa0()); - } -} diff --git a/.svn/pristine/0a/0acf62eb458f1486dfd9756cda52d3b95165f167.svn-base b/.svn/pristine/0a/0acf62eb458f1486dfd9756cda52d3b95165f167.svn-base deleted file mode 100644 index f588612..0000000 --- a/.svn/pristine/0a/0acf62eb458f1486dfd9756cda52d3b95165f167.svn-base +++ /dev/null @@ -1,8 +0,0 @@ -/** - * - */ -/** - * @author pantao - * - */ -package com.zhazhapan.qiniu.modules.constant; \ No newline at end of file diff --git a/.svn/pristine/10/100046f03a42e371bc8f212a275abc933a8fbdcb.svn-base b/.svn/pristine/10/100046f03a42e371bc8f212a275abc933a8fbdcb.svn-base deleted file mode 100644 index 4b90b48..0000000 --- a/.svn/pristine/10/100046f03a42e371bc8f212a275abc933a8fbdcb.svn-base +++ /dev/null @@ -1,33 +0,0 @@ -/** - * - */ -package com.zhazhapan.qiniu; - -import org.junit.Test; - -import com.google.gson.JsonArray; -import com.google.gson.JsonElement; -import com.google.gson.JsonObject; -import com.google.gson.JsonParser; -import com.zhazhapan.qiniu.util.Checker; - -/** - * @author pantao - * - */ -public class TestGson { - - public String configJson = "{accesskey:123456,secretkey:abcdef,buckets:[{bucket:zhazhapan,zone:华东}]}"; - - @Test - public void testGson() { - JsonObject json = new JsonParser().parse(configJson).getAsJsonObject(); - JsonElement buckets = json.get("buckets"); - if (Checker.isNotNull(buckets)) { - JsonArray array = buckets.getAsJsonArray(); - for (JsonElement element : array) { - System.out.println(((JsonObject) element).get("bucket").getAsString()); - } - } - } -} diff --git a/.svn/pristine/12/12e54b5a134fdc7115b1ae0fec9d55e9f75ad5b8.svn-base b/.svn/pristine/12/12e54b5a134fdc7115b1ae0fec9d55e9f75ad5b8.svn-base deleted file mode 100644 index e796619..0000000 --- a/.svn/pristine/12/12e54b5a134fdc7115b1ae0fec9d55e9f75ad5b8.svn-base +++ /dev/null @@ -1,22 +0,0 @@ -package com.zhazhapan.qiniu; - -import org.junit.Test; - -import org.junit.runner.RunWith; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.test.context.junit4.SpringRunner; - -/** - * @author pantao - * - */ - -@RunWith(SpringRunner.class) -@SpringBootTest -public class QiniuApplicationTest { - - @Test - public void contextLoads() { - } - -} diff --git a/.svn/pristine/17/1707c0c92b7294595e6d2fefd7a28698caf6bd2e.svn-base b/.svn/pristine/17/1707c0c92b7294595e6d2fefd7a28698caf6bd2e.svn-base deleted file mode 100644 index 2af7cef..0000000 --- a/.svn/pristine/17/1707c0c92b7294595e6d2fefd7a28698caf6bd2e.svn-base +++ /dev/null @@ -1,24 +0,0 @@ -target/ -!.mvn/wrapper/maven-wrapper.jar - -### STS ### -.apt_generated -.classpath -.factorypath -.project -.settings -.springBeans - -### IntelliJ IDEA ### -.idea -*.iws -*.iml -*.ipr - -### NetBeans ### -nbproject/private/ -build/ -nbbuild/ -dist/ -nbdist/ -.nb-gradle/ \ No newline at end of file diff --git a/.svn/pristine/31/314ef4deee9f01e14ae515d79ee3b9152cc3bce3.svn-base b/.svn/pristine/31/314ef4deee9f01e14ae515d79ee3b9152cc3bce3.svn-base deleted file mode 100644 index d05e2da..0000000 --- a/.svn/pristine/31/314ef4deee9f01e14ae515d79ee3b9152cc3bce3.svn-base +++ /dev/null @@ -1,83 +0,0 @@ -/** - * - */ -package com.zhazhapan.qiniu.config; - -import java.io.IOException; -import java.io.InputStream; -import java.net.URL; -import java.nio.file.Paths; - -import org.apache.log4j.Logger; - -import com.qiniu.storage.BucketManager; -import com.qiniu.storage.Configuration; -import com.qiniu.storage.UploadManager; -import com.qiniu.storage.persistent.FileRecorder; -import com.qiniu.util.Auth; -import com.zhazhapan.qiniu.QiniuApplication; -import com.zhazhapan.qiniu.modules.constant.Values; -import com.zhazhapan.qiniu.view.Dialogs; - -import javafx.application.Platform; - -/** - * @author pantao - * - */ - -public class QConfig { - - private Logger logger = Logger.getLogger(QConfig.class); - - /* - * 创建上传需要的Auth - */ - public void createAuth(String ak, String sk) { - QiniuApplication.auth = Auth.create(ak, sk); - } - - /* - * 配置文件上传环境 - */ - public boolean configUploadEnv(String zone, String bucket) { - if (!checkNet()) { - Platform.runLater(() -> { - Dialogs.showError(Values.NET_ERROR); - System.exit(0); - }); - return false; - } - logger.info("config file upload environment"); - // 构造一个带指定Zone对象的配置类 - Configuration configuration = new Configuration(QiniuApplication.zone.get(zone)); - // 生成上传凭证,然后准备上传 - String localTempDir = Paths.get(System.getenv("java.io.tmpdir"), bucket).toString(); - try { - FileRecorder fileRecorder = new FileRecorder(localTempDir); - QiniuApplication.uploadManager = new UploadManager(configuration, fileRecorder); - } catch (IOException e1) { - logger.error("load local temp directory failed, can't use file recorder"); - QiniuApplication.uploadManager = new UploadManager(configuration); - } - QiniuApplication.configuration = configuration; - QiniuApplication.upToken = QiniuApplication.auth.uploadToken(bucket); - QiniuApplication.bucketManager = new BucketManager(QiniuApplication.auth, configuration); - return true; - } - - /* - * 检查是否连接网络 - */ - public boolean checkNet() { - try { - URL url = new URL("https://www.qiniu.com/"); - InputStream in = url.openStream(); - in.close(); - return true; - } catch (IOException e) { - logger.error("doesn't connect internate"); - return false; - } - } -} diff --git a/.svn/pristine/37/37b8ffb4984af66c5bd47076352cbe4711ebfbde.svn-base b/.svn/pristine/37/37b8ffb4984af66c5bd47076352cbe4711ebfbde.svn-base deleted file mode 100644 index 6d7587a..0000000 --- a/.svn/pristine/37/37b8ffb4984af66c5bd47076352cbe4711ebfbde.svn-base +++ /dev/null @@ -1,31 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/.svn/pristine/3b/3b9cac08b88bfc58272c17f57ea1eb10ccafd4b3.svn-base b/.svn/pristine/3b/3b9cac08b88bfc58272c17f57ea1eb10ccafd4b3.svn-base deleted file mode 100644 index 74830a8..0000000 --- a/.svn/pristine/3b/3b9cac08b88bfc58272c17f57ea1eb10ccafd4b3.svn-base +++ /dev/null @@ -1,16 +0,0 @@ -package com.zhazhapan.qiniu; - -import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.test.context.junit4.SpringRunner; - -@RunWith(SpringRunner.class) -@SpringBootTest -public class QiniuApplicationTests { - - @Test - public void contextLoads() { - } - -} diff --git a/.svn/pristine/3b/3bfacd12709ea26da32afe93abade2a716cff95b.svn-base b/.svn/pristine/3b/3bfacd12709ea26da32afe93abade2a716cff95b.svn-base deleted file mode 100644 index 5f04203..0000000 --- a/.svn/pristine/3b/3bfacd12709ea26da32afe93abade2a716cff95b.svn-base +++ /dev/null @@ -1,236 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - - -
diff --git a/.svn/pristine/40/40788d3b7a2ee2c7fd84ef9ae6dc7bf1752a9517.svn-base b/.svn/pristine/40/40788d3b7a2ee2c7fd84ef9ae6dc7bf1752a9517.svn-base deleted file mode 100644 index 5bf251c..0000000 --- a/.svn/pristine/40/40788d3b7a2ee2c7fd84ef9ae6dc7bf1752a9517.svn-base +++ /dev/null @@ -1,225 +0,0 @@ -#!/bin/sh -# ---------------------------------------------------------------------------- -# Licensed to the Apache Software Foundation (ASF) under one -# or more contributor license agreements. See the NOTICE file -# distributed with this work for additional information -# regarding copyright ownership. The ASF licenses this file -# to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance -# with the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, -# software distributed under the License is distributed on an -# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -# KIND, either express or implied. See the License for the -# specific language governing permissions and limitations -# under the License. -# ---------------------------------------------------------------------------- - -# ---------------------------------------------------------------------------- -# Maven2 Start Up Batch script -# -# Required ENV vars: -# ------------------ -# JAVA_HOME - location of a JDK home dir -# -# Optional ENV vars -# ----------------- -# M2_HOME - location of maven2's installed home dir -# MAVEN_OPTS - parameters passed to the Java VM when running Maven -# e.g. to debug Maven itself, use -# set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 -# MAVEN_SKIP_RC - flag to disable loading of mavenrc files -# ---------------------------------------------------------------------------- - -if [ -z "$MAVEN_SKIP_RC" ] ; then - - if [ -f /etc/mavenrc ] ; then - . /etc/mavenrc - fi - - if [ -f "$HOME/.mavenrc" ] ; then - . "$HOME/.mavenrc" - fi - -fi - -# OS specific support. $var _must_ be set to either true or false. -cygwin=false; -darwin=false; -mingw=false -case "`uname`" in - CYGWIN*) cygwin=true ;; - MINGW*) mingw=true;; - Darwin*) darwin=true - # Use /usr/libexec/java_home if available, otherwise fall back to /Library/Java/Home - # See https://developer.apple.com/library/mac/qa/qa1170/_index.html - if [ -z "$JAVA_HOME" ]; then - if [ -x "/usr/libexec/java_home" ]; then - export JAVA_HOME="`/usr/libexec/java_home`" - else - export JAVA_HOME="/Library/Java/Home" - fi - fi - ;; -esac - -if [ -z "$JAVA_HOME" ] ; then - if [ -r /etc/gentoo-release ] ; then - JAVA_HOME=`java-config --jre-home` - fi -fi - -if [ -z "$M2_HOME" ] ; then - ## resolve links - $0 may be a link to maven's home - PRG="$0" - - # need this for relative symlinks - while [ -h "$PRG" ] ; do - ls=`ls -ld "$PRG"` - link=`expr "$ls" : '.*-> \(.*\)$'` - if expr "$link" : '/.*' > /dev/null; then - PRG="$link" - else - PRG="`dirname "$PRG"`/$link" - fi - done - - saveddir=`pwd` - - M2_HOME=`dirname "$PRG"`/.. - - # make it fully qualified - M2_HOME=`cd "$M2_HOME" && pwd` - - cd "$saveddir" - # echo Using m2 at $M2_HOME -fi - -# For Cygwin, ensure paths are in UNIX format before anything is touched -if $cygwin ; then - [ -n "$M2_HOME" ] && - M2_HOME=`cygpath --unix "$M2_HOME"` - [ -n "$JAVA_HOME" ] && - JAVA_HOME=`cygpath --unix "$JAVA_HOME"` - [ -n "$CLASSPATH" ] && - CLASSPATH=`cygpath --path --unix "$CLASSPATH"` -fi - -# For Migwn, ensure paths are in UNIX format before anything is touched -if $mingw ; then - [ -n "$M2_HOME" ] && - M2_HOME="`(cd "$M2_HOME"; pwd)`" - [ -n "$JAVA_HOME" ] && - JAVA_HOME="`(cd "$JAVA_HOME"; pwd)`" - # TODO classpath? -fi - -if [ -z "$JAVA_HOME" ]; then - javaExecutable="`which javac`" - if [ -n "$javaExecutable" ] && ! [ "`expr \"$javaExecutable\" : '\([^ ]*\)'`" = "no" ]; then - # readlink(1) is not available as standard on Solaris 10. - readLink=`which readlink` - if [ ! `expr "$readLink" : '\([^ ]*\)'` = "no" ]; then - if $darwin ; then - javaHome="`dirname \"$javaExecutable\"`" - javaExecutable="`cd \"$javaHome\" && pwd -P`/javac" - else - javaExecutable="`readlink -f \"$javaExecutable\"`" - fi - javaHome="`dirname \"$javaExecutable\"`" - javaHome=`expr "$javaHome" : '\(.*\)/bin'` - JAVA_HOME="$javaHome" - export JAVA_HOME - fi - fi -fi - -if [ -z "$JAVACMD" ] ; then - if [ -n "$JAVA_HOME" ] ; then - if [ -x "$JAVA_HOME/jre/sh/java" ] ; then - # IBM's JDK on AIX uses strange locations for the executables - JAVACMD="$JAVA_HOME/jre/sh/java" - else - JAVACMD="$JAVA_HOME/bin/java" - fi - else - JAVACMD="`which java`" - fi -fi - -if [ ! -x "$JAVACMD" ] ; then - echo "Error: JAVA_HOME is not defined correctly." >&2 - echo " We cannot execute $JAVACMD" >&2 - exit 1 -fi - -if [ -z "$JAVA_HOME" ] ; then - echo "Warning: JAVA_HOME environment variable is not set." -fi - -CLASSWORLDS_LAUNCHER=org.codehaus.plexus.classworlds.launcher.Launcher - -# traverses directory structure from process work directory to filesystem root -# first directory with .mvn subdirectory is considered project base directory -find_maven_basedir() { - - if [ -z "$1" ] - then - echo "Path not specified to find_maven_basedir" - return 1 - fi - - basedir="$1" - wdir="$1" - while [ "$wdir" != '/' ] ; do - if [ -d "$wdir"/.mvn ] ; then - basedir=$wdir - break - fi - # workaround for JBEAP-8937 (on Solaris 10/Sparc) - if [ -d "${wdir}" ]; then - wdir=`cd "$wdir/.."; pwd` - fi - # end of workaround - done - echo "${basedir}" -} - -# concatenates all lines of a file -concat_lines() { - if [ -f "$1" ]; then - echo "$(tr -s '\n' ' ' < "$1")" - fi -} - -BASE_DIR=`find_maven_basedir "$(pwd)"` -if [ -z "$BASE_DIR" ]; then - exit 1; -fi - -export MAVEN_PROJECTBASEDIR=${MAVEN_BASEDIR:-"$BASE_DIR"} -echo $MAVEN_PROJECTBASEDIR -MAVEN_OPTS="$(concat_lines "$MAVEN_PROJECTBASEDIR/.mvn/jvm.config") $MAVEN_OPTS" - -# For Cygwin, switch paths to Windows format before running java -if $cygwin; then - [ -n "$M2_HOME" ] && - M2_HOME=`cygpath --path --windows "$M2_HOME"` - [ -n "$JAVA_HOME" ] && - JAVA_HOME=`cygpath --path --windows "$JAVA_HOME"` - [ -n "$CLASSPATH" ] && - CLASSPATH=`cygpath --path --windows "$CLASSPATH"` - [ -n "$MAVEN_PROJECTBASEDIR" ] && - MAVEN_PROJECTBASEDIR=`cygpath --path --windows "$MAVEN_PROJECTBASEDIR"` -fi - -WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain - -exec "$JAVACMD" \ - $MAVEN_OPTS \ - -classpath "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar" \ - "-Dmaven.home=${M2_HOME}" "-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \ - ${WRAPPER_LAUNCHER} $MAVEN_CONFIG "$@" diff --git a/.svn/pristine/45/4584e09bab24b8c4ba83d5a3646af5ac154a8069.svn-base b/.svn/pristine/45/4584e09bab24b8c4ba83d5a3646af5ac154a8069.svn-base deleted file mode 100644 index 18b12d8..0000000 --- a/.svn/pristine/45/4584e09bab24b8c4ba83d5a3646af5ac154a8069.svn-base +++ /dev/null @@ -1,83 +0,0 @@ -/** - * - */ -package com.zhazhapan.qiniu; - -import java.io.File; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.InputStream; -import java.net.URL; -import java.net.URLConnection; - -import org.apache.log4j.Logger; - -import com.zhazhapan.qiniu.config.ConfigLoader; -import com.zhazhapan.qiniu.modules.constant.Values; -import com.zhazhapan.qiniu.util.Checker; -import com.zhazhapan.qiniu.util.Formatter; -import com.zhazhapan.qiniu.view.Dialogs; - -import javafx.application.Platform; - -/** - * @author pantao - * - */ -public class Downloader { - - private Logger logger = Logger.getLogger(Downloader.class); - - /** - * 下载文件 - */ - public void downloadFromNet(String downloadURL) { - if (!checkDownloadPath()) { - QiniuApplication.downloadPath = Dialogs.showInputDialog(null, Values.CONFIG_DOWNLOAD_PATH, - System.getProperty("user.home")); - if (!checkDownloadPath()) { - return; - } - ConfigLoader.writeConfig(); - } - ThreadPool.executor.submit(() -> { - checkDownloadPath(); - logger.info("start to download url: " + downloadURL); - int byteread = 0; - File file = new File(QiniuApplication.downloadPath + "/" + Formatter.getFileName(downloadURL)); - String log = "download success from url '" + downloadURL + "' to local '" + file.getAbsolutePath() + "'"; - try { - if (!file.exists()) { - file.createNewFile(); - } - URL url = new URL(downloadURL); - URLConnection conn = url.openConnection(); - InputStream inStream = conn.getInputStream(); - FileOutputStream fs = new FileOutputStream(file); - byte[] buffer = new byte[1024]; - while ((byteread = inStream.read(buffer)) != -1) { - fs.write(buffer, 0, byteread); - } - inStream.close(); - fs.close(); - logger.info(log); - } catch (IOException e) { - log = log.replace("success", "error") + ", message: " + e.getMessage(); - logger.error(log); - Platform.runLater(() -> Dialogs.showException(Values.DOWNLOAD_FILE_ERROR, e)); - } - }); - } - - public boolean checkDownloadPath() { - if (Checker.isNotEmpty(QiniuApplication.downloadPath)) { - File file = new File(QiniuApplication.downloadPath); - if (!file.exists()) { - file.mkdirs(); - logger.info("mkdir '" + QiniuApplication.downloadPath + "' success"); - } - return true; - } - return false; - } -} diff --git a/.svn/pristine/46/46ae1288eb185d8299665a784a054d88dcad8a77.svn-base b/.svn/pristine/46/46ae1288eb185d8299665a784a054d88dcad8a77.svn-base deleted file mode 100644 index ca8fc3a..0000000 --- a/.svn/pristine/46/46ae1288eb185d8299665a784a054d88dcad8a77.svn-base +++ /dev/null @@ -1,37 +0,0 @@ -/** - * - */ -package com.zhazhapan.qiniu; - -import java.util.regex.Matcher; -import java.util.regex.Pattern; - -import org.junit.Test; - -import com.zhazhapan.qiniu.util.Checker; - -/** - * @author pantao - * - */ -public class TestRegexp { - - @Test - public void test() { - Pattern pattern = Pattern.compile("(([^/\\\\:*\"<>|?]+)\\.)*[^/\\\\:*\"<>|?]+(\\?.*)?$", - Pattern.CASE_INSENSITIVE); - Matcher matcher = pattern.matcher("http://devtools.qiniu.com/qiniu.png"); - if (matcher.find()) { - System.out.println(matcher.group(0)); - } - } - - @Test - public void isHyperlink() { - System.out.println(Checker.isHyperLink("https://portal.qiniu.com/bucket/zhazhapan/resource")); - System.out.println(Checker.isHyperLink("http://portal.qiniu.com/bucket/zhazhapan/resource")); - System.out.println(Checker.isHyperLink("portal.qiniu.com/bucket/zhazhapan/resource")); - System.out.println(Checker.isHyperLink("oxns0wnsc.bkt.clouddn.com")); - System.out.println(Checker.isHyperLink("http://portal")); - } -} diff --git a/.svn/pristine/4b/4b9681f2249bfe203d733e56b40874d5bd72dbe1.svn-base b/.svn/pristine/4b/4b9681f2249bfe203d733e56b40874d5bd72dbe1.svn-base deleted file mode 100644 index a3718d3..0000000 Binary files a/.svn/pristine/4b/4b9681f2249bfe203d733e56b40874d5bd72dbe1.svn-base and /dev/null differ diff --git a/.svn/pristine/4e/4e48f2389ce2add1072d938f855066891aa9877c.svn-base b/.svn/pristine/4e/4e48f2389ce2add1072d938f855066891aa9877c.svn-base deleted file mode 100644 index 46ce20d..0000000 --- a/.svn/pristine/4e/4e48f2389ce2add1072d938f855066891aa9877c.svn-base +++ /dev/null @@ -1,281 +0,0 @@ -/** - * - */ -package com.zhazhapan.qiniu.view; - -import java.awt.Desktop; -import java.io.IOException; -import java.io.PrintWriter; -import java.io.StringWriter; -import java.net.URI; -import java.net.URISyntaxException; -import java.util.Optional; - -import org.apache.log4j.Logger; - -import com.zhazhapan.qiniu.QiniuApplication; -import com.zhazhapan.qiniu.config.ConfigLoader; -import com.zhazhapan.qiniu.controller.MainWindowController; -import com.zhazhapan.qiniu.modules.constant.Values; - -import javafx.application.Platform; -import javafx.geometry.Insets; -import javafx.scene.Node; -import javafx.scene.control.Alert; -import javafx.scene.control.Alert.AlertType; -import javafx.scene.control.ButtonBar.ButtonData; -import javafx.scene.control.ButtonType; -import javafx.scene.control.ComboBox; -import javafx.scene.control.Dialog; -import javafx.scene.control.Hyperlink; -import javafx.scene.control.Label; -import javafx.scene.control.TextArea; -import javafx.scene.control.TextField; -import javafx.scene.layout.GridPane; -import javafx.scene.layout.Priority; -import javafx.stage.Modality; -import javafx.stage.StageStyle; -import javafx.stage.Window; - -/** - * @author pantao 对JavaFX对话框进行封装 - */ -public class Dialogs { - - private Logger logger = Logger.getLogger(Dialogs.class); - - public boolean showFileMovableDialog() { - - return false; - } - - public void showInputKeyDialog() { - ButtonType ok = new ButtonType(Values.OK, ButtonData.OK_DONE); - Dialog dialog = getDialog(ok); - GridPane grid = new GridPane(); - grid.setHgap(10); - grid.setVgap(10); - grid.setPadding(new Insets(20, 10, 10, 10)); - - TextField ak = new TextField(); - ak.setMinWidth(400); - ak.setPromptText("Access Key"); - TextField sk = new TextField(); - sk.setPromptText("Secret Key"); - - Hyperlink hyperlink = new Hyperlink("查看我的KEY"); - hyperlink.setOnAction(event -> { - try { - Desktop.getDesktop().browse(new URI("https://portal.qiniu.com/user/key")); - } catch (IOException | URISyntaxException e) { - logger.error("can't open url 'https://portal.qiniu.com/user/key', message: " + e.getMessage()); - } - }); - - grid.add(hyperlink, 0, 0, 2, 1); - - grid.add(new Label("Access Key:"), 0, 1); - grid.add(ak, 1, 1); - grid.add(new Label("Secret Key:"), 0, 2); - grid.add(sk, 1, 2); - - Node okButton = dialog.getDialogPane().lookupButton(ok); - okButton.setDisable(true); - - // 监听文本框的输入状态 - ak.textProperty().addListener((observable, oldValue, newValue) -> { - okButton.setDisable(newValue.trim().isEmpty() || sk.getText().trim().isEmpty()); - }); - sk.textProperty().addListener((observable, oldValue, newValue) -> { - okButton.setDisable(newValue.trim().isEmpty() || ak.getText().trim().isEmpty()); - }); - - dialog.getDialogPane().setContent(grid); - - Platform.runLater(() -> ak.requestFocus()); - - dialog.setResultConverter(dialogButton -> { - if (dialogButton == ok) { - return new String[] { ak.getText(), sk.getText() }; - } - return null; - }); - - Optional result = dialog.showAndWait(); - result.ifPresent(key -> { - ConfigLoader.writeKey(key[0], key[1]); - }); - } - - public void showBucketAddableDialog() { - ButtonType ok = new ButtonType(Values.OK, ButtonData.OK_DONE); - Dialog dialog = getDialog(ok); - GridPane grid = new GridPane(); - grid.setHgap(10); - grid.setVgap(10); - grid.setPadding(new Insets(20, 10, 10, 10)); - - TextField bucket = new TextField(); - bucket.setPromptText(Values.BUCKET_NAME); - TextField url = new TextField(); - url.setPromptText(Values.BUCKET_URL); - // TextField zone = new TextField(); - ComboBox zone = new ComboBox(); - zone.getItems().addAll(Values.BUCKET_NAME_ARRAY); - zone.setValue(Values.BUCKET_NAME_ARRAY[0]); - - grid.add(new Label(Values.BUCKET_NAME), 0, 0); - grid.add(bucket, 1, 0); - grid.add(new Label(Values.BUCKET_URL), 0, 1); - grid.add(url, 1, 1); - grid.add(new Label(Values.BUCKET_ZONE_NAME), 0, 2); - grid.add(zone, 1, 2); - - Node okButton = dialog.getDialogPane().lookupButton(ok); - okButton.setDisable(true); - - // 监听文本框的输入状态 - bucket.textProperty().addListener((observable, oldValue, newValue) -> { - okButton.setDisable(newValue.trim().isEmpty()); - }); - - dialog.getDialogPane().setContent(grid); - - Platform.runLater(() -> bucket.requestFocus()); - - dialog.setResultConverter(dialogButton -> { - if (dialogButton == ok) { - return new String[] { bucket.getText(), zone.getValue() + " " + url.getText() }; - } - return null; - }); - - Optional result = dialog.showAndWait(); - result.ifPresent(res -> { - logger.info("bucket name: " + res[0] + ", zone name: " + res[1]); - Platform.runLater(() -> MainWindowController.getInstance().addItem(res[0])); - QiniuApplication.buckets.put(res[0], res[1]); - ConfigLoader.writeConfig(); - }); - } - - public Dialog getDialog(ButtonType ok) { - Dialog dialog = new Dialog(); - dialog.setTitle(Values.MAIN_TITLE); - dialog.setHeaderText(null); - - dialog.initModality(Modality.APPLICATION_MODAL); - - // 自定义确认和取消按钮 - ButtonType cancel = new ButtonType(Values.CANCEL, ButtonData.CANCEL_CLOSE); - dialog.getDialogPane().getButtonTypes().addAll(ok, cancel); - return dialog; - } - - public static Optional showInformation(String content) { - return showInformation(null, content); - } - - public static Optional showInformation(String header, String content) { - return alert(header, content, AlertType.INFORMATION); - } - - public static Optional showWarning(String content) { - return showWarning(null, content); - } - - public static Optional showWarning(String header, String content) { - return alert(header, content, AlertType.WARNING); - } - - public static Optional showError(String content) { - return showError(null, content); - } - - public static Optional showError(String header, String content) { - return alert(header, content, AlertType.ERROR); - } - - public static Optional showConfirmation(String content) { - return showConfirmation(null, content); - } - - public static Optional showConfirmation(String header, String content) { - return alert(header, content, AlertType.CONFIRMATION); - } - - public static Optional showException(Exception e) { - return showException(null, e); - } - - public static void showFatalError(String header, Exception e) { - showException(header, e); - System.exit(0); - } - - public static Optional showException(String header, Exception e) { - Alert alert = getAlert(header, "错误信息追踪:", AlertType.ERROR); - - StringWriter stringWriter = new StringWriter(); - PrintWriter printWriter = new PrintWriter(stringWriter); - e.printStackTrace(printWriter); - String exception = stringWriter.toString(); - - TextArea textArea = new TextArea(exception); - textArea.setEditable(false); - textArea.setWrapText(true); - - textArea.setMaxWidth(Double.MAX_VALUE); - textArea.setMaxHeight(Double.MAX_VALUE); - GridPane.setVgrow(textArea, Priority.ALWAYS); - GridPane.setHgrow(textArea, Priority.ALWAYS); - - GridPane gridPane = new GridPane(); - gridPane.setMaxWidth(Double.MAX_VALUE); - gridPane.add(textArea, 0, 0); - - alert.getDialogPane().setExpandableContent(gridPane); - - return alert.showAndWait(); - } - - public static Optional alert(String content) { - return alert(null, content); - } - - public static Optional alert(String content, AlertType alertType) { - return alert(null, content, alertType); - } - - public static Optional alert(String header, String content) { - return alert(header, content, AlertType.INFORMATION); - } - - public static Optional alert(String header, String content, AlertType alertType) { - return alert(header, content, alertType, Modality.NONE, null, StageStyle.DECORATED); - } - - public static Optional alert(String header, String content, AlertType alertType, Modality modality, - Window window, StageStyle style) { - return getAlert(header, content, alertType, modality, window, style).showAndWait(); - } - - public static Alert getAlert(String header, String content, AlertType alertType) { - return getAlert(header, content, alertType, Modality.APPLICATION_MODAL, null, StageStyle.DECORATED); - } - - public static Alert getAlert(String header, String content, AlertType alertType, Modality modality, Window window, - StageStyle style) { - Alert alert = new Alert(alertType); - - alert.setTitle(Values.MAIN_TITLE); - alert.setHeaderText(header); - alert.setContentText(content); - - alert.initModality(modality); - alert.initOwner(window); - alert.initStyle(style); - - return alert; - } -} diff --git a/.svn/pristine/55/55cbe9e802040f50fde6c9462aa2c5de921b225e.svn-base b/.svn/pristine/55/55cbe9e802040f50fde6c9462aa2c5de921b225e.svn-base deleted file mode 100644 index 8e46f81..0000000 --- a/.svn/pristine/55/55cbe9e802040f50fde6c9462aa2c5de921b225e.svn-base +++ /dev/null @@ -1,8 +0,0 @@ -/** - * - */ -/** - * @author pantao - * - */ -package com.zhazhapan.qiniu.view; \ No newline at end of file diff --git a/.svn/pristine/57/5799f087d75c138dbb7b8cf131e581034109b014.svn-base b/.svn/pristine/57/5799f087d75c138dbb7b8cf131e581034109b014.svn-base deleted file mode 100644 index bf67b66..0000000 --- a/.svn/pristine/57/5799f087d75c138dbb7b8cf131e581034109b014.svn-base +++ /dev/null @@ -1 +0,0 @@ -@CHARSET "UTF-8"; \ No newline at end of file diff --git a/.svn/pristine/5b/5b260a2e6d169af702d7d96eb73c3447530539da.svn-base b/.svn/pristine/5b/5b260a2e6d169af702d7d96eb73c3447530539da.svn-base deleted file mode 100644 index 88b07aa..0000000 --- a/.svn/pristine/5b/5b260a2e6d169af702d7d96eb73c3447530539da.svn-base +++ /dev/null @@ -1,21 +0,0 @@ -/** - * - */ -package com.zhazhapan.qiniu.util; - -import javafx.scene.input.Clipboard; -import javafx.scene.input.ClipboardContent; - -/** - * @author pantao - * - */ -@SuppressWarnings("restriction") -public class Utils extends com.sun.javafx.util.Utils { - - public static void copyToClipboard(String string) { - ClipboardContent content = new ClipboardContent(); - content.putString(string); - Clipboard.getSystemClipboard().setContent(content); - } -} diff --git a/.svn/pristine/63/632c8b8d948358902f748deceee787111310afde.svn-base b/.svn/pristine/63/632c8b8d948358902f748deceee787111310afde.svn-base deleted file mode 100644 index d858295..0000000 --- a/.svn/pristine/63/632c8b8d948358902f748deceee787111310afde.svn-base +++ /dev/null @@ -1,4 +0,0 @@ - - - - diff --git a/.svn/pristine/65/65f4c2e9f1ca3c948b5f3883e84cd1977822957c.svn-base b/.svn/pristine/65/65f4c2e9f1ca3c948b5f3883e84cd1977822957c.svn-base deleted file mode 100644 index a456079..0000000 --- a/.svn/pristine/65/65f4c2e9f1ca3c948b5f3883e84cd1977822957c.svn-base +++ /dev/null @@ -1,95 +0,0 @@ -/** - * - */ -package com.zhazhapan.qiniu.view; - -import java.util.Date; - -import org.apache.log4j.Logger; - -import com.zhazhapan.qiniu.FileExecutor; -import com.zhazhapan.qiniu.QiniuApplication; -import com.zhazhapan.qiniu.ThreadPool; -import com.zhazhapan.qiniu.config.ConfigLoader; -import com.zhazhapan.qiniu.controller.MainWindowController; -import com.zhazhapan.qiniu.modules.constant.Values; -import com.zhazhapan.qiniu.util.Checker; -import com.zhazhapan.qiniu.util.Formatter; - -import javafx.fxml.FXMLLoader; -import javafx.scene.Scene; -import javafx.scene.layout.BorderPane; -import javafx.stage.Stage; - -/** - * @author pantao - * - */ -public class MainWindow { - - private Stage stage; - - private Logger logger = Logger.getLogger(MainWindow.class); - - public MainWindow() { - - } - - public MainWindow(Stage stage) { - this.stage = stage; - } - - public void init(Stage stage) { - this.stage = stage; - init(); - } - - public void init() { - logger.info("start to init main stage"); - try { - BorderPane root = (BorderPane) FXMLLoader.load(getClass().getResource("MainWindow.fxml")); - Scene scene = new Scene(root); - stage.setScene(scene); - } catch (Exception e) { - logger.error("init stage error: " + e.getMessage()); - Dialogs.showFatalError(Values.INIT_APP_ERROR_HEADER, e); - } - stage.setTitle(Values.MAIN_TITLE); - stage.setResizable(false); - stage.setOnCloseRequest((e) -> { - ThreadPool.shutdown(); - ConfigLoader.checkWorkPath(); - // 将上传日志写入磁盘 - String content = MainWindowController.getInstance().uploadStatusTextArea.getText(); - if (Checker.isNotEmpty(content)) { - String logPath = QiniuApplication.workDir + "/upload_" - + Formatter.dateToString(new Date()).replaceAll("-", "_") + ".log"; - new FileExecutor().saveFile(logPath, content, true); - } - // 将删除记录写入磁盘 - String deleteContent = QiniuApplication.deleteLog.toString(); - if (Checker.isNotEmpty(deleteContent)) { - String logPath = QiniuApplication.workDir + "/delete_" - + Formatter.dateToString(new Date()).replaceAll("-", "_") + ".log"; - new FileExecutor().saveFile(logPath, deleteContent, true); - } - System.exit(0); - }); - QiniuApplication.stage = stage; - } - - public void hide() { - logger.info("hide main stage"); - stage.hide(); - } - - public void show() { - logger.info("show main stage"); - stage.show(); - } - - public void setStage(Stage stage) { - this.stage = stage; - } - -} diff --git a/.svn/pristine/66/66a81e614263d692626aecf6df3bcd672f70bf74.svn-base b/.svn/pristine/66/66a81e614263d692626aecf6df3bcd672f70bf74.svn-base deleted file mode 100644 index 440541d..0000000 --- a/.svn/pristine/66/66a81e614263d692626aecf6df3bcd672f70bf74.svn-base +++ /dev/null @@ -1,83 +0,0 @@ -/** - * - */ -package com.zhazhapan.qiniu.modules.constant; - -/** - * @author pantao - * - */ -public class Values { - - public static final String MAIN_TITLE = "七牛云管理工具"; - - public static final String INIT_APP_ERROR_HEADER = "初始化错误,无法继续运行"; - - public static final String APP_PATH_OF_WINDOWS = "C:/program files/Qiniu Tool"; - - public static final String APP_PATH_OF_UNIX = "/tmp/qiniu/tool"; - - public static final String CONFIG_PATH = "/config.json"; - - public static final String FORMAT_JSON_ERROR = "将字符串格式化为JSON失败"; - - public static final String FATAL_UNKNOW_ERROR = "发生了一些严重的未知错误,程序即将退出"; - - public static final String LOAD_CONFIG_ERROR = "加载配置失败,无法继续运行"; - - public static final String OK = "确的"; - - public static final String CANCEL = "取消"; - - public static final String JSON_TO_OBJECT_ERROR = "将JSON字符串转换成JSON对象失败"; - - public static final String BUCKET_NAME = "空间名称"; - - public static final String BUCKET_ZONE_NAME = "存储区域"; - - public static final String BUCKET_URL = "空间域名"; - - public static final String[] BUCKET_NAME_ARRAY = { "华东", "华北", "华南", "北美" }; - - public static final String FILE_CHOOSER_TITLE = "选择需要上传的文件"; - - public static final String OPEN_FILE_ERROR = "打开文件失败"; - - public static final String UPLOAD_ERROR = "上传文件失败"; - - public static final String UPLOAD_SUCCESS = "上传文件成功"; - - public static final String UPLOADING = "文件上传中。。。。。。\r\n"; - - public static final String NEED_SCHOOSE_BUCKET_OR_FILE = "请先选择一个存储空间或文件"; - - public static final String CONFIGING_UPLOAD_ENVIRONMENT = "正在配置文件上传环境,请耐心等待。。。。。。\r\n"; - - public static final String RELOAD_CONFIG = "是否重新载入配置文件?"; - - public static final String SAVE_FILE_ERROR = "保存文件失败"; - - public static final String DOMAIN_CONFIG_ERROR = "您还没有正确地配置空间域名"; - - public static final int BUCKET_LIST_LIMIT_SIZE = 1000; - - public static final long KB = 1024; - - public static final long MB = KB * 1024; - - public static final long GB = MB * 1024; - - public static final long TB = GB * 1024; - - public static final String REFRESH_SUCCESS = "刷新资源列表成功"; - - public static final String LIST_FILE_ERROR = "获取资源列表失败"; - - public static final String NET_ERROR = "没有连接到网络,无法运行程序"; - - public static final String DELETE_ERROR = "删除文件时发生异常"; - - public static final String CHANGE_FILE_TYPE_ERROR = "删除文件发生异常"; - - public static final String MOVE_OR_RENAME_ERROR = "移动或重命令文件失败"; -} diff --git a/.svn/pristine/69/6968500daab9703f999f70315f749bbd35829dc2.svn-base b/.svn/pristine/69/6968500daab9703f999f70315f749bbd35829dc2.svn-base deleted file mode 100644 index 21586f3..0000000 --- a/.svn/pristine/69/6968500daab9703f999f70315f749bbd35829dc2.svn-base +++ /dev/null @@ -1,47 +0,0 @@ -/** - * - */ -package com.zhazhapan.qiniu.util; - -import java.util.List; -import java.util.regex.Pattern; - -/** - * @author pantao - * - */ -public class Checker { - - public static boolean isNull(Object object) { - return object == null ? true : false; - } - - public static boolean isNotNull(Object object) { - return !isNull(object); - } - - public static boolean isNullOrEmpty(String string) { - return isNull(string) ? true : string.isEmpty(); - } - - public static boolean isNotEmpty(String string) { - return !isNullOrEmpty(string); - } - - public static String checkNull(String string) { - return isNull(string) ? "" : string; - } - - public static boolean isNotEmpty(List list) { - return isNull(list) ? false : !list.isEmpty(); - } - - public static boolean isHyperLink(String string) { - if (isNotEmpty(string)) { - Pattern pattern = Pattern.compile("^(https*://)?([a-z0-9]+\\.)+[a-z0-9]+(/[^\\s])*$", - Pattern.CASE_INSENSITIVE); - return pattern.matcher(string).matches(); - } - return false; - } -} diff --git a/.svn/pristine/6a/6abe378cdd0e36fd3107b733f18db622703d3e17.svn-base b/.svn/pristine/6a/6abe378cdd0e36fd3107b733f18db622703d3e17.svn-base deleted file mode 100644 index eb4fe74..0000000 --- a/.svn/pristine/6a/6abe378cdd0e36fd3107b733f18db622703d3e17.svn-base +++ /dev/null @@ -1,98 +0,0 @@ -package com.zhazhapan.qiniu; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.Map; - -import org.apache.log4j.Logger; -import org.springframework.boot.autoconfigure.SpringBootApplication; - -import com.qiniu.common.Zone; -import com.qiniu.storage.BucketManager; -import com.qiniu.storage.Configuration; -import com.qiniu.storage.UploadManager; -import com.qiniu.util.Auth; -import com.zhazhapan.qiniu.config.ConfigLoader; -import com.zhazhapan.qiniu.model.FileInfo; -import com.zhazhapan.qiniu.model.Key; -import com.zhazhapan.qiniu.modules.constant.Values; -import com.zhazhapan.qiniu.view.MainWindow; - -import javafx.application.Application; -import javafx.collections.ObservableList; -import javafx.stage.Stage; - -/** - * @author pantao - * - */ -@SpringBootApplication -public class QiniuApplication extends Application { - - public static MainWindow mainWindow = null; - - public static Key key = null; - - public static Map zone = new HashMap(); - - /** - * Value包括存储空间和空间域名,用英文空格分隔 - */ - public static Map buckets = new HashMap(); - - private static Logger logger = Logger.getLogger(QiniuApplication.class); - - public static Stage stage = null; - - public static ArrayList prefix = new ArrayList(); - - public static String workDir = null; - - public static Auth auth = null; - - public static UploadManager uploadManager = null; - - public static String upToken = null; - - public static Configuration configuration = null; - - public static BucketManager bucketManager = null; - - public static ObservableList data = null; - - public static StringBuilder deleteLog = new StringBuilder(); - - public static String downloadPath = null; - - /** - * 主程序入口 - */ - public static void main(String[] args) { - logger.info("start to run application"); - String osname = System.getProperties().getProperty("os.name").toLowerCase(); - logger.info("current operation system: " + osname); - if (osname.contains(Values.WINDOW_OS)) { - workDir = Values.APP_PATH_OF_WINDOWS; - } else { - workDir = Values.APP_PATH_OF_UNIX; - } - ConfigLoader.configPath = workDir + Values.CONFIG_PATH; - mainWindow = new MainWindow(); - launch(args); - } - - @Override - public void start(Stage stage) throws Exception { - ConfigLoader.loadConfig(); - mainWindow.init(stage); - mainWindow.show(); - initZone(); - } - - public void initZone() { - zone.put(Values.BUCKET_NAME_ARRAY[0], Zone.zone0()); - zone.put(Values.BUCKET_NAME_ARRAY[1], Zone.zone1()); - zone.put(Values.BUCKET_NAME_ARRAY[2], Zone.zone2()); - zone.put(Values.BUCKET_NAME_ARRAY[3], Zone.zoneNa0()); - } -} diff --git a/.svn/pristine/6a/6ae97b8aa1613c57654064f5a3ae4129e6897549.svn-base b/.svn/pristine/6a/6ae97b8aa1613c57654064f5a3ae4129e6897549.svn-base deleted file mode 100644 index 981d6dd..0000000 --- a/.svn/pristine/6a/6ae97b8aa1613c57654064f5a3ae4129e6897549.svn-base +++ /dev/null @@ -1,43 +0,0 @@ -/** - * - */ -package com.zhazhapan.qiniu.util; - -import java.awt.Desktop; -import java.io.IOException; -import java.net.URI; -import java.net.URISyntaxException; - -import org.apache.log4j.Logger; - -import com.zhazhapan.qiniu.modules.constant.Values; -import com.zhazhapan.qiniu.view.Dialogs; - -import javafx.scene.input.Clipboard; -import javafx.scene.input.ClipboardContent; - -/** - * @author pantao - * - */ -@SuppressWarnings("restriction") -public class Utils extends com.sun.javafx.util.Utils { - - private static Logger logger = Logger.getLogger(Utils.class); - - public static void copyToClipboard(String string) { - ClipboardContent content = new ClipboardContent(); - content.putString(string); - Clipboard.getSystemClipboard().setContent(content); - logger.info("copy '" + string + "' to clipboard"); - } - - public static void openLink(String url) { - try { - Desktop.getDesktop().browse(new URI(url)); - } catch (IOException | URISyntaxException e) { - logger.error("open url '" + url + "' failed, message: " + e.getMessage()); - Dialogs.showException(Values.OPEN_LINK_ERROR, e); - } - } -} diff --git a/.svn/pristine/70/703bd29ecdb83042c74adbafc4e4f39c949480ca.svn-base b/.svn/pristine/70/703bd29ecdb83042c74adbafc4e4f39c949480ca.svn-base deleted file mode 100644 index 0ff39b4..0000000 --- a/.svn/pristine/70/703bd29ecdb83042c74adbafc4e4f39c949480ca.svn-base +++ /dev/null @@ -1,50 +0,0 @@ -/** - * - */ -package com.zhazhapan.qiniu; - -import java.io.BufferedWriter; -import java.io.File; -import java.io.FileWriter; -import java.io.IOException; - -import org.apache.log4j.Logger; - -import com.zhazhapan.qiniu.modules.constant.Values; -import com.zhazhapan.qiniu.view.Dialogs; - -/** - * @author pantao - * - */ -public class FileExecutor { - - private Logger logger = Logger.getLogger(FileExecutor.class); - - public void saveFile(String path, String content) { - saveFile(path, content, false); - } - - public void saveFile(String path, String content, boolean append) { - saveFile(new File(path), content, append); - } - - public void saveFile(File file, String content) { - saveFile(file, content, false); - } - - public void saveFile(File file, String content, boolean append) { - try { - if (!file.exists()) { - file.createNewFile(); - } - BufferedWriter out = new BufferedWriter(new FileWriter(file, append)); - out.write(content); - out.close(); - logger.info("save file '" + file.getAbsolutePath() + "' success"); - } catch (IOException e) { - logger.error("save file failed, messages: " + e.getMessage()); - Dialogs.showException(Values.SAVE_FILE_ERROR, e); - } - } -} diff --git a/.svn/pristine/71/71f13b3842a5da937875e150eb1281af374ee485.svn-base b/.svn/pristine/71/71f13b3842a5da937875e150eb1281af374ee485.svn-base deleted file mode 100644 index 8fe581f..0000000 --- a/.svn/pristine/71/71f13b3842a5da937875e150eb1281af374ee485.svn-base +++ /dev/null @@ -1,62 +0,0 @@ -/** - * - */ -package com.zhazhapan.qiniu.model; - -/** - * @author pantao - * - */ -public class FileInfo { - - private String name; - - private String type; - - private String size; - - private String time; - - public FileInfo() { - - } - - public FileInfo(String name, String type, String size, String time) { - this.name = name; - this.type = type; - this.size = size; - this.time = time; - } - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - public String getType() { - return type; - } - - public void setType(String type) { - this.type = type; - } - - public String getSize() { - return size; - } - - public void setSize(String size) { - this.size = size; - } - - public String getTime() { - return time; - } - - public void setTime(String time) { - this.time = time; - } -} diff --git a/.svn/pristine/75/75825e50cdd30e20048f32d3da1a7ae4a20b973a.svn-base b/.svn/pristine/75/75825e50cdd30e20048f32d3da1a7ae4a20b973a.svn-base deleted file mode 100644 index 839d647..0000000 --- a/.svn/pristine/75/75825e50cdd30e20048f32d3da1a7ae4a20b973a.svn-base +++ /dev/null @@ -1,5 +0,0 @@ -eclipse.preferences.version=1 -encoding//src/main/java=UTF-8 -encoding//src/main/resources=UTF-8 -encoding//src/test/java=UTF-8 -encoding/=UTF-8 diff --git a/.svn/pristine/77/77d0b1a3d8bd9a61166f0cff973bb7e44a173a16.svn-base b/.svn/pristine/77/77d0b1a3d8bd9a61166f0cff973bb7e44a173a16.svn-base deleted file mode 100644 index 04cc8a7..0000000 --- a/.svn/pristine/77/77d0b1a3d8bd9a61166f0cff973bb7e44a173a16.svn-base +++ /dev/null @@ -1,8 +0,0 @@ -/** - * - */ -/** - * @author pantao - * - */ -package com.zhazhapan.qiniu.controller; \ No newline at end of file diff --git a/.svn/pristine/7b/7b89005a071cf15bdefa60523e5f578d6def7b8a.svn-base b/.svn/pristine/7b/7b89005a071cf15bdefa60523e5f578d6def7b8a.svn-base deleted file mode 100644 index b3df209..0000000 Binary files a/.svn/pristine/7b/7b89005a071cf15bdefa60523e5f578d6def7b8a.svn-base and /dev/null differ diff --git a/.svn/pristine/7f/7fad38a5f9adfd40ed386789b3228838ccb87cf7.svn-base b/.svn/pristine/7f/7fad38a5f9adfd40ed386789b3228838ccb87cf7.svn-base deleted file mode 100644 index 1f95309..0000000 --- a/.svn/pristine/7f/7fad38a5f9adfd40ed386789b3228838ccb87cf7.svn-base +++ /dev/null @@ -1,181 +0,0 @@ -/** - * - */ -package com.zhazhapan.qiniu; - -import java.util.ArrayList; -import java.util.Date; - -import org.apache.log4j.Logger; - -import com.qiniu.common.QiniuException; -import com.qiniu.http.Response; -import com.qiniu.storage.BucketManager; -import com.qiniu.storage.model.BatchStatus; -import com.zhazhapan.qiniu.config.QConfig; -import com.zhazhapan.qiniu.controller.MainWindowController; -import com.zhazhapan.qiniu.model.FileInfo; -import com.zhazhapan.qiniu.modules.constant.Values; -import com.zhazhapan.qiniu.util.Checker; -import com.zhazhapan.qiniu.util.Formatter; -import com.zhazhapan.qiniu.view.Dialogs; - -import javafx.collections.FXCollections; -import javafx.collections.ObservableList; - -/** - * @author pantao - * - */ -public class QManager { - - private Logger logger = Logger.getLogger(QManager.class); - - public enum FileAction { - COPY, MOVE - } - - /* - * 设置文件生存时间 - */ - public void setFileLife(String bucket, String key, int days) { - String log = "set file of '" + key + "' life to " + days + " day(s) "; - try { - QiniuApplication.bucketManager.deleteAfterDays(bucket, key, days); - logger.info(log + "success"); - } catch (QiniuException e) { - logger.error(log + "error, message: " + e.getMessage()); - Dialogs.showException(Values.MOVE_OR_RENAME_ERROR, e); - } - } - - /* - * 重命令文件 - */ - public Boolean renameFile(String bucket, String oldName, String newName) { - return moveFile(bucket, oldName, bucket, newName); - } - - /* - * 移动文件 - */ - public boolean moveFile(String fromBucket, String fromKey, String toBucket, String toKey) { - return moveOrCopyFile(fromBucket, fromKey, toBucket, toKey, FileAction.MOVE); - } - - /* - * 移动或复制文件 - */ - public boolean moveOrCopyFile(String fromBucket, String fromKey, String toBucket, String toKey, FileAction action) { - if (new QConfig().checkNet()) { - String log = "move file '" + fromKey + "' from bucket '" + fromBucket + "' to bucket '" + toBucket - + "', and rename file '" + toKey + "'"; - try { - if (action == FileAction.COPY) { - log.replace("move", "copy"); - QiniuApplication.bucketManager.copy(fromBucket, fromKey, toBucket, toKey, true); - } else { - QiniuApplication.bucketManager.move(fromBucket, fromKey, toBucket, toKey, true); - } - logger.info(log + " success"); - return true; - } catch (QiniuException e) { - logger.info(log + " failed, message: " + e.getMessage()); - Dialogs.showException(Values.MOVE_OR_RENAME_ERROR, e); - return false; - } - } - return false; - } - - /* - * 修改文件类型 - */ - public boolean changeType(String fileName, String newType, String bucket) { - if (new QConfig().checkNet()) { - String log = "change file '" + fileName + "' type '" + newType + "' on bucket '" + bucket; - try { - QiniuApplication.bucketManager.changeMime(bucket, fileName, newType); - logger.info(log + "' success"); - return true; - } catch (QiniuException e) { - logger.info(log + "' failed, message: " + e.getMessage()); - Dialogs.showException(Values.CHANGE_FILE_TYPE_ERROR, e); - return false; - } - } - return false; - } - - /* - * 批量删除文件,单次批量请求的文件数量不得超过1000 - */ - public void deleteFiles(ObservableList fileInfos, String bucket) { - if (Checker.isNotEmpty(fileInfos) && new QConfig().checkNet()) { - // 生成待删除的文件列表 - String[] files = new String[fileInfos.size()]; - ArrayList seletecFileInfos = new ArrayList(); - int i = 0; - for (FileInfo fileInfo : fileInfos) { - files[i] = fileInfo.getName(); - seletecFileInfos.add(fileInfo); - i++; - } - try { - BucketManager.BatchOperations batchOperations = new BucketManager.BatchOperations(); - batchOperations.addDeleteOp(bucket, files); - Response response = QiniuApplication.bucketManager.batch(batchOperations); - BatchStatus[] batchStatusList = response.jsonToObject(BatchStatus[].class); - MainWindowController main = MainWindowController.getInstance(); - boolean sear = Checker.isNotEmpty(main.searchTextField.getText()); - ObservableList currentRes = main.resTable.getItems(); - for (i = 0; i < files.length; i++) { - BatchStatus status = batchStatusList[i]; - String deleteLog = Formatter.datetimeToString(new Date()); - String file = files[i]; - if (status.code == 200) { - logger.info("delete file '" + file + "' success"); - deleteLog += "\tsuccess\t"; - QiniuApplication.data.remove(seletecFileInfos.get(i)); - if (sear) { - currentRes.remove(seletecFileInfos.get(i)); - } - } else { - logger.error("delete file '" + file + "' failed, message: " + status.data.error); - deleteLog += "\tfailed\t"; - Dialogs.showError("删除文件:" + file + " 失败"); - } - QiniuApplication.deleteLog.append(deleteLog + bucket + "\t" + file + "\r\n"); - } - } catch (QiniuException e) { - Dialogs.showException(Values.DELETE_ERROR, e); - } - } - } - - /* - * 获取空间文件列表,并映射到FileInfo - */ - public void listFileOfBucket() { - MainWindowController main = MainWindowController.getInstance(); - // 列举空间文件列表 - BucketManager.FileListIterator iterator = QiniuApplication.bucketManager - .createFileListIterator(main.bucketChoiceCombo.getValue(), "", Values.BUCKET_LIST_LIMIT_SIZE, ""); - ArrayList files = new ArrayList(); - logger.info("get file list of bucket"); - // 处理获取的file list结果 - while (iterator.hasNext()) { - com.qiniu.storage.model.FileInfo[] items = iterator.next(); - for (com.qiniu.storage.model.FileInfo item : items) { - // 将七牛的时间单位(100纳秒)转换成毫秒,然后转换成时间 - String time = Formatter.timeStampToString(item.putTime / 10000); - String size = Formatter.formatSize(item.fsize); - FileInfo file = new FileInfo(item.key, item.mimeType, size, time); - files.add(file); - logger.info("file name: " + item.key + ", file type: " + item.mimeType + ", file size: " + size - + ", file time: " + time); - } - } - QiniuApplication.data = FXCollections.observableArrayList(files); - } -} diff --git a/.svn/pristine/81/8196a861947fba6267db30f9541ad028c631e2d2.svn-base b/.svn/pristine/81/8196a861947fba6267db30f9541ad028c631e2d2.svn-base deleted file mode 100644 index 9cc84ea..0000000 Binary files a/.svn/pristine/81/8196a861947fba6267db30f9541ad028c631e2d2.svn-base and /dev/null differ diff --git a/.svn/pristine/8a/8a70f638f6a9c02fe3eecdf0b69214be32aed1ec.svn-base b/.svn/pristine/8a/8a70f638f6a9c02fe3eecdf0b69214be32aed1ec.svn-base deleted file mode 100644 index 019bd74..0000000 --- a/.svn/pristine/8a/8a70f638f6a9c02fe3eecdf0b69214be32aed1ec.svn-base +++ /dev/null @@ -1,143 +0,0 @@ -@REM ---------------------------------------------------------------------------- -@REM Licensed to the Apache Software Foundation (ASF) under one -@REM or more contributor license agreements. See the NOTICE file -@REM distributed with this work for additional information -@REM regarding copyright ownership. The ASF licenses this file -@REM to you under the Apache License, Version 2.0 (the -@REM "License"); you may not use this file except in compliance -@REM with the License. You may obtain a copy of the License at -@REM -@REM http://www.apache.org/licenses/LICENSE-2.0 -@REM -@REM Unless required by applicable law or agreed to in writing, -@REM software distributed under the License is distributed on an -@REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -@REM KIND, either express or implied. See the License for the -@REM specific language governing permissions and limitations -@REM under the License. -@REM ---------------------------------------------------------------------------- - -@REM ---------------------------------------------------------------------------- -@REM Maven2 Start Up Batch script -@REM -@REM Required ENV vars: -@REM JAVA_HOME - location of a JDK home dir -@REM -@REM Optional ENV vars -@REM M2_HOME - location of maven2's installed home dir -@REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands -@REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a key stroke before ending -@REM MAVEN_OPTS - parameters passed to the Java VM when running Maven -@REM e.g. to debug Maven itself, use -@REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 -@REM MAVEN_SKIP_RC - flag to disable loading of mavenrc files -@REM ---------------------------------------------------------------------------- - -@REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on' -@echo off -@REM enable echoing my setting MAVEN_BATCH_ECHO to 'on' -@if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO% - -@REM set %HOME% to equivalent of $HOME -if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%") - -@REM Execute a user defined script before this one -if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre -@REM check for pre script, once with legacy .bat ending and once with .cmd ending -if exist "%HOME%\mavenrc_pre.bat" call "%HOME%\mavenrc_pre.bat" -if exist "%HOME%\mavenrc_pre.cmd" call "%HOME%\mavenrc_pre.cmd" -:skipRcPre - -@setlocal - -set ERROR_CODE=0 - -@REM To isolate internal variables from possible post scripts, we use another setlocal -@setlocal - -@REM ==== START VALIDATION ==== -if not "%JAVA_HOME%" == "" goto OkJHome - -echo. -echo Error: JAVA_HOME not found in your environment. >&2 -echo Please set the JAVA_HOME variable in your environment to match the >&2 -echo location of your Java installation. >&2 -echo. -goto error - -:OkJHome -if exist "%JAVA_HOME%\bin\java.exe" goto init - -echo. -echo Error: JAVA_HOME is set to an invalid directory. >&2 -echo JAVA_HOME = "%JAVA_HOME%" >&2 -echo Please set the JAVA_HOME variable in your environment to match the >&2 -echo location of your Java installation. >&2 -echo. -goto error - -@REM ==== END VALIDATION ==== - -:init - -@REM Find the project base dir, i.e. the directory that contains the folder ".mvn". -@REM Fallback to current working directory if not found. - -set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR% -IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir - -set EXEC_DIR=%CD% -set WDIR=%EXEC_DIR% -:findBaseDir -IF EXIST "%WDIR%"\.mvn goto baseDirFound -cd .. -IF "%WDIR%"=="%CD%" goto baseDirNotFound -set WDIR=%CD% -goto findBaseDir - -:baseDirFound -set MAVEN_PROJECTBASEDIR=%WDIR% -cd "%EXEC_DIR%" -goto endDetectBaseDir - -:baseDirNotFound -set MAVEN_PROJECTBASEDIR=%EXEC_DIR% -cd "%EXEC_DIR%" - -:endDetectBaseDir - -IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig - -@setlocal EnableExtensions EnableDelayedExpansion -for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a -@endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS% - -:endReadAdditionalConfig - -SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe" - -set WRAPPER_JAR="%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.jar" -set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain - -%MAVEN_JAVA_EXE% %JVM_CONFIG_MAVEN_PROPS% %MAVEN_OPTS% %MAVEN_DEBUG_OPTS% -classpath %WRAPPER_JAR% "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" %WRAPPER_LAUNCHER% %MAVEN_CONFIG% %* -if ERRORLEVEL 1 goto error -goto end - -:error -set ERROR_CODE=1 - -:end -@endlocal & set ERROR_CODE=%ERROR_CODE% - -if not "%MAVEN_SKIP_RC%" == "" goto skipRcPost -@REM check for post script, once with legacy .bat ending and once with .cmd ending -if exist "%HOME%\mavenrc_post.bat" call "%HOME%\mavenrc_post.bat" -if exist "%HOME%\mavenrc_post.cmd" call "%HOME%\mavenrc_post.cmd" -:skipRcPost - -@REM pause the script if MAVEN_BATCH_PAUSE is set to 'on' -if "%MAVEN_BATCH_PAUSE%" == "on" pause - -if "%MAVEN_TERMINATE_CMD%" == "on" exit %ERROR_CODE% - -exit /B %ERROR_CODE% diff --git a/.svn/pristine/97/97f11e5242b0e306fafb39aa92a4329473a29953.svn-base b/.svn/pristine/97/97f11e5242b0e306fafb39aa92a4329473a29953.svn-base deleted file mode 100644 index 9482a7f..0000000 --- a/.svn/pristine/97/97f11e5242b0e306fafb39aa92a4329473a29953.svn-base +++ /dev/null @@ -1,19 +0,0 @@ -### 设置### -log4j.rootLogger = stdout,D,E - -log4j.appender.stdout = org.apache.log4j.ConsoleAppender -log4j.appender.stdout.Target = System.out -log4j.appender.stdout.layout = org.apache.log4j.PatternLayout -log4j.appender.stdout.layout.ConversionPattern = [%-5p] %d{yyyy-MM-dd HH:mm:ss,SSS} method:%l%n%m%n - -log4j.appender.D.File = /tmp/qiniu/tool/log.log -log4j.appender.D.Append = true -log4j.appender.D.Threshold = DEBUG -log4j.appender.D.layout = org.apache.log4j.PatternLayout -log4j.appender.D.layout.ConversionPattern = %-d{yyyy-MM-dd HH:mm:ss} [ %t:%r ] - [ %p ] %m%n - -log4j.appender.E.File = /tmp/qiniu/tool/log.log -log4j.appender.E.Append = true -log4j.appender.E.Threshold = ERROR -log4j.appender.E.layout = org.apache.log4j.PatternLayout -log4j.appender.E.layout.ConversionPattern = %-d{yyyy-MM-dd HH:mm:ss} [ %t:%r ] - [ %p ] %m%n \ No newline at end of file diff --git a/.svn/pristine/9c/9c3829c11f1a488025d15d71d8b938baa39ab2f2.svn-base b/.svn/pristine/9c/9c3829c11f1a488025d15d71d8b938baa39ab2f2.svn-base deleted file mode 100644 index 609d1ed..0000000 --- a/.svn/pristine/9c/9c3829c11f1a488025d15d71d8b938baa39ab2f2.svn-base +++ /dev/null @@ -1,68 +0,0 @@ - - - 4.0.0 - - com.zhazhapan - qiniu - 0.0.1-SNAPSHOT - jar - - qiniu - 七牛同步工具 - - - org.springframework.boot - spring-boot-starter-parent - 1.5.7.RELEASE - - - - - UTF-8 - UTF-8 - 1.8 - - - - - com.qiniu - qiniu-java-sdk - [7.2.0, 7.2.99] - - - org.springframework.boot - spring-boot-starter - - - - org.springframework.boot - spring-boot-starter-test - test - - - com.google.code.gson - gson - - - log4j - log4j - 1.2.17 - - - org.slf4j - slf4j-api - - - - - - - org.springframework.boot - spring-boot-maven-plugin - - - - - - diff --git a/.svn/pristine/9c/9cc2e7af7c77b23f11e76f9e5e7726e14a15b964.svn-base b/.svn/pristine/9c/9cc2e7af7c77b23f11e76f9e5e7726e14a15b964.svn-base deleted file mode 100644 index 7d68d87..0000000 Binary files a/.svn/pristine/9c/9cc2e7af7c77b23f11e76f9e5e7726e14a15b964.svn-base and /dev/null differ diff --git a/.svn/pristine/a7/a781ba5306cf6ded366073063e1dbd5fc61e8044.svn-base b/.svn/pristine/a7/a781ba5306cf6ded366073063e1dbd5fc61e8044.svn-base deleted file mode 100644 index 6c20e9f..0000000 --- a/.svn/pristine/a7/a781ba5306cf6ded366073063e1dbd5fc61e8044.svn-base +++ /dev/null @@ -1,40 +0,0 @@ - - - qiniu - - - - - - org.eclipse.wst.common.project.facet.core.builder - - - - - org.eclipse.jdt.core.javabuilder - - - - - org.springframework.ide.eclipse.core.springbuilder - - - - - org.springframework.ide.eclipse.boot.validation.springbootbuilder - - - - - org.eclipse.m2e.core.maven2Builder - - - - - - org.springframework.ide.eclipse.core.springnature - org.eclipse.jdt.core.javanature - org.eclipse.m2e.core.maven2Nature - org.eclipse.wst.common.project.facet.core.nature - - diff --git a/.svn/pristine/a9/a9b2a53e784f7ce09f5998332442ef4b94df6a69.svn-base b/.svn/pristine/a9/a9b2a53e784f7ce09f5998332442ef4b94df6a69.svn-base deleted file mode 100644 index 2b714a4..0000000 --- a/.svn/pristine/a9/a9b2a53e784f7ce09f5998332442ef4b94df6a69.svn-base +++ /dev/null @@ -1,35 +0,0 @@ -/** - * - */ -package com.zhazhapan.qiniu; - -import org.junit.Test; - -import com.zhazhapan.qiniu.util.Checker; -import com.zhazhapan.qiniu.util.Formatter; - -/** - * @author pantao - * - */ -public class RegexpTest { - - @Test - public void testGetFileName() { - String[] files = { "http://oxns0wnsc.bkt.clouddn.com/fims/css/distpicker.css", - "http://oxns0wnsc.bkt.clouddn.com/fims/css/easy-responsive-tabs.css", - "http://oxns0wnsc.bkt.clouddn.com/zhazhapan/test/%E6%BD%98%E6%BB%94-18780459330-Java%E5%BC%80%E5%8F%91.docx" }; - for (String file : files) { - System.out.println(Formatter.getFileName(file)); - } - } - - @Test - public void testHyperlink() { - System.out.println(Checker.isHyperLink("https://portal.qiniu.com/bucket/zhazhapan/resource")); - System.out.println(Checker.isHyperLink("http://portal.qiniu.com/bucket/zhazhapan/resource")); - System.out.println(Checker.isHyperLink("portal.qiniu.com/bucket/zhazhapan/resource")); - System.out.println(Checker.isHyperLink("oxns0wnsc.bkt.clouddn.com")); - System.out.println(Checker.isHyperLink("http://portal")); - } -} diff --git a/.svn/pristine/aa/aa2e3a5a41b7e87b00a5b45635bb0929bf337f8d.svn-base b/.svn/pristine/aa/aa2e3a5a41b7e87b00a5b45635bb0929bf337f8d.svn-base deleted file mode 100644 index 227783b..0000000 --- a/.svn/pristine/aa/aa2e3a5a41b7e87b00a5b45635bb0929bf337f8d.svn-base +++ /dev/null @@ -1,8 +0,0 @@ -/** - * - */ -/** - * @author pantao - * - */ -package com.zhazhapan.qiniu.model; \ No newline at end of file diff --git a/.svn/pristine/ad/adc83b19e793491b1c6ea0fd8b46cd9f32e592fc.svn-base b/.svn/pristine/ad/adc83b19e793491b1c6ea0fd8b46cd9f32e592fc.svn-base deleted file mode 100644 index 8b13789..0000000 --- a/.svn/pristine/ad/adc83b19e793491b1c6ea0fd8b46cd9f32e592fc.svn-base +++ /dev/null @@ -1 +0,0 @@ - diff --git a/.svn/pristine/ad/adf03c9e9acc658ace655cd695022f056336f977.svn-base b/.svn/pristine/ad/adf03c9e9acc658ace655cd695022f056336f977.svn-base deleted file mode 100644 index c315043..0000000 --- a/.svn/pristine/ad/adf03c9e9acc658ace655cd695022f056336f977.svn-base +++ /dev/null @@ -1 +0,0 @@ -distributionUrl=https://repo1.maven.org/maven2/org/apache/maven/apache-maven/3.5.0/apache-maven-3.5.0-bin.zip diff --git a/.svn/pristine/b1/b13e978b4db8dc891e60990dafa44a68d145c10c.svn-base b/.svn/pristine/b1/b13e978b4db8dc891e60990dafa44a68d145c10c.svn-base deleted file mode 100644 index b430255..0000000 --- a/.svn/pristine/b1/b13e978b4db8dc891e60990dafa44a68d145c10c.svn-base +++ /dev/null @@ -1,19 +0,0 @@ -### 设置### -log4j.rootLogger = stdout,D,E - -log4j.appender.stdout = org.apache.log4j.ConsoleAppender -log4j.appender.stdout.Target = System.out -log4j.appender.stdout.layout = org.apache.log4j.PatternLayout -log4j.appender.stdout.layout.ConversionPattern = [%-5p] %d{yyyy-MM-dd HH:mm:ss,SSS} method:%l%n%m%n - -log4j.appender.D.File = /tmp/qiniu.log -log4j.appender.D.Append = true -log4j.appender.D.Threshold = DEBUG -log4j.appender.D.layout = org.apache.log4j.PatternLayout -log4j.appender.D.layout.ConversionPattern = %-d{yyyy-MM-dd HH:mm:ss} [ %t:%r ] - [ %p ] %m%n - -log4j.appender.E.File = /tmp/qiniu.log -log4j.appender.E.Append = true -log4j.appender.E.Threshold = ERROR -log4j.appender.E.layout = org.apache.log4j.PatternLayout -log4j.appender.E.layout.ConversionPattern = %-d{yyyy-MM-dd HH:mm:ss} [ %t:%r ] - [ %p ] %m%n \ No newline at end of file diff --git a/.svn/pristine/b1/b1ab908527447844031011c7631ec6ba3dfb514d.svn-base b/.svn/pristine/b1/b1ab908527447844031011c7631ec6ba3dfb514d.svn-base deleted file mode 100644 index 6030ef8..0000000 --- a/.svn/pristine/b1/b1ab908527447844031011c7631ec6ba3dfb514d.svn-base +++ /dev/null @@ -1,330 +0,0 @@ -/** - * - */ -package com.zhazhapan.qiniu.view; - -import java.io.PrintWriter; -import java.io.StringWriter; -import java.util.Optional; - -import org.apache.log4j.Logger; - -import com.zhazhapan.qiniu.QiniuApplication; -import com.zhazhapan.qiniu.QiManager.FileAction; -import com.zhazhapan.qiniu.config.ConfigLoader; -import com.zhazhapan.qiniu.controller.MainWindowController; -import com.zhazhapan.qiniu.modules.constant.Values; -import com.zhazhapan.qiniu.util.Utils; - -import javafx.application.Platform; -import javafx.geometry.Insets; -import javafx.scene.Node; -import javafx.scene.control.Alert; -import javafx.scene.control.Alert.AlertType; -import javafx.scene.control.ButtonBar.ButtonData; -import javafx.scene.control.ButtonType; -import javafx.scene.control.CheckBox; -import javafx.scene.control.ComboBox; -import javafx.scene.control.Dialog; -import javafx.scene.control.Hyperlink; -import javafx.scene.control.Label; -import javafx.scene.control.TextArea; -import javafx.scene.control.TextField; -import javafx.scene.control.TextInputDialog; -import javafx.scene.layout.GridPane; -import javafx.scene.layout.Priority; -import javafx.stage.Modality; -import javafx.stage.StageStyle; -import javafx.stage.Window; -import javafx.util.Pair; - -/** - * @author pantao 对JavaFX对话框进行封装 - */ -public class Dialogs { - - private Logger logger = Logger.getLogger(Dialogs.class); - - public static String showInputDialog(String header, String content, String defaultValue) { - TextInputDialog dialog = new TextInputDialog(defaultValue); - dialog.setTitle(Values.MAIN_TITLE); - dialog.setHeaderText(header); - dialog.setContentText(content); - - Optional result = dialog.showAndWait(); - if (result.isPresent()) { - return result.get(); - } else { - return null; - } - } - - public Pair showFileMovableDialog(String bucket, String key, boolean setKey) { - MainWindowController main = MainWindowController.getInstance(); - ButtonType ok = new ButtonType(Values.OK, ButtonData.OK_DONE); - Dialog dialog = getDialog(ok); - - TextField keyTextField = new TextField(); - keyTextField.setPrefWidth(300); - keyTextField.setPromptText(Values.FILE_NAME); - keyTextField.setText(key); - ComboBox bucketCombo = new ComboBox(); - bucketCombo.getItems().addAll(main.bucketChoiceCombo.getItems()); - bucketCombo.setValue(bucket); - CheckBox copyasCheckBox = new CheckBox(Values.COPY_AS); - copyasCheckBox.setSelected(true); - - GridPane grid = getGridPane(); - grid.add(copyasCheckBox, 0, 0, 2, 1); - grid.add(new Label(Values.BUCKET_NAME), 0, 1); - grid.add(bucketCombo, 1, 1); - if (setKey) { - grid.add(new Label(Values.FILE_NAME), 0, 2); - grid.add(keyTextField, 1, 2); - Platform.runLater(() -> keyTextField.requestFocus()); - } - - dialog.getDialogPane().setContent(grid); - dialog.setResultConverter(dialogButton -> { - if (dialogButton == ok) { - return new String[] { bucketCombo.getValue(), keyTextField.getText() }; - } - return null; - }); - - Optional result = dialog.showAndWait(); - if (result.isPresent()) { - bucket = bucketCombo.getValue(); - key = keyTextField.getText(); - FileAction action = copyasCheckBox.isSelected() ? FileAction.COPY : FileAction.MOVE; - return new Pair(action, new String[] { bucket, key }); - } else { - return null; - } - } - - public void showInputKeyDialog() { - ButtonType ok = new ButtonType(Values.OK, ButtonData.OK_DONE); - Dialog dialog = getDialog(ok); - - TextField ak = new TextField(); - ak.setMinWidth(400); - ak.setPromptText("Access Key"); - TextField sk = new TextField(); - sk.setPromptText("Secret Key"); - - Hyperlink hyperlink = new Hyperlink("查看我的KEY"); - hyperlink.setOnAction(event -> Utils.openLink("https://portal.qiniu.com/user/key")); - - GridPane grid = getGridPane(); - grid.add(hyperlink, 0, 0, 2, 1); - grid.add(new Label("Access Key:"), 0, 1); - grid.add(ak, 1, 1); - grid.add(new Label("Secret Key:"), 0, 2); - grid.add(sk, 1, 2); - - Node okButton = dialog.getDialogPane().lookupButton(ok); - okButton.setDisable(true); - - // 监听文本框的输入状态 - ak.textProperty().addListener((observable, oldValue, newValue) -> { - okButton.setDisable(newValue.trim().isEmpty() || sk.getText().trim().isEmpty()); - }); - sk.textProperty().addListener((observable, oldValue, newValue) -> { - okButton.setDisable(newValue.trim().isEmpty() || ak.getText().trim().isEmpty()); - }); - - dialog.getDialogPane().setContent(grid); - - Platform.runLater(() -> ak.requestFocus()); - - dialog.setResultConverter(dialogButton -> { - if (dialogButton == ok) { - return new String[] { ak.getText(), sk.getText() }; - } - return null; - }); - - Optional result = dialog.showAndWait(); - result.ifPresent(key -> { - ConfigLoader.writeKey(key[0], key[1]); - }); - } - - public void showBucketAddableDialog() { - ButtonType ok = new ButtonType(Values.OK, ButtonData.OK_DONE); - Dialog dialog = getDialog(ok); - - TextField bucket = new TextField(); - bucket.setPromptText(Values.BUCKET_NAME); - TextField url = new TextField(); - url.setPromptText(Values.BUCKET_URL); - // TextField zone = new TextField(); - ComboBox zone = new ComboBox(); - zone.getItems().addAll(Values.BUCKET_NAME_ARRAY); - zone.setValue(Values.BUCKET_NAME_ARRAY[0]); - - GridPane grid = getGridPane(); - grid.add(new Label(Values.BUCKET_NAME), 0, 0); - grid.add(bucket, 1, 0); - grid.add(new Label(Values.BUCKET_URL), 0, 1); - grid.add(url, 1, 1); - grid.add(new Label(Values.BUCKET_ZONE_NAME), 0, 2); - grid.add(zone, 1, 2); - - Node okButton = dialog.getDialogPane().lookupButton(ok); - okButton.setDisable(true); - - // 监听文本框的输入状态 - bucket.textProperty().addListener((observable, oldValue, newValue) -> { - okButton.setDisable(newValue.trim().isEmpty()); - }); - - dialog.getDialogPane().setContent(grid); - - Platform.runLater(() -> bucket.requestFocus()); - - dialog.setResultConverter(dialogButton -> { - if (dialogButton == ok) { - return new String[] { bucket.getText(), zone.getValue() + " " + url.getText() }; - } - return null; - }); - - Optional result = dialog.showAndWait(); - result.ifPresent(res -> { - logger.info("bucket name: " + res[0] + ", zone name: " + res[1]); - Platform.runLater(() -> MainWindowController.getInstance().addItem(res[0])); - QiniuApplication.buckets.put(res[0], res[1]); - ConfigLoader.writeConfig(); - }); - } - - public GridPane getGridPane() { - GridPane grid = new GridPane(); - grid.setHgap(10); - grid.setVgap(10); - grid.setPadding(new Insets(10, 10, 10, 10)); - return grid; - } - - public Dialog getDialog(ButtonType ok) { - Dialog dialog = new Dialog(); - dialog.setTitle(Values.MAIN_TITLE); - dialog.setHeaderText(null); - - dialog.initModality(Modality.APPLICATION_MODAL); - - // 自定义确认和取消按钮 - ButtonType cancel = new ButtonType(Values.CANCEL, ButtonData.CANCEL_CLOSE); - dialog.getDialogPane().getButtonTypes().addAll(ok, cancel); - return dialog; - } - - public static Optional showInformation(String content) { - return showInformation(null, content); - } - - public static Optional showInformation(String header, String content) { - return alert(header, content, AlertType.INFORMATION); - } - - public static Optional showWarning(String content) { - return showWarning(null, content); - } - - public static Optional showWarning(String header, String content) { - return alert(header, content, AlertType.WARNING); - } - - public static Optional showError(String content) { - return showError(null, content); - } - - public static Optional showError(String header, String content) { - return alert(header, content, AlertType.ERROR); - } - - public static Optional showConfirmation(String content) { - return showConfirmation(null, content); - } - - public static Optional showConfirmation(String header, String content) { - return alert(header, content, AlertType.CONFIRMATION); - } - - public static Optional showException(Exception e) { - return showException(null, e); - } - - public static void showFatalError(String header, Exception e) { - showException(header, e); - System.exit(0); - } - - public static Optional showException(String header, Exception e) { - Alert alert = getAlert(header, "错误信息追踪:", AlertType.ERROR); - - StringWriter stringWriter = new StringWriter(); - PrintWriter printWriter = new PrintWriter(stringWriter); - e.printStackTrace(printWriter); - String exception = stringWriter.toString(); - - TextArea textArea = new TextArea(exception); - textArea.setEditable(false); - textArea.setWrapText(true); - - textArea.setMaxWidth(Double.MAX_VALUE); - textArea.setMaxHeight(Double.MAX_VALUE); - GridPane.setVgrow(textArea, Priority.ALWAYS); - GridPane.setHgrow(textArea, Priority.ALWAYS); - - GridPane gridPane = new GridPane(); - gridPane.setMaxWidth(Double.MAX_VALUE); - gridPane.add(textArea, 0, 0); - - alert.getDialogPane().setExpandableContent(gridPane); - - return alert.showAndWait(); - } - - public static Optional alert(String content) { - return alert(null, content); - } - - public static Optional alert(String content, AlertType alertType) { - return alert(null, content, alertType); - } - - public static Optional alert(String header, String content) { - return alert(header, content, AlertType.INFORMATION); - } - - public static Optional alert(String header, String content, AlertType alertType) { - return alert(header, content, alertType, Modality.NONE, null, StageStyle.DECORATED); - } - - public static Optional alert(String header, String content, AlertType alertType, Modality modality, - Window window, StageStyle style) { - return getAlert(header, content, alertType, modality, window, style).showAndWait(); - } - - public static Alert getAlert(String header, String content, AlertType alertType) { - return getAlert(header, content, alertType, Modality.APPLICATION_MODAL, null, StageStyle.DECORATED); - } - - public static Alert getAlert(String header, String content, AlertType alertType, Modality modality, Window window, - StageStyle style) { - Alert alert = new Alert(alertType); - - alert.setTitle(Values.MAIN_TITLE); - alert.setHeaderText(header); - alert.setContentText(content); - - alert.initModality(modality); - alert.initOwner(window); - alert.initStyle(style); - - return alert; - } -} diff --git a/.svn/pristine/b6/b6961cd7dc61566f8963b820197e25a1638e2106.svn-base b/.svn/pristine/b6/b6961cd7dc61566f8963b820197e25a1638e2106.svn-base deleted file mode 100644 index d1112e7..0000000 --- a/.svn/pristine/b6/b6961cd7dc61566f8963b820197e25a1638e2106.svn-base +++ /dev/null @@ -1,32 +0,0 @@ -/** - * - */ -package com.zhazhapan.qiniu; - -import java.util.concurrent.LinkedBlockingDeque; -import java.util.concurrent.ThreadFactory; -import java.util.concurrent.ThreadPoolExecutor; -import java.util.concurrent.TimeUnit; - -/** - * @author pantao - * - */ -public class ThreadPool { - - public static ThreadPoolExecutor executor = new ThreadPoolExecutor(2, 10, 5, TimeUnit.SECONDS, - new LinkedBlockingDeque(1), new ThreadFactory() { - @Override - public Thread newThread(Runnable r) { - return new Thread(r); - } - }); - - public static void shutdown() { - executor.shutdown(); - } - - public static void shutdownNow() { - executor.shutdownNow(); - } -} diff --git a/.svn/pristine/bd/bd762684f21a371402b2eb03a4a2bd2c7ad64d7d.svn-base b/.svn/pristine/bd/bd762684f21a371402b2eb03a4a2bd2c7ad64d7d.svn-base deleted file mode 100644 index 023037a..0000000 --- a/.svn/pristine/bd/bd762684f21a371402b2eb03a4a2bd2c7ad64d7d.svn-base +++ /dev/null @@ -1,33 +0,0 @@ -/** - * - */ -package com.zhazhapan.qiniu; - -import org.junit.Test; - -import com.google.gson.JsonArray; -import com.google.gson.JsonElement; -import com.google.gson.JsonObject; -import com.google.gson.JsonParser; -import com.zhazhapan.qiniu.util.Checker; - -/** - * @author pantao - * - */ -public class GsonTest { - - public String configJson = "{accesskey:123456,secretkey:abcdef,buckets:[{bucket:zhazhapan,zone:华东}]}"; - - @Test - public void testGson() { - JsonObject json = new JsonParser().parse(configJson).getAsJsonObject(); - JsonElement buckets = json.get("buckets"); - if (Checker.isNotNull(buckets)) { - JsonArray array = buckets.getAsJsonArray(); - for (JsonElement element : array) { - System.out.println(((JsonObject) element).get("bucket").getAsString()); - } - } - } -} diff --git a/.svn/pristine/bd/bd9649b795659115460eb4598712f214a302b672.svn-base b/.svn/pristine/bd/bd9649b795659115460eb4598712f214a302b672.svn-base deleted file mode 100644 index ae060e1..0000000 --- a/.svn/pristine/bd/bd9649b795659115460eb4598712f214a302b672.svn-base +++ /dev/null @@ -1,8 +0,0 @@ -/** - * - */ -/** - * @author pantao - * - */ -package com.zhazhapan.qiniu.util; \ No newline at end of file diff --git a/.svn/pristine/c6/c6131d6a4f5895d155af71023eef6cdc3d46e23e.svn-base b/.svn/pristine/c6/c6131d6a4f5895d155af71023eef6cdc3d46e23e.svn-base deleted file mode 100644 index 5fa6320..0000000 --- a/.svn/pristine/c6/c6131d6a4f5895d155af71023eef6cdc3d46e23e.svn-base +++ /dev/null @@ -1,53 +0,0 @@ -/** - * - */ -package com.zhazhapan.qiniu; - -import java.io.BufferedWriter; -import java.io.File; -import java.io.FileWriter; -import java.io.IOException; - -import org.apache.log4j.Logger; - -import com.zhazhapan.qiniu.modules.constant.Values; -import com.zhazhapan.qiniu.util.Checker; -import com.zhazhapan.qiniu.view.Dialogs; - -/** - * @author pantao - * - */ -public class FileExecutor { - - private Logger logger = Logger.getLogger(FileExecutor.class); - - public void saveFile(String path, String content) { - saveFile(path, content, false); - } - - public void saveFile(String path, String content, boolean append) { - saveFile(new File(path), content, append); - } - - public void saveFile(File file, String content) { - saveFile(file, content, false); - } - - public void saveFile(File file, String content, boolean append) { - if (Checker.isNotNull(file)) { - try { - if (!file.exists()) { - file.createNewFile(); - } - BufferedWriter out = new BufferedWriter(new FileWriter(file, append)); - out.write(content); - out.close(); - logger.info("save file '" + file.getAbsolutePath() + "' success"); - } catch (IOException e) { - logger.error("save file failed, messages: " + e.getMessage()); - Dialogs.showException(Values.SAVE_FILE_ERROR, e); - } - } - } -} diff --git a/.svn/pristine/c9/c9094061af8fb2d99bd07c7f791ba40d03551ef4.svn-base b/.svn/pristine/c9/c9094061af8fb2d99bd07c7f791ba40d03551ef4.svn-base deleted file mode 100644 index 4538a27..0000000 --- a/.svn/pristine/c9/c9094061af8fb2d99bd07c7f791ba40d03551ef4.svn-base +++ /dev/null @@ -1,93 +0,0 @@ -/** - * - */ -package com.zhazhapan.qiniu.view; - -import java.util.Date; - -import org.apache.log4j.Logger; - -import com.zhazhapan.qiniu.FileExecutor; -import com.zhazhapan.qiniu.QiniuApplication; -import com.zhazhapan.qiniu.config.ConfigLoader; -import com.zhazhapan.qiniu.controller.MainWindowController; -import com.zhazhapan.qiniu.modules.constant.Values; -import com.zhazhapan.qiniu.util.Checker; -import com.zhazhapan.qiniu.util.Formatter; - -import javafx.fxml.FXMLLoader; -import javafx.scene.Scene; -import javafx.scene.layout.BorderPane; -import javafx.stage.Stage; - -/** - * @author pantao - * - */ -public class MainWindow { - - private Stage stage; - - private Logger logger = Logger.getLogger(MainWindow.class); - - public MainWindow() { - - } - - public MainWindow(Stage stage) { - this.stage = stage; - } - - public void init(Stage stage) { - this.stage = stage; - init(); - } - - public void init() { - logger.info("start to init main stage"); - try { - BorderPane root = (BorderPane) FXMLLoader.load(getClass().getResource("MainWindow.fxml")); - Scene scene = new Scene(root); - stage.setScene(scene); - } catch (Exception e) { - logger.error("init stage error: " + e.getMessage()); - Dialogs.showFatalError(Values.INIT_APP_ERROR_HEADER, e); - } - stage.setTitle(Values.MAIN_TITLE); - stage.setResizable(false); - stage.setOnCloseRequest((e) -> { - ConfigLoader.checkWorkPath(); - // 将上传日志写入磁盘 - String content = MainWindowController.getInstance().uploadStatusTextArea.getText(); - if (Checker.isNotEmpty(content)) { - String logPath = QiniuApplication.workDir + "/upload_" - + Formatter.dateToString(new Date()).replaceAll("-", "_") + ".log"; - new FileExecutor().saveFile(logPath, content, true); - } - // 将删除记录写入磁盘 - String deleteContent = QiniuApplication.deleteLog.toString(); - if (Checker.isNotEmpty(deleteContent)) { - String logPath = QiniuApplication.workDir + "/delete_" - + Formatter.dateToString(new Date()).replaceAll("-", "_") + ".log"; - new FileExecutor().saveFile(logPath, deleteContent, true); - } - System.exit(0); - }); - QiniuApplication.stage = stage; - } - - public void hide() { - logger.info("hide main stage"); - stage.hide(); - } - - public void show() { - logger.info("show main stage"); - stage.show(); - } - - public void setStage(Stage stage) { - this.stage = stage; - } - -} diff --git a/.svn/pristine/cc/cc1dba7c00a8db66b3d91cdb13f59caed6612796.svn-base b/.svn/pristine/cc/cc1dba7c00a8db66b3d91cdb13f59caed6612796.svn-base deleted file mode 100644 index 944975c..0000000 --- a/.svn/pristine/cc/cc1dba7c00a8db66b3d91cdb13f59caed6612796.svn-base +++ /dev/null @@ -1,93 +0,0 @@ -/** - * - */ -package com.zhazhapan.qiniu.util; - -import java.text.DecimalFormat; -import java.text.SimpleDateFormat; -import java.util.Date; -import java.util.regex.Matcher; -import java.util.regex.Pattern; - -import org.apache.log4j.Logger; - -import com.google.gson.Gson; -import com.google.gson.GsonBuilder; -import com.google.gson.JsonElement; -import com.google.gson.JsonParser; -import com.zhazhapan.qiniu.modules.constant.Values; -import com.zhazhapan.qiniu.view.Dialogs; - -/** - * @author pantao - * - */ -public class Formatter { - - private static Logger logger = Logger.getLogger(Formatter.class); - - public static String formatSize(long size) { - if (size < Values.KB) { - return size + " B"; - } else if (size < Values.MB) { - return decimalFormat((double) size / Values.KB) + " KB"; - } else if (size < Values.GB) { - return decimalFormat((double) size / Values.MB) + " MB"; - } else if (size < Values.TB) { - return decimalFormat((double) size / Values.GB) + " GB"; - } else { - return decimalFormat((double) size / Values.TB) + " TB"; - } - } - - public static String decimalFormat(double number) { - return decimalFormat(number, "#0.00"); - } - - public static String decimalFormat(double number, String format) { - return new DecimalFormat(format).format(number); - } - - public static String timeStampToString(long time) { - return new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(time); - } - - public static String jsonFormat(String string) { - String json; - try { - Gson gson = new GsonBuilder().setPrettyPrinting().create(); - JsonParser jp = new JsonParser(); - JsonElement je = jp.parse(string); - json = gson.toJson(je); - } catch (Exception e) { - Dialogs.showException(Values.FORMAT_JSON_ERROR, e); - logger.error("format json string error,json: " + string); - json = string; - } - return json; - } - - public static String dateToString(Date date) { - return new SimpleDateFormat("yyyy-MM-dd").format(checkDate(date)); - } - - public static String datetimeToString(Date date) { - return new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(checkDate(date)); - } - - public static String getFileName(String string) { - if (Checker.isNotEmpty(string)) { - Pattern pattern = Pattern.compile("(([^/\\\\:*\"<>|?]+)\\.)*[^/\\\\:*\"<>|?]+(\\?.*)?$", - Pattern.CASE_INSENSITIVE); - Matcher matcher = pattern.matcher(string); - if (matcher.find() && Checker.isNotEmpty(matcher.group(0))) { - return matcher.group(0).split("\\?")[0]; - } - } - return "undefined"; - } - - private static Date checkDate(Date date) { - return Checker.isNull(date) ? new Date() : date; - } -} diff --git a/.svn/pristine/ce/ce65543e9da97dbfd4c5779875481fc410a14890.svn-base b/.svn/pristine/ce/ce65543e9da97dbfd4c5779875481fc410a14890.svn-base deleted file mode 100644 index aca8740..0000000 --- a/.svn/pristine/ce/ce65543e9da97dbfd4c5779875481fc410a14890.svn-base +++ /dev/null @@ -1,83 +0,0 @@ -/** - * - */ -package com.zhazhapan.qiniu.config; - -import java.io.IOException; -import java.io.InputStream; -import java.net.URL; -import java.nio.file.Paths; - -import org.apache.log4j.Logger; - -import com.qiniu.storage.BucketManager; -import com.qiniu.storage.Configuration; -import com.qiniu.storage.UploadManager; -import com.qiniu.storage.persistent.FileRecorder; -import com.qiniu.util.Auth; -import com.zhazhapan.qiniu.QiniuApplication; -import com.zhazhapan.qiniu.modules.constant.Values; -import com.zhazhapan.qiniu.view.Dialogs; - -import javafx.application.Platform; - -/** - * @author pantao - * - */ - -public class QiConfig { - - private Logger logger = Logger.getLogger(QiConfig.class); - - /** - * 创建上传需要的Auth - */ - public void createAuth(String ak, String sk) { - QiniuApplication.auth = Auth.create(ak, sk); - } - - /** - * 配置文件上传环境 - */ - public boolean configUploadEnv(String zone, String bucket) { - if (!checkNet()) { - Platform.runLater(() -> { - Dialogs.showError(Values.NET_ERROR); - System.exit(0); - }); - return false; - } - logger.info("config file upload environment"); - // 构造一个带指定Zone对象的配置类 - Configuration configuration = new Configuration(QiniuApplication.zone.get(zone)); - // 生成上传凭证,然后准备上传 - String localTempDir = Paths.get(QiniuApplication.workDir, bucket).toString(); - try { - FileRecorder fileRecorder = new FileRecorder(localTempDir); - QiniuApplication.uploadManager = new UploadManager(configuration, fileRecorder); - } catch (IOException e1) { - logger.error("load local temp directory failed, can't use file recorder"); - QiniuApplication.uploadManager = new UploadManager(configuration); - } - QiniuApplication.configuration = configuration; - QiniuApplication.upToken = QiniuApplication.auth.uploadToken(bucket); - QiniuApplication.bucketManager = new BucketManager(QiniuApplication.auth, configuration); - return true; - } - - /** - * 检查是否连接网络 - */ - public boolean checkNet() { - try { - URL url = new URL("https://www.qiniu.com/"); - InputStream in = url.openStream(); - in.close(); - return true; - } catch (IOException e) { - logger.error("doesn't connect internate"); - return false; - } - } -} diff --git a/.svn/pristine/cf/cf312811015204f2128d5591904fef8323de3939.svn-base b/.svn/pristine/cf/cf312811015204f2128d5591904fef8323de3939.svn-base deleted file mode 100644 index 1e9ee30..0000000 --- a/.svn/pristine/cf/cf312811015204f2128d5591904fef8323de3939.svn-base +++ /dev/null @@ -1,8 +0,0 @@ -/** - * - */ -/** - * @author pantao - * - */ -package com.zhazhapan.qiniu.config; \ No newline at end of file diff --git a/.svn/pristine/d6/d654da0eb3b8d0d09660d140918e85c8005637d9.svn-base b/.svn/pristine/d6/d654da0eb3b8d0d09660d140918e85c8005637d9.svn-base deleted file mode 100644 index 43f3e75..0000000 --- a/.svn/pristine/d6/d654da0eb3b8d0d09660d140918e85c8005637d9.svn-base +++ /dev/null @@ -1,28 +0,0 @@ -# 七牛云——对象存储管理工具介绍 - -**由于我是一个七牛的重度使用者(主要是对象存储),每次上传文件、复制链接、下载文件都必须用浏览器打开网页,而且还要登录,感觉好麻烦啊,干脆就自己开发了一个这样的工具(使用JavaFX编写),打包成jar包。** - -**主要功能就是文件的上传下载,获取存储空间中的文件列表,搜索文件(支持正则表达式),复制文件外链,删除文件,移动(或复制)文件,重命名文件名,设置文件的生存时间。** - -**功能截图:** - -- 主窗口界面: - - ![程序主界面](http://img.blog.csdn.net/20171015221834257?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvcXFfMjY5NTQ3NzM=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast) - -- 资源管理界面: - - ![资源管理界面](http://img.blog.csdn.net/20171015222108447?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvcXFfMjY5NTQ3NzM=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast) - - > 说明:操作文件时,需要选中文件才能操作(支持多选),由于下载私有空间的文件需要临时授权,所以文件的下载分为私有下载(生成临时授权然后下载文件)和公有下载(直接下载文件)。 - - *移动文件的界面:* - - ![移动文件界面](http://img.blog.csdn.net/20171015222512819?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvcXFfMjY5NTQ3NzM=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast) - - > 说明:勾选“保存文件副本”时表示当前操作为复制,不勾选时表示移动(会删除本存储空间的文件),默认勾选。 - - -- [**下载jar包**](http://oq3iwfipo.bkt.clouddn.com/tools/zhazhapan/qiniu.jar "七牛云——对象存储管理工具jar包下载地址") - -- [**项目源代码**](https://github.com/zhazhapan/qiniu "七牛云——对象存储管理工具项目源码地址") \ No newline at end of file diff --git a/.svn/pristine/de/de97481b76fdb4657156fa3688991dfcc56006d1.svn-base b/.svn/pristine/de/de97481b76fdb4657156fa3688991dfcc56006d1.svn-base deleted file mode 100644 index 65d8191..0000000 --- a/.svn/pristine/de/de97481b76fdb4657156fa3688991dfcc56006d1.svn-base +++ /dev/null @@ -1,238 +0,0 @@ -/** - * - */ -package com.zhazhapan.qiniu; - -import java.io.UnsupportedEncodingException; -import java.net.URLEncoder; -import java.util.ArrayList; -import java.util.Date; - -import org.apache.log4j.Logger; - -import com.qiniu.common.QiniuException; -import com.qiniu.http.Response; -import com.qiniu.storage.BucketManager; -import com.qiniu.storage.model.BatchStatus; -import com.zhazhapan.qiniu.config.QiConfig; -import com.zhazhapan.qiniu.controller.MainWindowController; -import com.zhazhapan.qiniu.model.FileInfo; -import com.zhazhapan.qiniu.modules.constant.Values; -import com.zhazhapan.qiniu.util.Checker; -import com.zhazhapan.qiniu.util.Formatter; -import com.zhazhapan.qiniu.view.Dialogs; - -import javafx.collections.FXCollections; -import javafx.collections.ObservableList; - -/** - * @author pantao - * - */ -public class QiManager { - - private Logger logger = Logger.getLogger(QiManager.class); - - public enum FileAction { - // 复制或移动文件 - COPY, MOVE - } - - /** - * 私有下载 - */ - public void privateDownload(String fileName, String domain) { - try { - String encodedFileName = URLEncoder.encode(fileName, "utf-8"); - String publicUrl = String.format("%s/%s", domain, encodedFileName); - // 自定义链接过期时间(小时) - long expireInSeconds = 24; - new Downloader().downloadFromNet(QiniuApplication.auth.privateDownloadUrl(publicUrl, expireInSeconds)); - } catch (UnsupportedEncodingException e) { - urlError(e); - } - } - - /** - * 公有下载 - */ - public void publicDownload(String fileName, String domain) { - String url = getPublicURL(fileName, domain); - if (Checker.isNotEmpty(url)) { - new Downloader().downloadFromNet(url); - } - } - - public String getPublicURL(String fileName, String domain) { - try { - String encodedFileName = URLEncoder.encode(fileName, "utf-8"); - return String.format("%s/%s", domain, encodedFileName); - } catch (UnsupportedEncodingException e) { - urlError(e); - return null; - } - } - - /** - * 更新镜像源 - */ - public void updateFile(String bucket, String key) { - String log = "update file '" + key + "' on bucket '" + bucket; - try { - QiniuApplication.bucketManager.prefetch(bucket, key); - logger.info(log + "' success"); - } catch (QiniuException e) { - logger.error(log + "' error, message: " + e.getMessage()); - Dialogs.showException(Values.UPDATE_ERROR, e); - } - } - - /** - * 设置文件生存时间 - */ - public void setFileLife(String bucket, String key, int days) { - String log = "set file of '" + key + "' life to " + days + " day(s) "; - try { - QiniuApplication.bucketManager.deleteAfterDays(bucket, key, days); - logger.info(log + "success"); - } catch (QiniuException e) { - logger.error(log + "error, message: " + e.getMessage()); - Dialogs.showException(Values.MOVE_OR_RENAME_ERROR, e); - } - } - - /** - * 重命令文件 - */ - public Boolean renameFile(String bucket, String oldName, String newName) { - return moveFile(bucket, oldName, bucket, newName); - } - - /** - * 移动文件 - */ - public boolean moveFile(String fromBucket, String fromKey, String toBucket, String toKey) { - return moveOrCopyFile(fromBucket, fromKey, toBucket, toKey, FileAction.MOVE); - } - - /** - * 移动或复制文件 - */ - public boolean moveOrCopyFile(String fromBucket, String fromKey, String toBucket, String toKey, FileAction action) { - if (new QiConfig().checkNet()) { - String log = "move file '" + fromKey + "' from bucket '" + fromBucket + "' to bucket '" + toBucket - + "', and rename file '" + toKey + "'"; - try { - if (action == FileAction.COPY) { - log = log.replaceAll("^move", "copy"); - QiniuApplication.bucketManager.copy(fromBucket, fromKey, toBucket, toKey, true); - } else { - QiniuApplication.bucketManager.move(fromBucket, fromKey, toBucket, toKey, true); - } - logger.info(log + " success"); - return true; - } catch (QiniuException e) { - logger.error(log + " failed, message: " + e.getMessage()); - Dialogs.showException(Values.MOVE_OR_RENAME_ERROR, e); - return false; - } - } - return false; - } - - /** - * 修改文件类型 - */ - public boolean changeType(String fileName, String newType, String bucket) { - if (new QiConfig().checkNet()) { - String log = "change file '" + fileName + "' type '" + newType + "' on bucket '" + bucket; - try { - QiniuApplication.bucketManager.changeMime(bucket, fileName, newType); - logger.info(log + "' success"); - return true; - } catch (QiniuException e) { - logger.error(log + "' failed, message: " + e.getMessage()); - Dialogs.showException(Values.CHANGE_FILE_TYPE_ERROR, e); - return false; - } - } - return false; - } - - /** - * 批量删除文件,单次批量请求的文件数量不得超过1000 - */ - public void deleteFiles(ObservableList fileInfos, String bucket) { - if (Checker.isNotEmpty(fileInfos) && new QiConfig().checkNet()) { - // 生成待删除的文件列表 - String[] files = new String[fileInfos.size()]; - ArrayList seletecFileInfos = new ArrayList(); - int i = 0; - for (FileInfo fileInfo : fileInfos) { - files[i] = fileInfo.getName(); - seletecFileInfos.add(fileInfo); - i++; - } - try { - BucketManager.BatchOperations batchOperations = new BucketManager.BatchOperations(); - batchOperations.addDeleteOp(bucket, files); - Response response = QiniuApplication.bucketManager.batch(batchOperations); - BatchStatus[] batchStatusList = response.jsonToObject(BatchStatus[].class); - MainWindowController main = MainWindowController.getInstance(); - boolean sear = Checker.isNotEmpty(main.searchTextField.getText()); - ObservableList currentRes = main.resTable.getItems(); - for (i = 0; i < files.length; i++) { - BatchStatus status = batchStatusList[i]; - String deleteLog = Formatter.datetimeToString(new Date()); - String file = files[i]; - if (status.code == 200) { - logger.info("delete file '" + file + "' success"); - deleteLog += "\tsuccess\t"; - QiniuApplication.data.remove(seletecFileInfos.get(i)); - if (sear) { - currentRes.remove(seletecFileInfos.get(i)); - } - } else { - logger.error("delete file '" + file + "' failed, message: " + status.data.error); - deleteLog += "\tfailed\t"; - Dialogs.showError("删除文件:" + file + " 失败"); - } - QiniuApplication.deleteLog.append(deleteLog + bucket + "\t" + file + "\r\n"); - } - } catch (QiniuException e) { - Dialogs.showException(Values.DELETE_ERROR, e); - } - } - } - - /** - * 获取空间文件列表,并映射到FileInfo - */ - public void listFileOfBucket() { - MainWindowController main = MainWindowController.getInstance(); - // 列举空间文件列表 - BucketManager.FileListIterator iterator = QiniuApplication.bucketManager - .createFileListIterator(main.bucketChoiceCombo.getValue(), "", Values.BUCKET_LIST_LIMIT_SIZE, ""); - ArrayList files = new ArrayList(); - logger.info("get file list of bucket"); - // 处理获取的file list结果 - while (iterator.hasNext()) { - com.qiniu.storage.model.FileInfo[] items = iterator.next(); - for (com.qiniu.storage.model.FileInfo item : items) { - // 将七牛的时间单位(100纳秒)转换成毫秒,然后转换成时间 - String time = Formatter.timeStampToString(item.putTime / 10000); - String size = Formatter.formatSize(item.fsize); - FileInfo file = new FileInfo(item.key, item.mimeType, size, time); - files.add(file); - logger.info("file name: " + item.key + ", file type: " + item.mimeType + ", file size: " + size - + ", file time: " + time); - } - } - QiniuApplication.data = FXCollections.observableArrayList(files); - } - - private void urlError(Exception e) { - logger.error("generate url error: " + e.getMessage()); - Dialogs.showException(Values.GENERATE_URL_ERROR, e); - } -} diff --git a/.svn/pristine/e1/e1d8a5e5b0495ab00929407c30e150aa3b5949e5.svn-base b/.svn/pristine/e1/e1d8a5e5b0495ab00929407c30e150aa3b5949e5.svn-base deleted file mode 100644 index 714351a..0000000 --- a/.svn/pristine/e1/e1d8a5e5b0495ab00929407c30e150aa3b5949e5.svn-base +++ /dev/null @@ -1,5 +0,0 @@ -eclipse.preferences.version=1 -org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 -org.eclipse.jdt.core.compiler.compliance=1.8 -org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning -org.eclipse.jdt.core.compiler.source=1.8 diff --git a/.svn/pristine/ed/ed10b343e9d14f2622057d6c227f5fc270eb1de8.svn-base b/.svn/pristine/ed/ed10b343e9d14f2622057d6c227f5fc270eb1de8.svn-base deleted file mode 100644 index 3c21159..0000000 --- a/.svn/pristine/ed/ed10b343e9d14f2622057d6c227f5fc270eb1de8.svn-base +++ /dev/null @@ -1,211 +0,0 @@ -/** - * - */ -package com.zhazhapan.qiniu.config; - -import java.io.BufferedReader; -import java.io.BufferedWriter; -import java.io.File; -import java.io.FileReader; -import java.io.FileWriter; -import java.io.IOException; -import java.util.Map; - -import org.apache.log4j.Logger; - -import com.google.gson.Gson; -import com.google.gson.JsonArray; -import com.google.gson.JsonElement; -import com.google.gson.JsonObject; -import com.google.gson.JsonParser; -import com.zhazhapan.qiniu.QiniuApplication; -import com.zhazhapan.qiniu.controller.MainWindowController; -import com.zhazhapan.qiniu.model.Key; -import com.zhazhapan.qiniu.modules.constant.Values; -import com.zhazhapan.qiniu.util.Checker; -import com.zhazhapan.qiniu.util.Formatter; -import com.zhazhapan.qiniu.view.Dialogs; - -import javafx.application.Platform; -import javafx.event.ActionEvent; - -/** - * @author pantao - * - */ -public class ConfigLoader { - - private static Logger logger = Logger.getLogger(ConfigLoader.class); - - public static String configPath = null; - - /** - * 加载配置文件 - */ - public static void loadConfig() { - logger.info("start to load configuration"); - File config = new File(configPath); - if (config.exists()) { - // 读取配置文件内容 - JsonObject json = readConfig(); - if (Checker.isNull(json)) { - showInputKeyDialog(); - } else { - // 读取Key - try { - String ak = json.get("accesskey").getAsString(); - String sk = json.get("secretkey").getAsString(); - QiniuApplication.key = new Key(ak, sk); - new QiConfig().createAuth(ak, sk); - } catch (Exception e) { - logger.error("read key from configuration failed, message: " + e.getMessage()); - Dialogs.showException(Values.LOAD_CONFIG_ERROR, e); - showInputKeyDialog(); - } - // 读取Bucket - JsonElement buckets = json.get("buckets"); - if (Checker.isNotNull(buckets)) { - logger.info("load buckets into memory"); - JsonArray array = buckets.getAsJsonArray(); - boolean setvalue = true; - for (JsonElement element : array) { - JsonObject obj = (JsonObject) element; - String bucket = obj.get("bucket").getAsString(); - JsonElement url = obj.get("url"); - String zone = obj.get("zone").getAsString(); - String zones = zone + " " + (Checker.isNull(url) ? "" : url.getAsString()); - QiniuApplication.buckets.put(bucket, zones); - Platform.runLater(() -> MainWindowController.getInstance().addItem(bucket)); - if (setvalue) { - Platform.runLater(() -> { - MainWindowController.getInstance().bucketChoiceCombo.setValue(bucket); - MainWindowController.getInstance().zoneText.setText(zone); - }); - setvalue = false; - } - } - } else { - MainWindowController.getInstance().showBucketAddableDialog(new ActionEvent()); - } - // 读取文件前缀 - JsonElement prefix = json.get("prefix"); - if (Checker.isNotNull(prefix)) { - JsonArray array = prefix.getAsJsonArray(); - Platform.runLater(() -> { - for (JsonElement element : array) { - String string = element.getAsString(); - QiniuApplication.prefix.add(string); - MainWindowController.getInstance().filePrefixCombo.getItems().add(string); - } - }); - } - // 读取下载的目录 - JsonElement download = json.get("download"); - if (Checker.isNotNull(download)) { - QiniuApplication.downloadPath = download.getAsString(); - } - } - } else { - logger.info("there is no configuration file, starting to create"); - checkWorkPath(); - // 创建配置文件 - try { - config.createNewFile(); - logger.info("create file 'qiniu.conf' success"); - } catch (IOException e) { - logger.error("create configuration file failed, messages: " + e.getMessage()); - Dialogs.showFatalError(Values.LOAD_CONFIG_ERROR, e); - } - showInputKeyDialog(); - } - // 如果Key是Null则退出程序 - if (Checker.isNull(QiniuApplication.key)) { - System.exit(0); - } - } - - /** - * 检测工作文件夹是否存在 - */ - public static void checkWorkPath() { - File dir = new File(QiniuApplication.workDir); - if (!dir.exists()) { - dir.mkdirs(); - logger.info("mkdir '" + QiniuApplication.workDir + "' success"); - } - } - - /** - * 初始状态时要求用户输入AccessKey和SecretKey,否则退出程序 - */ - public static void showInputKeyDialog() { - logger.info("show dialog to require user input key"); - new Dialogs().showInputKeyDialog(); - } - - public static void writeKey(String accessKey, String secretKey) { - QiniuApplication.key = new Key(accessKey, secretKey); - writeConfig(); - } - - public static JsonObject readConfig() { - StringBuilder config = new StringBuilder(); - JsonObject jsonObject = null; - try { - logger.info("load configuration into memory"); - BufferedReader reader = new BufferedReader(new FileReader(configPath)); - String line; - while ((line = reader.readLine()) != null) { - config.append(line); - } - reader.close(); - jsonObject = new JsonParser().parse(config.toString()).getAsJsonObject(); - } catch (IOException e) { - logger.error("load configuration error, messages: " + e.getMessage()); - Dialogs.showFatalError(Values.LOAD_CONFIG_ERROR, e); - } catch (Exception e) { - logger.error("convert json string to json object failed, app'll reset"); - Dialogs.showException(Values.JSON_TO_OBJECT_ERROR, e); - } - return jsonObject; - } - - public static void writeConfig() { - JsonObject config = new JsonObject(); - // Key - config.addProperty("accesskey", QiniuApplication.key.getAccessKey()); - config.addProperty("secretkey", QiniuApplication.key.getSecretKey()); - JsonArray buckets = new JsonArray(); - // Bucket - for (Map.Entry entry : QiniuApplication.buckets.entrySet()) { - JsonObject json = new JsonObject(); - json.addProperty("bucket", entry.getKey()); - String[] zones = entry.getValue().split(" "); - json.addProperty("zone", zones[0]); - json.addProperty("url", zones.length > 1 ? zones[1] : ""); - buckets.add(json); - } - config.add("buckets", buckets); - // Prefix - JsonArray prefix = new JsonArray(); - for (String string : QiniuApplication.prefix) { - prefix.add(string); - } - config.add("prefix", prefix); - // Download URL - config.addProperty("download", QiniuApplication.downloadPath); - writeConfig(new Gson().toJson(config)); - } - - public static void writeConfig(String configJson) { - try { - BufferedWriter out = new BufferedWriter(new FileWriter(configPath, false)); - out.write(Formatter.jsonFormat(configJson)); - out.close(); - logger.info("rewrite configuration success"); - } catch (IOException e) { - logger.error("rewrite configuration file failed, messages: " + e.getMessage()); - Dialogs.showFatalError(Values.LOAD_CONFIG_ERROR, e); - } - } -} diff --git a/.svn/pristine/f7/f736d8644a1a45c10ed41270eba486c54d7cb37a.svn-base b/.svn/pristine/f7/f736d8644a1a45c10ed41270eba486c54d7cb37a.svn-base deleted file mode 100644 index 698a110..0000000 --- a/.svn/pristine/f7/f736d8644a1a45c10ed41270eba486c54d7cb37a.svn-base +++ /dev/null @@ -1,111 +0,0 @@ -/** - * - */ -package com.zhazhapan.qiniu.util; - -import java.io.UnsupportedEncodingException; -import java.net.URLDecoder; -import java.text.DecimalFormat; -import java.text.SimpleDateFormat; -import java.util.Date; -import java.util.regex.Matcher; -import java.util.regex.Pattern; - -import org.apache.log4j.Logger; - -import com.google.gson.Gson; -import com.google.gson.GsonBuilder; -import com.google.gson.JsonElement; -import com.google.gson.JsonParser; -import com.zhazhapan.qiniu.modules.constant.Values; -import com.zhazhapan.qiniu.view.Dialogs; - -/** - * @author pantao - * - */ -public class Formatter { - - private static Logger logger = Logger.getLogger(Formatter.class); - - public static int stringToInt(String string) { - if (Checker.isNumber(string)) { - return Integer.parseInt(string); - } - return 0; - } - - public static final Pattern FILE_NAME_PATTERN = Pattern - .compile("(([^/\\\\:*\"<>|?]+)\\.)*[^/\\\\:*\"<>|?]+(\\?.*)?$", Pattern.CASE_INSENSITIVE); - - public static String formatSize(long size) { - if (size < Values.KB) { - return size + " B"; - } else if (size < Values.MB) { - return decimalFormat((double) size / Values.KB) + " KB"; - } else if (size < Values.GB) { - return decimalFormat((double) size / Values.MB) + " MB"; - } else if (size < Values.TB) { - return decimalFormat((double) size / Values.GB) + " GB"; - } else { - return decimalFormat((double) size / Values.TB) + " TB"; - } - } - - public static String decimalFormat(double number) { - return decimalFormat(number, "#0.00"); - } - - public static String decimalFormat(double number, String format) { - return new DecimalFormat(format).format(number); - } - - public static String timeStampToString(long time) { - return new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(time); - } - - public static String jsonFormat(String string) { - String json; - try { - Gson gson = new GsonBuilder().setPrettyPrinting().create(); - JsonParser jp = new JsonParser(); - JsonElement je = jp.parse(string); - json = gson.toJson(je); - } catch (Exception e) { - Dialogs.showException(Values.FORMAT_JSON_ERROR, e); - logger.error("format json string error,json: " + string); - json = string; - } - return json; - } - - public static String dateToString(Date date) { - return new SimpleDateFormat("yyyy-MM-dd").format(checkDate(date)); - } - - public static String datetimeToString(Date date) { - return new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(checkDate(date)); - } - - public static String getFileName(String string) { - if (Checker.isNotEmpty(string)) { - try { - string = URLDecoder.decode(string, "UTF-8"); - } catch (UnsupportedEncodingException e) { - logger.error("decode url '" + string + "' error use encoding utf-8, message: " + e.getMessage()); - } - Matcher matcher = FILE_NAME_PATTERN.matcher(string); - if (matcher.find() && Checker.isNotEmpty(matcher.group(0))) { - String name = matcher.group(0).split("\\?")[0]; - if (Checker.isNotEmpty(name)) { - return name; - } - } - } - return "undefined"; - } - - private static Date checkDate(Date date) { - return Checker.isNull(date) ? new Date() : date; - } -} diff --git a/.svn/pristine/f8/f87c0a26e53812b9be4451262558c86121b6c55d.svn-base b/.svn/pristine/f8/f87c0a26e53812b9be4451262558c86121b6c55d.svn-base deleted file mode 100644 index b2777a1..0000000 --- a/.svn/pristine/f8/f87c0a26e53812b9be4451262558c86121b6c55d.svn-base +++ /dev/null @@ -1,549 +0,0 @@ -/** - * - */ -package com.zhazhapan.qiniu.controller; - -import java.awt.Desktop; -import java.io.File; -import java.io.IOException; -import java.util.ArrayList; -import java.util.Date; -import java.util.HashMap; -import java.util.List; -import java.util.Optional; -import java.util.regex.Pattern; - -import org.apache.log4j.Logger; - -import com.qiniu.common.QiniuException; -import com.zhazhapan.qiniu.FileExecutor; -import com.zhazhapan.qiniu.QiManager; -import com.zhazhapan.qiniu.QiniuApplication; -import com.zhazhapan.qiniu.ThreadPool; -import com.zhazhapan.qiniu.QiManager.FileAction; -import com.zhazhapan.qiniu.config.ConfigLoader; -import com.zhazhapan.qiniu.config.QiConfig; -import com.zhazhapan.qiniu.model.FileInfo; -import com.zhazhapan.qiniu.modules.constant.Values; -import com.zhazhapan.qiniu.util.Checker; -import com.zhazhapan.qiniu.util.Formatter; -import com.zhazhapan.qiniu.util.Utils; -import com.zhazhapan.qiniu.view.Dialogs; - -import javafx.application.Platform; -import javafx.collections.FXCollections; -import javafx.collections.ObservableList; -import javafx.event.ActionEvent; -import javafx.fxml.FXML; -import javafx.scene.control.Button; -import javafx.scene.control.ButtonType; -import javafx.scene.control.ComboBox; -import javafx.scene.control.Hyperlink; -import javafx.scene.control.SelectionMode; -import javafx.scene.control.TableColumn; -import javafx.scene.control.TableView; -import javafx.scene.control.TextArea; -import javafx.scene.control.TextField; -import javafx.scene.control.cell.PropertyValueFactory; -import javafx.scene.control.cell.TextFieldTableCell; -import javafx.scene.input.KeyEvent; -import javafx.stage.FileChooser; -import javafx.util.Pair; - -/** - * @author pantao - * - */ -public class MainWindowController { - - private Logger logger = Logger.getLogger(MainWindowController.class); - - @FXML - public ComboBox bucketChoiceCombo; - - @FXML - public TextField zoneText; - - @FXML - private Button bucketAddableButton; - - @FXML - private Button resetKeyButton; - - @FXML - public TextArea uploadStatusTextArea; - - @FXML - private TextArea selectedFileTextArea; - - @FXML - public ComboBox filePrefixCombo; - - @FXML - private TextField bucketDomainTextField; - - @FXML - public TableView resTable; - - @FXML - public TextField searchTextField; - - @FXML - private TableColumn nameCol; - - @FXML - private TableColumn typeCol; - - @FXML - private TableColumn sizeCol; - - @FXML - private TableColumn timeCol; - - @FXML - private Hyperlink toCsdnBlog; - - @FXML - private Hyperlink toHexoBlog; - - @FXML - private Hyperlink toGithubSource; - - @FXML - private Hyperlink toIntro; - - @FXML - Hyperlink toIntro1; - - private static MainWindowController mainWindowController = null; - - private String status = ""; - - public static MainWindowController getInstance() { - return mainWindowController; - } - - public enum DownloadWay { - // 下载的方式,包括私有和公有 - PRIVATE, PUBLIC - } - - /* - * 初始化 - */ - @FXML - private void initialize() { - mainWindowController = this; - nameCol.setCellValueFactory(new PropertyValueFactory<>("name")); - // 文件名可编辑 - nameCol.setCellFactory(TextFieldTableCell.forTableColumn()); - nameCol.setOnEditCommit(v -> { - String name = ""; - FileInfo fileInfo = v.getTableView().getItems().get(v.getTablePosition().getRow()); - if (new QiManager().renameFile(bucketChoiceCombo.getValue(), v.getOldValue(), v.getNewValue())) { - name = v.getNewValue(); - } else { - name = v.getOldValue(); - } - if (Checker.isNotEmpty(searchTextField.getText())) { - QiniuApplication.data.get(QiniuApplication.data.indexOf(fileInfo)).setName(name); - } - fileInfo.setName(name); - }); - typeCol.setCellValueFactory(new PropertyValueFactory<>("type")); - // 文件类型可编辑 - typeCol.setCellFactory(TextFieldTableCell.forTableColumn()); - typeCol.setOnEditCommit(v -> { - FileInfo fileInfo = v.getTableView().getItems().get(v.getTablePosition().getRow()); - String type = ""; - if (new QiManager().changeType(fileInfo.getName(), v.getNewValue(), bucketChoiceCombo.getValue())) { - type = v.getNewValue(); - } else { - type = v.getOldValue(); - } - if (Checker.isNotEmpty(searchTextField.getText())) { - QiniuApplication.data.get(QiniuApplication.data.indexOf(fileInfo)).setType(type); - } - fileInfo.setType(type); - }); - sizeCol.setCellValueFactory(new PropertyValueFactory<>("size")); - timeCol.setCellValueFactory(new PropertyValueFactory<>("time")); - resTable.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE); - // BucketChoiceComboBox改变事件,改变后并配置新的上传环境 - bucketChoiceCombo.getSelectionModel().selectedItemProperty().addListener((observable, oldValue, newValue) -> { - String[] zones = QiniuApplication.buckets.get(newValue).split(" "); - zoneText.setText(zones[0]); - searchTextField.clear(); - if (Checker.isHyperLink(zones[1])) { - bucketDomainTextField.setText(zones[1]); - } else { - logger.warn("doesn't config the domain of bucket correctly yet"); - bucketDomainTextField.setText(Values.DOMAIN_CONFIG_ERROR); - } - ThreadPool.executor.submit(() -> { - if (new QiConfig().configUploadEnv(zones[0], newValue)) { - // 加载文件列表 - setResTableData(); - } - }); - }); - // 超链接添加监听 - toCsdnBlog.setOnAction(e -> Utils.openLink("http://csdn.zhazhapan.com")); - toHexoBlog.setOnAction(e -> Utils.openLink("http://zhazhapan.com")); - toGithubSource.setOnAction(e -> Utils.openLink("https://github.com/zhazhapan/github")); - String introPage = "http://zhazhapan.com/2017/10/15/%E4%B8%83%E7%89%9B%E4%BA%91%E2%80" - + "%94%E2%80%94%E5%AF%B9%E8%B1%A1%E5%AD%98%E5%82%A8%E7%AE%A1%E7%90%86%E5%B7%A5" - + "%E5%85%B7%E4%BB%8B%E7%BB%8D/"; - toIntro.setOnAction(e -> Utils.openLink(introPage)); - toIntro1.setOnAction(e -> Utils.openLink("http://blog.csdn.net/qq_26954773/article/details/78245100")); - } - - /** - * 用浏览器打开文件 - */ - public void openFile() { - ObservableList selectedItems = resTable.getSelectionModel().getSelectedItems(); - if (Checker.isNotEmpty(selectedItems)) { - String filename = selectedItems.get(0).getName(); - String url = "http://" + new QiManager().getPublicURL(filename, bucketDomainTextField.getText()); - Utils.openLink(url); - } - } - - /** - * 私有下载 - */ - public void privateDownload() { - download(DownloadWay.PRIVATE); - } - - public void download(DownloadWay way) { - ObservableList selectedItems = resTable.getSelectionModel().getSelectedItems(); - if (Checker.isNotEmpty(selectedItems)) { - QiManager manager = new QiManager(); - String domain = "http://" + bucketDomainTextField.getText(); - if (way == DownloadWay.PUBLIC) { - logger.debug("start to public download"); - for (FileInfo fileInfo : selectedItems) { - manager.publicDownload(fileInfo.getName(), domain); - } - } else { - logger.debug("start to private download"); - for (FileInfo fileInfo : selectedItems) { - manager.privateDownload(fileInfo.getName(), domain); - } - } - } - } - - /** - * 公有下载 - */ - public void publicDownload() { - download(DownloadWay.PUBLIC); - } - - /** - * 更新镜像源 - */ - public void updateFile() { - ObservableList selectedItems = resTable.getSelectionModel().getSelectedItems(); - if (Checker.isNotEmpty(selectedItems)) { - QiManager manager = new QiManager(); - for (FileInfo fileInfo : selectedItems) { - manager.updateFile(bucketChoiceCombo.getValue(), fileInfo.getName()); - } - } - } - - /** - * 设置文件生存时间 - */ - public void setLife() { - ObservableList selectedItems = resTable.getSelectionModel().getSelectedItems(); - if (Checker.isNotEmpty(selectedItems)) { - String lifeStr = Dialogs.showInputDialog(null, Values.FILE_LIFE, Values.DEFAULT_FILE_LIFE); - if (Checker.isNumber(lifeStr)) { - int life = Formatter.stringToInt(lifeStr); - QiManager manager = new QiManager(); - for (FileInfo fileInfo : selectedItems) { - manager.setFileLife(bucketChoiceCombo.getValue(), fileInfo.getName(), life); - } - } - } - } - - /** - * 显示移动或复制文件的窗口 - */ - public void showFileMovableDialog() { - ObservableList selectedItems = resTable.getSelectionModel().getSelectedItems(); - Pair pair = null; - String bucket = bucketChoiceCombo.getValue(); - if (Checker.isEmpty(selectedItems)) { - // 没有选择文件,结束方法 - return; - } else if (selectedItems.size() > 1) { - pair = new Dialogs().showFileMovableDialog(bucket, "", false); - } else { - pair = new Dialogs().showFileMovableDialog(bucket, selectedItems.get(0).getName(), true); - } - if (Checker.isNotNull(pair)) { - boolean useNewKey = Checker.isNotEmpty(pair.getValue()[1]); - ObservableList resData = resTable.getItems(); - QiManager manager = new QiManager(); - for (FileInfo fileInfo : selectedItems) { - String fb = bucketChoiceCombo.getValue(); - String tb = pair.getValue()[0]; - String name = useNewKey ? pair.getValue()[1] : fileInfo.getName(); - boolean move = manager.moveOrCopyFile(fb, fileInfo.getName(), tb, name, pair.getKey()); - if (pair.getKey() == FileAction.MOVE && move) { - boolean sear = Checker.isNotEmpty(searchTextField.getText()); - if (fb != tb) { - // 删除数据源 - QiniuApplication.data.remove(fileInfo); - if (sear) { - resData.remove(fileInfo); - } - } else { - // 更新文件名 - fileInfo.setName(name); - if (sear) { - QiniuApplication.data.get(QiniuApplication.data.indexOf(fileInfo)).setName(name); - } - } - } - } - } - } - - /** - * 删除文件 - */ - public void deleteFiles() { - ObservableList fileInfos = resTable.getSelectionModel().getSelectedItems(); - new QiManager().deleteFiles(fileInfos, bucketChoiceCombo.getValue()); - } - - /** - * 复制链接 - */ - public void copyLink() { - ObservableList fileInfos = resTable.getSelectionModel().getSelectedItems(); - if (Checker.isNotEmpty(fileInfos)) { - // 只复制选中的第一个文件的链接 - String link = "http://" + bucketDomainTextField.getText() + "/" + fileInfos.get(0).getName(); - Utils.copyToClipboard(link); - logger.info("copy link: " + link); - } - } - - /** - * 搜索资源文件,忽略大小写 - */ - public void searchFile(KeyEvent event) { - ArrayList files = new ArrayList(); - String search = Checker.checkNull(searchTextField.getText()); - logger.info("search file: " + search); - try { - // 正则匹配查询 - Pattern pattern = Pattern.compile(search, Pattern.CASE_INSENSITIVE); - for (FileInfo file : QiniuApplication.data) { - if (pattern.matcher(file.getName()).find()) { - files.add(file); - } - } - } catch (Exception e) { - logger.warn("pattern '" + search + "' compile error, message: " + e.getMessage()); - } - resTable.setItems(FXCollections.observableArrayList(files)); - } - - /** - * 刷新资源列表 - */ - public void refreshResTable() { - if (!new QiConfig().checkNet()) { - Dialogs.showWarning(Values.NET_ERROR); - return; - } - setResTableData(); - Dialogs.showInformation(Values.REFRESH_SUCCESS); - } - - /** - * 将从存储空间获取的文件列表映射到Table - */ - public void setResTableData() { - ThreadPool.executor.submit(() -> { - new QiManager().listFileOfBucket(); - Platform.runLater(() -> resTable.setItems(QiniuApplication.data)); - }); - } - - /** - * 添加bucket到ComboBox - */ - public void addItem(String bucket) { - if (!bucketChoiceCombo.getItems().contains(bucket)) { - bucketChoiceCombo.getItems().add(bucket); - } - } - - /** - * 保存文件的上传状态 - */ - public void saveUploadStatus() { - FileChooser chooser = new FileChooser(); - chooser.setTitle(Values.FILE_CHOOSER_TITLE); - chooser.setInitialDirectory(new File(System.getProperty("user.home"))); - File file = chooser.showSaveDialog(QiniuApplication.stage); - new FileExecutor().saveFile(file, uploadStatusTextArea.getText()); - } - - /** - * 复制上传状态到剪贴板 - */ - public void copyUploadStatus() { - Utils.copyToClipboard(uploadStatusTextArea.getText()); - } - - /** - * 清空文件的上传状态 - */ - public void clearUploadStatus() { - uploadStatusTextArea.clear(); - } - - /** - * 选择要上传的文件 - */ - public void selectFile() { - logger.info("show file chooser dialog"); - FileChooser chooser = new FileChooser(); - chooser.setTitle(Values.FILE_CHOOSER_TITLE); - chooser.setInitialDirectory(new File(System.getProperty("user.home"))); - List files = chooser.showOpenMultipleDialog(QiniuApplication.stage); - if (Checker.isNotEmpty(files)) { - for (File file : files) { - selectedFileTextArea.insertText(0, file.getAbsolutePath() + "\r\n"); - } - } - } - - /** - * 上传选择的文件 - */ - public void uploadFile() { - if (Checker.isNullOrEmpty(zoneText.getText()) || Checker.isNullOrEmpty(selectedFileTextArea.getText())) { - // 没有选择存储空间或文件,不能上传文件 - Dialogs.showWarning(Values.NEED_SCHOOSE_BUCKET_OR_FILE); - return; - } - // 新建一个上传文件的线程 - ThreadPool.executor.submit(() -> { - Platform.runLater(() -> uploadStatusTextArea.insertText(0, Values.CONFIGING_UPLOAD_ENVIRONMENT)); - String bucket = bucketChoiceCombo.getValue(); - // 默认不指定key的情况下,以文件内容的hash值作为文件名 - String key = Checker.checkNull(filePrefixCombo.getValue()); - String[] paths = selectedFileTextArea.getText().split("\n"); - // 去掉\r\n的长度 - int end = Values.UPLOADING.length() - 2; - Platform.runLater( - () -> uploadStatusTextArea.deleteText(0, Values.CONFIGING_UPLOAD_ENVIRONMENT.length() - 1)); - for (String path : paths) { - if (Checker.isNotEmpty(path)) { - Platform.runLater(() -> uploadStatusTextArea.insertText(0, Values.UPLOADING)); - try { - logger.info("start to upload file: " + path); - File file = new File(path); - String filename = "undefined"; - String url = "http://" + QiniuApplication.buckets.get(bucket).split(" ")[1] + "/"; - // 判断文件是否存在 - if (file.exists()) { - filename = key + file.getName(); - QiniuApplication.uploadManager.put(path, filename, QiniuApplication.upToken); - status = Formatter.datetimeToString(new Date()) + "\tsuccess\t" + url + filename + "\t" - + path; - logger.info("upload file '" + path + "' to bucket '" + bucket + "' success"); - } else if (Checker.isHyperLink(path)) { - // 抓取网络文件到空间中 - logger.info(path + " is a hyper link"); - filename = key + Formatter.getFileName(path); - QiniuApplication.bucketManager.fetch(path, bucket, filename); - status = Formatter.datetimeToString(new Date()) + "\tsuccess\t" + url + filename + "\t" - + path; - logger.info("fetch remote file '" + path + "' to bucket '" + bucket + "' success"); - } else { - // 文件不存在 - logger.info("file '" + path + "' not exists"); - status = Formatter.datetimeToString(new Date()) + "\tfailed\t" + path; - } - } catch (QiniuException e) { - status = Formatter.datetimeToString(new Date()) + "\terror\t" + path; - logger.error("upload error, message: " + e.getMessage()); - Platform.runLater(() -> Dialogs.showException(Values.UPLOAD_ERROR, e)); - } - Platform.runLater(() -> { - uploadStatusTextArea.deleteText(0, end); - uploadStatusTextArea.insertText(0, status); - }); - } - Platform.runLater(() -> selectedFileTextArea.deleteText(0, path.length() + (paths.length > 1 ? 1 : 0))); - } - Platform.runLater(() -> { - // 将光标移到最前面 - uploadStatusTextArea.positionCaret(0); - // 清空待上传的文件列表 - selectedFileTextArea.clear(); - }); - // 添加文件前缀到配置文件 - if (Checker.isNotEmpty(key) && !QiniuApplication.prefix.contains(key)) { - Platform.runLater(() -> filePrefixCombo.getItems().add(key)); - QiniuApplication.prefix.add(key); - ConfigLoader.writeConfig(); - } - setResTableData(); - }); - } - - /** - * 打开配置文件 - */ - public void openConfigFile() { - try { - Desktop.getDesktop().open(new File(ConfigLoader.configPath)); - logger.info("open config file"); - Optional result = Dialogs.showConfirmation(Values.RELOAD_CONFIG); - if (result.get() == ButtonType.OK) { - // 重新载入配置文件 - QiniuApplication.buckets = new HashMap(10); - QiniuApplication.prefix = new ArrayList(); - bucketChoiceCombo.getItems().clear(); - filePrefixCombo.getItems().clear(); - ConfigLoader.loadConfig(); - } - } catch (IOException e) { - logger.error("open config file error, message: " + e.getMessage()); - Dialogs.showException(Values.OPEN_FILE_ERROR, e); - } catch (Exception e) { - logger.error("can't open config file, message: " + e.getMessage()); - Dialogs.showException(Values.OPEN_FILE_ERROR, e); - } - } - - /** - * 重置Key - */ - public void resetKey() { - ConfigLoader.showInputKeyDialog(); - } - - /** - * 添加存储空间 - */ - public void showBucketAddableDialog(ActionEvent event) { - logger.info("show bucket addable dialog"); - new Dialogs().showBucketAddableDialog(); - } -} diff --git a/.svn/pristine/fa/fa2c97eaff8f605915b57785952181d5d9a785a5.svn-base b/.svn/pristine/fa/fa2c97eaff8f605915b57785952181d5d9a785a5.svn-base deleted file mode 100644 index 7e30d91..0000000 Binary files a/.svn/pristine/fa/fa2c97eaff8f605915b57785952181d5d9a785a5.svn-base and /dev/null differ diff --git a/.svn/pristine/fd/fdc827aee8edc9b9a55077f16f0811b7a13d3c8e.svn-base b/.svn/pristine/fd/fdc827aee8edc9b9a55077f16f0811b7a13d3c8e.svn-base deleted file mode 100644 index 96b30f9..0000000 --- a/.svn/pristine/fd/fdc827aee8edc9b9a55077f16f0811b7a13d3c8e.svn-base +++ /dev/null @@ -1,4 +0,0 @@ -activeProfiles=pom.xml -eclipse.preferences.version=1 -resolveWorkspaceProjects=true -version=1 diff --git a/.svn/wc.db b/.svn/wc.db deleted file mode 100644 index 302eaf9..0000000 Binary files a/.svn/wc.db and /dev/null differ