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 javax.servlet.http.HttpSession ;
022    import javax.servlet.http.HttpServletResponse;
023    import javax.servlet.http.HttpServletRequest;
024    import javax.servlet.jsp.tagext.TagSupport ;
025    import javax.servlet.jsp.JspWriter ;
026    
027    import java.io.IOException;
028    
029    /**
030     * マルチセãƒ?‚·ョン起動チェãƒ?‚¯を行いますã?
031     *
032     * こã?タグは、特殊で、ä¸?•ªæœ?¸Š位ã?JSP(通常は、jsp/index.jsp)に仕込ã‚?�“とでã€?
033     * マルチセãƒ?‚·ョン起動チェãƒ?‚¯を行いますã?
034     * とくに、TopMenuTag と関連しており、このタグが存在しなã�?�¨、メニューã�?
035     * 動作しませんã€?
036     * こã?タグでは、URLXfer による、リンク変換転送をサポã?トしますã?
037     * URLのXFER変数をキーに、GE17 ãƒ??ブルを検索しã?æŒ?®šã?URLへ sendRedirect しますã?
038     *
039     * @og.formSample
040     * ●形式ï¼?lt;og:jspInit />
041     * ●body?šなã�?
042     *
043     * ●使用ä¾?
044     *    <og:jspInit />
045     *
046     * @og.rev 4.0.0.0 (2005/08/31) 新規作æ?
047     * @og.group メニュー制御
048     *
049     * @version  4.0
050     * @author   Kohei Naruse
051     * @since    JDK5.0,
052     */
053    public class JspInitTag extends TagSupport {
054            //* こã?プログラãƒ??VERSIONæ–?­—å?を設定しますã?       {@value} */
055            private static final String VERSION = "4.3.4.1 (2008/12/08)" ;
056    
057            private static final long serialVersionUID = 434120081208L ;
058    
059            // 3.8.0.0 (2005/06/07)
060            private static int count = 0;
061    
062            /**
063             * Taglibの終äº?‚¿グが見つかったときに処ç�?�™ã‚?doEndTag() ã‚?オーバã?ライドしますã?
064             *
065             * @og.rev 4.1.1.0 (2008/02/07) UserInfo の再作æ?する機è?を追åŠ?
066             * @og.rev 4.2.2.0 (2008/05/28) Guestユーザ対å¿?
067             * @og.rev 4.3.4.1 (2008/12/08) UserInfo の再作æ?する機è?を削除
068             *
069             * @return      後続å?ç�??æŒ?¤º
070             */
071            @Override
072            public int doEndTag() {
073    
074                    // Tomcat 初期起動時の common/SystemParameter.java でエラーが発生したå?合ã?
075                    String errMsg = HybsSystem.sys( HybsSystem.LOCAL_CONTX_ERR_KEY );
076                    if( errMsg != null ) {
077                            try {
078                                    JspWriter out = pageContext.getOut();
079                                    out.println( "<html><body><pre>" );
080                                    out.println( errMsg );
081                                    out.println( "</pre></body></html>" );
082                            }
083                            catch(IOException ex) {
084                                    errMsg = "画面出力時の PageContext の取得時にエラーが発生しましたã€?
085                                                    + HybsSystem.CR
086                                                    + errMsg ;
087                                    throw new HybsSystemException( errMsg,ex );             // 3.5.5.4 (2004/04/15) 引数の並びé ?¤‰更
088                            }
089                            return(SKIP_PAGE);              // ペã?ジの残りの処ç�?‚’行わなã�??
090                    }
091    
092                    HttpSession session = pageContext.getSession();
093                    HttpServletRequest request = ( HttpServletRequest )pageContext.getRequest();
094                    synchronized( JspInitTag.class ) {
095                            // 3.8.0.0 (2005/06/07) 同ä¸?‚»ãƒ?‚·ョンでのマルチ起動対策を行いますã?
096                            String cnt = String.valueOf( count++ ) ;
097                            session.setAttribute( HybsSystem.MULTI_SESSION_CHECK, cnt );
098                    }
099    
100                    // URLXfer による、リンク変換転送機è?
101                    String key = request.getParameter( "XFER" );
102                    if( key != null ) {
103                            URLXfer xfer = new URLXfer();
104                            String url = xfer.getRedirectURL( key );
105                            if( url != null ) {
106                                    try {
107                                            HttpServletResponse response = (HttpServletResponse)pageContext.getResponse();
108                                            response.sendRedirect( url );
109                                            return(SKIP_PAGE);              // ペã?ジの残りの処ç�?‚’行わなã�??
110                                    } catch ( IOException ex ) {
111                                            String errMsg2 = "URLの振りå?けå?ç�?™‚に IOException が発生しましたã€?XFER=" + key;
112                                            throw new HybsSystemException( errMsg2,ex );
113                                    }
114                            }
115                    }
116    
117                    // 4.3.4.1 (2008/12/08) UserInfo の再作æ?する機è?を削除
118                    //4.1.1.0 (2008/02/07) UserInfo の再作æ?するように変更
119    //              UserInfo userInfo = ( UserInfo )session.getAttribute( HybsSystem.USERINFO_KEY );
120    //              if( userInfo != null ) {
121    //                      userInfo.clear();
122    //              }
123    //              session.removeAttribute( HybsSystem.USERINFO_KEY );
124    
125    //              String userID = request.getRemoteUser();
126    //              if( userID == null ) { userID = request.getParameter( "USERID" ); } // 4.2.2.0 (2008/05/28)
127    //              if( userID == null ) { userID = "GUEST"; } // 4.2.2.0 (2008/05/28) ゲストを利用可能にする
128    //              userInfo = UserInfoFactory.newInstance( userID.toUpperCase( Locale.JAPAN ),request.getRemoteAddr(),null );
129    //              ResourceManager resource = ResourceFactory.newInstance( userInfo.getLang() );
130    //              resource.makeGUIInfos( userInfo );
131    //              session.setAttribute( HybsSystem.USERINFO_KEY, userInfo );
132    
133                    return(EVAL_PAGE);              // ペã?ジの残りを評価するã€?
134            }
135    }