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.4.3 (2014/03/28)" ;
058    
059            private static final long serialVersionUID = 574320140328L ;
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             *
072             * @return      後続å?ç??æŒ?¤º
073             */
074            @Override
075            public int doEndTag() {
076                    // 5.7.4.3 (2014/03/28) エラー時ã§ã‚‚ã?debug=true ãŒã‚れã?ã€ç¶™ç¶šã™ã‚‹ã?
077                    HttpServletRequest request = ( HttpServletRequest )pageContext.getRequest();
078                    boolean debug = "true".equalsIgnoreCase( request.getParameter( "debug" ) );
079    
080                    // Tomcat åˆæœŸèµ·å‹•時㮠common/SystemParameter.java ã§ã‚¨ãƒ©ãƒ¼ãŒç™ºç”Ÿã—ãŸå?åˆã?
081                    String errMsg = HybsSystem.sys( HybsSystem.LOCAL_CONTX_ERR_KEY );
082    //              if( errMsg != null ) {
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( errMsg );
089                                    out.println( StringUtil.htmlFilter( errMsg ) );
090                                    out.println( "</pre></body></html>" );
091                            }
092                            catch(IOException ex) {
093                                    errMsg = "ç”»é¢å‡ºåŠ›æ™‚ã® PageContext ã®å–得時ã«ã‚¨ãƒ©ãƒ¼ãŒç™ºç”Ÿã—ã¾ã—ãŸã€?
094                                                    + HybsSystem.CR
095                                                    + errMsg ;
096                                    throw new HybsSystemException( errMsg,ex );             // 3.5.5.4 (2004/04/15) 引数ã®ä¸¦ã³é ?¤‰æ›´
097                            }
098                            return(SKIP_PAGE);              // ペã?ã‚¸ã®æ®‹ã‚Šã®å‡¦ç?‚’行ã‚ãªã??
099                    }
100    
101                    HttpSession session = pageContext.getSession();
102    //              HttpServletRequest request = ( HttpServletRequest )pageContext.getRequest(); 5.7.4.3 (2014/03/28)
103                    synchronized( JspInitTag.class ) {
104                            // 3.8.0.0 (2005/06/07) åŒä¸?‚»ãƒ?‚·ãƒ§ãƒ³ã§ã®ãƒžãƒ«ãƒèµ·å‹•対策を行ã„ã¾ã™ã?
105                            String cnt = String.valueOf( count++ ) ;
106                            session.setAttribute( HybsSystem.MULTI_SESSION_CHECK, cnt );
107                    }
108    
109                    // URLXfer ã«ã‚ˆã‚‹ã€ãƒªãƒ³ã‚¯å¤‰æ›è»¢é€æ©Ÿè?
110                    String key = request.getParameter( "XFER" );
111                    if( key != null ) {
112                            URLXfer xfer = new URLXfer();
113                            String url = xfer.getRedirectURL( key );
114                            if( url != null ) {
115                                    try {
116                                            HttpServletResponse response = (HttpServletResponse)pageContext.getResponse();
117                                            response.sendRedirect( url );
118                                            return(SKIP_PAGE);              // ペã?ã‚¸ã®æ®‹ã‚Šã®å‡¦ç?‚’行ã‚ãªã??
119                                    } catch ( IOException ex ) {
120                                            String errMsg2 = "URLã®æŒ¯ã‚Šå?ã‘å?ç?™‚ã« IOException ãŒç™ºç”Ÿã—ã¾ã—ãŸã€?XFER=" + key;
121                                            throw new HybsSystemException( errMsg2,ex );
122                                    }
123                            }
124                    }
125    
126                    // 4.3.4.1 (2008/12/08) UserInfo ã®å†ä½œæ?ã™ã‚‹æ©Ÿè?を削除
127                    //4.1.1.0 (2008/02/07) UserInfo ã®å†ä½œæ?ã™ã‚‹ã‚ˆã†ã«å¤‰æ›´
128    //              UserInfo userInfo = ( UserInfo )session.getAttribute( HybsSystem.USERINFO_KEY );
129    //              if( userInfo != null ) {
130    //                      userInfo.clear();
131    //              }
132    //              session.removeAttribute( HybsSystem.USERINFO_KEY );
133    
134    //              String userID = request.getRemoteUser();
135    //              if( userID == null ) { userID = request.getParameter( "USERID" ); } // 4.2.2.0 (2008/05/28)
136    //              if( userID == null ) { userID = "GUEST"; } // 4.2.2.0 (2008/05/28) ゲストを利用å¯èƒ½ã«ã™ã‚‹
137    //              userInfo = UserInfoFactory.newInstance( userID.toUpperCase( Locale.JAPAN ),request.getRemoteAddr(),null );
138    //              ResourceManager resource = ResourceFactory.newInstance( userInfo.getLang() );
139    //              resource.makeGUIInfos( userInfo );
140    //              session.setAttribute( HybsSystem.USERINFO_KEY, userInfo );
141    
142                    return(EVAL_PAGE);              // ペã?ã‚¸ã®æ®‹ã‚Šã‚’評価ã™ã‚‹ã€?
143            }
144    }