?? abstractpageservice.java
字號:
// Copyright 2005-2007 onetsoft.com
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
package com.onetsoft.fastjsp;
import com.onetsoft.fastjsp.request.PageData;
import com.onetsoft.fastjsp.request.multipart.DefaultMultipartDecoder;
import com.onetsoft.fastjsp.request.multipart.MultipartDecoder;
import com.onetsoft.fastjsp.util.StringUtils;
import com.onetsoft.fastjsp.util.Util;
import com.onetsoft.fastjsp.util.Constants;
import java.io.UnsupportedEncodingException;
/**
* 自定義頁面服務(wù)應(yīng)繼承此類
*
* @author <a href="mailto:hgw@onetsoft.com">hgw</a>
*/
public abstract class AbstractPageService implements PageService {
AbstractPageCycle cycle = null;
ActionsManager actionsManager = null;
ComponentsManager componentsManager = null;
LayoutManager layoutManager = null;
AbstractPage page = null;
AbstractServicer servicer = null;
MultipartDecoder decoder = null;
LocaleStateManager localeStateManager = null;
PageData data = null;
boolean formRequest = false;
boolean started = false;
ValidationDelegateComboImpl delegateCombo = new ValidationDelegateComboImpl();
protected AbstractPageService(Servicer servicer) {
this.servicer = (AbstractServicer) servicer;
attach();
}
private void attach() {
layoutManager = servicer.module.layoutManagerFactory.getLayoutManager(servicer.pageParams);
/* try {
servicer.request.setCharacterEncoding(servicer.module.charset);
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}*/
/**
* 此設(shè)置經(jīng)測試只對表單提交有效,而url的參數(shù)(靜態(tài)參數(shù)和動態(tài)查詢參數(shù))的decoding、encoding均以module.charset為準(zhǔn)。
* 注意:這里不強(qiáng)行設(shè)置,而留給其他顯示設(shè)置,如:filter中設(shè)置request.setCharacterEncoding("utf-8");滿足用戶需要“完全統(tǒng)一”編碼的情形!
*/
// Debug.debug("AbstractServicer.init() Line:88....request.getCharacterEncoding():" + request.getCharacterEncoding());
// Debug.debug("AbstractServicer.init() Line:90....module.charset:" + module.charset);
if (servicer.request.getCharacterEncoding() == null) {
try {
servicer.request.setCharacterEncoding(Constants.UTF_8); //utf-8是最安全穩(wěn)妥的編碼
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
}
//Parse request type.
// Note:When submitting a form ,the form "method" should be "post",otherwise the "contentType" from request will be null!!!
String contentType = servicer.request.getContentType();
if (StringUtils.METHOD_POST.equalsIgnoreCase(servicer.getRequest().getMethod()) && contentType != null &&
(contentType.startsWith(StringUtils.CONTENTTYPE_FORM_NORMAL)
|| contentType.startsWith(StringUtils.CONTENTTYPE_FORM_MULTIPART))) {
formRequest = true;
}
}
public void initialize() {
cycle = createCycle(this);
localeStateManager = servicer.module.localeStateManagerFactory.getLocaleStateManager();
localeStateManager.init(cycle);
}
final void start() {
if (started) return;
componentsManager = layoutManager.getComponentsManager(servicer.pageParams.pageClass);
if (!servicer.pageParams.defaultPageUsed) {
actionsManager = layoutManager.getActionsManager(servicer.pageParams.pageClass);
}
try {
decodeRequest();
} finally {
data = new PageDataImpl(servicer, decoder);
servicer.stateURL.decodeAfterDataBuild(data);
componentsManager.instanceComponents(cycle);
}
try {
beginRequest();
if (!servicer.pageParams.defaultPageUsed)
actionsManager.execute(this);
componentsManager.initComponentsFields(cycle);
} finally {
endRequest();
started = true;
}
}
/**
* 啟動頁面服務(wù)會調(diào)用此方法
* 可在這里執(zhí)行自定義服務(wù)過程
*/
protected void beginRequest() {
}
/**
* 用戶請求處理
*
* @since 3.0
*/
protected void endRequest() {
}
/**
* 停止頁面服務(wù)
* 一般用于清除當(dāng)前請求狀態(tài)以及同步用戶狀態(tài)等
* 注:每次頁面請求執(zhí)行完畢都必須執(zhí)行此方法
*
* @throws java.io.IOException
*/
public void end() {
localeStateManager.commitChange(cycle);
}
/**
* 解析請求參數(shù)
* 所解析的參數(shù)包括:標(biāo)準(zhǔn)的url請求參數(shù)、表單參數(shù)、上傳表單參數(shù)
* 注:此方法執(zhí)行前已經(jīng)對靜態(tài)url作了參數(shù)解析
*
* @see PageParamsImpl
* @see AbstractServicer
*/
private void decodeRequest() {
String contentType = servicer.request.getContentType();
try {
if (contentType != null && contentType.startsWith(StringUtils.CONTENTTYPE_FORM_MULTIPART)) {
decoder = new DefaultMultipartDecoder(servicer.pageParams.parameterMap, servicer.module.getUploadConfig());
servicer.request = decoder.decode(servicer.request);
} else {
ParamsHelper.decodeRequestParameterMap(servicer.request, servicer.pageParams.parameterMap, servicer.module.encoding);
}
} finally {
if (decoder == null)
decoder = Util.EMPTY_DECODER;
}
}
public PageCycle getCycle() {
return cycle;
}
/**
* 創(chuàng)建page cycle
* 所有自定義page cycle應(yīng)繼承{@link AbstractPageCycle}
*
* @param pageService
* @return
*/
protected abstract AbstractPageCycle createCycle(AbstractPageService pageService);
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -