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

📄 submitlinktag.java

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

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

import java.io.IOException;
import java.util.MissingResourceException;
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.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;

/**
 * 僒僽儈僢僩愱梡偺LINK僞僌偱偡丅
 * im-J2EE Framework傪巊梡偡傞応崌偺僙僢僔儑儞僼儗乕儉儚乕僋丄僒乕價僗僼儗乕儉儚乕僋偺堦晹偲側傝傑偡丅
 *
 * @author INTRAMART
 * @since 4.2
 */
public class SubmitLinkTag extends BodyTagSupport {

    private static class SubmitLinkEventsAttributes 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 SubmitLinkEventsAttributes events;

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

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

    /**
     * 僼僅乕儉柤
     */
    private String form;

    /**
     * name
     */
    private String name;

    /**
     * accesskey
     */
    private String accesskey;

    /**
     * shape
     */
    private String shape;

    /**
     * coords
     */
    private String coords;

    /**
     * tabindex
     */
    private String tabindex;

    /**
     * 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;

    /**
     * SubmitLinkTag傪怴婯偵惗惉偟傑偡丅
     */
    public SubmitLinkTag() {
        super();
        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 SubmitLinkEventsAttributes();
    }

    /**
     * 奐巒僞僌傪専抦偟偨偲偒偵JSP僄儞僕儞偐傜屇偽傟傑偡丅
     * SUBMIT LINK僞僌傪夝庍偟傑偡丅
     *
     * @return EVAL_BODY_BUFFERED
     * @throws JspException 僞僌偺夝庍帪偵椺奜偑敪惗
     */
    public int doStartTag() throws JspException {
        return EVAL_BODY_BUFFERED;
    }

    /**
     * 廔椆僞僌傪専抦偟偨偲偒偵JSP僄儞僕儞偐傜屇偽傟傑偡丅
     * SUBMIT LINK僞僌傪廔椆偟傑偡丅
     *
     * @return EVAL_PAGE
     * @throws JspException 僞僌偺廔椆帪偵椺奜偑敪惗
     */
    public int doEndTag() throws JspException {
        String contextPath = null;
        String url = null;
        Vector hrefParams = null;
        FrameworkTagParam param = null;
        FormTag targetForm = null;
        String formName = null;

        // 埲壓偺桪愭弴埵偱儖乕儖偱僒僽儈僢僩偡傞Form偺name懏惈傪寛掕
        // 侾丏form懏惈偑巜掕偝傟偰偄傞応崌丄偦偺傑傑巊梡
        // 俀丏奜懁偺Form僞僌偺name懏惈傪巊梡
        // 俁丏偦偺懠偺応崌偼FrameworkTagException傪throw
        formName = getForm();
        if (formName == null || formName.trim().equals("")) {
            // 懏惈form偑巜掕偝傟偰偄側偄応崌丄奜晹偺Form僞僌傪庢摼
            try {
                targetForm =
                    (FormTag)findAncestorWithClass(this, FormTag.class);
                if (targetForm == null) {
                    String message = null;
                    try {
                        message =
                            ResourceBundle
                                .getBundle("jp.co.intra_mart.framework.base.web.tag.i18n")
                                .getString("SubmitLinkTag.FormNameNeeds");
                    } catch (MissingResourceException e) {
                    }
                    throw new FrameworkTagException(message);
                }
            } catch (Exception e) {
                throw new FrameworkTagException(e.getMessage(), e);
            }
            formName = targetForm.getName();
        }

        try {
            //--- 捛壛 Start ---
            String formAction = 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
				+ "/"
				+ targetForm.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("")) {
                    if (targetForm != null) {
                        applicationID = targetForm.getApplication();
                    }
                    if (applicationID == null) {
                        applicationID = "";
                    }
                }

                // 僒乕價僗ID偺庢摼
                serviceID = getService();
                if (serviceID == null || serviceID.equals("")) {
                    if (targetForm != null) {
                        serviceID = targetForm.getService();
                    }
                    if (serviceID == null) {
                        serviceID = "";
                    }
                }

                // 傾僾儕働乕僔儑儞I,僒乕價僗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());

            // A僞僌奐巒
            pageContext.getOut().print("<A href=\"javascript:void(0);\"");

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

            // accesskey
            writer.printAttribute("accesskey", getAccesskey());

            // shape
            writer.printAttribute("shape", getShape());

            // coords
            writer.printAttribute("coords", getCoords());

            // tabindex
            writer.printAttribute("tabindex", getTabindex());

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

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

            // 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(">");

            // 撪梕偺昞帵
            pageContext.getOut().print(bodyContent.getString());

⌨️ 快捷键说明

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