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

📄 linktag.java

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

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

import java.util.Collection;
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僞僌偱偡丅
 * intra-mart僼儗乕儉儚乕僋傪巊梡偡傞応崌偺僙僢僔儑儞僼儗乕儉儚乕僋丄僒乕價僗僼儗乕儉儚乕僋偺堦晹偲側傝傑偡丅
 *
 * @author INTRAMART
 * @version 1.0
 */
public class LinkTag extends BodyTagSupport implements ParameterSendable {

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

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

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

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

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

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

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

    /**
     * 僷儔儊乕僞偺廤崌
     */
    private Collection params;

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

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

    /**
     * charset
     */
    private String charset;

    /**
     * type
     */
    private String type;

    /**
     * name
     */
    private String name;

    /**
     * hreflang
     */
    private String hreflang;

    /**
     * rel
     */
    private String rel;

    /**
     * rev
     */
    private String rev;

    /**
     * accesskey
     */
    private String accesskey;

    /**
     * shape
     */
    private String shape;

    /**
     * coords
     */
    private String coords;

    /**
     * target
     *
     * @since 3.2
     */
    private String target;

    /**
     * tabindex
     */
    private String tabindex;

    /**
     * onfocus
     */
    private String onfocus;

    /**
     * onblur
     */
    private String onblur;

    /**
     * LinkTag傪怴婯偵惗惉偟傑偡丅
     */
    public LinkTag() {
        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.params = null;
        this.coreAttrs = new CoreAttributes();
        this.i18n = new I18nAttributes();
        this.events = new EventsAttributes();
    }

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

        return EVAL_BODY_BUFFERED;
    }

    /**
     * 廔椆僞僌傪専抦偟偨偲偒偵JSP僄儞僕儞偐傜屇偽傟傑偡丅
     * LINK僞僌傪廔椆偟傑偡丅
     *
     * @return EVAL_PAGE
     * @throws JspException 僞僌偺廔椆帪偵椺奜偑敪惗
     */
    public int doEndTag() throws JspException {
        String contextPath = null;
        String url = null;
        Vector hrefParams = 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();
            
            // 僷儔儊乕僞
            hrefParams = new Vector();
            if (this.params != null) {
                hrefParams.addAll(this.params);
            }

            // 儕僋僄僗僩偲儗僗億儞僗偺庢摼
            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 = "";
                }

                // 僒乕價僗ID偺庢摼
                serviceID = 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(
                /*-- 曄峏 2004.04.28 ---
                							contextPath + serviceServletPath,
                -----------------------*/
                tempPath, hrefParams, encoding));
            } else {
                // Version 3.2 屳姺梡
                if (factory.isEncodeRequired()) {
                    url =
                        factory
                            .encodeURL(
                                pageContext.getRequest(),
                                pageContext.getResponse(),
                                TagWriter.createURL(
                    /*-- 曄峏 2004.04.28 ---
                                                    contextPath + serviceServletPath,
                    -----------------------*/
                    tempPath, hrefParams, encoding));
                } else {
                    param = new FrameworkTagParam();
                    param.setName(this.sessionHandler.getSessionParameter());
                    param.setValue(
                        this
                            .sessionManager
                            .getSessionObject(pageContext.getRequest())
                            .getSessionID());
                    hrefParams.add(param);
                    url =
                        TagWriter.createURL(
                            contextPath + this.serviceHandler.getServiceServletPath(),
                            hrefParams,
                            encoding);
                }
            }

            // A僞僌奐巒
            pageContext.getOut().print("<A href=\"" + url + "\"");

            // charset
            writer.printAttribute("charset", getCharset());

            // type
            writer.printAttribute("type", getType());

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

            // hreflang
            writer.printAttribute("hreflang", getHreflang());

            // rel
            writer.printAttribute("rel", getRel());

            // rev
            writer.printAttribute("rev", getRev());

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

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

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

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

            // target
            writer.printAttribute("target", getTarget());

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

            // 僞僌偺廔椆
            pageContext.getOut().print("</A>");
        } catch (Exception e) {
            throw new FrameworkTagException(e.getMessage(), e);
        }

        return EVAL_PAGE;
    }

    /**
     * 僷儔儊乕僞傪捛壛偟傑偡丅
     *
     * @param name 僷儔儊乕僞柤
     * @param value 僷儔儊乕僞偺抣
     */
    public void addParameter(String name, String value) {
        FrameworkTagParam param = new FrameworkTagParam();
        param.setName(name);
        param.setValue(value);
        this.params.add(param);
    }

    /**
     * charset傪庢摼偟傑偡丅
     *
     * @return charset
     */
    public String getCharset() {
        return this.charset;
    }

    /**
     * charset傪愝掕偟傑偡丅
     *
     * @param charset charset
     */
    public void setCharset(String charset) {
        this.charset = charset;
    }

    /**
     * type傪庢摼偟傑偡丅
     *
     * @return type
     */
    public String getType() {
        return this.type;
    }

    /**
     * type傪愝掕偟傑偡丅
     *
     * @param type type
     */
    public void setType(String type) {
        this.type = type;
    }

    /**
     * name傪庢摼偟傑偡丅
     *
     * @return name
     */
    public String getName() {
        return this.name;
    }

    /**
     * name傪愝掕偟傑偡丅
     *
     * @param name name
     */
    public void setName(String name) {
        this.name = name;
    }

    /**
     * 傾僾儕働乕僔儑儞傪庢摼偟傑偡丅
     *
     * @return 傾僾儕働乕僔儑儞
     */
    public String getApplication() {
        return this.application;
    }

    /**
     * 傾僾儕働乕僔儑儞傪愝掕偟傑偡丅
     *
     * @param application 傾僾儕働乕僔儑儞
     */
    public void setApplication(String application) {
        this.application = application;
    }

⌨️ 快捷键说明

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