⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 submittag.java

📁 intra_mart是日本NDD公司开发的著名企业应用解决方案中间件。集成了J2ee服务器
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/*
 * SubmitTag.java
 *
 * Created on 2002/08/12, 13:16
 */

package jp.co.intra_mart.framework.base.web.tag;

import java.util.ResourceBundle;
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.tagext.BodyTagSupport;

import jp.co.intra_mart.framework.base.session.SessionFactory;
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.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;

import java.io.IOException;
import java.util.MissingResourceException;
import javax.servlet.jsp.JspException;

/**
 * Submit僞僌偱偡丅
 * intra-mart僼儗乕儉儚乕僋偺Form僞僌撪偱偺傒巊梡偱偒傞僞僌偱偡丅
 *
 * @author INTRAMART
 * @since 3.2
 */
public class SubmitTag extends BodyTagSupport {

    private static class SubmitEventsAttributes extends EventsAttributes {

        /**
         * onClick僀儀儞僩偵捛壛偡傞僗僋儕僾僩
         */
        private String onClickScript;

        /**
         * onClick僀儀儞僩偵捛壛偡傞僗僋儕僾僩傪愝掕偟傑偡丅
         *
         * @param parent onClick僀儀儞僩偵捛壛偡傞僗僋儕僾僩
         */
        public void setOnClickScript(String onClickScript) {
            this.onClickScript = onClickScript;
        }

        /**
         * onClick僀儀儞僩偵捛壛偡傞僗僋儕僾僩傪庢摼偟傑偡丅
         *
         * @return onClick僀儀儞僩偵捛壛偡傞僗僋儕僾僩
         */
        public String getOnClickScript() {
            return this.onClickScript;
        }

        /**
         * 懏惈<CODE>onClick</CODE>傪弌椡偟傑偡丅
         *
         * @throws IOException 弌椡拞偵椺奜偑敪惗
         */
        protected void printOnClick() throws IOException {
            // 僗僋儕僾僩傪捛壛
            String script = getOnClickScript();

			// 儐乕僓掕媊偺僗僋儕僾僩偑巜掕偝傟偰偄傞応崌丄
			// 撪梕偵傛偭偰僒僽儈僢僩偡傞偐偳偆偐傪寛掕
			if (getOnClick() != null) {
				String realScript = "";
				realScript =
					"var myFunction = new Function(&quot;"
						+ getOnClick()
						+ "&quot;); var result = myFunction();"
						+ " if (result == undefined || result == true) {"
						+ script
						+ "};";
				script = realScript;
			}
            getTagWriter().printAttribute("onClick", script);
        }
    }

    /**
     * 僒乕價僗僾儘僷僥傿僴儞僪儔
     */
    private ServicePropertyHandler serviceHandler;

    /**
     * 僐傾懏惈
     */
    private CoreAttributes coreAttrs;

    /**
     * 崙嵺壔懏惈
     */
    private I18nAttributes i18n;

    /**
     * 僀儀儞僩懏惈
     */
    private SubmitEventsAttributes events;

    /**
     * 傾僾儕働乕僔儑儞
     */
    private String application;

    /**
     * 僒乕價僗
     */
    private String service;

    /**
     * name
     */
    private String name;

    /**
     * value
     */
    private String value;

    /**
     * onFocus
     */
    private String onFocus;

    /**
     * onBlur
     */
    private String onBlur;

    /**
     * 僒乕價僗儅僱乕僕儍
     *
     * @since 4.3
     */
    private ServiceManager serviceManager;

    /**
     * 僙僢僔儑儞儅僱乕僕儍
     *
     * @since 4.3
     */
    private SessionManager sessionManager;

    /**
     * 僙僢僔儑儞僾儘僷僥傿僴儞僪儔
     *
     * @since 4.3
     */
    private SessionPropertyHandler sessionHandler;

    /**
     * SubmitTag傪怴婯偵惗惉偟傑偡丅
     */
    public SubmitTag() {
        try {
            this.sessionManager = SessionManager.getSessionManager();
            this.sessionHandler =
                this.sessionManager.getSessionPropertyHandler();
            this.serviceManager = ServiceManager.getServiceManager();
            this.serviceHandler =
                ServiceManager.getServiceManager().getServicePropertyHandler();
        } catch (Exception e) {
            //
        }
        this.coreAttrs = new CoreAttributes();
        this.i18n = new I18nAttributes();
        this.events = new SubmitEventsAttributes();
    }

