IT-KIMI_SHI\SINOIT.KIMI
2018-06-01 521993214708c66a5498bd669c94a661c11484b2
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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
package frame.config;
 
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
 
import javax.servlet.ServletContext;
 
import frame.data.DataBaseType;
import frame.data.DataCell;
import frame.data.Variant;
import frame.expression.Expression;
import frame.expression.VariantContext;
import frame.expression.VariantRequestParams;
import frame.util.Util;
 
 
public class Configer extends VariantContext {
 
    private static Configer instance;
    private static Object lock = new Object();
    
    private Map<String, String> params;
    private List<DataCell> clientSysparams;
    private String DataBase_Schema = null;
    private String Path_Application;
    private String Path_WebInfo;
    private String Path_Config;
    private String Path_SQL;
    private DataBaseType dataBaseType;
 
    private Configer() {
        
    }
    
    public static Configer getInstance() {
        if (instance == null) {
            synchronized (lock) {
                if (instance == null) {
                    instance = new Configer();
                }
            }
        }
        
        return instance;
    }
    
    public static void init(ServletContext servletContext) {
        getInstance();
        
        instance.params = new HashMap<String, String>();
        instance.clientSysparams = new ArrayList<DataCell>();
 
        instance.Path_Application = servletContext.getRealPath("").replace("\\", "/");
        instance.Path_WebInfo = servletContext.getRealPath("/WEB-INF").replace("\\", "/");
        instance.Path_Config = instance.Path_WebInfo + "/config/";
        instance.Path_SQL = instance.Path_WebInfo + "/sql/";
    }
 
    public static void afterLoadParams() {
        String typeString = getParam("dataBaseType");
        instance.dataBaseType = DataBaseType.valueOfString(typeString);
    }
 
    public static void addParam(String name, String value, boolean client) throws Exception {
        Expression expression = new Expression(value);
        
        if (!expression.isVariantEmpty()) {
            instance.setParametersTo(expression);
            value = expression.getString();
        }
        
        instance.params.put(name.toLowerCase(), value);
        
        if (client) {
            instance.clientSysparams.add(new DataCell(name, new Variant(value)));
        }
    }
    
    @Override
    public String getStringValue(String variantName, VariantRequestParams requestParams) {
        if (variantName == null) {
            return null;
        }
        
        if ("path_application".equalsIgnoreCase(variantName)) {
            return Path_Application;
        }
        else if ("path_config".equalsIgnoreCase(variantName)) {
            return Path_Config;
        }
        else if ("path_sql".equalsIgnoreCase(variantName)) {
            return Path_SQL;
        }
        else if ("path_webinfo".equalsIgnoreCase(variantName)) {
            return Path_WebInfo;
        }
        else {
            return params.get(variantName.toLowerCase());
        }
    }
 
    public static String getParam(String name) {
        if (name == null) {
            return null;
        }
 
        return instance.params.get(name.toLowerCase());
    }
 
    public static String getPath_WebInfo() {
        return instance.Path_WebInfo;
    }
 
    public static String getPath_Config() {
        return instance.Path_Config;
    }
 
    public static String getPath_TimerConfig() {
        return instance.Path_Config + "timer.properties";
    }
 
    public static String getWebserviceURI() {
        return "http://www.jydatas.com/";
    }
 
    public static String getPath_Application() {
        return instance.Path_Application;
    }
    
    public static String getPath_Application(String subpath) {
        if (subpath == null) {
            return instance.Path_Application;
        }
        
        subpath = subpath.replace("\\", "/");
        
        if ('/' != subpath.charAt(0)) {
            subpath = "/" + subpath;
        }
        
        if ('/' != subpath.charAt(subpath.length() - 1)) {
            subpath = subpath + "/";
        }
        
        return instance.Path_Application + subpath;
    }
 
    public static String getPath_LoggerConfig() {
        return instance.Path_Config + "log4j.properties";
    }
 
    public static String getPath_ActivePeriodConfig() {
        return instance.Path_Config + "activeperiod.properties";
    }
 
    public static String getPath_SQLConfig() {
        return instance.Path_SQL;
    }
 
    public static String getPath_SQLDTD() {
        return instance.Path_Config + "sql.dtd";
    }
 
    public static String getPath_MainConfig() {
        return instance.Path_Config + "config.xml";
    }
 
    public static String getPath_Datasource() {
        return instance.Path_Config + "datasource.xml";
    }
 
    public static String getPath_Upload(String username) {
        return instance.Path_Application + "/upload/" + username;
    }
 
    public static String getPath_Temp() {
        return instance.Path_Application + "/temp";
    }
    
    public static String getPath_Temp(String username) {
        return instance.Path_Application + "/temp/" + username;
    }    
 
    public static String getPath_WXConfig() {
        return instance.Path_Config + "weixin.properties";
    }
 
    public static List<DataCell> getClientSysparams() {
        return instance.clientSysparams;
    }
 
    // ***************Page******************//
    public static String getPage_TimeOut() {
        String appName = getParam("appName");
        String timeOutPage = getParam("timeOutPage");
 
        return "/" + appName + "/" + timeOutPage;
    }
 
    public static DataBaseType getDataBaseType() {
        return instance.dataBaseType;
    }
 
    public static String getPath_ImageLib(String typeCode) {
        return instance.Path_Application + "/imagelib/" + typeCode + "/" + Util.newDateTimeStr("yyyyMM") + "/";
    }
 
    public static boolean isMultiplyDatasoure() {
        String lowerCase = "multipleDataSource".toLowerCase();
        String multi = instance.params.get(lowerCase);
        return Util.stringToBoolean(multi);
    }
 
    public static String getDataBase_Schema() {
        return instance.DataBase_Schema;
    }
 
    public static void setDataBase_Schema(String dataBase_Schema) {
        instance.DataBase_Schema = dataBase_Schema;
    }
 
}