📄 formtag.java
字号:
/*
* FormTag.java
*
* Created on 2002/01/15, 17:24
*/
package jp.co.intra_mart.framework.base.web.tag;
import java.net.URLEncoder;
import java.util.Vector;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.tagext.BodyTagSupport;
import jp.co.intra_mart.framework.base.service.ServiceManager;
import jp.co.intra_mart.framework.base.service.ServicePropertyHandler;
import jp.co.intra_mart.framework.base.service.ServiceSecurityFilter;
import jp.co.intra_mart.framework.base.service.ServiceServlet;
import jp.co.intra_mart.framework.base.session.SessionFactory;
import jp.co.intra_mart.framework.base.session.SessionManager;
import jp.co.intra_mart.framework.base.session.SessionPropertyException;
import jp.co.intra_mart.framework.base.session.SessionPropertyHandler;
import jp.co.intra_mart.framework.base.web.tag.attribute.CoreAttributes;
import jp.co.intra_mart.framework.base.web.tag.attribute.EventsAttributes;
import jp.co.intra_mart.framework.base.web.tag.attribute.I18nAttributes;
import jp.co.intra_mart.framework.util.SecurityUtil;
/**
* FORM僞僌偱偡丅
* intra-mart僼儗乕儉儚乕僋傪巊梡偡傞応崌偺僙僢僔儑儞僼儗乕儉儚乕僋丄僒乕價僗僼儗乕儉儚乕僋偺堦晹偲側傝傑偡丅
*
* @author INTRAMART
* @version 1.0
*/
public class FormTag extends BodyTagSupport {
/**
* 僙僢僔儑儞儅僱乕僕儍
*/
private SessionManager sessionManager;
/**
* 僙僢僔儑儞僾儘僷僥傿僴儞僪儔
*/
private SessionPropertyHandler sessionHandler;
/**
* 僒乕價僗儅僱乕僕儍
*/
private ServiceManager serviceManager;
/**
* 僒乕價僗僾儘僷僥傿僴儞僪儔
*/
private ServicePropertyHandler serviceHandler;
/**
* 僐傾懏惈
*/
private CoreAttributes coreAttrs;
/**
* 崙嵺壔懏惈
*/
private I18nAttributes i18n;
/**
* 僀儀儞僩懏惈
*/
private EventsAttributes events;
/**
* 傾僾儕働乕僔儑儞
*/
private String application;
/**
* 僒乕價僗
*/
private String service;
/**
* method
*/
private String method;
/**
* enctype
*/
private String enctype;
/**
* accept
*/
private String accept;
/**
* name
*/
private String name;
/**
* onSubmit
*/
private String onSubmit;
/**
* onReset
*/
private String onReset;
/**
* accept-charset
*/
private String acceptCharset;
/**
* target
*/
private String target;
/**
* FormTag傪怴婯偵惗惉偟傑偡丅
*/
public FormTag() {
super();
try {
this.sessionManager = SessionManager.getSessionManager();
this.sessionHandler =
this.sessionManager.getSessionPropertyHandler();
this.serviceManager = ServiceManager.getServiceManager();
this.serviceHandler =
this.serviceManager.getServicePropertyHandler();
} catch (Exception e) {
throw new RuntimeException(e);
}
this.coreAttrs = new CoreAttributes();
this.i18n = new I18nAttributes();
this.events = new EventsAttributes();
}
/**
* 奐巒僞僌傪専抦偟偨偲偒偵JSP僄儞僕儞偐傜屇偽傟傑偡丅
* FORM僞僌傪夝庍偟傑偡丅
*
* @return EVAL_BODY_BUFFERED
* @throws JspException 僞僌偺夝庍帪偵椺奜偑敪惗
*/
public int doStartTag() throws JspException {
String contextPath = null;
String url = null;
Vector serviceParams = null;
FrameworkTagParam param = null;
SessionFactory factory;
HttpSession httpSession = null;
String applicationID = null;
String serviceID = null;
String strCode = null;
String securityExt = null;
String tempPath = null;
String errorPage = null;
try {
TagWriter writer = new TagWriter(pageContext.getOut());
// Version 3.2 屳姺梡
contextPath = this.serviceHandler.getContextPath();
if (contextPath == null) {
contextPath =
((HttpServletRequest)pageContext.getRequest())
.getContextPath();
}
tempPath = contextPath
+ "/"
+ getApplication()
+ ServiceServlet.REQUEST_SEPARATOR
+ getService()
+ "."
+ serviceManager.getExtesion();
// 僷儔儊乕僞
serviceParams = new Vector();
// 儕僋僄僗僩偲儗僗億儞僗偺庢摼
HttpServletRequest request =
(HttpServletRequest)pageContext.getRequest();
HttpServletResponse response =
(HttpServletResponse)pageContext.getResponse();
// 僙僉儏儕僥傿偺奼挘巕傪庢摼
securityExt =
(String)request.getAttribute(
ServiceSecurityFilter.ID_SERVICE_SECURITY_FILTER);
// 暥帤僄儞僐乕僨傿儞僌偺庢摼
String encoding =
this.serviceManager.getEncoding(request, response);
// 僙僉儏儕僥傿偑桳岠偺偲偒
if (securityExt != null) {
// 僙僢僔儑儞庢摼
httpSession = request.getSession(false);
if (httpSession == null) {
try {
errorPage =
this.sessionHandler.getSessionErrorPagePath();
} catch (SessionPropertyException e) {
throw new ServletException(e.getMessage(), e);
}
request.getRequestDispatcher(errorPage).forward(
request,
response);
return SKIP_BODY;
}
// 傾僾儕働乕僔儑儞ID庢摼
applicationID = getApplication();
if (applicationID == null) {
applicationID = "";
}
// 僒乕價僗ID偺庢摼
serviceID = getService();
if (serviceID == null) {
serviceID = "";
}
// 傾僾儕働乕僔儑儞ID,僒乕價僗ID丄僙僢僔儑儞偵傛傝埫崋傪嶌惉
strCode =
SecurityUtil.createCheckSum(
applicationID,
serviceID,
httpSession);
tempPath = contextPath + "/" + strCode + "." + securityExt;
}
// 僙僢僔儑儞傪娷傔偨URL偺庢摼
factory = this.sessionManager.getSessionFactory();
if (factory == null) {
url =
((HttpServletResponse)pageContext.getResponse()).encodeURL(
TagWriter.createURL(tempPath, serviceParams, encoding));
} else {
// Version 3.2 屳姺梡
if (factory.isEncodeRequired()) {
url =
factory.encodeURL(
pageContext.getRequest(),
pageContext.getResponse(),
TagWriter.createURL(
tempPath,
serviceParams,
encoding));
} else {
url = contextPath + this.serviceHandler.getServiceServletPath();
}
}
// FORM僞僌奐巒
pageContext.getOut().print("<FORM action=\"" + url + "\"");
// method
if (getMethod() != null && !getMethod().equals("")) {
writer.printAttribute("method", getMethod());
}
// enctype
writer.printAttribute("enctype", getEnctype());
// accept
writer.printAttribute("accept", getAccept());
// name
writer.printAttribute("name", getName());
// onSubmit
writer.printAttribute("onSubmit", getOnsubmit());
// onReset
writer.printAttribute("onReset", getOnreset());
// accept-charset
writer.printAttribute("accept-charset", getAcceptcharset());
// target
writer.printAttribute("target", getTarget());
// ID
writer.printAttribute("id", getId());
// 僐傾懏惈
this.coreAttrs.setTagWriter(writer);
this.coreAttrs.printAttributes();
// 崙嵺壔懏惈
this.i18n.setTagWriter(writer);
this.i18n.printAttributes();
// 僀儀儞僩懏惈
this.events.setTagWriter(writer);
this.events.printAttributes();
// 僞僌偺廔椆
pageContext.getOut().print(">");
// 僙僢僔儑儞ID
if (factory != null && !factory.isEncodeRequired()) {
// Version 3.2 屳姺梡
pageContext.getOut().print(
"<INPUT type=\"hidden\" name=\""
+ this.sessionHandler.getSessionParameter()
+ "\" value=\""
+ URLEncoder.encode(
this
.sessionManager
.getSessionObject(pageContext.getRequest())
.getSessionID(),
"ISO-8859-1")
+ "\">");
}
} catch (Exception e) {
throw new FrameworkTagException(e.getMessage(), e);
}
return EVAL_BODY_BUFFERED;
}
/**
* 廔椆僞僌傪専抦偟偨偲偒偵JSP僄儞僕儞偐傜屇偽傟傑偡丅
* FORM僞僌傪廔椆偟傑偡丅
*
* @return EVAL_PAGE
* @throws JspException 僞僌偺廔椆帪偵椺奜偑敪惗
*/
public int doEndTag() throws JspException {
try {
// 撪梕偺昞帵
pageContext.getOut().print(bodyContent.getString());
// 僞僌偺廔椆
pageContext.getOut().print("</FORM>");
} catch (Exception e) {
throw new FrameworkTagException(e.getMessage(), e);
}
return EVAL_PAGE;
}
/**
* 懏惈<CODE>application</CODE>偺抣傪庢摼偟傑偡丅
*
* @return 傾僾儕働乕僔儑儞
*/
public String getApplication() {
return this.application;
}
/**
* 懏惈<CODE>application</CODE>偺抣傪愝掕偟傑偡丅
*
* @param application 傾僾儕働乕僔儑儞
*/
public void setApplication(String application) {
this.application = application;
}
/**
* 懏惈<CODE>service</CODE>偺抣傪庢摼偟傑偡丅
*
* @return 僒乕價僗
*/
public String getService() {
return this.service;
}
/**
* 懏惈<CODE>service</CODE>偺抣傪愝掕偟傑偡丅
*
* @param service 僒乕價僗
*/
public void setService(String service) {
this.service = service;
}
/**
* 懏惈<CODE>method</CODE>偺抣傪庢摼偟傑偡丅
*
* @return method
*/
public String getMethod() {
return this.method;
}
/**
* 懏惈<CODE>method</CODE>偺抣傪愝掕偟傑偡丅
*
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -