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.2.0 (2021/11/30)" ; 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 * 158 * @param value 入力値 159 * 160 * @return データの編集用文字列 161 * @og.rtnNotNull 162 */ 163 @Override 164 public String getValue( final String value ) { 165 if( prmAry != null && prmAry.length < CNT_ARY ) { 166 return "<span class=\"error\">" + errMsg + "</span>"; 167 } 168 169 final String tag = new TagBuffer( "input" ) 170 .add( "name" , name ) 171 .add( "id" , name , isNull( attributes.get( "id" ) ) ) 172 .add( "value" , value ) 173 .add( "size" , size1 ) 174 .add( tagBuffer.makeTag() ) 175 .makeTag(); 176 177 if( hidden ) { 178 return tag; 179 } else { 180 final StringBuilder buf = new StringBuilder(BUFFER_MIDDLE); 181 buf.append( tag ); 182 183 // 日付送り戻し対応 184 if( prmAry != null && prmAry.length > 0 ) { 185 final String nmid = isNull( attributes.get( "id" ) ) ? name : attributes.get( "id" ); 186 // 第一回目の処理は、日付戻しを指定します。 187 // 第二回目の処理は、初期化します。 188 // 第三回目の処理は、日付送りを指定します。 189 for( int i=0; i<CNT_ARY; i++ ) { 190 buf.append( String.format( FR_STR + FR_END, "YMD", nmid, value, prmAry[i], isSubm, FR_IMG[i] ) ); 191 } 192 } 193 return buf.toString(); 194 } 195 } 196 197 /** 198 * name属性を変えた、データ表示/編集用のHTML文字列を作成します。 199 * テーブル上の name に 行番号を付加して、名前_行番号 で登録するキーを作成し, 200 * リクエスト情報を1つ毎のフィールドで処理できます。 201 * 202 * @og.rev 8.0.2.0 (2021/11/30) 日付送り戻し対応 203 * 204 * @param row 行番号 205 * @param value 入力値 206 * 207 * @return データ表示/編集用の文字列 208 * @og.rtnNotNull 209 */ 210 @Override 211 public String getValue( final int row,final String value ) { 212 if( prmAry != null && prmAry.length < CNT_ARY ) { 213 return "<span class=\"error\">" + errMsg + " row=" + row + "</span>"; 214 } 215 216 final String name2 = name + HybsSystem.JOINT_STRING + row; 217 218 final String tag = new TagBuffer( "input" ) 219 .add( "name" , name2 ) 220 .add( "id" , name2 , isNull( attributes.get( "id" ) ) ) 221 .add( "value" , value ) 222 .add( "size" , size2 ) 223 .add( tagBuffer.makeTag() ) 224 .makeTag( row,value ); 225 226 if( hidden ) { 227 return tag; 228 } else { 229 final StringBuilder buf = new StringBuilder(BUFFER_MIDDLE); 230 buf.append( tag ); 231 232 // 日付送り戻し対応 233 if( prmAry != null && prmAry.length > 0 ) { 234 final String nmid = isNull( attributes.get( "id" ) ) ? name2 : attributes.get( "id" ); 235 // 第一回目の処理は、日付戻しを指定します。 236 // 第二回目の処理は、初期化します。 237 // 第三回目の処理は、日付送りを指定します。 238 for( int i=0; i<CNT_ARY; i++ ) { 239 buf.append( String.format( FR_STR + FR_END, "YMD", nmid, value, prmAry[i], isSubm, FR_IMG[i] ) ); 240 } 241 } 242 return buf.toString(); 243 } 244 } 245}