资源工具

master
wangbing 5 years ago
parent 46ad3a03f1
commit 9e16cc8377

@ -16,7 +16,6 @@ import javafx.scene.control.CheckBox;
import javafx.scene.control.ContextMenu; import javafx.scene.control.ContextMenu;
import javafx.scene.control.MenuItem; import javafx.scene.control.MenuItem;
import javafx.scene.control.RadioButton; import javafx.scene.control.RadioButton;
import javafx.scene.control.SplitPane;
import javafx.scene.control.TableCell; import javafx.scene.control.TableCell;
import javafx.scene.control.TableColumn; import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView; import javafx.scene.control.TableView;
@ -64,6 +63,7 @@ import xyz.wbsite.dbtool.javafx.tool.Tool;
import xyz.wbsite.dbtool.javafx.view.DBCheckBoxTableCell; import xyz.wbsite.dbtool.javafx.view.DBCheckBoxTableCell;
import xyz.wbsite.dbtool.web.frame.utils.ResourceUtil; import xyz.wbsite.dbtool.web.frame.utils.ResourceUtil;
import java.io.InputStream;
import java.net.URL; import java.net.URL;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashSet; import java.util.HashSet;
@ -112,15 +112,12 @@ public class JavaFxApplication extends Application {
System.exit(0); System.exit(0);
} }
}); });
primaryStage.getIcons().add(new Image(ResourceUtil.getResourceInput("icon.png"))); primaryStage.getIcons().add(new Image(ResourceUtil.getInput("icon.png")));
} }
@Override @Override
public void init() throws Exception { public void init() throws Exception {
URL main = JavaFxApplication.class.getClassLoader().getResource("fxml/main.fxml"); URL main = ResourceUtil.getURL("classpath:fxml/main.fxml");
if (main == null) {
main = getClass().getResource("../../../fxml/main.fxml");
}
mMainLoader = new FXMLLoader(main); mMainLoader = new FXMLLoader(main);
mMainLoader.load(); mMainLoader.load();
mainController = mMainLoader.getController(); mainController = mMainLoader.getController();

@ -10,6 +10,7 @@ import xyz.wbsite.dbtool.javafx.tool.Tool;
import xyz.wbsite.dbtool.web.frame.utils.ResourceUtil; import xyz.wbsite.dbtool.web.frame.utils.ResourceUtil;
import java.io.File; import java.io.File;
import java.net.URL;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
@ -96,22 +97,22 @@ public class ApiCallable implements Callable {
HashMap<String, Object> ctx = new HashMap<String, Object>(); HashMap<String, Object> ctx = new HashMap<String, Object>();
ctx.put("domain", String.join(".", domainList)); ctx.put("domain", String.join(".", domainList));
for (String name : ResourceUtil.getResourceFiles("/modules/Java_api/frame/base/")) { for (String name : ResourceUtil.listFileName("/modules/Java_api/frame/base/")) {
freeMarkerManager.outputTemp(Tool.createFile(base, name), "Java_api/frame/base/" + name, ctx); freeMarkerManager.outputTemp(Tool.createFile(base, name), "Java_api/frame/base/" + name, ctx);
} }
for (String name : ResourceUtil.getResourceFiles("/modules/Java_api/frame/client/")) { for (String name : ResourceUtil.listFileName("/modules/Java_api/frame/client/")) {
freeMarkerManager.outputTemp(Tool.createFile(client, name), "Java_api/frame/client/" + name, ctx); freeMarkerManager.outputTemp(Tool.createFile(client, name), "Java_api/frame/client/" + name, ctx);
} }
for (String name : ResourceUtil.getResourceFiles("/modules/Java_api/frame/utils/")) { for (String name : ResourceUtil.listFileName("/modules/Java_api/frame/utils/")) {
if (name.equals("ValidationUtil.java")){//去掉验证 减少体积 if (name.equals("ValidationUtil.java")){//去掉验证 减少体积
continue; continue;
} }
freeMarkerManager.outputTemp(Tool.createFile(utils, name), "Java_api/frame/utils/" + name, ctx); freeMarkerManager.outputTemp(Tool.createFile(utils, name), "Java_api/frame/utils/" + name, ctx);
} }
for (String name : ResourceUtil.getResourceFiles("/modules/Java_api/frame/okhttp3/")) { for (String name : ResourceUtil.listFileName("/modules/Java_api/frame/okhttp3/")) {
freeMarkerManager.outputTemp(Tool.createFile(okhttp3, name), "Java_api/frame/okhttp3/" + name, ctx); freeMarkerManager.outputTemp(Tool.createFile(okhttp3, name), "Java_api/frame/okhttp3/" + name, ctx);
} }
} }

