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
021 import java.util.Map;
022 import java.util.HashMap;
023 import java.io.ObjectOutputStream;
024 import java.io.ObjectInputStream;
025 import java.io.IOException;
026
027 /**
028 * ViewFormTag にパラメーターを渡す為のスーパ?クラスです?
029 *
030 * ViewForm 関連の?ラスは、特殊?専用化?傾向が強くなりつつあり?
031 * 設定するパラメーターも増えて?す?これら?パラメータを?共通?
032 * ViewFormインターフェースに設定することは、得策とは?られな??
033 * パラメーターを?して渡すよ?します?
034 * ただし?key1=**** val2=**** ?渡し方では、エラーチェ???動ドキュメント化
035 * が難しいため、各ViewFormのサブクラスごとに、パラメータクラスを作?し?
036 * それら?スーパ?クラスとして、最終的には、同?法で、パラメータオブジェク?
037 * として渡すことにします?
038 *
039 * @og.rev 3.5.4.8 (2004/02/23) 新規作?
040 * @og.group 画面表示
041 *
042 * @version 4.0
043 * @author Kazuhiko Hasegawa
044 * @since JDK5.0,
045 */
046 public class ViewParamTag extends CommonTagSupport {
047 //* こ?プログラ??VERSION??を設定します? {@value} */
048 private static final String VERSION = "5.5.5.6 (2012/08/31)" ;
049
050 private static final long serialVersionUID = 555620120831L ;
051
052 private transient Map<String,String> param = null; // 3.5.6.2 (2004/07/05)
053
054 /**
055 * Taglibの終?グが見つかったときに処??doEndTag() ?オーバ?ライドします?
056 *
057 * @return 後続????
058 */
059 @Override
060 public int doEndTag() {
061 debugPrint(); // 4.0.0 (2005/02/28)
062 ViewFormTag viewform = (ViewFormTag)findAncestorWithClass( this,ViewFormTag.class );
063 if( viewform == null ) {
064 // String errMsg = "<b>こ?タグは、ViewFormTagの??(要?に記述してください?/b>";
065 String errMsg = "<b>" + getTagName() + "タグは、ViewFormTagの??(要?に記述してください?/b>";
066 throw new HybsSystemException( errMsg );
067 }
068
069 viewform.setParam( param );
070
071 return(EVAL_PAGE);
072 }
073
074 /**
075 * タグリブオブジェクトをリリースします?
076 * キャ?ュされて再利用される?で、フィールド?初期設定を行います?
077 *
078 */
079 @Override
080 protected void release2() {
081 super.release2(); // 3.5.6.0 (2004/06/18) 追?抜けて?)
082 param = null;
083 }
084
085 /**
086 * パラメータのMapを?期設定します?
087 *
088 * パラメータのキーと値の初期値をセ?したMapを?期設定します?
089 * 処??タイミングとして、すでにパラメータ変数は、設定されて?す?
090 * ?も設定されて???合?、param == null なので、引数の初期値マップを
091 * そ?まま?コピ?して?作?します?
092 * すでに、登録されて?場合?、キーが存在して?ため、キーの存在しな?
093 * ??タのみ、?期?マップからコピ?します?
094 *
095 * @og.rev 5.5.5.6 (2012/08/31) 新規追?
096 *
097 * @param map パラメータのMap
098 */
099 protected void initParam( final Map<String,String> map ) {
100 if( param == null ) {
101 param = new HashMap<String,String>( map );
102 }
103 else {
104 for ( String key : map.keySet() ) {
105 if( !param.containsKey( key ) ) { // キーが存在しなければ、?期化??を登録する?
106 param.put( key,map.get( key ) );
107 }
108 }
109 }
110 }
111
112 /**
113 * パラメータのキーと値をセ?します?
114 *
115 * パラメータのキーと値をセ?します?
116 *
117 * @param key キー
118 * @param value 値
119 */
120 protected void putParam( final String key, final String value ) {
121 if( key != null ) {
122 if( param == null ) { param = new HashMap<String,String>(); }
123 param.put( key,value );
124 }
125 }
126
127 /**
128 * シリアライズ用のカスタ?リアライズ書き込みメソ?
129 *
130 * @og.rev 4.0.0.0 (2006/09/31) 新規追?
131 * @serialData ?のオブジェクト?、シリアライズされません?
132 *
133 * @param strm ObjectOutputStreamオブジェク?
134 * @throws IOException 入出力エラーが発生した??
135 */
136 private void writeObject( final ObjectOutputStream strm ) throws IOException {
137 strm.defaultWriteObject();
138 }
139
140 /**
141 * シリアライズ用のカスタ?リアライズ読み込みメソ?
142 *
143 * ここでは、transient 宣?れた?変数の??初期化が?なフィールド?み設定します?
144 *
145 * @og.rev 4.0.0.0 (2006/09/31) 新規追?
146 * @serialData ?のオブジェクト?、シリアライズされません?
147 *
148 * @param strm ObjectInputStreamオブジェク?
149 * @see #release2()
150 * @throws IOException シリアライズに関する入出力エラーが発生した??
151 * @throws ClassNotFoundException クラスを見つけることができなかった??
152 */
153 private void readObject( final ObjectInputStream strm ) throws IOException , ClassNotFoundException {
154 strm.defaultReadObject();
155 }
156
157 /**
158 * こ?オブジェクト???表現を返します?
159 * 基本???目?使用します?
160 *
161 * @og.rev 5.2.1.0 (2010/10/01) Map の?表示方法を変更
162 *
163 * @return こ?クラスの??表現
164 */
165 @Override
166 public String toString() {
167 StringBuilder rtn = new StringBuilder( HybsSystem.BUFFER_MIDDLE );
168
169 rtn.append( "[" ).append( this.getClass().getName() ).append( "]" ).append( HybsSystem.CR );
170 // rtn.append( param ).append( HybsSystem.CR );
171 if( param != null ) {
172 for ( Map.Entry<String, String> ent : param.entrySet() ) {
173 rtn.append( ent.getKey() ).append( "=" ).append( ent.getValue() ).append( HybsSystem.CR );
174 }
175 }
176
177 return rtn.toString();
178 }
179 }