Skip to content

Commit d10d444

Browse files
author
shimingxy
committed
v1.3 RC
1 parent fe2d3ed commit d10d444

File tree

3 files changed

+75
-63
lines changed

3 files changed

+75
-63
lines changed
Lines changed: 72 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -1,71 +1,81 @@
11
package org.maxkey.util;
22

33
import java.io.UnsupportedEncodingException;
4-
54
import org.slf4j.Logger;
65
import org.slf4j.LoggerFactory;
76

87
public class PathUtils {
9-
private final Logger _logger = LoggerFactory.getLogger(PathUtils.class);
10-
private static PathUtils instance = null;
11-
private String classPath;
12-
private String appPath;
13-
public static String WEB_INFO = "/WEB-INF/";
14-
15-
public static synchronized PathUtils getInstance() {
16-
if (instance == null) {
17-
instance = new PathUtils();
18-
instance._logger.debug("getInstance()" +" new PathUtils instance");
19-
}
20-
return instance;
21-
}
8+
private static final Logger _logger = LoggerFactory.getLogger(PathUtils.class);
9+
private static PathUtils instance = null;
10+
private String classPath;
11+
private String appPath;
12+
public static String WEB_INFO = "/WEB-INF/";
13+
14+
/**
15+
* getInstance .
16+
* @return
17+
*/
18+
public static synchronized PathUtils getInstance() {
19+
if (instance == null) {
20+
instance = new PathUtils();
21+
PathUtils._logger.debug("getInstance()" + " new PathUtils instance");
22+
}
23+
return instance;
24+
}
25+
26+
/**
27+
* PathUtils.
28+
*/
29+
public PathUtils() {
30+
try {
31+
classPath = java.net.URLDecoder.decode(
32+
PathUtils.class.getResource("PathUtils.xml").getFile(),
33+
"UTF-8"
34+
);
35+
_logger.debug("PathUtils() PathUtils " + classPath);
36+
} catch (UnsupportedEncodingException e) {
37+
e.printStackTrace();
38+
}
39+
40+
String fileProtocol = PathUtils.class.getResource("PathUtils.properties").getProtocol();
41+
_logger.info("Properties Protocol:"
42+
+ PathUtils.class.getResource("PathUtils.properties").getProtocol());
43+
44+
if (fileProtocol.equalsIgnoreCase("file") && classPath.indexOf("file:") == 0) {
45+
classPath = classPath.substring(5, classPath.length());
46+
} else if (fileProtocol.equalsIgnoreCase("jar") && classPath.indexOf("file:") == 0) {
47+
// file:/Server/webapps/app
48+
classPath = classPath.substring(5, classPath.length());
49+
} else if (fileProtocol.equalsIgnoreCase("wsjar") && classPath.indexOf("file:") == 0) {
50+
classPath = classPath.substring(5, classPath.length());
51+
} else if (classPath.equalsIgnoreCase("file:")) {
52+
classPath = classPath.substring(5, classPath.length());
53+
}
54+
55+
_logger.info("PathUtils Class Path : " + classPath);
56+
classPath = classPath.substring(0, classPath.indexOf("/org/maxkey/util/PathUtils.xml"));
57+
if (classPath.indexOf(WEB_INFO) == -1) {
58+
appPath = classPath.substring(0, classPath.lastIndexOf("/"));
59+
} else {
60+
appPath = classPath.substring(0, classPath.lastIndexOf(WEB_INFO));
61+
}
62+
63+
System.setProperty("APP_PATH", appPath);
64+
System.setProperty("CLASSES_PATH", classPath);
65+
66+
_logger.info("PathUtils App Path : " + appPath);
67+
_logger.info("PathUtils Class Path : " + classPath);
68+
}
69+
70+
public String getAppPath() {
71+
return appPath + "/";
72+
}
73+
74+
public String getClassPath() {
75+
return classPath + "/";
76+
}
2277

23-
public PathUtils() {
24-
try {
25-
classPath = java.net.URLDecoder.decode(PathUtils.class.getResource("PathUtils.properties").getFile(),"UTF-8");
26-
_logger.debug("PathUtils() PathUtils " +classPath);
27-
} catch (UnsupportedEncodingException e) {
28-
e.printStackTrace();
29-
}
30-
31-
String fileProtocol=PathUtils.class.getResource("PathUtils.properties").getProtocol();
32-
_logger.info("Properties Protocol:"+PathUtils.class.getResource("PathUtils.properties").getProtocol());
33-
34-
if(fileProtocol.equalsIgnoreCase("file")&&classPath.indexOf("file:")==0){
35-
classPath=classPath.substring(5, classPath.length());
36-
}else if(fileProtocol.equalsIgnoreCase("jar")&&classPath.indexOf("file:")==0){
37-
// file:/Server/webapps/app
38-
classPath=classPath.substring(5, classPath.length());
39-
}else if(fileProtocol.equalsIgnoreCase("wsjar")&&classPath.indexOf("file:")==0){
40-
classPath=classPath.substring(5, classPath.length());
41-
}else if(classPath.equalsIgnoreCase("file:")){
42-
classPath=classPath.substring(5, classPath.length());
43-
}
44-
45-
_logger.info("PathUtils Class Path : " + classPath);
46-
classPath=classPath.substring(0,classPath.indexOf("/org/maxkey/util/PathUtils.properties"));
47-
if(classPath.indexOf(WEB_INFO)==-1) {
48-
appPath=classPath.substring(0,classPath.lastIndexOf("/"));
49-
}else {
50-
appPath=classPath.substring(0,classPath.lastIndexOf(WEB_INFO));
51-
}
52-
53-
System.setProperty("APP_PATH", appPath);
54-
System.setProperty("CLASSES_PATH", classPath);
55-
56-
_logger.info("PathUtils App Path : " + appPath);
57-
_logger.info("PathUtils Class Path : " + classPath);
58-
}
59-
60-
public String getAppPath(){
61-
return appPath + "/";
62-
}
63-
64-
public String getClassPath(){
65-
return classPath + "/";
66-
}
67-
68-
public String getWebInf(){
69-
return (classPath.lastIndexOf(WEB_INFO)>-1)? (appPath + WEB_INFO) : "";
70-
}
78+
public String getWebInf() {
79+
return (classPath.lastIndexOf(WEB_INFO) > -1) ? (appPath + WEB_INFO) : "";
80+
}
7181
}

maxkey-core/src/main/java/org/maxkey/util/PathUtils.properties

Lines changed: 0 additions & 1 deletion
This file was deleted.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<root>
2+
org.maxkey.util.PathUtils
3+
</root>

0 commit comments

Comments
 (0)