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.plugin.column; 017 018import org.opengion.hayabusa.common.HybsSystem; // 8.0.2.0 (2021/11/30) Add 019import org.opengion.hayabusa.db.AbstractEditor; 020import org.opengion.hayabusa.db.CellEditor; 021import org.opengion.hayabusa.db.DBColumn; 022import org.opengion.fukurou.util.TagBuffer; // 8.0.2.0 (2021/11/30) Add 023import org.opengion.fukurou.util.StringUtil; // 8.0.2.0 (2021/11/30) Add 024import org.opengion.fukurou.util.XHTMLTag; 025 026import static org.opengion.fukurou.util.StringUtil.isNull; // 8.0.2.0 (2021/11/30) Add 027 028/** 029 * YMD エディターは、カラムのデータを日付(年/月/日)編集する場合に使用するクラスです。 030 * 031 * カラムの表示に必要な属性は, DBColumn オブジェクト より取り出します。 032 * このクラスは、DBColumn オブジェクト毎に1つ作成されます。 033 * 034 * 8.0.2.0 (2021/11/30) 035 * カラムのパラメータの情報より、日付送り戻しの機能が使えます。 036 * 例:D-1,D0,D+1 or D-1,D0,D+1,true 037 * 038 * 第一引数は、日付戻しを指定します。 039 * 第二引数は、初期化します。 040 * 第三引数は、日付送りを指定します。 041 * 第四引数は、検索ボタンを押すか押さないか[true/false]を指定します。 (初期値:false) 042 * 043 * 日付についての加減算処理を行うためのコマンドを指定します。 044 * ・SYXX :年の最初の日付を指定の分だけ進めます。(SY-1なら先年の1月1日、SY1なら翌年の1月1日) 045 * ・SDXX :月の最初の日付を指定の分だけ進めます。(SD-1なら先月の1日、SD1なら翌月の1日) 046 * ・SWXX :週初め(月曜日)を指定の分だけ進めます。(SW-1なら先週の月曜日、SW1なら翌週の月曜日) 047 * ・EYXX :年の最後の日付を指定の分だけ進めます。(EY-1なら先年の年末、EY1なら翌年の年末) 048 * ・EDXX :月の最後の日付を指定の分だけ進めます。(ED-1なら先月の月末、ED1なら翌月の月末) 049 * ・EWXX :週末(日曜日)を指定の分だけ進めます。(EW-1なら先週の日曜日、EW1なら翌週の日曜日) 050 * ・YXX :年を指定の分だけ進めます。(Y-1なら1年前、Y1なら1年後) 051 * ・MXX :月を指定の分だけ進めます。(M-1なら1月前、M1なら1月後) 052 * ・DXX :日を指定の分だけ進めます。(D-1なら1日前、D1なら1日後) 053 * ※ 数字がゼロのコマンドは初期化します。 054 * ※ 数字がないコマンドはサーバー上のシステム日付をセットします。 055 * 056 * @og.rev 8.0.2.0 (2021/11/30) 日付送り戻し対応 057 * 058 * @og.group データ編集 059 * 060 * @version 4.0 061 * @author Kazuhiko Hasegawa 062 * @since JDK5.0, 063 */ 064public class Editor_YMD extends AbstractEditor { 065 /** このプログラムのVERSION文字列を設定します。 {@value} */ 066 private static final String VERSION = "8.0.3.0 (2021/12/17)" ; 067 068 // 8.0.2.0 (2021/11/30) 日付送り戻し対応 069 private static final int CNT_ARY = 3; 070 private static final String JSP_ICON = HybsSystem.sys( "JSP_ICON" ) ; 071 private static final String FR_STR = "<a href=\"#\" onClick=\"dateFeedRtn('%1$s','%2$s','%3$s','%4$s','%5$s');\" style=\"margin:0 5px 0 3px\" >"; 072 private static final String FR_END = "<img src=\"" + JSP_ICON + "/%6$s\" alt=\"%4$s\" title=\"%4$s\" /></a>"; 073 private static final String[] FR_IMG = { "FR_PREV.png", "FR_CIRCLE.png", "FR_NEXT.png" }; 074 075 private String isSubm = "false"; // 検索ボタンを押すか押さないか 076 private String errMsg; // エラーメッセージ 077 private String[] prmAry; // 編集パラメータ 078 079 private final boolean hidden; // 非表示 080 081 /** 082 * デフォルトコンストラクター。 083 * このコンストラクターで、基本オブジェクトを作成します。 084 * 085 * @og.rev 3.1.1.1 (2003/04/03) 各オブジェクトから自分のインスタンスを返すファクトリメソッドを追加。 086 * @og.rev 8.0.2.0 (2021/11/30) 日付送り戻し対応 087 * 088 */ 089// public Editor_YMD() { super(); } // これも、自動的に呼ばれるが、空のメソッドを作成すると警告されるので、明示的にしておきます。 090 // 8.0.2.0 (2021/11/30) Modify 091 public Editor_YMD() { 092 super(); 093 isSubm = "false"; 094 errMsg = null; 095 prmAry = null; 096 hidden = true; 097 } 098 099 /** 100 * DBColumnオブジェクトを指定したprivateコンストラクター。 101 * 102 * @og.rev 3.1.1.1 (2003/04/03) 各オブジェクトから自分のインスタンスを返すファクトリメソッドを追加。 103 * @og.rev 3.5.6.0 (2004/06/18) XHTMLTag の 内部配列 INPUT_KEY を隠蔽します。 104 * @og.rev 8.0.2.0 (2021/11/30) 日付送り戻し対応 105 * 106 * @param clm DBColumnオブジェクト 107 */ 108 private Editor_YMD( final DBColumn clm ) { 109 super( clm ); 110 tagBuffer.add( XHTMLTag.inputAttri( attributes ) ); 111 112 final boolean disabled = "disabled".equalsIgnoreCase( attributes.get( "disabled" ) ); 113 final boolean readonly = "readonly".equalsIgnoreCase( attributes.get( "readonly" ) ); // 8.0.2.0 (2021/11/30) 114 115 // 8.0.2.0 (2021/11/30) Add 日付送り戻し対応 116 hidden = disabled || readonly ; 117 if( !hidden ) { 118 // 例:D-1,D0,D+1 or D-1,D0,D+1,true 119 final String prmStr = clm.getEditorParam(); 120 if( prmStr != null ) { 121 prmAry = StringUtil.csv2Array( prmStr ); 122 // パラメータの第四引数がある場合 123 if( prmAry.length > CNT_ARY ) { 124 isSubm = prmAry[CNT_ARY]; 125 } else if( prmAry.length < CNT_ARY ) { 126 errMsg = "editorParam の設定が不足です。" 127 + " name=" + name 128 + " label=" + clm.getLabel() 129 + " editorParam=" + clm.getEditorParam(); 130 System.out.println( errMsg ); 131 } 132 } 133 } 134 } 135 136 /** 137 * 各オブジェクトから自分のインスタンスを返します。 138 * 自分自身をキャッシュするのか、新たに作成するのかは、各サブクラスの実装に 139 * まかされます。 140 * 141 * @og.rev 3.1.1.1 (2003/04/03) 各オブジェクトから自分のインスタンスを返すファクトリメソッドを追加。 142 * @og.rev 3.1.2.1 (2003/04/10) synchronized を、削除します。 143 * 144 * @param clm DBColumnオブジェクト 145 * 146 * @return CellEditorオブジェクト 147 * @og.rtnNotNull 148 */ 149 public CellEditor newInstance( final DBColumn clm ) { 150 return new Editor_YMD( clm ); 151 } 152 153 /** 154 * データの編集用文字列を返します。 155 * 156 * @og.rev 8.0.2.0 (2021/11/30) 日付送り戻し対応 157 * @og.rev 8.0.3.0 (2021/12/17) イメージにname属性を付けるため、spanタグで囲います。 158 * 159 * @param value 入力値 160 * 161 * @return データの編集用文字列 162 * @og.rtnNotNull 163 */ 164 @Override 165 public String getValue( final String value ) { 166 if( prmAry != null && prmAry.length < CNT_ARY ) { 167 return "<span class=\"error\">" + errMsg + "</span>"; 168 } 169 170 final String tag = new TagBuffer( "input" ) 171 .add( "name" , name ) 172 .add( "id" , name , isNull( attributes.get( "id" ) ) ) 173 .add( "value" , value ) 174 .add( "size" , size1 ) 175 .add( tagBuffer.makeTag() ) 176 .makeTag(); 177 178 if( hidden ) { 179 return tag; 180 } else { 181 final StringBuilder buf = new StringBuilder(BUFFER_MIDDLE) 182 .append( tag ); 183 184 // 日付送り戻し対応 185 if( prmAry != null && prmAry.length > 0 ) { 186 buf.append( "<span name=\"img" ).append( name ).append( "\">" ); // 8.0.3.0 (2021/12/17) 187 final String nmid = isNull( attributes.get( "id" ) ) ? name : attributes.get( "id" ); 188 // 第一回目の処理は、日付戻しを指定します。 189 // 第二回目の処理は、初期化します。 190 // 第三回目の処理は、日付送りを指定します。 191 for( int i=0; i<CNT_ARY; i++ ) { 192 buf.append( String.format( FR_STR + FR_END, "YMD", nmid, value, prmAry[i], isSubm, FR_IMG[i] ) ); 193 } 194 buf.append( "</span>" ); // 8.0.3.0 (2021/12/17) 195 } 196 return buf.toString(); 197 } 198 } 199 200 /** 201 * name属性を変えた、データ表示/編集用のHTML文字列を作成します。 202 * テーブル上の name に 行番号を付加して、名前_行番号 で登録するキーを作成し, 203 * リクエスト情報を1つ毎のフィールドで処理できます。 204 * 205 * @og.rev 8.0.2.0 (2021/11/30) 日付送り戻し対応 206 * @og.rev 8.0.3.0 (2021/12/17) イメージにname属性を付けるため、spanタグで囲います。 207 * 208 * @param row 行番号 209 * @param value 入力値 210 * 211 * @return データ表示/編集用の文字列 212 * @og.rtnNotNull 213 */ 214 @Override 215 public String getValue( final int row,final String value ) { 216 if( prmAry != null && prmAry.length < CNT_ARY ) { 217 return "<span class=\"error\">" + errMsg + " row=" + row + "</span>"; 218 } 219 220 final String name2 = name + HybsSystem.JOINT_STRING + row; 221 222 final String tag = new TagBuffer( "input" ) 223 .add( "name" , name2 ) 224 .add( "id" , name2 , isNull( attributes.get( "id" ) ) ) 225 .add( "value" , value ) 226 .add( "size" , size2 ) 227 .add( tagBuffer.makeTag() ) 228 .makeTag( row,value ); 229 230 if( hidden ) { 231 return tag; 232 } else { 233 final StringBuilder buf = new StringBuilder(BUFFER_MIDDLE) 234 .append( tag ); 235 236 // 日付送り戻し対応 237 if( prmAry != null && prmAry.length > 0 ) { 238 final String nmid = isNull( attributes.get( "id" ) ) ? name2 : attributes.get( "id" ); 239 // 第一回目の処理は、日付戻しを指定します。 240 // 第二回目の処理は、初期化します。 241 // 第三回目の処理は、日付送りを指定します。 242 buf.append( "<span name=\"img" ).append( name2 ).append( "\">" ); // 8.0.3.0 (2021/12/17) 243 for( int i=0; i<CNT_ARY; i++ ) { 244 buf.append( String.format( FR_STR + FR_END, "YMD", nmid, value, prmAry[i], isSubm, FR_IMG[i] ) ); 245 } 246 buf.append( "</span>" ); // 8.0.3.0 (2021/12/17) 247 } 248 return buf.toString(); 249 } 250 } 251}