fix:修复读取中文路径文件异常
This commit is contained in:
3
.gitignore
vendored
3
.gitignore
vendored
@@ -1 +1,2 @@
|
|||||||
.idea
|
.idea
|
||||||
|
*.iml
|
||||||
72
pom.xml
72
pom.xml
@@ -19,6 +19,49 @@
|
|||||||
|
|
||||||
<description>this is javafx framework that simplified coding</description>
|
<description>this is javafx framework that simplified coding</description>
|
||||||
|
|
||||||
|
<properties>
|
||||||
|
<cglib.version>3.1</cglib.version>
|
||||||
|
<junit.version>4.13.1</junit.version>
|
||||||
|
<slf4j-log4j12.version>1.7.21</slf4j-log4j12.version>
|
||||||
|
<tomcat.version>9.0.48</tomcat.version>
|
||||||
|
<commons-lang3.version>3.12.0</commons-lang3.version>
|
||||||
|
</properties>
|
||||||
|
<dependencies>
|
||||||
|
<!-- 第三方动态代理库 -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>cglib</groupId>
|
||||||
|
<artifactId>cglib</artifactId>
|
||||||
|
<version>${cglib.version}</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!-- Junit单元测试 -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>junit</groupId>
|
||||||
|
<artifactId>junit</artifactId>
|
||||||
|
<version>${junit.version}</version>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!-- log4j 日志 -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.slf4j</groupId>
|
||||||
|
<artifactId>slf4j-log4j12</artifactId>
|
||||||
|
<version>${slf4j-log4j12.version}</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.apache.tomcat.embed</groupId>
|
||||||
|
<artifactId>tomcat-embed-core</artifactId>
|
||||||
|
<version>${tomcat.version}</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.apache.commons</groupId>
|
||||||
|
<artifactId>commons-lang3</artifactId>
|
||||||
|
<version>${commons-lang3.version}</version>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
|
||||||
<distributionManagement>
|
<distributionManagement>
|
||||||
<repository>
|
<repository>
|
||||||
<id>javafx-plus</id>
|
<id>javafx-plus</id>
|
||||||
@@ -30,35 +73,6 @@
|
|||||||
</snapshotRepository>
|
</snapshotRepository>
|
||||||
</distributionManagement>
|
</distributionManagement>
|
||||||
|
|
||||||
<dependencies>
|
|
||||||
<!-- 第三方动态代理库 -->
|
|
||||||
<dependency>
|
|
||||||
<groupId>cglib</groupId>
|
|
||||||
<artifactId>cglib</artifactId>
|
|
||||||
<version>3.1</version>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<!-- Junit单元测试 -->
|
|
||||||
<dependency>
|
|
||||||
<groupId>junit</groupId>
|
|
||||||
<artifactId>junit</artifactId>
|
|
||||||
<version>4.11</version>
|
|
||||||
<scope>test</scope>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<!-- log4j 日志 -->
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.slf4j</groupId>
|
|
||||||
<artifactId>slf4j-log4j12</artifactId>
|
|
||||||
<version>1.7.21</version>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.apache.tomcat.embed</groupId>
|
|
||||||
<artifactId>tomcat-embed-core</artifactId>
|
|
||||||
<version>9.0.29</version>
|
|
||||||
</dependency>
|
|
||||||
</dependencies>
|
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
<!--配置Maven 对resource文件 过滤 -->
|
<!--配置Maven 对resource文件 过滤 -->
|
||||||
<resources>
|
<resources>
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ import cn.edu.scau.biubiusuisui.utils.ClassUtil;
|
|||||||
import cn.edu.scau.biubiusuisui.utils.FileUtil;
|
import cn.edu.scau.biubiusuisui.utils.FileUtil;
|
||||||
import cn.edu.scau.biubiusuisui.utils.LogUtil;
|
import cn.edu.scau.biubiusuisui.utils.LogUtil;
|
||||||
|
|
||||||
|
import java.io.UnsupportedEncodingException;
|
||||||
import java.lang.annotation.Annotation;
|
import java.lang.annotation.Annotation;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -25,7 +26,6 @@ import java.util.Set;
|
|||||||
*/
|
*/
|
||||||
public class FXPlusApplication {
|
public class FXPlusApplication {
|
||||||
private static final IFXPlusLogger logger = FXPlusLoggerFactory.getLogger(FXPlusApplication.class);
|
private static final IFXPlusLogger logger = FXPlusLoggerFactory.getLogger(FXPlusApplication.class);
|
||||||
// Application
|
|
||||||
|
|
||||||
private static FXWindowParser windowAnnotationParser = new FXWindowParser();
|
private static FXWindowParser windowAnnotationParser = new FXWindowParser();
|
||||||
|
|
||||||
@@ -37,7 +37,11 @@ public class FXPlusApplication {
|
|||||||
|
|
||||||
public static void start(Class clazz, BeanBuilder beanBuilder) {
|
public static void start(Class clazz, BeanBuilder beanBuilder) {
|
||||||
logger.info("starting JavaFX-Plus Application");
|
logger.info("starting JavaFX-Plus Application");
|
||||||
logger.info("\n" + FileUtil.readFileFromResources("banner.txt"));
|
try {
|
||||||
|
logger.info("\n" + FileUtil.readFileFromResources("banner.txt"));
|
||||||
|
} catch (UnsupportedEncodingException e) {
|
||||||
|
logger.error("\n read classpath:banner.txt error, you can ignore it");
|
||||||
|
}
|
||||||
// 初始化日志路径
|
// 初始化日志路径
|
||||||
LogUtil.initLog4jBase();
|
LogUtil.initLog4jBase();
|
||||||
|
|
||||||
@@ -56,15 +60,15 @@ public class FXPlusApplication {
|
|||||||
for (String dir : sets) {
|
for (String dir : sets) {
|
||||||
logger.info("scanning directory: " + dir);
|
logger.info("scanning directory: " + dir);
|
||||||
ClassUtil classUtil = new ClassUtil();
|
ClassUtil classUtil = new ClassUtil();
|
||||||
List<String> temps = classUtil.scanAllClassName(dir);
|
List<String> temps = null;
|
||||||
for (String className : temps) {
|
try {
|
||||||
try {
|
temps = classUtil.scanAllClassName(dir);
|
||||||
|
for (String className : temps) {
|
||||||
logger.info("loading class: " + className);
|
logger.info("loading class: " + className);
|
||||||
loadFXPlusClass(className, beanBuilder);
|
loadFXPlusClass(className, beanBuilder);
|
||||||
} catch (ClassNotFoundException e) {
|
|
||||||
logger.error(e.getMessage());
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
}
|
||||||
|
} catch (UnsupportedEncodingException | ClassNotFoundException exception) {
|
||||||
|
logger.error("{}", exception);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ import javafx.stage.Stage;
|
|||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.io.UnsupportedEncodingException;
|
||||||
import java.lang.annotation.Annotation;
|
import java.lang.annotation.Annotation;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
@@ -249,8 +250,8 @@ public class FXBaseController extends Pane {
|
|||||||
} else {
|
} else {
|
||||||
logger.warn("the icon file has not existed");
|
logger.warn("the icon file has not existed");
|
||||||
}
|
}
|
||||||
} catch (ProtocolNotSupport protocolNotSupport) {
|
} catch (ProtocolNotSupport | UnsupportedEncodingException exception) {
|
||||||
logger.error(protocolNotSupport.getMessage(), protocolNotSupport);
|
logger.error(exception.getMessage(), exception);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,6 @@
|
|||||||
package cn.edu.scau.biubiusuisui.log;
|
package cn.edu.scau.biubiusuisui.log;
|
||||||
|
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author suisui
|
* @author suisui
|
||||||
* @version 1.2
|
* @version 1.2
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package cn.edu.scau.biubiusuisui.utils;
|
|||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.io.UnsupportedEncodingException;
|
||||||
import java.lang.annotation.Annotation;
|
import java.lang.annotation.Annotation;
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
@@ -22,7 +23,14 @@ public class ClassUtil {
|
|||||||
classLoader = getClass().getClassLoader();
|
classLoader = getClass().getClassLoader();
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<String> getAllFXControllerClassName(String base, List<String> nameList) {
|
/**
|
||||||
|
* 获取所有FxController的类名
|
||||||
|
*
|
||||||
|
* @param base 基础目录路径
|
||||||
|
* @param nameList 类名列表
|
||||||
|
* @return 所有FXController的类名列表
|
||||||
|
*/
|
||||||
|
private List<String> getAllFXControllerClassName(String base, List<String> nameList) throws UnsupportedEncodingException {
|
||||||
String splashPath = StringUtil.dotToSplash(base);
|
String splashPath = StringUtil.dotToSplash(base);
|
||||||
URL url = classLoader.getResource(splashPath);
|
URL url = classLoader.getResource(splashPath);
|
||||||
String filePath = StringUtil.getRootPath(url);
|
String filePath = StringUtil.getRootPath(url);
|
||||||
@@ -42,7 +50,7 @@ public class ClassUtil {
|
|||||||
return nameList;
|
return nameList;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<String> scanAllClassName(String base) {
|
public List<String> scanAllClassName(String base) throws UnsupportedEncodingException {
|
||||||
return getAllFXControllerClassName(base, new LinkedList<>());
|
return getAllFXControllerClassName(base, new LinkedList<>());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -62,7 +70,9 @@ public class ClassUtil {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static List<String> readFromDirectory(String path) {
|
private static List<String> readFromDirectory(String path) {
|
||||||
if (path == null) return null;
|
if (path == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
return readFromFileDirectory(path);
|
return readFromFileDirectory(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import cn.edu.scau.biubiusuisui.log.IFXPlusLogger;
|
|||||||
|
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
|
import java.net.URLDecoder;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author jack
|
* @author jack
|
||||||
@@ -34,7 +35,7 @@ public class FileUtil {
|
|||||||
* @return
|
* @return
|
||||||
* @description 读取resources文件夹下的file,相对于resources的文件路径,如 resources/config.conf 则只需 config.conf
|
* @description 读取resources文件夹下的file,相对于resources的文件路径,如 resources/config.conf 则只需 config.conf
|
||||||
*/
|
*/
|
||||||
public static String readFileFromResources(String filePath) {
|
public static String readFileFromResources(String filePath) throws UnsupportedEncodingException {
|
||||||
URL url = FileUtil.class.getClassLoader().getResource(filePath);
|
URL url = FileUtil.class.getClassLoader().getResource(filePath);
|
||||||
if (url != null) {
|
if (url != null) {
|
||||||
String path = StringUtil.getRootPath(url);
|
String path = StringUtil.getRootPath(url);
|
||||||
|
|||||||
@@ -0,0 +1,14 @@
|
|||||||
|
package cn.edu.scau.biubiusuisui.utils;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author suisui
|
||||||
|
* @version 1.2.0
|
||||||
|
* <p> Description: JavaFx-Plus常量 </p>
|
||||||
|
* @time 2021/9/5 10:36 下午
|
||||||
|
*/
|
||||||
|
public interface IFxPlusConstants {
|
||||||
|
/**
|
||||||
|
* 项目默认编码 UTF-8
|
||||||
|
*/
|
||||||
|
String DEFAULT_CHARSET = "UTF-8";
|
||||||
|
}
|
||||||
@@ -2,8 +2,11 @@ package cn.edu.scau.biubiusuisui.utils;
|
|||||||
|
|
||||||
import cn.edu.scau.biubiusuisui.log.FXPlusLoggerFactory;
|
import cn.edu.scau.biubiusuisui.log.FXPlusLoggerFactory;
|
||||||
import cn.edu.scau.biubiusuisui.log.IFXPlusLogger;
|
import cn.edu.scau.biubiusuisui.log.IFXPlusLogger;
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
|
||||||
|
import java.io.UnsupportedEncodingException;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
|
import java.net.URLDecoder;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author jack
|
* @author jack
|
||||||
@@ -11,20 +14,20 @@ import java.net.URL;
|
|||||||
* @version 1.0
|
* @version 1.0
|
||||||
* @date 2019/6/25 3:46
|
* @date 2019/6/25 3:46
|
||||||
* @since JavaFX2.0 JDK1.8
|
* @since JavaFX2.0 JDK1.8
|
||||||
|
* @since 1.3.0 add:继承StringUtils
|
||||||
*/
|
*/
|
||||||
public class StringUtil {
|
public class StringUtil extends StringUtils {
|
||||||
private static IFXPlusLogger logger = FXPlusLoggerFactory.getLogger(StringUtil.class);
|
private static IFXPlusLogger logger = FXPlusLoggerFactory.getLogger(StringUtil.class);
|
||||||
|
|
||||||
private StringUtil() {
|
private StringUtil() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* "file:/home/whf/cn/fh" -> "/home/whf/cn/fh"
|
* "file:/home/whf/cn/fh" -> "/home/whf/cn/fh"
|
||||||
* "jar:file:/home/whf/foo.jar!cn/fh" -> "/home/whf/foo.jar"
|
* "jar:file:/home/whf/foo.jar!cn/fh" -> "/home/whf/foo.jar"
|
||||||
*/
|
*/
|
||||||
public static String getRootPath(URL url) {
|
public static String getRootPath(URL url) throws UnsupportedEncodingException {
|
||||||
String fileUrl = url.getFile();
|
String fileUrl = URLDecoder.decode(url.getFile(),IFxPlusConstants.DEFAULT_CHARSET);
|
||||||
int pos = fileUrl.indexOf('!');
|
int pos = fileUrl.indexOf('!');
|
||||||
|
|
||||||
if (-1 == pos) {
|
if (-1 == pos) {
|
||||||
@@ -51,7 +54,6 @@ public class StringUtil {
|
|||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public static String splashToDot(String name) {
|
public static String splashToDot(String name) {
|
||||||
|
|
||||||
return name.replaceAll("/", "\\.");
|
return name.replaceAll("/", "\\.");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -63,7 +65,6 @@ public class StringUtil {
|
|||||||
if (-1 != pos) {
|
if (-1 != pos) {
|
||||||
return name.substring(0, pos);
|
return name.substring(0, pos);
|
||||||
}
|
}
|
||||||
|
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -76,7 +77,6 @@ public class StringUtil {
|
|||||||
public static String trimURI(String uri) {
|
public static String trimURI(String uri) {
|
||||||
String trimmed = uri.substring(1);
|
String trimmed = uri.substring(1);
|
||||||
int splashIndex = trimmed.indexOf('/');
|
int splashIndex = trimmed.indexOf('/');
|
||||||
|
|
||||||
return trimmed.substring(splashIndex);
|
return trimmed.substring(splashIndex);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -103,8 +103,7 @@ public class StringUtil {
|
|||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public static String toInstanceName(String name) {
|
public static String toInstanceName(String name) {
|
||||||
String result = name.substring(0, 1).toLowerCase().concat(name.substring(1));
|
return name.substring(0, 1).toLowerCase().concat(name.substring(1));
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -114,8 +113,7 @@ public class StringUtil {
|
|||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public static String toClassName(String name) {
|
public static String toClassName(String name) {
|
||||||
String result = name.substring(0, 1).toUpperCase().concat(name.substring(1));
|
return name.substring(0, 1).toUpperCase().concat(name.substring(1));
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ log4j.appender.D=org.apache.log4j.DailyRollingFileAppender
|
|||||||
# MacOS
|
# MacOS
|
||||||
log4j.appender.D.File=${log.base}/logs/debug/javafxplus.log
|
log4j.appender.D.File=${log.base}/logs/debug/javafxplus.log
|
||||||
log4j.appender.D.Append=true
|
log4j.appender.D.Append=true
|
||||||
log4j.appender.D.Threshold=DEBUG
|
log4j.appender.D.Threshold=DEBUG
|
||||||
log4j.appender.D.layout=org.apache.log4j.PatternLayout
|
log4j.appender.D.layout=org.apache.log4j.PatternLayout
|
||||||
log4j.appender.D.layout.ConversionPattern=[%p] %-d{yyyy-MM-dd HH:mm:ss} [%t] [%l] - %m%n
|
log4j.appender.D.layout.ConversionPattern=[%p] %-d{yyyy-MM-dd HH:mm:ss} [%t] [%l] - %m%n
|
||||||
### 输出ERROR 级别以上的日志到=E://logs/error.log ###
|
### 输出ERROR 级别以上的日志到=E://logs/error.log ###
|
||||||
@@ -22,6 +22,6 @@ log4j.appender.E=org.apache.log4j.DailyRollingFileAppender
|
|||||||
# MacOS
|
# MacOS
|
||||||
log4j.appender.E.File=${log.base}/logs/error/javafxplus.log
|
log4j.appender.E.File=${log.base}/logs/error/javafxplus.log
|
||||||
log4j.appender.E.Append=true
|
log4j.appender.E.Append=true
|
||||||
log4j.appender.E.Threshold=ERROR
|
log4j.appender.E.Threshold=ERROR
|
||||||
log4j.appender.E.layout=org.apache.log4j.PatternLayout
|
log4j.appender.E.layout=org.apache.log4j.PatternLayout
|
||||||
log4j.appender.E.layout.ConversionPattern=[%p] %-d{yyyy-MM-dd HH:mm:ss} [%t] [%l] - %m%n
|
log4j.appender.E.layout.ConversionPattern=[%p] %-d{yyyy-MM-dd HH:mm:ss} [%t] [%l] - %m%n
|
||||||
Reference in New Issue
Block a user