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
018/**
019 * データのコード情報を取り扱うSelectionクラスの、NULL時オブジェクトです。
020 *
021 * 以前は、Selection オブジェクトが null の場合に、NullPointerException で
022 * いきなりエラーで停止していましたが、この、NULLセレクションを作成することで、
023 * 取りあえず、どういう状況なのか、判るようにします。
024 *
025 * @og.rev 5.7.3.0 (2014/02/07) 新規追加
026 * @og.rev 5.7.7.1 (2014/06/13) Selectionオブジェクトの基本実装とします。
027 * @og.group 選択データ制御
028 *
029 * @version  4.0
030 * @author   Kazuhiko Hasegawa
031 * @since    JDK5.0,
032 */
033public class Selection_NULL implements Selection {
034        private final String    initMsg ;
035
036        /**
037         * デフォルトコンストラクター
038         * 継承元のクラスから、呼び出させるように、作成しておきます。
039         *
040         * @og.rev 5.7.7.1 (2014/06/13) 新規追加
041         */
042        public Selection_NULL() { initMsg = null; }
043
044        /**
045         * 引数に初期メッセージを指定して作成する、コンストラクター
046         *
047         * @og.rev 5.7.3.0 (2014/02/07) 新規追加
048         * @og.rev 6.2.6.0 (2015/06/19) type別Selectionの場合、ラベルリソースを使用する為、言語を引数で渡す。
049         * @og.rev 6.3.4.0 (2015/08/01) Selection_NULL の引数から、lang 属性を削除します。
050         *
051         * @param       strCode 初期メッセージ文字列
052         */
053        public Selection_NULL( final String strCode ) {
054                initMsg = strCode ;
055        }
056
057        /**
058         * 初期値が選択済みの 選択肢(オプション)を返します。
059         * 無条件で、初期メッセージを返します。
060         *
061         * @og.rev 5.7.3.0 (2014/02/07) 新規追加
062         *
063         * @param   selectValue  選択されている値
064         * @param   seqFlag  シーケンスアクセス機能 [true:ON/false:OFF]
065         * @param   useShortLabel ラベル(短)をベースとしたオプション表示を行うかどうか(常にfalse)。
066         *
067         * @return  オプションタグ
068         * @og.rtnNotNull
069         * @og.rtnNotNull
070         */
071        @Override
072        public String getOption( final String selectValue,final boolean seqFlag, final boolean useShortLabel ) {
073                return initMsg + " value=[" + selectValue + "]";
074        }
075
076        /**
077         * 初期値が選択済みの 選択肢(オプション)を返します。
078         * このオプションは、引数の値を初期値とするオプションタグを返します。
079         * ※ このクラスでは実装されていません。→ 実装を入れます。
080         *
081         * @og.rev 6.0.4.0 (2014/11/28) 実装を入れます。
082         * @og.rev 6.2.2.4 (2015/04/24) メソッド変更。旧 #getRadio( String , String , boolean )
083         *
084         * @param   name         ラジオの name
085         * @param   selectValue  選択されている値
086         * @param   useLabel     ラベル表示の有無 [true:有/false:無]
087         *
088         * @return  オプションタグ
089         * @og.rtnNotNull
090         */
091        @Override
092        public String getOption( final String name,final String selectValue,final boolean useLabel ) {
093                return initMsg + " name=[" + name + "] value=[" + selectValue + "]";
094        }
095
096        /**
097         * 選択肢(value)に対するラベルを返します。
098         * 選択肢(value)が、存在しなかった場合は、選択肢そのものを返します。
099         * getValueLabel( XX ) は、getValueLabel( XX,false ) と同じです。
100         *
101         * @param   selectValue 選択肢の値
102         *
103         * @return  選択肢のラベル
104         * @see     #getValueLabel( String,boolean )
105         */
106        @Override
107        public String getValueLabel( final String selectValue ) {
108                return getValueLabel( selectValue,false );
109        }
110
111        /**
112         * 選択肢(value)に対するラベルを返します。
113         * 無条件で、初期メッセージを返します。
114         *
115         * @og.rev 5.7.3.0 (2014/02/07) 新規追加
116         *
117         * @param       selectValue     選択肢の値
118         * @param       isSLbl  短縮ラベルを [true:使用する/false:しない](常に false)
119         *
120         * @return  選択肢のラベル
121         * @og.rtnNotNull
122         * @see     #getValueLabel( String )
123         */
124        @Override
125        public String getValueLabel( final String selectValue,final boolean isSLbl ) {
126                return initMsg + " value=[" + selectValue + "]";
127        }
128
129        /**
130         * オブジェクトのキャッシュが時間切れかどうかを返します。
131         * キャッシュが時間切れ(無効)であれば、true を、有効であれば、
132         * false を返します。
133         *
134         * ※ ここでは、常に false を返します。
135         *
136         * @return  キャッシュが時間切れなら true
137         */
138        @Override
139        public boolean isTimeOver() {
140                return false;
141        }
142
143        /**
144         * コードリソースのパラメータを適切な文字列に変換して返します。
145         * 通常であれば、そのままセットすればよいのですが、既存の処理が、
146         * class属性にセットするという仕様だったので、互換性を考慮した変換を行います。
147         * ここでは、
148         *   ① "=" を含む場合は、そのままセット
149         *   ② disabled 単体の場合は、disabled="disabled" をセット
150         *   ③ それ以外は、class= の後に、引数をセット
151         * します。
152         * 今後は、パラメータに、class="AAA" とセットすることで、徐々に
153         * この変換処理を無くしていきます。
154         *
155         * @og.rev 6.2.0.0 (2015/02/27) コードリソースのパラメータの指定方法を変更します。
156         *
157         * @param       buf                     変換結果を格納するStringBuilder
158         * @param       paramKey        変換処理の対象となるパラメータ
159         * @return  引数と同じ、StringBuilder
160         */
161        protected StringBuilder setCodeParam( final StringBuilder buf , final String paramKey ) {
162                if( paramKey != null && !paramKey.isEmpty() ) {
163                        if( paramKey.indexOf( '=' ) > 0 ) {                                                     // ①
164                                buf.append( ' ' ).append( paramKey );
165                        }
166                        else if( "disabled".equalsIgnoreCase( paramKey ) ) {            // ②
167                                buf.append( " disabled=\"" ).append( paramKey ).append( '"' );
168                        }
169                        else {                                                                                                          // ③
170                                buf.append( " class=\"" ).append( paramKey ).append( '"' );
171                        }
172                }
173                return buf ;
174        }
175}