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.HybsSystemException;
019 import static org.opengion.fukurou.util.StringUtil.nval ;
020
021 import java.io.ObjectOutputStream;
022 import java.io.ObjectInputStream;
023 import java.io.IOException;
024
025 /**
026 * ProcessTag に対して、引数(パラメータ)を渡すã?入れ子ã?子クラスですã?
027 *
028 * @og.formSample
029 * ●形式ï¼?lt;og:param key="ZZZ" value="AAA,BBB" />
030 * ●body?šあã‚?EVAL_BODY_BUFFERED:BODYを評価しã?{@XXXX} を解析しまã�?
031 *
032 * ●Tag定義??
033 * <og:param
034 * key ○ã?TAG】リクエスト情報 に登録するキーをセãƒ?ƒˆしますã?(å¿??)
035 * value 【TAG】リクエスト情報 に登録する値をセãƒ?ƒˆしまã�?
036 * debug 【TAG】デバッグæƒ??をå?力するかどã�?�‹[true/false]を指定しまã�?初期値:false)
037 * > ... Body ...
038 * </og:param>
039 *
040 * ●使用ä¾?
041 * ä¸?ˆ¬çš?�ª変数の渡し方
042 * <og:process ?¥?¥?¥?¥?¥ >
043 * <og:param key="AAA" value="111" />
044 * <og:param key="BBB" value="222" />
045 * <og:param key="CCC" value="333" />
046 * <og:param key="DDD" value="444" />
047 * </og:process >
048 *
049 * BODY 部に記述した変数の渡し方
050 * <og:process ?¥?¥?¥?¥?¥ >
051 * <og:param key="SQL" >
052 * SELECT * FROM DUAL
053 * </og:param>
054 * </og:process >
055 *
056 * @og.group 画面表示
057 *
058 * @version 4.0
059 * @author Kazuhiko Hasegawa
060 * @since JDK5.0,
061 */
062 public class ParamTag extends CommonTagSupport {
063 //* こã?プログラãƒ??VERSIONæ–?—å?を設定しますã? {@value} */
064 private static final String VERSION = "4.0.0.0 (2006/09/31)" ;
065
066 private static final long serialVersionUID = 400020060931L ;
067
068 private String key = null;
069 private String value = null;
070
071 /**
072 * Taglibの開始タグが見つかったときに処ç�?�™ã‚?doStartTag() ã‚?オーバã?ライドしますã?
073 *
074 * @return 後続å?ç�??æŒ?¤º( EVAL_BODY_BUFFERED )
075 */
076 @Override
077 public int doStartTag() {
078 return ( EVAL_BODY_BUFFERED ); // Body を評価する
079 }
080
081 /**
082 * Taglibのタグ本体を処ç�?�™ã‚?doAfterBody() ã‚?オーバã?ライドしますã?
083 *
084 * @return 後続å?ç�??æŒ?¤º(SKIP_BODY)
085 */
086 @Override
087 public int doAfterBody() {
088 if( value == null || value.length() <= 0 ) {
089 value = getBodyString();
090 }
091
092 return ( SKIP_BODY );
093 }
094
095 /**
096 * Taglibの終äº?‚¿グが見つかったときに処ç�?�™ã‚?doEndTag() ã‚?オーバã?ライドしますã?
097 *
098 * @return 後続å?ç�??æŒ?¤º
099 */
100 @Override
101 public int doEndTag() {
102 debugPrint(); // 4.0.0 (2005/02/28)
103 ProcessTag process = (ProcessTag)findAncestorWithClass( this,ProcessTag.class );
104 if( process == null ) {
105 String errMsg = "<b>こã?タグは、ProcessTag のå†??(要ç´?に記述してくださいã€?/b>";
106 throw new HybsSystemException( errMsg );
107 }
108
109 process.addParam( key,value );
110
111 return(EVAL_PAGE);
112 }
113
114 /**
115 * タグリブオブジェクトをリリースしますã?
116 * キャãƒ?‚·ュされて再利用されるã?で、フィールドã?初期設定を行いますã?
117 *
118 */
119 @Override
120 protected void release2() {
121 super.release2();
122 key = null;
123 value = null;
124 }
125
126 /**
127 * 【TAG】リクエスト情報 に登録するキーをセãƒ?ƒˆしますã?
128 *
129 * @og.tag リクエスト情報 に登録するキーをセãƒ?ƒˆしますã?
130 *
131 * @param key1 リクエスト情報に登録するキー
132 */
133 public void setKey( final String key1 ) {
134 key = nval( getRequestParameter( key1 ),key ) ;
135 }
136
137 /**
138 * 【TAG】リクエスト情報 に登録する値をセãƒ?ƒˆしますã?
139 *
140 * @og.tag リクエスト情報 に登録する値をセãƒ?ƒˆしますã?
141 *
142 * @param val リクエスト情報に登録する値
143 */
144 public void setValue( final String val ) {
145 value = nval( getRequestParameter( val ),value );
146 }
147
148 /**
149 * シリアライズ用のカスタãƒ?‚·リアライズ書き込みメソãƒ?ƒ‰
150 *
151 * @og.rev 4.0.0.0 (2006/09/31) 新規追åŠ?
152 * @serialData
153 *
154 * @param strm ObjectOutputStreamオブジェクãƒ?
155 */
156 private void writeObject( final ObjectOutputStream strm ) throws IOException {
157 strm.defaultWriteObject();
158 }
159
160 /**
161 * シリアライズ用のカスタãƒ?‚·リアライズ読み込みメソãƒ?ƒ‰
162 *
163 * ここでは、transient 宣è¨?�•れたå†?ƒ¨変数のå†??初期化がå¿?¦�なフィールドã?み設定しますã?
164 *
165 * @og.rev 4.0.0.0 (2006/09/31) 新規追åŠ?
166 * @serialData
167 *
168 * @param strm ObjectInputStreamオブジェクãƒ?
169 * @see #release2()
170 */
171 private void readObject( final ObjectInputStream strm ) throws IOException , ClassNotFoundException {
172 strm.defaultReadObject();
173 }
174
175 /**
176 * こã?オブジェクトã?æ–?—å?表現を返しますã?
177 * 基本çš?�«ãƒ?ƒ�ãƒ?‚°目çš?�«使用しますã?
178 *
179 * @return こã?クラスのæ–?—å?表現
180 */
181 @Override
182 public String toString() {
183 return org.opengion.fukurou.util.ToString.title( this.getClass().getName() )
184 .println( "VERSION" ,VERSION )
185 .println( "key" ,key )
186 .println( "value" ,value )
187 .fixForm().toString() ;
188 }
189 }