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.hayabusa.db;
017
018import org.opengion.fukurou.model.NativeType;
019import org.opengion.fukurou.util.Attributes;
020import org.opengion.fukurou.util.ErrorMessage;
021import org.opengion.fukurou.util.TagBuffer;
022import org.opengion.hayabusa.common.HybsSystem;
023import org.opengion.hayabusa.common.HybsSystemException;
024import org.opengion.hayabusa.resource.CodeData;
025import org.opengion.hayabusa.resource.ColumnData;
026import org.opengion.hayabusa.resource.LabelData;
027import org.opengion.hayabusa.resource.RoleMode;
028
029/**
030 * DBType インターフェースを継承した Abstractクラスです。
031 * getRendererValue( String value ) 、getEditorValue( String value ) 、
032 * isValueChack( String ) メソッドを、サブクラスで実装する必要があります。
033 *
034 * @og.rev 3.4.0.0 (2003/09/01) 表示パラメータ、編集パラメータ、文字パラメータの追加。
035 * @og.group テーブル管理
036 *
037 * @version  4.0
038 * @author   Kazuhiko Hasegawa
039 * @since    JDK5.0,
040 */
041public final class DBColumn {
042
043        // 3.5.4.2 (2003/12/15) COLUMNS_MAXSIZE を定義しておきます。
044        private final int COLUMNS_MAXSIZE = HybsSystem.sysInt( "HTML_COLUMNS_MAXSIZE" ) ;   // 表示フィールドの大きさ
045
046        private final ColumnData columnData ;
047        private final LabelData  labelData ;
048        private final CodeData   codeData ;
049
050        private final CellRenderer      cellRenderer    ;               // 表示用レンデラー
051        private final CellEditor        cellEditor              ;               // 編集用エディター
052        private final DBType            dbType                  ;               // データのタイプ
053
054        private final String            lang                    ;               // 言語
055        private final boolean           writable                ;               // カラムが書き込み可能かどうか
056        private final String            defValue                ;               // データのデフォルト値
057        private final Attributes        rendAttri               ;               // 表示用レンデラー追加用属性
058        private final Attributes        editAttri               ;               // 編集用エディター追加用属性
059        private final boolean           addNoValue              ;               // メニューに空の選択リストを追加するかどうか        // 3.5.5.7 (2004/05/10)
060        private final String            dbid                    ;               // データベース接続先ID
061        private final boolean           official                ;               // カラムリソースから作成されたかどうか           // 3.6.0.7 (2004/11/06)
062
063        private final int                       checkLevel              ;               // DBColumn の 整合性チェックを行うレベルを規定します。
064
065        private final Selection         selection               ;               // 4.0.0.0 (2007/11/07)
066
067        private final String            eventColumn             ;       // 4.3.6.0 (2009/04/01) イベントカラム
068        private final String            rawEditParameter;       // 4.3.6.0 (2009/04/01) {@XXXX}の変換がされていない生パラメータ
069        private final String            rawRendParameter;       // 5.1.7.0  (2009/04/01) {@XXXX}の変換がされていない生パラメータ
070        private final String            eventURL                ;       // 4.3.6.0 (2009/04/01) イベントカラムで利用するURL
071
072        private final String            useSLabel               ;       // 5.5.1.0 (2012/04/03) MENUのベース表示の切り替え
073        private final String            noDisplayVal    ;       // 5.6.2.3 (2013/03/22) 非表示文字の設定
074
075        private final boolean           stringOutput    ;       // 5.7.6.3 (2013/05/23) ファイルレンデラ出力時のフラグ
076
077        /**
078         * DBColumnConfig オブジェクトより作成されるコンストラクター
079         * すべての情報は、インスタンス作成時に設定します。
080         * このオブジェクトは、1度作成されると変更されることはありません。
081         *
082         * @og.rev 4.0.0.0 (2005/01/31) 新規追加
083         * @og.rev 4.0.0.0 (2007/11/07) Selectionオブジェクトをキャッシュする
084         * @og.rev 4.3.6.0 (2009/04/01) eventColumnの対応
085         * @og.rev 5.1.7.0 (2010/06/01) 動的プルダウン実装見直し
086         * @og.rev 5.5.1.0 (2012/04/03) useSLabel対応
087         * @og.rev 5.6.2.3 (2013/03/22) 非表示文字の設定。noDisplayVal追加
088         * @og.rev 5.7.3.0 (2014/02/07) SelectionFactory 対応
089         * @og.rev 5.7.6.3 (2014/05/23) stringOutput対応
090         *
091         * @param   lang    言語
092         * @param   clmData カラムデータオブジェクト
093         * @param   lblData ラベルデータオブジェクト
094         * @param   cdData  コードデータオブジェクト
095         */
096        public DBColumn( final String     lang,
097                                         final ColumnData clmData ,
098                                         final LabelData  lblData ,
099                                         final CodeData   cdData ) {
100                this.lang       = lang ;
101                this.columnData = clmData ;
102                this.labelData  = lblData ;
103                this.codeData   = cdData  ;
104
105                writable  = true ;
106
107                try {
108                        dbType = DBTypeFactory.newInstance( columnData.getDbType() );
109                }
110                catch( RuntimeException ex ) {
111                        String errMsg = "dbType の作成に失敗しました。"
112                                                + " name=[" + columnData.getName() + "]"
113                                                + " dbType=[" + columnData.getDbType() + "] "
114                                                + ex.getMessage();
115                        throw new HybsSystemException( errMsg,ex );
116                }
117
118                rendAttri       = null  ;
119                editAttri       = null  ;
120                addNoValue      = false ;
121                official        = true  ;               // 3.6.0.7 (2004/11/06)
122                checkLevel      = -1;
123                dbid            = null  ;               // 標準から作成されるカラムオブジェクトは、DEFAULT 接続先を設定する。
124
125                eventColumn  = null;            // 4.3.6.0 (2009/04/01)
126                rawEditParameter = clmData.getEditorParam(); // 4.3.6.0 (2009/04/01)
127                rawRendParameter = clmData.getRendererParam(); // 5.1.7.0 (2010/06/01)
128                eventURL         = null;                // 4.3.6.0 (2009/04/01)
129
130                useSLabel       = "auto";               // 5.5.1.0
131                noDisplayVal= null;                     // 5.6.2.3 (2013/03/22) 非表示文字の設定
132
133                stringOutput = HybsSystem.sysBool( "USE_STRING_EXCEL_OUTPUT" );         // 5.7.6.3 (2014/05/23)
134
135                String def = columnData.getDefault();
136                if( def != null ) { defValue = def; }
137                else {              defValue = dbType.getDefault() ; }
138
139                // 5.7.3.0 (2014/02/07) SelectionFactory 対応
140                selection = ( codeData == null ? null : SelectionFactory.newSelection( "MENU",codeData ) );
141
142                try {
143                        cellRenderer = DBCellFactory.newRenderer( columnData.getRenderer(),this );
144                        cellEditor   = DBCellFactory.newEditor(   columnData.getEditor(),  this );
145                }
146                catch( RuntimeException ex ) {
147                        String errMsg = "Renderer,Editor の作成に失敗しました。"
148                                                + " name=[" + columnData.getName() + "]"
149                                                + " Renderer=[" + columnData.getRenderer() + "] "
150                                                + " Editor=[" + columnData.getEditor() + "] "
151                                                + ex.getMessage();
152                        throw new HybsSystemException( errMsg,ex );
153                }
154        }
155
156        /**
157         * DBColumnConfig オブジェクトより作成されるコンストラクター
158         * すべての情報は、インスタンス作成時に設定します。
159         * このオブジェクトは、1度作成されると変更されることはありません。
160         *
161         * @og.rev 4.0.0.0 (2007/11/07) Selectionオブジェクトをキャッシュする
162         * @og.rev 5.1.7.0 (2010/06/01) 動的プルダウン実装見直し
163         * @og.rev 5.1.8.0 (2010/07/01) メソッド名変更(getDefValue ⇒ getDefault)
164         * @og.rev 5.5.1.0 (2012/04/03) useSLabel対応
165         * @og.rev 5.6.2.3 (2013/03/22) 非表示文字の設定。noDisplayVal追加
166         * @og.rev 5.6.6.0 (2013/07/05) codeKeyVal 属性を使用した、Selection_KEYVAL オブジェクトの作成
167         * @og.rev 5.7.3.0 (2014/02/07) SelectionFactory 対応
168         * @og.rev 5.7.6.3 (2014/05/23) stringOutput対応
169         *
170         * @param   config DBColumnConfigオブジェクト
171         */
172        public DBColumn( final DBColumnConfig config ) {
173                lang      = config.getLang()            ;
174
175                columnData      = config.getColumnData();
176                labelData       = config.getLabelData();
177                codeData        = config.getCodeData();
178
179                writable        = config.isWritable();
180                dbType          = DBTypeFactory.newInstance( columnData.getDbType() );
181                rendAttri       = config.getRendererAttributes();
182                editAttri       = config.getEditorAttributes();
183                addNoValue      = config.isAddNoValue();
184                official        = config.isOfficial();          // 3.6.0.7 (2004/11/06)
185                dbid            = config.getDbid();
186
187                eventColumn      = config.getEventColumn();      // 4.3.6.0 (2009/04/01)
188                rawEditParameter = config.getRawEditParameter(); // 4.3.6.0 (2009/04/01)
189                rawRendParameter = config.getRawRendParameter(); // 5.1.7.0 (2010/06/01) 動的プルダウン実装見直し
190                eventURL                 = config.getEventURL();                 // 4.3.6.0 (2009/04/01)
191
192                useSLabel                = config.getUseSLabel();               // 5.5.1.0 (2012/04/03)
193                noDisplayVal     = config.getNoDisplayVal();    // 5.6.2.3 (2013/03/22) 非表示文字の設定
194
195                stringOutput     = config.isStringOutput();             // 5.7.6.3 (2014/05/23)
196
197                // DBColumn の 整合性チェックを行うレベルを規定します。
198                String CHECK_LEVEL = HybsSystem.sys( "DB_OFFICIAL_COLUMN_CHECK_LEVEL" );
199                if( !official && CHECK_LEVEL != null && CHECK_LEVEL.length() > 0 ) {
200                        checkLevel = Integer.parseInt( CHECK_LEVEL );
201                }
202                else {
203                        checkLevel = -1;
204                }
205
206                String def = config.getDefault();
207                if( def != null ) { defValue = def; }
208                else {              defValue = dbType.getDefault() ; }
209
210                // 5.6.6.0 (2013/07/05) codeKeyVal 属性を使用した、Selection_KEYVAL オブジェクトの作成
211                // 優先順位は、codeData オブジェクトで、codeKeyVal を利用したSelectionは、DBColumnConfig からのみ作成可能
212                if( codeData != null ) {
213                        // 5.7.3.0 (2014/02/07) SelectionFactory 対応
214                        selection = SelectionFactory.newSelection( "MENU",codeData );
215                }
216                else {
217                        String codeKeyVal = config.getCodeKeyVal();
218                        if( codeKeyVal != null ) {
219                                // 5.7.3.0 (2014/02/07) SelectionFactory 対応
220                                selection = SelectionFactory.newSelection( "KEYVAL", codeKeyVal );
221                        }
222                        else {
223                                selection = null;
224                        }
225                }
226
227                cellRenderer = DBCellFactory.newRenderer( columnData.getRenderer(),this );
228                cellEditor   = DBCellFactory.newEditor( columnData.getEditor(),this );
229        }
230
231        /**
232         * 言語を返します。
233         *
234         * @return  言語
235         */
236        public String getLang() {
237                return lang;
238        }
239
240        /**
241         * カラム名を返します。
242         *
243         * @return  カラム名
244         */
245        public String getName() {
246                return columnData.getName();
247        }
248
249        /**
250         * カラムのラベル名を返します。
251         *
252         * @return  カラムのラベル名
253         */
254        public String getLabel() {
255                return labelData.getLabel();
256        }
257
258        /**
259         * カラムのラベル名を返します。
260         *
261         * @return  カラムのラベル名(名前(短))
262         */
263        public String getShortLabel() {
264                return labelData.getShortLabel();
265        }
266
267        /**
268         * カラムのラベル名を返します。
269         *
270         * @return  カラムのラベル名(名前(長))
271         */
272        public String getLongLabel() {
273                return labelData.getLongLabel();
274        }
275
276        /**
277         * カラムのクラスを文字列にした名称を返します。
278         * これは,HTML上の各種タグに,データベース定義に応じたクラス名を
279         * 表します。(VARCHAR2、NUMBER など)
280         *
281         * これは、カラムのデータタイプ(X,S9など)と機能的に重複しますが、
282         * そのカラムが、大まかな分類で、文字列であるか、数字であるかを示します。
283         *
284         * 画面表示上の右寄せ、左寄せや、IMEのON/OFFなどの CSSファイルの指定は、
285         * カラムのデータタイプ(X,S9など)ですが、テーブルソート時のソート条件
286         * は、この クラス文字列(VARCHAR2、NUMBER)を参照します。
287         *
288         * @return  カラムのクラスを文字列にした名称(VARCHAR2、NUMBER など)
289         */
290        public String getClassName() {
291                return columnData.getClassName();
292        }
293
294        /**
295         * フィールドのデータ長を返します。
296         * 通常は、整数型の文字列とデータ長は同じですが,小数点を表すデータ長は
297         * x,y 形式の場合、x + 2 桁で表されます。(マイナス記号と小数点記号)
298         * 7,3 は、 xxxx,yyy のフォーマットで、データ長は、9 になります。
299         *
300         * @og.rev 2.1.1.2 (2002/11/21) 最大桁数入力時の桁数チェックの間違いを訂正。
301         * @og.rev 4.0.0.0 (2005/01/31) メソッド名変更 getMaxlength() → getTotalSize()
302         *
303         * @return  データ長定義文字列
304         */
305        public int getTotalSize() {
306                return columnData.getTotalSize();
307        }
308
309        /**
310         * フィールドの使用桁数を返します。
311         * 少数指定の場合は、"7,3" のようなカンマで整数部、小数部を区切った書式になります。
312         * 7,3 は、 xxxx,yyy のフォーマットで、整数部4桁、小数部3桁を意味します。
313         *
314         * @return  使用桁数
315         */
316        public String getMaxlength() {
317                return columnData.getMaxlength();
318        }
319
320        /**
321         * フィールドの整数部のデータ長を返します。
322         * 通常は、整数型の文字列とデータ長は同じですが,小数点を表すデータ長は
323         * x,y 形式の場合、x - y 桁で表されます。(マイナス記号含まず)
324         * 7,3 は、 xxxx,yyy のフォーマットで、データ長は、4 になります。
325         *
326         * @return  データ長定義文字列
327         */
328        public int getSizeX() {
329                return columnData.getSizeX() ;
330        }
331
332        /**
333         * フィールドの小数部のデータ長を返します。
334         * 通常は、整数型の文字列では、0 になりますが,小数点を表すデータ長は
335         * x,y 形式の場合、y 桁で表されます。
336         * 7,3 は、 xxxx,yyy のフォーマットで、データ長は、3 になります。
337         *
338         * @return  データ長定義文字列
339         */
340        public int getSizeY() {
341                return columnData.getSizeY() ;
342        }
343
344        /**
345         * カラムの表示桁数を返します。
346         * viewLength は、設定した場合のみ、使用できます。通常は、null が返ります。
347         *
348         * @og.rev 3.5.5.5 (2004/04/23) 新規追加
349         * @og.rev 4.0.0.0 (2005/01/31) メソッド名変更 getSize() → getViewLength()
350         *
351         * @return      カラムの文字桁数
352         */
353        public String getViewLength() {
354                return columnData.getViewLength();
355        }
356
357        /**
358         * カラムが書き込み可能かどうかを返します。
359         *
360         * @return  カラムが書き込み可能かどうか
361         */
362        public boolean isWritable() {
363                return writable;
364        }
365
366        /**
367         * データの値そのものではなく、その値のラベル文字を返します。
368         *
369         * @og.rev 3.5.5.4 (2004/04/15) value が null の場合は、""(ゼロストリング)にする。
370         *
371         * @param   value       入力値
372         *
373         * @return  データ表示用の文字列
374         */
375        public String getRendererValue( final String value ) {
376                return cellRenderer.getValue( (value != null ) ? value : "" );
377        }
378
379        /**
380         * データ表示用のHTML文字列を作成します。
381         * 行番号毎に異なる値を返すことの出来る DBCellRenderer を使用することが出来ます。
382         *
383         * @og.rev 3.5.5.7 (2004/05/10) 行番号に無関係に、値を返すように変更します。
384         * @og.rev 4.0.0.0 (2005/11/30) 行番号に対応した値を返すように変更します。
385         *
386         * @param   row         行番号
387         * @param   value       入力値
388         *
389         * @return  データ編集用の文字列
390         */
391        public String getRendererValue( final int row,final String value ) {
392                return cellRenderer.getValue( row,(value != null ) ? value : "" );
393        }
394
395        /**
396         * データ編集用のHTML文字列を作成します。
397         *
398         * @og.rev 3.5.5.4 (2004/04/15) value が null の場合は、""(ゼロストリング)にする。
399         *
400         * @param   value       入力値
401         *
402         * @return  データ編集用の文字列
403         */
404        public String getEditorValue( final String value ) {
405                return cellEditor.getValue( (value != null ) ? value : "" );
406        }
407
408        /**
409         * データ編集用のHTML文字列を作成します。
410         * 行番号付の編集データを作成します。名前_行番号 で登録する為、
411         * リクエスト情報を1つ毎のフィールドで処理できます。
412         *
413         * @param   row         行番号
414         * @param   value       入力値
415         *
416         * @return  データ編集用の文字列
417         */
418        public String getEditorValue( final int row,final String value ) {
419                return cellEditor.getValue( row,(value != null ) ? value : "" );
420        }
421
422        /**
423         * データ出力用の固定長文字列を作成します。
424         * HOST送信用桁数がセットされていれば、そちらを優先します。
425         *
426         * @og.rev 3.5.4.5 (2004/01/23) エンコード指定に変更します。
427         *
428         * @param   value       対象の値
429         * @param   encode      固定長で変換する文字エンコード
430         *
431         * @return  データ編集用の文字列
432         */
433        public String getWriterValue( final String value,final String encode ) {
434                return dbType.valueFill( value ,columnData.getSizeX(), columnData.getSizeY(), encode );
435        }
436
437        /**
438         * データの表示用レンデラーを返します。
439         *
440         * @og.rev 3.8.0.2 (2005/07/11) 新規追加
441         *
442         * @return      データの表示用レンデラー
443         */
444        public String getRenderer() {
445                return columnData.getRenderer() ;
446        }
447
448        /**
449         * データの編集用エディターを返します。
450         *
451         * @og.rev 3.8.0.2 (2005/07/11) 新規追加
452         *
453         * @return      データの編集用エディター
454         */
455        public String getEditor() {
456                return columnData.getEditor() ;
457        }
458
459        /**
460         * 文字種別名を返します。
461         * カラムの文字種別名名称を返します。
462         * これは,HTML上の各種タグに,データベース定義に応じたクラスを
463         * セットし,CSS(Cascading Style Sheet)の class="xxxxx" とする事により
464         * 各種スタイルを表現するのに使用します。
465         *
466         * ここでは, カラムリソースの DBTYPE 属性で指定の文字列(X,S9,KXなど)を返します。
467         *
468         * @return  データの文字種別(X,KX,S9 など)
469         */
470        public String getDbType() {
471                return columnData.getDbType() ;
472        }
473
474        /**
475         * データのNATIVEの型の識別コードを返します。
476         *
477         * @og.rev 4.1.1.2 (2008/02/28) Enum型(fukurou.model.NativeType)に変更
478         *
479         * @return  NATIVEの型の識別コード(DBType で規定)
480         * @see org.opengion.fukurou.model.NativeType
481         */
482        public NativeType getNativeType() {
483                return dbType.getNativeType();
484        }
485
486        /**
487         * そのカラムの,デフォルト値の値を返します。
488         *
489         * カラムリソースに デフォルト情報が登録されている場合は,その値を返します。
490         * デフォルト値が設定されていない場合は, null を返します。
491         *
492         * @return  デフォルト値(無ければ null)
493         */
494        public String getDefault() {
495                return defValue;
496        }
497
498        /**
499         * 表示用レンデラーのパラメータを取得します。
500         *
501         * @og.rev 3.4.0.0 (2003/09/01) 新規追加
502         *
503         * @return      表示用レンデラーのパラメータ
504         */
505        public String getRendererParam() {
506                return columnData.getRendererParam();
507        }
508
509        /**
510         * 編集用エディターのパラメータを取得します。
511         *
512         * @og.rev 3.4.0.0 (2003/09/01) 新規追加
513         *
514         * @return      編集用エディターのパラメータ
515         */
516        public String getEditorParam() {
517                return columnData.getEditorParam();
518        }
519
520        /**
521         * データタイプのパラメータを取得します。
522         *
523         * @og.rev 3.4.0.0 (2003/09/01) 新規追加
524         *
525         * @return      データタイプのパラメータ
526         */
527        public String getDbTypeParam() {
528                return columnData.getDbTypeParam();
529        }
530
531        /**
532         * カラムロールを取得します。
533         *
534         * @og.rev 4.0.0.0 (2005/11/30) 新規追加
535         *
536         * @return      カラムロール
537         */
538        public String getRoles() {
539                return columnData.getRoles();
540        }
541
542        /**
543         * カラムオブジェクトのロールモードを返します。
544         *
545         * @og.rev 4.3.0.0 (2008/07/04) ロールモードマルチ対応
546         *
547         * @return カラムオブジェクトのロールモード
548         */
549        public RoleMode getRoleMode() {
550                return columnData.getRoleMode();
551        }
552
553        /**
554         * 接続先IDを返します。
555         *
556         * @return  接続先ID
557         */
558        public String getDbid() {
559                return dbid;
560        }
561
562        /**
563         * String引数の文字列を+1した文字列を返します。
564         * これは、英字の場合(A,B,C など)は、B,C,D のように,最終桁の文字コードを
565         * +1 します。
566         * 文字列が数字タイプの場合は, 数字に変換して、+1 します。(桁上がりもあり)
567         * 混在タイプの場合は,最後の桁だけを確認して +1します。
568         * 引数が null の場合と、ゼロ文字列("")の場合は,引数を,そのまま返します。
569         *
570         * ※ 機能拡張:第2引数に指定の文字列(数字、日付等)を指定する事で、
571         *    引数の文字列に、任意の値を加算できるようにします。
572         *    ただし、すべての DBTypeではなく、ある程度特定します。
573         *    対象外の DBTypeで、第2引数が null 出ない場合は、Exception を Throwsします。
574         *    第2引数が、null の場合は、従来と同じ+1します。
575         *
576         * @og.rev 5.6.0.3 (2012/01/24) ADD に、引数の値を加算する機能を追加します。
577         *
578         * @param   value  引数の文字列
579         * @param   add    加算する文字列(null の場合は、従来と同じ、+1 します。)
580         *
581         * @return  引数の文字列を+1した文字列。または、任意の値を加算した文字列。
582         */
583        public String valueAdd( final String value,final String add ) {
584                // DBType の実装の関係で、旧メソッドは残しておきます。
585                if( add == null || add.isEmpty()  ) {
586                        return dbType.valueAdd( value );
587                }
588                else {
589                        return dbType.valueAdd( value , add );
590                }
591        }
592
593        /**
594         * データが登録可能かどうかをチェックします。
595         * データがエラーの場合は、そのエラー内容を返します。
596         *
597         * @og.rev 3.6.0.0 (2004/09/22) dbType パラメータを引数に追加
598         * @og.rev 3.6.0.7 (2004/11/06) official属性がfalseの場合、チェックレベルに対応したチェックを行う。
599         * @og.rev 3.8.0.8 (2005/10/03) 企画改善 61200-050921-02 ラベルからHTMLタグを削除する。
600         * @og.rev 5.2.2.0 (2010/11/01) 内部処理を、#valueCheck( value , true ) に委譲。
601         *
602         * @param   value       チェック対象の値
603         *
604         * @return  エラー内容  正常時は null
605         * @see         #valueCheck( String , boolean )
606         */
607        public ErrorMessage valueCheck( final String value ) {
608                return valueCheck( value , true );
609        }
610
611        /**
612         * データが登録可能かどうかをチェックします。
613         * データがエラーの場合は、そのエラー内容を返します。
614         *
615         * @og.rev 3.6.0.0 (2004/09/22) dbType パラメータを引数に追加
616         * @og.rev 3.6.0.7 (2004/11/06) official属性がfalseの場合、チェックレベルに対応したチェックを行う。
617         * @og.rev 3.8.0.8 (2005/10/03) 企画改善 61200-050921-02 ラベルからHTMLタグを削除する。
618         * @og.rev 5.2.2.0 (2010/11/01) 厳密にチェック(isStrict=true)するフラグを追加
619         *
620         * @param   value               チェック対象の値
621         * @param   isStrict    厳密にチェック(isStrict=true)するかどうか
622         *
623         * @return  エラー内容  正常時は null
624         */
625        public ErrorMessage valueCheck( final String value , final boolean isStrict ) {
626
627                // 3.8.0.8 (2005/10/03) ラベルからHTMLタグを削除する。
628                String lbl = labelData.getLabel() ;
629                if( lbl.indexOf( '<' ) >= 0 ) {
630                        lbl = lbl.replaceAll( "<[^>]*>","" );
631                }
632
633                // 5.2.2.0 (2010/11/01) 厳密にチェック(isStrict=true)するフラグを追加
634                ErrorMessage errMsg = dbType.valueCheck( lbl,value,columnData.getSizeX(), columnData.getSizeY(),columnData.getDbTypeParam() , isStrict );
635                if( checkLevel >= 0 ) {
636                        // ERR0034:指定のカラムオブジェクトには、カラムリソースが存在しません。name={0} label={1}
637                        errMsg.addMessage( 0,checkLevel,"ERR0034", columnData.getName(),labelData.getLabel() );
638                }
639                return errMsg ;
640        }
641
642        /**
643         * エディターで編集されたデータを登録する場合に、データそのものを
644         * 変換して、実登録データを作成します。
645         * 例えば,大文字のみのフィールドなら、大文字化します。
646         * 実登録データの作成は、DBType オブジェクトを利用しますので,
647         * これと DBCellEditor とがアンマッチの場合は、うまくデータ変換
648         * されない可能性がありますので、注意願います。
649         *
650         * @param   value 一般に編集データとして登録されたデータ
651         *
652         * @return  修正後の文字列(一般にデータベースに登録するデータ)
653         */
654        public String valueSet( final String value ) {
655                return dbType.valueSet( value );
656        }
657
658        /**
659         * action で指定されたコマンドを実行して、値の変換を行います。
660         * oldValue(旧データ)は、元のDBTableModelに設定されていた値です。通常は、
661         * この値を使用してカラム毎に変換を行います。newValue(新データ)は、引数で
662         * 指定された新しい値です。この値には、パラメータを指定して変換方法を
663         * 制御することも可能です。
664         * 指定のアクションがカラムで処理できない場合は、エラーになります。
665         *
666         * @param   action アクションコマンド
667         * @param   oldValue 入力データ(旧データ)
668         * @param   newValue 入力データ(新データ)
669         *
670         * @return      実行後のデータ
671         */
672        public String valueAction( final String action,final String oldValue,final String newValue ) {
673                return dbType.valueAction( action,oldValue,newValue );
674        }
675
676        /**
677         * 内部の設定情報オブジェクトを返します。
678         * このオブジェクトを ローカルで書き換えて、DBColumn を作るようにします。
679         *
680         * @og.rev 3.1.0.0 (2003/03/20) DBColumnConfig 関係の見直し。
681         * @og.rev 3.4.0.0 (2003/09/01) 表示パラメータ、編集パラメータ、文字パラメータの追加。
682         * @og.rev 3.5.5.5 (2004/04/23) size 属性の意味を変更、maxlength 属性を追加。
683         * @og.rev 3.5.5.8 (2004/05/20) codeName 属性を追加。
684         * @og.rev 3.6.0.7 (2004/11/06) カラムリソースから作成されたかどうか(official属性追加)
685         * @og.rev 5.1.8.0 (2010/07/01) すべての属性を設定するようにします。
686         * @og.rev 5.5.1.0 (2012/04/03) useSLabel対応
687         * @og.rev 5.6.2.3 (2013/03/22) 非表示文字の設定。noDisplayVal追加
688         * @og.rev 5.7.6.3 (2014/05/23) stringOutput対応
689         *
690         * @return      設定情報オブジェクト
691         */
692        public DBColumnConfig getConfig() {
693                // 互換性確保のため、DBColumnConfig の コンストラクタは修正していません。
694
695                DBColumnConfig config =
696                        new DBColumnConfig(
697                                                lang                                                    ,
698                                                columnData.getName()                    ,
699                                                labelData                                               ,
700                                                columnData.getClassName()               ,
701                                                columnData.getMaxlength()               ,
702                                                String.valueOf( writable )              ,
703                                                columnData.getRenderer()                ,
704                                                columnData.getEditor()                  ,
705                                                codeData                                                ,
706                                                columnData.getDbType()                  ,
707                                                defValue                                                ,
708                                                columnData.getRendererParam()   ,
709                                                columnData.getEditorParam()             ,
710                                                columnData.getDbTypeParam()             ,
711                                                columnData.getRoles()                   ,               // 4.0.0 (2005/11/30)
712                                                official                                                ,               // 3.6.0.7 (2004/11/06)
713                                                dbid     ) ;
714                config.setViewLength( columnData.getViewLength() );
715
716                // 5.1.8.0 (2010/07/01) すべての属性を設定するようにします。
717                // コンストラクタは修正していないため、セッターメソッド経由で渡します。
718                config.setRendererAttributes( rendAttri );
719                config.setEditorAttributes( editAttri );
720                config.setAddNoValue( addNoValue );
721                config.setEventColumn( eventColumn );
722                config.setRawEditParameter( rawEditParameter );
723                config.setRawRendParameter( rawRendParameter );
724                config.setEventURL( eventURL );
725
726                config.setUseSLabel( useSLabel );                       // 5.5.1.0 (2012/04/03)
727                config.setNoDisplayVal( noDisplayVal );         // 5.6.2.3 (2013/03/22) 非表示文字の設定
728
729                config.setStringOutput( stringOutput );         // 5.7.6.3 (2014/05/23) 
730
731                return config ;
732        }
733
734        /**
735         * 表示用レンデラーの追加属性を返します。
736         *
737         * @og.rev 3.1.0.0 (2003/03/20) DBColumnConfig オブジェクトの内部キープを廃止
738         *
739         * @return   属性リスト
740         */
741        public Attributes getRendererAttributes() {
742                return rendAttri ;
743        }
744
745        /**
746         * 編集用エディター用の追加属性を返します。
747         *
748         * @og.rev 3.1.0.0 (2003/03/20) DBColumnConfig オブジェクトの内部キープを廃止
749         *
750         * @return   属性リスト
751         */
752        public Attributes getEditorAttributes() {
753                return editAttri ;
754        }
755
756        /**
757         * メニューに空の選択リストを追加するかどうかを取得します。
758         *
759         * @og.rev 3.5.5.7 (2004/05/10) 新規追加
760         *
761         * @return      空の選択リストを追加するかどうか(true:追加する/false:追加しない)
762         */
763        public boolean isAddNoValue() {
764                return addNoValue ;
765        }
766
767        /**
768         * このカラムオブジェクトがカラムリソースより正式に作られたかどうかを取得します。
769         * カラムリソースが無い場合は、仮オブジェクトかデータベースメタデータより作成されます。
770         * その場合は、チェック機能が緩くなるため、正式なカラムオブジェクトと区別する為に
771         * この属性を持ちます。
772         *
773         * @og.rev 3.6.0.7 (2004/11/06) 新規追加
774         *
775         * @return      正式に作られたかどうか(true:正式/false:暫定)
776         */
777        public boolean isOfficial() {
778                return official ;
779        }
780
781        /**
782         * カラムのラベルデータオブジェクトを返します。
783         *
784         * @return  カラムのラベルデータオブジェクト
785         */
786        public LabelData getLabelData() {
787                return labelData;
788        }
789
790        /**
791         * カラムのコードデータオブジェクトを返します。
792         * コードデータが存在しない場合は、null を返します。
793         * 受け取り側で、null かどうか判定してから使用してください。
794         *
795         * @og.rev 5.2.1.0 (2010/10/01) codeData が null でも、そのまま返します。
796         *
797         * @return  カラムのコードデータオブジェクト
798         */
799        public CodeData getCodeData() {
800                return codeData;
801        }
802
803        /**
804         * 最大入力サイズ(maxlength)より、実際のフィールドのサイズを求めます。
805         *
806         * maxlength : colums_maxsize ~  ⇒ size="maxlength"  変換しません。
807         *
808         * ただし、maxlength が、colums_maxsize を超える場合は、colums_maxsize とします。
809         *
810         * @og.rev 4.0.0.0 (2005/01/31) getFieldSize メソッドを XHTMLTag から DBColumn へ移動
811         * @og.rev 4.0.0.0 (2007/02/05) ADJUSTMENT 処理を廃止します。(CSSにて対応)
812         *
813         * @param maxlength       実際の最大桁数
814         * @param colums_maxsize 表示上の最大桁数。
815         *
816         * @return 表示すべきサイズ
817         * @see #getFieldSize( int )
818         */
819        public int getFieldSize( final int maxlength,final int colums_maxsize ) {
820                int size = maxlength;
821
822                if( size <= 0 || size > colums_maxsize ) {
823                        size = colums_maxsize;
824                }
825
826                return size;
827        }
828
829        /**
830         * 最大入力サイズ(maxlength)より、実際のフィールドのサイズを求めます。
831         *
832         * maxlength : colums_maxsize ~  ⇒ size="maxlength"  変換しません。
833         *
834         * ただし、maxlength が、COLUMNS_MAXSIZE を超える場合は、COLUMNS_MAXSIZE とします。
835         *
836         * @og.rev 4.0.0.0 (2005/01/31) getFieldSize メソッドを XHTMLTag から DBColumn へ移動
837         * @og.rev 4.0.0.0 (2007/02/05) ADJUSTMENT 処理を廃止します。(CSSにて対応)
838         *
839         * @param maxlength       実際の最大桁数
840         *
841         * @return 表示すべきサイズ
842         * @see #getFieldSize( int ,int )
843         */
844        public int getFieldSize( final int maxlength ) {
845                return getFieldSize( maxlength,COLUMNS_MAXSIZE );
846        }
847
848        /**
849         * コードリソースSelectionオブジェクトを返します。
850         *
851         * @og.rev 4.0.0.0 (2007/11/02) 新規追加
852         * @og.rev 5.7.3.0 (2014/02/07) null 対応(コードリソースの設定不良等)
853         * @og.rev 5.7.7.1 (2014/06/13) XXXMENU の editor は、警告を出さない。
854         *
855         * @return コードSelectionオブジェクト
856         */
857        public Selection getSelection() {
858        // 5.6.1.1 (2013/02/08) 暫定処置。とりあえずエラーは発生させない。
859        //      if( selection == null ) {
860        //              String errMsg = "コードリソースが定義されていません。" + HybsSystem.CR
861        //                                      + "name=[" + getName() + "],label=[" + getLabel() + "]" ;       // 5.1.8.0 (2010/07/01) errMsg 修正
862        //              throw new HybsSystemException( errMsg );
863        //      }
864
865                // 5.7.3.0 (2014/02/07) null 対応(コードリソースの設定不良等)
866                if( selection == null ) {
867                        // 5.7.7.1 (2014/06/13) XXXMENU の editor は、警告を出さない。
868                        String editor = getEditor();
869                        if( editor != null && editor.contains( "MENU" ) ) {
870                                return null;
871                        }
872                        else {
873                                String errMsg = "clm=[" + getName() + "],label=[" + getLabel() + "]のコードリソースが定義されていません。" ;
874                                System.err.println( "警告:" + errMsg );
875                                return SelectionFactory.newSelection( "NULL",errMsg );
876                        }
877                }
878
879                return selection ;
880        }
881
882        /**
883         * イベントカラム(親カラム)
884         *
885         * @og.rev 4.3.6.0 (2009/04/01)
886         *
887         * @return イベントカラム
888         */
889        public String getEventColumn() {
890                return eventColumn ;
891        }
892
893        /**
894         * {&#064;XXXX}を変換していない状態の編集パラメータを返します。
895         *
896         * @og.rev 4.3.6.0 (2009/04/01)
897         *
898         * @return 生編集パラメータ
899         */
900        public String getRawEditParam() {
901                return rawEditParameter ;
902        }
903
904        /**
905         * {&#064;XXXX}を変換していない状態の編集パラメータを返します。
906         *
907         * @og.rev 5.1.7.0 (2010/06/01) 動的プルダウン実装見直し
908         *
909         * @return 生表示パラメータ
910         */
911        public String getRawRendParam() {
912                return rawRendParameter ;
913        }
914
915        /**
916         * eventColumn利用時にJSで利用するURL
917         *
918         * @og.rev 4.3.6.0 (2009/04/01)
919         *
920         * @return イベントURL
921         */
922        public String getEventURL() {
923                return eventURL ;
924        }
925
926        /**
927         * 引数のタグ文字列に対して、イベントカラムの実行に必要なspanタグを付加した
928         * 文字列を返します。
929         *
930         * @param tag タグ文字列
931         * @param initVal 子カラムの初期値
932         * @param writable タグの要素が書き込み可能かどうか
933         *
934         * @return spanタグを付加したタグ文字列
935         */
936        public String getEventColumnTag( final String tag, final String initVal, final boolean writable ) {
937                return getEventColumnTag( tag, initVal, -1, writable );
938        }
939
940        /**
941         * 引数のタグ文字列に対して、イベントカラムの実行に必要なspanタグを付加した
942         * 文字列を返します。
943         *
944         * @param tag タグ文字列
945         * @param initVal 子カラムの初期値
946         * @param row 行番号
947         * @param writable タグの要素が書き込み可能かどうか
948         *
949         * @return spanタグを付加したタグ文字列
950         */
951        public String getEventColumnTag( final String tag, final String initVal, final int row, final boolean writable ) {
952                TagBuffer span = new TagBuffer( "span" );
953                span.add( "class", HybsSystem.EVENT_COLUMN_CLASS );
954                span.add( HybsSystem.EVENT_COLUMN_ID,  columnData.getName() + ( row < 0 ? "" : HybsSystem.JOINT_STRING + row ) );
955                span.add( HybsSystem.EVENT_COLUMN_INITVAL, initVal );
956                span.add( HybsSystem.EVENT_COLUMN_WRITABLE, String.valueOf( writable ) );
957                span.setBody( tag );
958                return span.makeTag();
959        }
960
961        /**
962         * セットされている表示パラメータ、編集パラメータに"{&#064;XXXX}"が含まれているか(パラメーターのパースが必要か)を
963         * 返します。
964         *
965         * @og.rev 6.0.0.1 (2014/04/25) 内部処理変更
966         *
967         * @return "{&#064;XXXX}"が含まれているか(含まれている場合true)
968         */
969        public boolean isNeedsParamParse() {
970                return  ( rawRendParameter != null && rawRendParameter.indexOf( "{@" ) >= 0 )
971                        ||      ( rawEditParameter != null && rawEditParameter.indexOf( "{@" ) >= 0 );
972        }
973
974        /**
975         * ラベル短ベースのメニューにするかどうか
976         *
977         * @og.rev 5.5.1.0 (2012/04/03)
978         *
979         * @return イベントカラム
980         */
981        public String getUseSLabel() {
982                return useSLabel ;
983        }
984
985        /**
986         * 非表示文字列を返します。
987         *
988         * これは、例えば、数字型の場合は、0 がデフォルトなどの場合、
989         * あえて表示したくないなどのケースに使います。
990         * そのような状況が設定されていない場合は、null が返されます。
991         *
992         * @og.rev 5.6.2.3 (2013/03/22) 新規追加
993         *
994         * @return 非表示文字
995         */
996        public String getNoDisplayVal() {
997                return noDisplayVal ;
998        }
999
1000        /**
1001         * レンデラー利用ファイル出力時に数値等も文字タイプに固定するかどうか(初期値:true)
1002         *
1003         * Excel出力時に利用されます。
1004         * 通常はtrue(文字タイプ固定)です。
1005         * このフラグをfalseにする事でdbTypeに従った出力になります。
1006         *
1007         * @og.rev 5.7.6.3 (2014/05/23) 新規追加
1008         *
1009         * @return renderer利用ファイル出力時のString出力フラグ(true:String出力/false:dbType次第)
1010         */
1011        public boolean isStringOutput() {
1012                return stringOutput ;
1013        }
1014}