@ -19,12 +19,15 @@ import xyz.wbsite.dbtool.web.frame.utils.ResourceUtil;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.net.URL;
import java.sql.Connection; import java.sql.Connection;
import java.sql.DriverManager; import java.sql.DriverManager;
import java.sql.SQLException; import java.sql.SQLException;
import java.sql.Statement; import java.sql.Statement;
import java.util.ArrayList;
import java.util.Date; import java.util.Date;
import java.util.HashMap; import java.util.HashMap;
import java.util.List;
import java.util.concurrent.Callable; import java.util.concurrent.Callable;
public class SpringBootCallable implements Callable { public class SpringBootCallable implements Callable {
@ -155,7 +158,7 @@ public class SpringBootCallable implements Callable {
if (project.getFrame().value() == Frame..value()) {//管理架构 if (project.getFrame().value() == Frame..value()) {//管理架构
File wsys = Tool.createPath(ajax, "wsys"); File wsys = Tool.createPath(ajax, "wsys");
for (String name : ResourceUtil.getResourceFiles("/modules/SpringBoot/java/action/ajax/wsys/")) { for (String name : ResourceUtil.listFileName("/modules/SpringBoot/java/action/ajax/wsys/")) {
freeMarkerManager.outputTemp(Tool.createFile(wsys, name), "SpringBoot/java/action/ajax/wsys/" + name, ctx); freeMarkerManager.outputTemp(Tool.createFile(wsys, name), "SpringBoot/java/action/ajax/wsys/" + name, ctx);
} }
} }
@ -185,7 +188,7 @@ public class SpringBootCallable implements Callable {
if (project.getFrame().value() >= Frame..value()) {//生成系统模块 if (project.getFrame().value() >= Frame..value()) {//生成系统模块
File wsys = Tool.createPath(api, "wsys"); File wsys = Tool.createPath(api, "wsys");
for (String name : ResourceUtil.getResourceFiles("/modules/SpringBoot/java/action/api/wsys/")) { for (String name : ResourceUtil.listFileName("/modules/SpringBoot/java/action/api/wsys/")) {
freeMarkerManager.outputTemp(Tool.createFile(wsys, name), "SpringBoot/java/action/api/wsys/" + name, ctx); freeMarkerManager.outputTemp(Tool.createFile(wsys, name), "SpringBoot/java/action/api/wsys/" + name, ctx);
} }
} }
@ -337,15 +340,15 @@ public class SpringBootCallable implements Callable {
File mgr = Tool.createPath(root, "wsys", "mgr"); File mgr = Tool.createPath(root, "wsys", "mgr");
File req = Tool.createPath(root, "wsys", "req"); File req = Tool.createPath(root, "wsys", "req");
File rsp = Tool.createPath(root, "wsys", "rsp"); File rsp = Tool.createPath(root, "wsys", "rsp");
for (String name : ResourceUtil.getResourceFiles("/modules/SpringBoot/java/module/wsys/ent/")) { for (String name : ResourceUtil.listFileName("/modules/SpringBoot/java/module/wsys/ent/")) {
freeMarkerManager.outputTemp(Tool.createFile(ent, name), "SpringBoot/java/module/wsys/ent/" + name, ctx); freeMarkerManager.outputTemp(Tool.createFile(ent, name), "SpringBoot/java/module/wsys/ent/" + name, ctx);
} }
for (String name : ResourceUtil.getResourceFiles("/modules/SpringBoot/java/module/wsys/mgr/")) { for (String name : ResourceUtil.listFileName("/modules/SpringBoot/java/module/wsys/mgr/")) {
freeMarkerManager.outputTemp(Tool.createFile(mgr, name), "SpringBoot/java/module/wsys/mgr/" + name, ctx); freeMarkerManager.outputTemp(Tool.createFile(mgr, name), "SpringBoot/java/module/wsys/mgr/" + name, ctx);
} }
for (String name : ResourceUtil.getResourceFiles("/modules/SpringBoot/java/module/wsys/mpr/")) { for (String name : ResourceUtil.listFileName("/modules/SpringBoot/java/module/wsys/mpr/")) {
if (name.endsWith(".java")) { if (name.endsWith(".java")) {
freeMarkerManager.outputTemp(Tool.createFile(mpr, name), "SpringBoot/java/module/wsys/mpr/" + name, ctx); freeMarkerManager.outputTemp(Tool.createFile(mpr, name), "SpringBoot/java/module/wsys/mpr/" + name, ctx);
} else if (name.contains(project.getDatabase().name())) { } else if (name.contains(project.getDatabase().name())) {
@ -353,11 +356,11 @@ public class SpringBootCallable implements Callable {
} }
} }
for (String name : ResourceUtil.getResourceFiles("/modules/SpringBoot/java/module/wsys/req/")) { for (String name : ResourceUtil.listFileName("/modules/SpringBoot/java/module/wsys/req/")) {
freeMarkerManager.outputTemp(Tool.createFile(req, name), "SpringBoot/java/module/wsys/req/" + name, ctx); freeMarkerManager.outputTemp(Tool.createFile(req, name), "SpringBoot/java/module/wsys/req/" + name, ctx);
} }
for (String name : ResourceUtil.getResourceFiles("/modules/SpringBoot/java/module/wsys/rsp/")) { for (String name : ResourceUtil.listFileName("/modules/SpringBoot/java/module/wsys/rsp/")) {
freeMarkerManager.outputTemp(Tool.createFile(rsp, name), "SpringBoot/java/module/wsys/rsp/" + name, ctx); freeMarkerManager.outputTemp(Tool.createFile(rsp, name), "SpringBoot/java/module/wsys/rsp/" + name, ctx);
} }
} }
@ -384,7 +387,7 @@ public class SpringBootCallable implements Callable {
//auth //auth
{ {
File auth = Tool.createPath(root, "auth"); File auth = Tool.createPath(root, "auth");
for (String name : ResourceUtil.getResourceFiles("/modules/SpringBoot/java/frame/auth/")) { for (String name : ResourceUtil.listFileName("/modules/SpringBoot/java/frame/auth/")) {
freeMarkerManager.outputTemp(Tool.createFile(auth, name), "SpringBoot/java/frame/auth/" + name, ctx); freeMarkerManager.outputTemp(Tool.createFile(auth, name), "SpringBoot/java/frame/auth/" + name, ctx);
} }
} }
@ -392,7 +395,7 @@ public class SpringBootCallable implements Callable {
//base //base
{ {
File base = Tool.createPath(root, "base"); File base = Tool.createPath(root, "base");
for (String name : ResourceUtil.getResourceFiles("/modules/SpringBoot/java/frame/base/")) { for (String name : ResourceUtil.listFileName("/modules/SpringBoot/java/frame/base/")) {
freeMarkerManager.outputTemp(Tool.createFile(base, name), "SpringBoot/java/frame/base/" + name, ctx); freeMarkerManager.outputTemp(Tool.createFile(base, name), "SpringBoot/java/frame/base/" + name, ctx);
} }
} }
@ -400,7 +403,7 @@ public class SpringBootCallable implements Callable {
//utils //utils
{ {
File utils = Tool.createPath(root, "utils"); File utils = Tool.createPath(root, "utils");
for (String name : ResourceUtil.getResourceFiles("/modules/SpringBoot/java/frame/utils/")) { for (String name : ResourceUtil.listFileName("/modules/SpringBoot/java/frame/utils/")) {
freeMarkerManager.outputTemp(Tool.createFile(utils, name), "SpringBoot/java/frame/utils/" + name, ctx); freeMarkerManager.outputTemp(Tool.createFile(utils, name), "SpringBoot/java/frame/utils/" + name, ctx);
} }
} }
@ -408,7 +411,7 @@ public class SpringBootCallable implements Callable {
//schedule //schedule
{ {
File schedule = Tool.createPath(root, "schedule"); File schedule = Tool.createPath(root, "schedule");
for (String name : ResourceUtil.getResourceFiles("/modules/SpringBoot/java/frame/schedule/")) { for (String name : ResourceUtil.listFileName("/modules/SpringBoot/java/frame/schedule/")) {
freeMarkerManager.outputTemp(Tool.createFile(schedule, name), "SpringBoot/java/frame/schedule/" + name, ctx); freeMarkerManager.outputTemp(Tool.createFile(schedule, name), "SpringBoot/java/frame/schedule/" + name, ctx);
} }
} }
@ -420,22 +423,22 @@ public class SpringBootCallable implements Callable {
File exception = Tool.createPath(excel, "exception"); File exception = Tool.createPath(excel, "exception");
File excelhandler = Tool.createPath(excel, "handler"); File excelhandler = Tool.createPath(excel, "handler");
File excellistener = Tool.createPath(excel, "listener"); File excellistener = Tool.createPath(excel, "listener");
for (String name : ResourceUtil.getResourceFiles("/modules/SpringBoot/java/frame/excel/")) { for (String name : ResourceUtil.listFileName("/modules/SpringBoot/java/frame/excel/")) {
freeMarkerManager.outputTemp(Tool.createFile(excel, name), "SpringBoot/java/frame/excel/" + name, ctx); freeMarkerManager.outputTemp(Tool.createFile(excel, name), "SpringBoot/java/frame/excel/" + name, ctx);
} }
for (String name : ResourceUtil.getResourceFiles("/modules/SpringBoot/java/frame/excel/annotation/")) { for (String name : ResourceUtil.listFileName("/modules/SpringBoot/java/frame/excel/annotation/")) {
freeMarkerManager.outputTemp(Tool.createFile(excelannotation, name), "SpringBoot/java/frame/excel/annotation/" + name, ctx); freeMarkerManager.outputTemp(Tool.createFile(excelannotation, name), "SpringBoot/java/frame/excel/annotation/" + name, ctx);
} }
for (String name : ResourceUtil.getResourceFiles("/modules/SpringBoot/java/frame/excel/converter/")) { for (String name : ResourceUtil.listFileName("/modules/SpringBoot/java/frame/excel/converter/")) {
freeMarkerManager.outputTemp(Tool.createFile(excelconverter, name), "SpringBoot/java/frame/excel/converter/" + name, ctx); freeMarkerManager.outputTemp(Tool.createFile(excelconverter, name), "SpringBoot/java/frame/excel/converter/" + name, ctx);
} }
for (String name : ResourceUtil.getResourceFiles("/modules/SpringBoot/java/frame/excel/exception/")) { for (String name : ResourceUtil.listFileName("/modules/SpringBoot/java/frame/excel/exception/")) {
freeMarkerManager.outputTemp(Tool.createFile(exception, name), "SpringBoot/java/frame/excel/exception/" + name, ctx); freeMarkerManager.outputTemp(Tool.createFile(exception, name), "SpringBoot/java/frame/excel/exception/" + name, ctx);
} }
for (String name : ResourceUtil.getResourceFiles("/modules/SpringBoot/java/frame/excel/handler/")) { for (String name : ResourceUtil.listFileName("/modules/SpringBoot/java/frame/excel/handler/")) {
freeMarkerManager.outputTemp(Tool.createFile(excelhandler, name), "SpringBoot/java/frame/excel/handler/" + name, ctx); freeMarkerManager.outputTemp(Tool.createFile(excelhandler, name), "SpringBoot/java/frame/excel/handler/" + name, ctx);
} }
for (String name : ResourceUtil.getResourceFiles("/modules/SpringBoot/java/frame/excel/listener/")) { for (String name : ResourceUtil.listFileName("/modules/SpringBoot/java/frame/excel/listener/")) {
freeMarkerManager.outputTemp(Tool.createFile(excellistener, name), "SpringBoot/java/frame/excel/listener/" + name, ctx); freeMarkerManager.outputTemp(Tool.createFile(excellistener, name), "SpringBoot/java/frame/excel/listener/" + name, ctx);
} }
} }
@ -445,7 +448,7 @@ public class SpringBootCallable implements Callable {
File mail = Tool.createPath(root, "mail"); File mail = Tool.createPath(root, "mail");
File message = Tool.createPath(mail, "message"); File message = Tool.createPath(mail, "message");
freeMarkerManager.outputTemp(Tool.createFile(mail, "WMailSender.java"), "SpringBoot/java/frame/mail/WMailSender.java", ctx); freeMarkerManager.outputTemp(Tool.createFile(mail, "WMailSender.java"), "SpringBoot/java/frame/mail/WMailSender.java", ctx);
for (String name : ResourceUtil.getResourceFiles("/modules/SpringBoot/java/frame/mail/message/")) { for (String name : ResourceUtil.listFileName("/modules/SpringBoot/java/frame/mail/message/")) {
freeMarkerManager.outputTemp(Tool.createFile(message, name), "SpringBoot/java/frame/mail/message/" + name, ctx); freeMarkerManager.outputTemp(Tool.createFile(message, name), "SpringBoot/java/frame/mail/message/" + name, ctx);
} }
} }
@ -453,7 +456,7 @@ public class SpringBootCallable implements Callable {
//validation //validation
{ {
File validation = Tool.createPath(root, "validation"); File validation = Tool.createPath(root, "validation");
for (String name : ResourceUtil.getResourceFiles("/modules/SpringBoot/java/frame/validation/")) { for (String name : ResourceUtil.listFileName("/modules/SpringBoot/java/frame/validation/")) {
freeMarkerManager.outputTemp(Tool.createFile(validation, name), "SpringBoot/java/frame/validation/" + name, ctx); freeMarkerManager.outputTemp(Tool.createFile(validation, name), "SpringBoot/java/frame/validation/" + name, ctx);
} }
} }
@ -476,7 +479,7 @@ public class SpringBootCallable implements Callable {
ctx.put("moduleName", project.getName()); ctx.put("moduleName", project.getName());
//task //task
for (String name : ResourceUtil.getResourceFiles("/modules/SpringBoot/java/task/")) { for (String name : ResourceUtil.listFileName("/modules/SpringBoot/java/task/")) {
if (name.contains("TokenTask") && project.getFrame().value() == Frame..value()) { if (name.contains("TokenTask") && project.getFrame().value() == Frame..value()) {
continue; continue;
} }
@ -548,7 +551,7 @@ public class SpringBootCallable implements Callable {
if (wsysModule == null || !wsysModule.getNeedGenerate()) {// 覆盖 if (wsysModule == null || !wsysModule.getNeedGenerate()) {// 覆盖
File wsys = Tool.createPath(dbtool, "wsys_table"); File wsys = Tool.createPath(dbtool, "wsys_table");
for (String name : ResourceUtil.getResourceFiles("/modules/SpringBoot/resources/dbtool/wsys_table/")) { for (String name : ResourceUtil.listFileName("/modules/SpringBoot/resources/dbtool/wsys_table/")) {
if (name.contains(project.getDatabase().name())) { if (name.contains(project.getDatabase().name())) {
freeMarkerManager.outputTemp(Tool.createFile(wsys, name), "SpringBoot/resources/dbtool/wsys_table/" + name, ctx); freeMarkerManager.outputTemp(Tool.createFile(wsys, name), "SpringBoot/resources/dbtool/wsys_table/" + name, ctx);
} }
@ -656,7 +659,7 @@ public class SpringBootCallable implements Callable {
Module wsysModule = tryGetModule(project, "wsys");// 防止与系统冲突,一般不会重复,通常是架构重新设计时遇到 Module wsysModule = tryGetModule(project, "wsys");// 防止与系统冲突,一般不会重复,通常是架构重新设计时遇到
if (wsysModule == null || !wsysModule.getNeedGenerate()) { if (wsysModule == null || !wsysModule.getNeedGenerate()) {
File wsys = Tool.createPath(screen, "wsys"); File wsys = Tool.createPath(screen, "wsys");
for (String name : ResourceUtil.getResourceFiles("/modules/SpringBoot/resources/templates/screen/module/wsys/")) { for (String name : ResourceUtil.listFileName("/modules/SpringBoot/resources/templates/screen/module/wsys/")) {
Tool.outputResource("SpringBoot/resources/templates/screen/module/wsys/" + name, Tool.createFile(wsys, name)); Tool.outputResource("SpringBoot/resources/templates/screen/module/wsys/" + name, Tool.createFile(wsys, name));
} }
} }
@ -730,7 +733,7 @@ public class SpringBootCallable implements Callable {
ctx.put("project", project); ctx.put("project", project);
File wsys = Tool.createPath(root, "wsys"); File wsys = Tool.createPath(root, "wsys");
for (String apiFile : ResourceUtil.getResourceFiles("/modules/SpringBoot/test/wsys/")) { for (String apiFile : ResourceUtil.listFileName("/modules/SpringBoot/test/wsys/")) {
freeMarkerManager.outputTemp(Tool.createFile(wsys, apiFile), "SpringBoot/test/wsys/" + apiFile, ctx); freeMarkerManager.outputTemp(Tool.createFile(wsys, apiFile), "SpringBoot/test/wsys/" + apiFile, ctx);
} }
freeMarkerManager.outputTemp(Tool.createFile(root, "DataInit.java"), "SpringBoot/test/DataInit.java", ctx); freeMarkerManager.outputTemp(Tool.createFile(root, "DataInit.java"), "SpringBoot/test/DataInit.java", ctx);
@ -745,4 +748,5 @@ public class SpringBootCallable implements Callable {
} }
return null; return null;
} }
} }

@ -122,7 +122,7 @@ public class Dialog {
public static void showYesNo(String title, String message, ConfirmCall call) { public static void showYesNo(String title, String message, ConfirmCall call) {
Alert alert = new Alert(Alert.AlertType.CONFIRMATION); Alert alert = new Alert(Alert.AlertType.CONFIRMATION);
Stage stage = (Stage) alert.getDialogPane().getScene().getWindow(); Stage stage = (Stage) alert.getDialogPane().getScene().getWindow();
stage.getIcons().add(new Image(ResourceUtil.getResourceInput("icon.png"))); stage.getIcons().add(new Image(ResourceUtil.getInput("icon.png")));
alert.setHeaderText(null); alert.setHeaderText(null);
alert.setTitle(title); alert.setTitle(title);
alert.setContentText(message); alert.setContentText(message);
@ -143,7 +143,7 @@ public class Dialog {
public void run() { public void run() {
Alert alert = new Alert(Alert.AlertType.ERROR); Alert alert = new Alert(Alert.AlertType.ERROR);
Stage stage = (Stage) alert.getDialogPane().getScene().getWindow(); Stage stage = (Stage) alert.getDialogPane().getScene().getWindow();
stage.getIcons().add(new Image(ResourceUtil.getResourceInput("icon.png"))); stage.getIcons().add(new Image(ResourceUtil.getInput("icon.png")));
alert.setTitle("错误"); alert.setTitle("错误");
alert.setX(JavaFxApplication.primaryStage.getX() + JavaFxApplication.primaryStage.getWidth() / 2 - 213); alert.setX(JavaFxApplication.primaryStage.getX() + JavaFxApplication.primaryStage.getWidth() / 2 - 213);
alert.setY(JavaFxApplication.primaryStage.getY() + JavaFxApplication.primaryStage.getHeight() / 2 - 70); alert.setY(JavaFxApplication.primaryStage.getY() + JavaFxApplication.primaryStage.getHeight() / 2 - 70);
@ -159,7 +159,7 @@ public class Dialog {
public void run() { public void run() {
Alert alert = new Alert(Alert.AlertType.INFORMATION); Alert alert = new Alert(Alert.AlertType.INFORMATION);
Stage stage = (Stage) alert.getDialogPane().getScene().getWindow(); Stage stage = (Stage) alert.getDialogPane().getScene().getWindow();
stage.getIcons().add(new Image(ResourceUtil.getResourceInput("icon.png"))); stage.getIcons().add(new Image(ResourceUtil.getInput("icon.png")));
alert.setTitle("消息"); alert.setTitle("消息");
alert.setX(JavaFxApplication.primaryStage.getX() + JavaFxApplication.primaryStage.getWidth() / 2 - 213); alert.setX(JavaFxApplication.primaryStage.getX() + JavaFxApplication.primaryStage.getWidth() / 2 - 213);
alert.setY(JavaFxApplication.primaryStage.getY() + JavaFxApplication.primaryStage.getHeight() / 2 - 70); alert.setY(JavaFxApplication.primaryStage.getY() + JavaFxApplication.primaryStage.getHeight() / 2 - 70);
@ -177,7 +177,7 @@ public class Dialog {
dialog = new javafx.scene.control.Dialog(); dialog = new javafx.scene.control.Dialog();
dialog.setTitle("提示"); dialog.setTitle("提示");
Stage stage = (Stage) dialog.getDialogPane().getScene().getWindow(); Stage stage = (Stage) dialog.getDialogPane().getScene().getWindow();
stage.getIcons().add(new Image(ResourceUtil.getResourceInput("icon.png"))); stage.getIcons().add(new Image(ResourceUtil.getInput("icon.png")));
dialog.setResult("1"); dialog.setResult("1");
dialog.setX(JavaFxApplication.primaryStage.getX() + JavaFxApplication.primaryStage.getWidth() / 2 - 68); dialog.setX(JavaFxApplication.primaryStage.getX() + JavaFxApplication.primaryStage.getWidth() / 2 - 68);
dialog.setY(JavaFxApplication.primaryStage.getY() + JavaFxApplication.primaryStage.getHeight() / 2 - 70); dialog.setY(JavaFxApplication.primaryStage.getY() + JavaFxApplication.primaryStage.getHeight() / 2 - 70);

@ -11,6 +11,8 @@ import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.OutputStream; import java.io.OutputStream;
import java.io.PrintWriter; import java.io.PrintWriter;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@ -126,6 +128,37 @@ public class FileUtil {
} }
} }
public static FileOutputStream openOutputStream(File file) throws IOException {
if (file.exists()) {
if (file.isDirectory()) {
throw new IOException("File '" + file + "' exists but is a directory");
} else if (!file.canRead()) {
throw new IOException("File '" + file + "' cannot be read");
} else {
return new FileOutputStream(file);
}
} else {
throw new FileNotFoundException("File '" + file + "' does not exist");
}
}
/**
* @param fileLocation
* @return URL
*/
public static URL getURL(String fileLocation) {
try {
return new URL(fileLocation);
} catch (MalformedURLException var6) {
try {
return (new File(fileLocation)).toURI().toURL();
} catch (MalformedURLException var5) {
var5.printStackTrace();
}
}
return null;
}
public static byte[] toByteArray(InputStream input, long size) throws IOException { public static byte[] toByteArray(InputStream input, long size) throws IOException {
if (size > 2147483647L) { if (size > 2147483647L) {
throw new IllegalArgumentException("Size cannot be greater than Integer max value: " + size); throw new IllegalArgumentException("Size cannot be greater than Integer max value: " + size);

@ -1,19 +1,21 @@
package xyz.wbsite.dbtool.web.frame.utils; package xyz.wbsite.dbtool.web.frame.utils;
import org.springframework.boot.system.ApplicationHome; import org.springframework.boot.system.ApplicationHome;
import org.springframework.core.io.ClassPathResource; import org.springframework.core.io.ClassPathResource;
import org.springframework.util.ResourceUtils; import org.springframework.util.ResourceUtils;
import java.io.File; import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.net.URL;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Enumeration; import java.util.Enumeration;
import java.util.List; import java.util.List;
import java.util.jar.JarEntry; import java.util.jar.JarEntry;
import java.util.jar.JarFile; import java.util.jar.JarFile;
import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;
/** /**
@ -25,27 +27,78 @@ import java.util.regex.Pattern;
*/ */
public class ResourceUtil extends ResourceUtils { public class ResourceUtil extends ResourceUtils {
/**
*
* :E:\...\classes
* JAR: E:\...\***.jar
*
* @return jar
*/
public static File getApplicationHome() {
ApplicationHome home = new ApplicationHome(ResourceUtil.class);
return home.getSource();
}
/**
*
*
* @param resourcePath
* @return
*/
public static List<String> listFileName(String resourcePath) {
if (!resourcePath.endsWith("/")) {
resourcePath = resourcePath + "/";
}
List<String> result = new ArrayList<>();
List<URL> urls = ResourceUtil.listURL(resourcePath);
for (URL url : urls) {
File file1 = new File(url.getFile());
if (file1.isFile()) {
result.add(file1.getName());
} else if (!file1.isDirectory() && !url.getFile().endsWith("/")) {
result.add(file1.getName());
}
}
return result;
}
/**
* @param resourceLocation
* @return URL
* @throws FileNotFoundException
*/
public static URL getURL(String resourceLocation) throws FileNotFoundException {
if (!resourceLocation.startsWith("classpath:")) {
resourceLocation = "classpath:" + resourceLocation;
}
return ResourceUtils.getURL(resourceLocation);
}
/** /**
* : /modules/dir/ * : /modules/dir/
* *
* @param resourcePath * @param resourcePath
* @return * @return
*/ */
public static List<String> getResourceFiles(String resourcePath) { public static List<URL> listURL(String resourcePath) {
List<String> result = new ArrayList<>(); if (!resourcePath.startsWith("/")) {
resourcePath = "/" + resourcePath;
}
if (!resourcePath.endsWith("/")) {
resourcePath = resourcePath + "/";
}
List<URL> result = new ArrayList<>();
File applicationHome = getApplicationHome(); File applicationHome = getApplicationHome();
if (applicationHome.getAbsolutePath().endsWith(".jar")) { if (applicationHome.getName().endsWith(".jar")) {
try { try {
Pattern pattern = Pattern.compile(".*" + resourcePath + "(.+\\..+)"); Pattern pattern = Pattern.compile("BOOT-INF/classes" + resourcePath + "[^/]+/?$");
JarFile jarFile = new JarFile(applicationHome); JarFile jarFile = new JarFile(applicationHome);
Enumeration<JarEntry> entries = jarFile.entries(); Enumeration<JarEntry> entries = jarFile.entries();
while (entries.hasMoreElements()) { while (entries.hasMoreElements()) {
JarEntry jarEntry = entries.nextElement(); JarEntry jarEntry = entries.nextElement();
String name = jarEntry.getName(); String name = jarEntry.getName();
if (pattern.matcher(name).find()) {
if (name.matches(".*" + resourcePath + "(.+\\..+)")) { result.add(getURL(name));
Matcher matcher = pattern.matcher(name);
if (matcher.find()) result.add(matcher.group(1));
} }
} }
} catch (IOException e) { } catch (IOException e) {
@ -56,36 +109,24 @@ public class ResourceUtil extends ResourceUtils {
ClassPathResource cpr = new ClassPathResource(resourcePath); ClassPathResource cpr = new ClassPathResource(resourcePath);
File in = cpr.getFile(); File in = cpr.getFile();
for (File file : in.listFiles()) { for (File file : in.listFiles()) {
String name = file.getName(); result.add(FileUtil.getURL(file.getAbsolutePath()));
if (name.matches(".+\\..+")) result.add(name);
} }
return result; return result;
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
} }
} }
return result; return result;
} }
/** /**
* jar *
*
* @return jar
*/
public static File getApplicationHome() {
ApplicationHome home = new ApplicationHome(ResourceUtil.class);
return home.getSource();
}
/**
* resource
* *
* @return * @return
*/ */
public static InputStream getResourceInput(String resource) { public static InputStream getInput(String resourceLocation) {
try { try {
ClassPathResource classPathResource = new ClassPathResource(resource); ClassPathResource classPathResource = new ClassPathResource(resourceLocation);
return classPathResource.getInputStream(); return classPathResource.getInputStream();
} catch (IOException e) { } catch (IOException e) {
return null; return null;
@ -93,53 +134,54 @@ public class ResourceUtil extends ResourceUtils {
} }
/** /**
* jar *
* *
* @return * @return
*/ */
public static boolean copyResource2File(String resource, File file) { public static byte[] getBytes(String resourceLocation) {
InputStream resourceInput = getResourceInput(resource); InputStream is = null;
FileOutputStream fileOutputStream = null; byte[] result = null;
try { try {
if (!file.exists()) { is = getInput(resourceLocation);
file.createNewFile(); result = new byte[is.available()];
} is.read(result);
fileOutputStream = new FileOutputStream(file);
FileUtil.copy(resourceInput, fileOutputStream);
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
return false;
} finally { } finally {
try { try {
if (fileOutputStream != null) fileOutputStream.close(); if (is != null) is.close();
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
} }
} }
return true; return result;
} }
/** /**
* *
* *
* @return * @param resourceLocation
* @param file
* @return
*/ */
public static byte[] getResourceBytes(String resource) { public static boolean copyToFile(String resourceLocation, File file) {
InputStream is = null; InputStream resourceInput = getInput(resourceLocation);
byte[] result = null; FileOutputStream fileOutputStream = null;
try { try {
is = getResourceInput(resource); fileOutputStream = FileUtil.openOutputStream(file);
result = new byte[is.available()]; FileUtil.copy(resourceInput, fileOutputStream);
is.read(result);
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
return false;
} finally { } finally {
try { try {
if (is != null) is.close(); if (fileOutputStream != null) fileOutputStream.close();
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
} }
} }
return result; return true;
} }
} }

@ -154,6 +154,37 @@ public class FileUtil {
} }
} }
public static FileOutputStream openOutputStream(File file) throws IOException {
if (file.exists()) {
if (file.isDirectory()) {
throw new IOException("File '" + file + "' exists but is a directory");
} else if (!file.canRead()) {
throw new IOException("File '" + file + "' cannot be read");
} else {
return new FileOutputStream(file);
}
} else {
throw new FileNotFoundException("File '" + file + "' does not exist");
}
}
/**
* @param fileLocation
* @return URL
*/
public static URL getURL(String fileLocation) {
try {
return new URL(fileLocation);
} catch (MalformedURLException var6) {
try {
return (new File(fileLocation)).toURI().toURL();
} catch (MalformedURLException var5) {
var5.printStackTrace();
}
}
return null;
}
public static byte[] toByteArray(InputStream input, long size) throws IOException { public static byte[] toByteArray(InputStream input, long size) throws IOException {
if (size > 2147483647L) { if (size > 2147483647L) {
throw new IllegalArgumentException("Size cannot be greater than Integer max value: " + size); throw new IllegalArgumentException("Size cannot be greater than Integer max value: " + size);

@ -5,15 +5,16 @@ import org.springframework.core.io.ClassPathResource;
import org.springframework.util.ResourceUtils; import org.springframework.util.ResourceUtils;
import java.io.File; import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.net.URL;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Enumeration; import java.util.Enumeration;
import java.util.List; import java.util.List;
import java.util.jar.JarEntry; import java.util.jar.JarEntry;
import java.util.jar.JarFile; import java.util.jar.JarFile;
import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;
/** /**
@ -25,27 +26,78 @@ import java.util.regex.Pattern;
*/ */
public class ResourceUtil extends ResourceUtils { public class ResourceUtil extends ResourceUtils {
/**
*
* :E:\...\classes
* JAR: E:\...\***.jar
*
* @return jar
*/
public static File getApplicationHome() {
ApplicationHome home = new ApplicationHome(ResourceUtil.class);
return home.getSource();
}
/**
*
*
* @param resourcePath
* @return
*/
public static List<String> listFileName(String resourcePath) {
if (!resourcePath.endsWith("/")) {
resourcePath = resourcePath + "/";
}
List<String> result = new ArrayList<>();
List<URL> urls = ResourceUtil.listURL(resourcePath);
for (URL url : urls) {
File file1 = new File(url.getFile());
if (file1.isFile()) {
result.add(file1.getName());
} else if (!file1.isDirectory() && !url.getFile().endsWith("/")) {
result.add(file1.getName());
}
}
return result;
}
/**
* @param resourceLocation
* @return URL
* @throws FileNotFoundException
*/
public static URL getURL(String resourceLocation) throws FileNotFoundException {
if (!resourceLocation.startsWith("classpath:")) {
resourceLocation = "classpath:" + resourceLocation;
}
return ResourceUtils.getURL(resourceLocation);
}
/** /**
* : /modules/dir/ * : /modules/dir/
* *
* @param resourcePath * @param resourcePath
* @return * @return
*/ */
public static List<String> getResourceFiles(String resourcePath) { public static List<URL> listURL(String resourcePath) {
List<String> result = new ArrayList<>(); if (!resourcePath.startsWith("/")) {
resourcePath = "/" + resourcePath;
}
if (!resourcePath.endsWith("/")) {
resourcePath = resourcePath + "/";
}
List<URL> result = new ArrayList<>();
File applicationHome = getApplicationHome(); File applicationHome = getApplicationHome();
if (applicationHome.getAbsolutePath().endsWith(".jar")) { if (applicationHome.getName().endsWith(".jar")) {
try { try {
Pattern pattern = Pattern.compile(".*" + resourcePath + "(.+\\..+)"); Pattern pattern = Pattern.compile("BOOT-INF/classes" + resourcePath + "[^/]+/?$");
JarFile jarFile = new JarFile(applicationHome); JarFile jarFile = new JarFile(applicationHome);
Enumeration<JarEntry> entries = jarFile.entries(); Enumeration<JarEntry> entries = jarFile.entries();
while (entries.hasMoreElements()) { while (entries.hasMoreElements()) {
JarEntry jarEntry = entries.nextElement(); JarEntry jarEntry = entries.nextElement();
String name = jarEntry.getName(); String name = jarEntry.getName();
if (pattern.matcher(name).find()) {
if (name.matches(".*" + resourcePath + "(.+\\..+)")) { result.add(getURL(name));
Matcher matcher = pattern.matcher(name);
if (matcher.find()) result.add(matcher.group(1));
} }
} }
} catch (IOException e) { } catch (IOException e) {
@ -56,36 +108,24 @@ public class ResourceUtil extends ResourceUtils {
ClassPathResource cpr = new ClassPathResource(resourcePath); ClassPathResource cpr = new ClassPathResource(resourcePath);
File in = cpr.getFile(); File in = cpr.getFile();
for (File file : in.listFiles()) { for (File file : in.listFiles()) {
String name = file.getName(); result.add(FileUtil.getURL(file.getAbsolutePath()));
if (name.matches(".+\\..+")) result.add(name);
} }
return result; return result;
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
} }
} }
return result; return result;
} }
/** /**
* jar *
* *
* @return jar * @return
*/ */
public static File getApplicationHome() { public static InputStream getInput(String resourceLocation) {
ApplicationHome home = new ApplicationHome(ResourceUtil.class);
return home.getSource();
}
/**
* resource
*
* @return
*/
public static InputStream getResourceInput(String resource) {
try { try {
ClassPathResource classPathResource = new ClassPathResource(resource); ClassPathResource classPathResource = new ClassPathResource(resourceLocation);
return classPathResource.getInputStream(); return classPathResource.getInputStream();
} catch (IOException e) { } catch (IOException e) {
return null; return null;
@ -93,53 +133,52 @@ public class ResourceUtil extends ResourceUtils {
} }
/** /**
* jar *
* *
* @return * @return
*/ */
public static boolean copyResource2File(String resource, File file) { public static byte[] getBytes(String resourceLocation) {
InputStream resourceInput = getResourceInput(resource); InputStream is = null;
FileOutputStream fileOutputStream = null; byte[] result = null;
try { try {
if (!file.exists()) { is = getInput(resourceLocation);
file.createNewFile(); result = new byte[is.available()];
} is.read(result);
fileOutputStream = new FileOutputStream(file);
FileUtil.copy(resourceInput, fileOutputStream);
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
return false;
} finally { } finally {
try { try {
if (fileOutputStream != null) fileOutputStream.close(); if (is != null) is.close();
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
} }
} }
return true; return result;
} }
/** /**
* *
* *
* @return * @param resourceLocation
* @param file
* @return
*/ */
public static byte[] getResourceBytes(String resource) { public static boolean copyToFile(String resourceLocation, File file) {
InputStream is = null; InputStream resourceInput = getInput(resourceLocation);
byte[] result = null; FileOutputStream fileOutputStream = null;
try { try {
is = getResourceInput(resource); fileOutputStream = FileUtil.openOutputStream(file);
result = new byte[is.available()]; FileUtil.copy(resourceInput, fileOutputStream);
is.read(result);
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
return false;
} finally { } finally {
try { try {
if (is != null) is.close(); if (fileOutputStream != null) fileOutputStream.close();
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
} }
} }
return result; return true;
} }
} }
Loading…
Cancel
Save

Powered by TurnKey Linux.