    /**
     * 奐巒僞僌傪専抦偟偨偲偒偵JSP僄儞僕儞偐傜屇偽傟傑偡丅
     * Submit僞僌傪夝庍偟傑偡丅
     *
     * @throws JspException JSP弌椡帪偵椺奜偑敪惗
     * @return EVAL_BODY_BUFFERED
     */
    public int doStartTag() throws JspException {
        FormTag form = null;
        String formName = null;

        // 奜晹偺Form僞僌偺庢摼
        try {
            form = (FormTag)findAncestorWithClass(this, FormTag.class);
            if (form == null) {
                String message = null;
                try {
                    message =
                        ResourceBundle
                            .getBundle("jp.co.intra_mart.framework.base.web.tag.i18n")
                            .getString("SubmitTag.SubmitMustInForm");
                } catch (MissingResourceException e) {
                }
                throw new FrameworkTagException(message);
            }
        } catch (Exception e) {
            throw new FrameworkTagException(e.getMessage(), e);
        }

        // Form偺name懏惈傪庢摼
        formName = form.getName();
        if (formName == null || formName.trim().length() == 0) {
            String message = null;
            try {
                message =
                    ResourceBundle
                        .getBundle("jp.co.intra_mart.framework.base.web.tag.i18n")
                        .getString("SubmitTag.FormNeedsNameAtttibute");
            } catch (MissingResourceException e) {
            }
            throw new FrameworkTagException(message);
        }

        try {
            //--- 捛壛 Start ---
            String contextPath = null;
            String url = null;
            Vector serviceParams = null;
            SessionFactory factory;

            HttpSession httpSession = null;
            String applicationID = null;
            String serviceID = null;
            String strCode = null;

            String securityExt = null;
            String tempPath = null;

            String errorPage = null;

            // Form偺action懏惈傪惗惉(<FORM>僞僌偺action傪惗惉偡傞偺偲摨偠偔)
            // Version 3.2 屳姺梡
            contextPath = this.serviceHandler.getContextPath();
            if (contextPath == null) {
                contextPath =
                    ((HttpServletRequest)pageContext.getRequest())
                        .getContextPath();
            }

            // URL惗惉丅傾僾儕働乕僔儑儞ID偑愝掕偝傟偰偄側偄応崌偼form偺傾僾儕働乕僔儑儞ID傪庢摼
            if (getApplication() == null  || getApplication().trim().length() == 0) {
                tempPath = contextPath
				+ "/"
				+ form.getApplication()
				+ ServiceServlet.REQUEST_SEPARATOR
				+ getService()
				+ "."
				+ serviceManager.getExtesion();
            } else {
                tempPath = contextPath
				+ "/"
				+ getApplication()
				+ ServiceServlet.REQUEST_SEPARATOR
				+ getService()
				+ "."
				+ serviceManager.getExtesion();
            }

            // 僷儔儊乕僞
            serviceParams = new Vector();

            // 儕僋僄僗僩偲儗僗億儞僗偺庢摼
            HttpServletRequest request =
                (HttpServletRequest)pageContext.getRequest();
            HttpServletResponse response =
                (HttpServletResponse)pageContext.getResponse();

            // 儕僋僄僗僩偺懏惈抣傪庢摼偡傞乮ServiceSecurityFilter僼儔僌乯
            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.equals("")) {
                    applicationID = form.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();
                }
            }
            //--- 捛壛 End ---

            // onClick僀儀儞僩偺僗僋儕僾僩偺愝掕
            String scriptActionVariableName = "im_action";
            String script = "";
            script += "var "
                + scriptActionVariableName
                + " = document."
                + formName
                + ".action; ";

            // document.mainform.action 偵抣傪戙擖偡傞丅
            if (url != null && url.trim().length() != 0) {
                script += "document." + formName + ".action = '" + url + "'; ";
            }

            script += "document." + formName + ".submit(); ";
            script += "document."
                + formName
                + ".action = "
                + scriptActionVariableName
                + "; ";
            script += "return false;";
            this.events.setOnClickScript(script);

            TagWriter writer = new TagWriter(pageContext.getOut());

            // Submit僞僌奐巒
            pageContext.getOut().print("<INPUT type=\"button\"");

            // name
            writer.printAttribute("name", getName());

            // value
            writer.printAttribute("value", getValue());

            // onfocus
            writer.printAttribute("onfocus", getOnfocus());

            // onblur
            writer.printAttribute("onblur", getOnblur());

            // ID
            writer.printAttribute("id", getId());

            // 僐傾懏惈
            this.coreAttrs.setTagWriter(writer);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -