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 */ 016package org.opengion.hayabusa.taglib; 017 018import org.opengion.hayabusa.common.HybsSystem; 019import org.opengion.hayabusa.common.HybsSystemException; 020import org.opengion.hayabusa.resource.URLXfer; 021import org.opengion.fukurou.util.StringUtil ; 022 023import javax.servlet.http.HttpSession ; 024import javax.servlet.http.HttpServletResponse; 025import javax.servlet.http.HttpServletRequest; 026import javax.servlet.jsp.tagext.TagSupport ; 027import javax.servlet.jsp.JspWriter ; 028 029import 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 * ●形式:<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 */ 055public 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}