-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutil.jsp
116 lines (95 loc) · 3.73 KB
/
util.jsp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
<%@ page import="java.io.FileInputStream" %>
<%@ page import="java.io.FileOutputStream" %>
<%@ page import="java.io.OutputStream" %>
<%@ page import="java.io.InputStream" %>
<%@ page import="java.io.File" %>
<%@ page import="java.util.Properties" %>
<%@ page import="java.util.Map" %>
<%@ page import="java.util.TreeMap" %>
<%@ page import="java.io.IOException" %>
<%@ page import="javax.servlet.ServletContext" %>
<%@ page import="java.util.Comparator" %>
<%!
private static final String PROFILE_DIR = "ProfileDir";
private static final String HOME_DIR = "HomeDir";
public class Store {
String profileDir;
String homeDir;
String adminPassword;
public Store(ServletContext application) throws IOException {
Properties p = loadProperties(new File(application.getRealPath("/WEB-INF/exportgui.properties")));
profileDir = p.getProperty(PROFILE_DIR);
homeDir = p.getProperty(HOME_DIR);
adminPassword = p.getProperty("password");
}
public Properties loadProfile(String name) throws IOException {
return loadProperties(getProfileFile(name));
}
void storeProfile(Properties profile) throws IOException {
String name = profile.getProperty("name");
storeProperties(profile, getProfileFile(name));
}
public Map loadAllProfiles() throws IOException {
File files[] = getProfilesDir().listFiles();
Map<String, Properties> profiles = new TreeMap<String, Properties>(new Comparator<String>() {
@Override
public int compare(String s1, String s2) {
return s1 != null ? s1.compareToIgnoreCase(s2) : 0;
}
});
for (File f : files) {
if (f.getName().endsWith(".properties")) {
Properties profile = loadProperties(f);
profiles.put(profile.getProperty("longname"), profile);
}
}
return profiles;
}
public void storeJob(Properties job) throws IOException {
String jobId = "" + (int) (Math.random() * 1000000);
storeProperties(job, getJobFile(jobId));
}
public File getProfileFile(String profileName) {
return new File(getProfilesDir(), profileName + ".properties");
}
public File getProfilesDir() {
return new File(profileDir);
}
public File getJobFile(String jobId) {
return new File(getJobsDir(), jobId);
}
public File getJobsDir() {
return new File(homeDir + "/jobs/incoming");
}
public File getExportDir(String profileName) {
return new File(homeDir + "/files/" + profileName + "/marc");
}
public File getLogDir(String profileName) {
return new File(homeDir + "/files/" + profileName + "/logs");
}
public String getAdminPassword() {
return adminPassword;
}
}
public Store getStore(ServletContext application) throws IOException {
return new Store(application);
}
public static Properties loadProperties(File file) throws IOException {
Properties properties = new Properties();
InputStream input = new FileInputStream(file);
try {
properties.load(input);
} finally {
input.close();
}
return properties;
}
private static void storeProperties(Properties properties, File file) throws IOException {
OutputStream output = new FileOutputStream(file);
try {
properties.store(output, null);
} finally {
output.close();
}
}
%>