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                            throw new HybsSystemException( errMsg );
066                    }
067    
068                    viewform.setParam( param );
069    
070                    return(EVAL_PAGE);
071            }
072    
073            /**
074             * タグリブオブジェクトをリリースしますã?
075             * キャãƒ?‚·ュされて再利用されるã?で、フィールドã?初期設定を行いますã?
076             *
077             */
078            @Override
079            protected void release2() {
080                    super.release2();               // 3.5.6.0 (2004/06/18) 追åŠ?抜けてã�?�Ÿ)
081                    param = null;
082            }
083    
084            /**
085             * パラメータのMapをå?期設定しますã?
086             *
087             * パラメータのキーと値の初期値をセãƒ?ƒˆしたMapをå?期設定しますã?
088             * 処ç�??タイミングとして、すでにパラメータ変数は、設定されてã�?�¾すã?
089             * ä¸?�¤も設定されてã�?�ªã�??合ã?、param == null なので、引数の初期値マップを
090             * そã?まま?ˆコピã?して?‰作æ?しますã?
091             * すでに、登録されてã�?‚‹場合ã?、キーが存在してã�?‚‹ため、キーの存在しなã�?
092             * ãƒ??タのみ、å?期å?マップからコピã?しますã?
093             *
094             * @og.rev 5.5.5.6 (2012/08/31) 新規追åŠ?
095             *
096             * @param   map         パラメータのMap
097             */
098            protected void initParam( final Map<String,String> map ) {
099                    if( param == null ) {
100                            param = new HashMap<String,String>( map );
101                    }
102                    else {
103                            for ( String key : map.keySet() ) {
104                                    if( !param.containsKey( key ) ) {       // キーが存在しなければ、å?期化æƒ??を登録するã€?
105                                            param.put( key,map.get( key ) );
106                                    }
107                            }
108                    }
109            }
110    
111            /**
112             * パラメータのキーと値をセãƒ?ƒˆしますã?
113             *
114             * パラメータのキーと値をセãƒ?ƒˆしますã?
115             *
116             * @param   key         キー
117             * @param   value       値
118             */
119            protected void putParam( final String key, final String value ) {
120                    if( key != null ) {
121                            if( param == null ) { param = new HashMap<String,String>(); }
122                            param.put( key,value );
123                    }
124            }
125    
126            /**
127             * シリアライズ用のカスタãƒ?‚·リアライズ書き込みメソãƒ?ƒ‰
128             *
129             * @og.rev 4.0.0.0 (2006/09/31) 新規追åŠ?
130             * @serialData
131             *
132             * @param       strm    ObjectOutputStreamオブジェクãƒ?
133             */
134            private void writeObject( final ObjectOutputStream strm ) throws IOException {
135                    strm.defaultWriteObject();
136            }
137    
138            /**
139             * シリアライズ用のカスタãƒ?‚·リアライズ読み込みメソãƒ?ƒ‰
140             *
141             * ここでは、transient 宣è¨?�•れたå†?ƒ¨変数のå†??初期化がå¿?¦�なフィールドã?み設定しますã?
142             *
143             * @og.rev 4.0.0.0 (2006/09/31) 新規追åŠ?
144             * @serialData
145             *
146             * @param       strm    ObjectInputStreamオブジェクãƒ?
147             * @see #release2()
148             */
149            private void readObject( final ObjectInputStream strm ) throws IOException , ClassNotFoundException {
150                    strm.defaultReadObject();
151            }
152    
153            /**
154             * こã?オブジェクトã?æ–?­—å?表現を返しますã?
155             * 基本çš?�«ãƒ?ƒ�ãƒ?‚°目çš?�«使用しますã?
156             *
157             * @og.rev 5.2.1.0 (2010/10/01) Map のå†?®¹表示方法を変更
158             *
159             * @return こã?クラスのæ–?­—å?表現
160             */
161            @Override
162            public String toString() {
163                    StringBuilder rtn = new StringBuilder( HybsSystem.BUFFER_MIDDLE );
164    
165                    rtn.append( "[" ).append( this.getClass().getName() ).append( "]" ).append( HybsSystem.CR );
166    //              rtn.append( param     ).append( HybsSystem.CR );
167                    if( param != null ) {
168                            for ( Map.Entry<String, String> ent : param.entrySet() ) {
169                                    rtn.append( ent.getKey() ).append( "=" ).append( ent.getValue() ).append( HybsSystem.CR );
170                            }
171                    }
172    
173                    return rtn.toString();
174            }
175    }