001    /*
002     * Copyright (c) 2009 The openGion Project.
003     *
004     * Licensed under the Apache License, Version 2.0 (the "License");
005     * you may not use this file except in compliance with the License.
006     * You may obtain a copy of the License at
007     *
008     *     http://www.apache.org/licenses/LICENSE-2.0
009     *
010     * Unless required by applicable law or agreed to in writing, software
011     * distributed under the License is distributed on an "AS IS" BASIS,
012     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
013     * either express or implied. See the License for the specific language
014     * governing permissions and limitations under the License.
015     */
016    package org.opengion.hayabusa.taglib;
017    
018    import org.opengion.hayabusa.common.HybsSystem;
019    import org.opengion.hayabusa.common.HybsSystemException;
020    import org.opengion.hayabusa.resource.URLXfer;
021    import org.opengion.fukurou.util.StringUtil ;
022    
023    import javax.servlet.http.HttpSession ;
024    import javax.servlet.http.HttpServletResponse;
025    import javax.servlet.http.HttpServletRequest;
026    import javax.servlet.jsp.tagext.TagSupport ;
027    import javax.servlet.jsp.JspWriter ;
028    
029    import java.io.IOException;
030    
031    /**
032     * マルチセãƒ?‚·ョン起動チェãƒ?‚¯を行いますã?
033     *
034     * こã?タグは、特殊で、ä¸?•ªæœ?¸Š位ã?JSP(通常は、jsp/index.jsp)に仕込ã‚?�“とでã€?
035     * マルチセãƒ?‚·ョン起動チェãƒ?‚¯を行いますã?
036     * とくに、TopMenuTag と関連しており、このタグが存在しなã�?�¨、メニューã�?
037     * 動作しませんã€?
038     * こã?タグでは、URLXfer による、リンク変換転送をサポã?トしますã?
039     * URLのXFER変数をキーに、GE17 ãƒ??ブルを検索しã?æŒ?®šã?URLへ sendRedirect しますã?
040     *
041     * @og.formSample
042     * ●形式ï¼?lt;og:jspInit />
043     * ●body?šなã�?
044     *
045     * ●使用ä¾?
046     *    <og:jspInit />
047     *
048     * @og.rev 4.0.0.0 (2005/08/31) 新規作æ?
049     * @og.group メニュー制御
050     *
051     * @version  4.0
052     * @author   Kohei Naruse
053     * @since    JDK5.0,
054     */
055    public class JspInitTag extends TagSupport {
056            //* こã?プログラãƒ??VERSIONæ–?­—å?を設定しますã?       {@value} */
057            private static final String VERSION = "5.7.6.2 (2014/05/16)" ;
058    
059            private static final long serialVersionUID = 576220140516L ;
060    
061            // 3.8.0.0 (2005/06/07)
062            private static int count = 0;
063    
064            /**
065             * Taglibの終äº?‚¿グが見つかったときに処ç�?�™ã‚?doEndTag() ã‚?オーバã?ライドしますã?
066             *
067             * @og.rev 4.1.1.0 (2008/02/07) UserInfo の再作æ?する機è?を追åŠ?
068             * @og.rev 4.2.2.0 (2008/05/28) Guestユーザ対å¿?
069             * @og.rev 4.3.4.1 (2008/12/08) UserInfo の再作æ?する機è?を削除
070             * @og.rev 5.7.4.3 (2014/03/28) 出力すã‚?HTML は、フィルターしますã?
071             * @og.rev 5.7.6.2 (2014/05/16) IEのHTML5機è?が有効か無効かã?判定キーを削除(初期åŒ?しますã?
072             *
073             * @return      後続å?ç�??æŒ?¤º
074             */
075            @Override
076            public int doEndTag() {
077                    // 5.7.4.3 (2014/03/28) エラー時でもã?debug=true があれã?、継続するã?
078                    HttpServletRequest request = ( HttpServletRequest )pageContext.getRequest();
079                    boolean debug = "true".equalsIgnoreCase( request.getParameter( "debug" ) );
080    
081                    // Tomcat 初期起動時の common/SystemParameter.java でエラーが発生したå?合ã?
082                    String errMsg = HybsSystem.sys( HybsSystem.LOCAL_CONTX_ERR_KEY );
083                    if( errMsg != null && !debug ) {
084                            try {
085                                    JspWriter out = pageContext.getOut();
086                                    out.println( "<html><body><pre>" );
087                                    // 5.7.4.3 (2014/03/28) 出力すã‚?HTML は、フィルターしますã?
088                                    out.println( StringUtil.htmlFilter( errMsg ) );
089                                    out.println( "</pre></body></html>" );
090                            }
091                            catch(IOException ex) {
092                                    errMsg = "画面出力時の PageContext の取得時にエラーが発生しましたã€?
093                                                    + HybsSystem.CR
094                                                    + errMsg ;
095                                    throw new HybsSystemException( errMsg,ex );             // 3.5.5.4 (2004/04/15) 引数の並びé ?¤‰更
096                            }
097                            return SKIP_PAGE ;              // ペã?ジの残りの処ç�?‚’行わなã�??
098                    }
099    
100                    HttpSession session = pageContext.getSession();
101                    synchronized( JspInitTag.class ) {
102                            // 3.8.0.0 (2005/06/07) 同ä¸?‚»ãƒ?‚·ョンでのマルチ起動対策を行いますã?
103                            String cnt = String.valueOf( count++ ) ;
104                            session.setAttribute( HybsSystem.MULTI_SESSION_CHECK, cnt );
105                    }
106    
107                    // 5.7.6.2 (2014/05/16) IEのHTML5機è?が有効か無効かã?判定キーを削除(初期åŒ?しますã?
108                    session.removeAttribute( HybsSystem.IE_HTML5_KEY );
109    
110                    // URLXfer による、リンク変換転送機è?
111                    String key = request.getParameter( "XFER" );
112                    if( key != null ) {
113                            URLXfer xfer = new URLXfer();
114                            String url = xfer.getRedirectURL( key );
115                            if( url != null ) {
116                                    try {
117                                            HttpServletResponse response = (HttpServletResponse)pageContext.getResponse();
118                                            response.sendRedirect( url );
119                                            return SKIP_PAGE ;              // ペã?ジの残りの処ç�?‚’行わなã�??
120                                    } catch ( IOException ex ) {
121                                            String errMsg2 = "URLの振りå?けå?ç�?™‚に IOException が発生しましたã€?XFER=" + key;
122                                            throw new HybsSystemException( errMsg2,ex );
123                                    }
124                            }
125                    }
126    
127                    return EVAL_PAGE ;              // ペã?ジの残りを評価するã€?
128            }
129    }