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.fukurou.util.ErrorMessage;
021 import org.opengion.fukurou.util.XHTMLTag;
022 import org.opengion.fukurou.util.Attributes;
023
024 import static org.opengion.fukurou.util.StringUtil.nval ;
025
026 import java.util.Locale ;
027 import java.io.ObjectOutputStream;
028 import java.io.ObjectInputStream;
029 import java.io.IOException;
030
031 /**
032 * エラーメãƒ?‚»ージã‚?表形式で表示するタグですã?
033 *
034 * Query 関係ã?実行時にエラー/ワーニングが発生すると、HybsSystem.ERR_MSG_KEY をキーに
035 * ErrorMessage オブジェクãƒ?をセãƒ?‚·ョンに登録しますã?
036 * こã?æƒ??をå?に、表é¡?TITLE)かã?å†?®¹(BODY)を表示しますã?
037 * 基本çš?�«は?Œ表題表示時には?Œリンクを張りã?共通エラー表示画面をオープン
038 * 出来る様になってã�?�¾すã?
039 *
040 * @og.formSample
041 * ●形式ï¼?
042 * <og:errorMessage command="{@command}" clear="{@clear}" />
043 * ●body?šなã�?
044 *
045 * ●Tag定義??
046 * <og:errorMessage
047 * command 【TAG】コマンãƒ?NEW,RENEW,RESET,REVIEW)をセãƒ?ƒˆしまã�?
048 * clear 【TAG】メãƒ?‚»ージをå?期化するかどã�?�‹[true/false]を指定しまã�?初期値:false)
049 * viewType 【TAG】表示形式ã?表é¡?TITLE)かã?å†?®¹(BODY)』をæŒ?®šしまã�?初期値:TITLE)
050 * displayMsg 【TAG】plsqlUpdate の結果を画面上に表示するメãƒ?‚»ージIDを指定しまã�?初期値:MSG0059『登録しましたã€?
051 * warningMsg 【TAG】登録処ç�?®Ÿ行後ã?ワーニング結果を画面上に表示するメãƒ?‚»ージIDを指定しまã�?初期値:ERR0020)
052 * debug 【TAG】デバッグæƒ??をå?力するかどã�?�‹[true/false]を指定しまã�?初期値:false)
053 * />
054 *
055 * ●使用ä¾?
056 * result.jsp 等ã?SQL登録実行後ã?戻り画面に、上記タグをé?置すればã€?
057 * エラーメãƒ?‚»ージが存在すれば,リンクとなって現れã?無ければ,なにã‚?
058 * 現れませんã€?
059 * リンクのとび先ã?自動的に設定されますã?
060 * なおã?clear="true" またã?、command="NEW" の場合に、エラーメãƒ?‚»ージはã€?
061 * クリアされますã?
062 *
063 * [entry.jsp]
064 * <% String forwardPage="result.jsp"; %>
065 * <jsp:forward page="<%= response.encodeRedirectURL( forwardPage ) %>" >
066 * <jsp:param name="command" value="REVIEW" />
067 * <jsp:param name="clear" value="false" />
068 * </jsp:forward>
069 *
070 * [result.jsp]
071 * <og:errorMessage command="{@command}" clear="{@clear}" />
072 *
073 * @og.group エラー処ç�?
074 *
075 * @version 4.0
076 * @author Kazuhiko Hasegawa
077 * @since JDK5.0,
078 */
079 public class ErrorMessageTag extends CommonTagSupport {
080 //* こã?プログラãƒ??VERSIONæ–?—å?を設定しますã? {@value} */
081 private static final String VERSION = "5.2.1.0 (2010/10/01)" ;
082
083 private static final long serialVersionUID = 521020101001L ;
084
085 /** command 引数に渡す事ã?出来ã‚?コマンãƒ? 新è¦?{@value} */
086 public static final String CMD_NEW = "NEW" ;
087 /** command 引数に渡す事ã?出来ã‚?コマンãƒ? 再検索 {@value} */
088 public static final String CMD_RENEW = "RENEW" ;
089 /** command 引数に渡す事ã?出来ã‚?コマンãƒ? 取æ¶?{@value} */
090 public static final String CMD_RESET = "RESET" ;
091 /** command 引数に渡す事ã?出来ã‚?コマンãƒ? 再表示 {@value} */
092 public static final String CMD_REVIEW = "REVIEW" ;
093 /** command 引数に渡す事ã?出来ã‚?コマンãƒ?リスãƒ? */
094 // private static final String[] COMMAND_LIST = new String[] { CMD_NEW , CMD_RENEW , CMD_RESET , CMD_REVIEW };
095 private static final String errMsgId = HybsSystem.ERR_MSG_KEY;
096 private final String errMsgFile = HybsSystem.sys( "ERR_MSG_FILENAME" );
097 private final int maxRowCount = HybsSystem.sysInt( "DB_MAX_ROW_COUNT" ) ;
098
099 private transient ErrorMessage errMessage = null;
100 private String command = null;
101 private boolean msgClear = false;
102 private String viewType = "TITLE"; // TITLE/BODY
103
104 // 2.0.1.0 (2002/10/10) ãƒ?ƒ•ォルト表示しなã�?�‹らã?MSG0059=登録しました。に変更しますã?
105 private String displayMsg = "MSG0059"; // 初期値は『登録しました。ã?
106 private String warningMsg = "ERR0020"; // ãƒ??タ登録時にワーニングが発生しましたã€?
107
108 /**
109 * Taglibの開始タグが見つかったときに処ç�?�™ã‚?doStartTag() ã‚?オーバã?ライドしますã?
110 *
111 * @og.rev 3.5.4.0 (2003/11/25) エラーオブジェクトã?クリアに、RENEW or null も追åŠ?�—ますã?
112 *
113 * @return 後続å?ç�??æŒ?¤º(SKIP_BODY)
114 */
115 @Override
116 public int doStartTag() {
117 // クリアが指示されるか、コマンドが NEW or RESET or RENEW or null の場合ã?、エラーをクリアするã€?
118 if( msgClear || CMD_NEW.equals( command ) || CMD_RESET.equals( command ) ) {
119 // 3.5.4.9 (2004/02/25) RENEW の時ã?、エラーをクリアしなã�??
120 removeSessionAttribute( errMsgId );
121 msgClear = true;
122 }
123 else {
124 errMessage = (ErrorMessage)getSessionAttribute( errMsgId );
125 if( errMessage == null ) { msgClear = true; }
126 }
127
128 return(SKIP_BODY); // Body を評価しなã�?
129 }
130
131 /**
132 * Taglibの終äº?‚¿グが見つかったときに処ç�?�™ã‚?doEndTag() ã‚?オーバã?ライドしますã?
133 *
134 * @og.rev 2.1.0.3 (2002/11/08) command = NEW のときも、ã?登録しました。ã?メãƒ?‚»ージが表示されるバグを修正
135 * @og.rev 3.1.1.2 (2003/04/04) Tomcat4.1 対応ã?release2() ã‚?doEndTag()で呼ぶã€?
136 * @og.rev 3.5.5.2 (2004/04/02) TaglibUtil.makeHTMLErrorTable メソãƒ?ƒ‰を利用
137 * @og.rev 4.0.0.0 (2007/10/18) メãƒ?‚»ージリソース統å�? getResource().getMessage â‡?getResource().getLabel )
138 * @og.rev 4.1.3.0 (2008/09/04) メãƒ?‚»ージをspanで囲ã�?画面遷移なしモード対å¿?
139 * @og.rev 5.2.1.0 (2010/10/01) 戻るリンク時に不要な改行が出力される件に対å¿?
140 *
141 * @return 後続å?ç�??æŒ?¤º
142 */
143 @Override
144 public int doEndTag() {
145 debugPrint(); // 4.0.0 (2005/02/28)
146
147 String msg = null;
148 if( errMessage == null ) {
149 if( CMD_REVIEW.equals( command ) || CMD_RENEW.equals( command ) ) {
150 // 5.2.1.0 (2010/10/01) 戻るリンク時に不要な改行が出力される件に対å¿?
151 // msg = getResource().getMessage( displayMsg ) + HybsSystem.BR;
152 msg = getResource().getLabel( displayMsg );
153 if( msg != null && msg.length() > 0 ) { msg += HybsSystem.BR; }
154 }
155 }
156 else {
157 if( "TITLE".equalsIgnoreCase( viewType ) ) {
158 msg = makeTitle();
159 }
160 else if( "BODY".equalsIgnoreCase( viewType ) ) {
161 msg = TaglibUtil.makeHTMLErrorTable( errMessage,getResource() ); // 3.5.5.2 (2004/04/02)
162 }
163 else {
164 String errMsg = "viewType属æ?に TITLE/BODY 以外ã?é ?›®が指定されてã�?�¾すã?"
165 + "[" + viewType + "]" ;
166 throw new HybsSystemException( errMsg );
167 }
168 }
169
170 jspPrint( "<span class=\"errmsg\">" ); // 4.1.3.0 (2008/09/04)
171 if( msg != null && msg.length() > 0 ) { jspPrint( msg ); }
172 jspPrint( "</span>" );
173
174 return(EVAL_PAGE);
175 }
176
177 /**
178 * タグリブオブジェクトをリリースしますã?
179 * キャãƒ?‚·ュされて再利用されるã?で、フィールドã?初期設定を行いますã?
180 *
181 * @og.rev 2.0.0.4 (2002/09/27) カスタãƒ?‚¿グの release() メソãƒ?ƒ‰をã?追åŠ?
182 * @og.rev 2.0.1.0 (2002/10/10) ãƒ?ƒ•ォルト表示しなã�?�‹らã?MSG0059=登録しました。に変更しますã?
183 * @og.rev 3.1.1.2 (2003/04/04) Tomcat4.1 対応ã?release2() ã‚?doEndTag()で呼ぶã€?
184 *
185 */
186 @Override
187 protected void release2() {
188 super.release2();
189 command = null;
190 errMessage = null;
191 msgClear = false;
192 viewType = "TITLE"; // TITLE/BODY
193 displayMsg = "MSG0059"; // 初期値は『登録しました。ã?
194 warningMsg = "ERR0020"; // ãƒ??タ登録時にワーニングが発生しましたã€?
195 }
196
197 /**
198 * エラーメãƒ?‚»ージをタグæƒ??のæ–?—å?に変換して返しますã?
199 *
200 * ここでは、正常なメãƒ?‚»ージも異常なメãƒ?‚»ージも作æ?しますã?
201 *
202 * @og.rev 3.6.0.1 (2004/09/29) ワーニング、エラー時ã?スタイルシートを適用
203 * @og.rev 3.6.0.7 (2004/11/06) target 属æ?ã‚?_new から _blank に変更
204 * @og.rev 4.0.0.0 (2007/10/18) メãƒ?‚»ージリソース統å�? getResource().getMessage â‡?getResource().getLabel )
205 * @og.rev 5.1.7.0 (2010/06/01) エラー・ワーニングメãƒ?‚»ージの後に改行を入れる(displayMsgと仕様を合わせる)
206 *
207 * @return エラーメãƒ?‚»ージのタグæƒ??æ–?—å?
208 */
209 private String makeTitle() {
210 String href = getContextPath() + "/" + errMsgFile ;
211
212 Attributes attri = new Attributes();
213 attri.set( "href" , href );
214 attri.set( "target" , "_blank" ); // 3.6.0.7 (2004/11/06)
215
216 final String title ;
217 if( warningMsg != null ) {
218 title = "<span class=\"msg_warning\">"
219 // + getResource().getMessage( warningMsg )
220 + getResource().getLabel( warningMsg )
221 // 5.1.7.0 (2010/06/01) ワーニングメãƒ?‚»ージの後に改行を入れる
222 + "</span>" + HybsSystem.BR;
223 }
224 else {
225 title = "<span class=\"msg_error\">"
226 + errMessage.getTitle()
227 // 5.1.7.0 (2010/06/01) エラーメãƒ?‚»ージの後に改行を入れる
228 + "</span>" + HybsSystem.BR;
229 }
230
231 attri.set( "body" , title );
232
233 String key = "pageSize";
234 String val = String.valueOf( maxRowCount );
235 String urlEnc = XHTMLTag.urlEncode( key,val );
236
237 return XHTMLTag.link( attri,urlEnc ) ;
238 }
239
240 /**
241 * 【TAG】コマンãƒ?NEW,RENEW,RESET,REVIEW)をセãƒ?ƒˆしますã?
242 *
243 * @og.tag
244 * コマンドã?,HTMLから(get/post)æŒ?®šされますã?で,CMD_xxx で設定される
245 * フィールド定数値のã�?�¥れかをã?æŒ?®šできますã?
246 *
247 * @param cmd コマンãƒ?public static final 宣è¨?�•れてã�?‚‹æ–?—å?)
248 * @see <a href="../../../../constant-values.html#org.opengion.hayabusa.taglib.ErrorMessageTag.CMD_NEW">コマンド定数</a>
249 */
250 public void setCommand( final String cmd ) {
251 String cmd2 = getRequestParameter( cmd );
252 if( cmd2 != null && cmd2.length() > 0 ) { command = cmd2.toUpperCase(Locale.JAPAN); }
253 }
254
255 /**
256 * 【TAG】メãƒ?‚»ージをå?期化するかどã�?�‹[true/false]を指定しまã�?初期値:false)ã€?
257 *
258 * @og.tag
259 * メãƒ?‚»ージは、ä¸?ˆ¬には?Œエラーメãƒ?‚»ージかワーニングですã?
260 * æœ?µ‚å?ç�?�§メãƒ?‚»ージが無ければ?Œ標準でクリアしますã?
261 * またã?command ã�?NEW の場合も、メãƒ?‚»ージは自動でクリアされますã?
262 * 初期値は、クリアしなã�?(true 以å¤?ですã?
263 *
264 * @param flag [true:クリアする/それ以å¤?しない]
265 */
266 public void setClear( final String flag ) {
267 msgClear = nval( getRequestParameter( flag ),msgClear );
268 }
269
270 /**
271 * 【TAG】表示形式ã?表é¡?TITLE)かã?å†?®¹(BODY)』をæŒ?®šしまã�?初期値:TITLE)ã€?
272 *
273 * @og.tag
274 * ä¸?ˆ¬には?Œ表é¡?TITLE) を表示しておきますã?
275 * 表題表示時には?Œリンクを張りã?共通エラー表示画面をオープン
276 * 出来る様になってã�?�¾すã?
277 *
278 * @param flag 表示形å¼?表é¡?TITLE)かã?å†?®¹(BODY)
279 */
280 public void setViewType( final String flag ) {
281 viewType = nval( getRequestParameter( flag ),viewType );
282 }
283
284 /**
285 * 【TAG】plsqlUpdate の結果を画面上に表示するメãƒ?‚»ージIDを指定しまã�?初期値:MSG0059『登録しましたã€?ã€?
286 *
287 * @og.tag
288 * æŒ?®šしたメãƒ?‚»ージをリソースから取得して表示しますã?
289 * 表示させたくなã�??合ã?, displayMsg = "MSG0065" をセãƒ?ƒˆしてくださいã€?
290 * 初期値は、MSG0059『登録しました。ã?を表示しますã?
291 *
292 * @og.rev 2.0.1.0 (2002/10/10) ãƒ?ƒ•ォルト表示しなã�?�‹らã?MSG0059=登録しました。に変更しますã?
293 * @og.rev 3.2.0.0 (2003/05/22) 引数に何もセãƒ?ƒˆされなã�?�¨きに、デフォルトã?æ–?—を表示するように変更ã€?
294 *
295 * @param id ãƒ?‚£スプレイに表示させるメãƒ?‚»ージ ID
296 */
297 public void setDisplayMsg( final String id ) {
298 displayMsg = nval( getRequestParameter( id ),displayMsg );
299 // String ids = getRequestParameter( id );
300 // if( ids != null ) { displayMsg = ids; }
301 }
302
303 /**
304 * 【TAG】登録処ç�?®Ÿ行後ã?ワーニング結果を画面上に表示するメãƒ?‚»ージIDを指定しまã�?初期値:ERR0020)ã€?
305 *
306 * @og.tag
307 * æŒ?®šしたメãƒ?‚»ージをリソースから取得して表示しますã?
308 * 表示させたくなã�??合ã?, warningMsg = "" をセãƒ?ƒˆしてくださいã€?
309 * 初期値は、ERR0020『データ登録時にワーニングが発生しました。ã?を表示しますã?
310 *
311 * @og.rev 2.0.1.0 (2002/10/10) ãƒ?ƒ•ォルト表示しなã�?�‹らã?ERR0020=ãƒ??タ登録時にワーニングが発生しました。に変更しますã?
312 *
313 * @param id ãƒ?‚£スプレイに表示させるメãƒ?‚»ージ ID
314 */
315 public void setWarningMsg( final String id ) {
316 // warningMsg = nval( getRequestParameter( id ),warningMsg );
317 String ids = getRequestParameter( id );
318 if( ids != null ) { warningMsg = ids; }
319 }
320
321 /**
322 * シリアライズ用のカスタãƒ?‚·リアライズ書き込みメソãƒ?ƒ‰
323 *
324 * @og.rev 4.0.0.0 (2006/09/31) 新規追åŠ?
325 * @serialData ä¸?ƒ¨のオブジェクトã?、シリアライズされませんã€?
326 *
327 * @param strm ObjectOutputStreamオブジェクãƒ?
328 * @throws IOException 入出力エラーが発生したå?å�?
329 */
330 private void writeObject( final ObjectOutputStream strm ) throws IOException {
331 strm.defaultWriteObject();
332 }
333
334 /**
335 * シリアライズ用のカスタãƒ?‚·リアライズ読み込みメソãƒ?ƒ‰
336 *
337 * ここでは、transient 宣è¨?�•れたå†?ƒ¨変数のå†??初期化がå¿?¦�なフィールドã?み設定しますã?
338 *
339 * @og.rev 4.0.0.0 (2006/09/31) 新規追åŠ?
340 * @serialData ä¸?ƒ¨のオブジェクトã?、シリアライズされませんã€?
341 *
342 * @param strm ObjectInputStreamオブジェクãƒ?
343 * @see #release2()
344 * @throws IOException シリアライズに関する入出力エラーが発生したå?å�?
345 * @throws ClassNotFoundException クラスを見つけることができなかったå?å�?
346 */
347 private void readObject( final ObjectInputStream strm ) throws IOException , ClassNotFoundException {
348 strm.defaultReadObject();
349 }
350
351 /**
352 * ãƒ?ƒ�ãƒ?‚°時ã?æ–?—å?を返しますã?
353 *
354 * @return こã?オブジェクトã?ãƒ?ƒ�ãƒ?‚°表現æ–?—å?
355 */
356 @Override
357 public String toString() {
358 return org.opengion.fukurou.util.ToString.title( this.getClass().getName() )
359 .println( "VERSION" ,VERSION )
360 .println( "errMsgId" ,errMsgId )
361 .println( "errMsgFile" ,errMsgFile )
362 .println( "maxRowCount" ,maxRowCount)
363 .println( "command" ,command )
364 .println( "msgClear" ,msgClear )
365 .println( "viewType" ,viewType )
366 .println( "displayMsg" ,displayMsg )
367 .println( "warningMsg" ,warningMsg )
368 .println( "Other..." ,getAttributes().getAttribute() )
369 .fixForm().toString() ;
370 }
371 }