ActiveRecordPlugin.setDevMode(constants.getDevMode());
2.initOreillyCos();就是一个上传组件 初始化代码很简单,看看就明白
private void initOreillyCos() {
Constants ct = constants;
if (OreillyCos.isMultipartSupported()) {
String uploadedFileSaveDirectory = ct.getUploadedFileSaveDirectory();
if (uploadedFileSaveDirectory == null || "".equals(uploadedFileSaveDirectory.trim())) {
uploadedFileSaveDirectory = PathKit.getWebRootPath() + File.separator + "upload" + File.separator;
ct.setUploadedFileSaveDirectory(uploadedFileSaveDirectory);
/*File file = new File(uploadedFileSaveDirectory);
if (!file.exists())
file.mkdirs();*/
}
OreillyCos.init(uploadedFileSaveDirectory, ct.getMaxPostSize(), ct.getEncoding());
}
}
3.OreillyCos.isMultipartSupported() 代码也很简单,我直接贴上代码
/**
* OreillyCos.
*/
public class OreillyCos {
private static Boolean isMultipartSupported = null;
public static boolean isMultipartSupported() {
if (isMultipartSupported == null) {
detectOreillyCos();
}
return isMultipartSupported;
}
public static void init(String saveDirectory, int maxPostSize, String encoding) {
if (isMultipartSupported()) {
MultipartRequest.init(saveDirectory, maxPostSize, encoding);
}
}
private static void detectOreillyCos() {
try {
Class.forName("com.oreilly.servlet.MultipartRequest");
isMultipartSupported = true;
} catch (ClassNotFoundException e) {
isMultipartSupported = false;
}
}
}
4uploadedFileSaveDirectory = PathKit.getWebRootPath() + File.separator + "upload" + File.separator;
我就介绍一下 PathKit.getWebRootPath()这段代码,其实就是前面我们第一个initPathUtil() 的初始化的值
5initI18n();就是初始化国际化,很简单代码
private void initI18n() {
String i18nResourceBaseName = constants.getI18nResourceBaseName();
if (i18nResourceBaseName != null) {
I18N.init(i18nResourceBaseName, constants.getI18nDefaultLocale(), constants.getI18nMaxAgeOfCookie());
}
}
6.initTokenManager(); 防止重复提交
我介绍一下TokenManager.init(tokenCache);里面的代码
public static void init(ITokenCache tokenCache) {
if (tokenCache == null)
return;
TokenManager.tokenCache = tokenCache;
long halfTimeOut = Const.MIN_SECONDS_OF_TOKEN_TIME_OUT * 1000 / 2;
new Timer().schedule(new TimerTask() {public void run() {removeTimeOutToken();}},
halfTimeOut,
halfTimeOut);
}
private static void removeTimeOutToken() {
List<Token> tokenInCache = tokenCache.getAll();
if (tokenInCache == null)
return;
List<Token> timeOutTokens = new ArrayList<Token>();
long currentTime = System.currentTimeMillis();
// find and save all time out tokens
for (Token token : tokenInCache)
if (token.getExpirationTime() <= currentTime)
timeOutTokens.add(token);
// remove all time out tokens
for (Token token : timeOutTokens)
tokenCache.remove(token);
}