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    }