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.resource;
017    
018    import java.text.MessageFormat;
019    
020    import org.opengion.hayabusa.common.HybsSystem ;
021    import org.opengion.fukurou.util.StringUtil ;
022    
023    /**
024     * systemId , lang に対応したラベル??タを作?します?
025     *
026     * ラベル??タは??目(CLM)に対して、各種ラベル??を持って?す?
027     * 従来のラベルは、表示名称として、?類しか持って?せんでしたが?
028     * ラベル??タは?種類?名称と?種類?概要を持って?す?
029     *
030     *   label       : 名称(長)      従来のラベルと同じで定義された文字そのも?です?
031     *   shortLabel  : 名称(HTML短)  概要説明をバルーン表示する短?称です?
032     *   longLabel   : 名称(HTML長)  概要説明をバルーン表示する長?称です?
033     *   description : 概要説?     カラ??説明やバルーンに使用します?
034     *
035     * 名称(HTML長)は、従来の表示名称にあたります?これは、??ラベルとして
036     * 使用されます?名称(HTML短)は、テーブル?のヘッ??の様に、特殊なケースで?
037     * 簡略化された名称を使用するときに利用されます?こ??替え?、?動で判断されます?
038     * 名称(HTML短)に、なにも設定されて???合?、名称(HTML長)が?動的に使用されます?で
039     * 初期??タ移行時には、そのまま??常時も??ブルヘッ??時も同じ???
040     * 使用されます?
041     * ただし??表示の?、EXCEL出力などの??タには、名称(長)が使用されます?
042     * これは、名称(HTML短)?称(HTML長)は、Tips表示を行う為のHTML構文を採用して?為
043     * ?スト等に出力するには不適?からです?また?EXCEL等???ルでは、ラベル名が
044     * 長くてもセル?で調整できる為、簡略化された名称よりも正式名称で出力します?
045     *
046     * ラベル??タを作?する場合?、同?ベルで、作?区?KBSAKU)違いの場合??
047     * ?大きな作?区?持つコードを使用します?
048     * 作?区?KBSAKU)は?:シス?予??1:アプリ設定?2:ユーザー設?と?具合に
049     * カスタマイズの度合いに応じて大きな数字を割り当てることで、キー??を上書き修正
050     * することが可能になります?(削除することは出来ません?
051     *
052     * @og.rev 4.0.0.0 (2004/12/31) 新規作?
053     * @og.group リソース管?
054     *
055     * @version  4.0
056     * @author   Kazuhiko Hasegawa
057     * @since    JDK5.0,
058     */
059    public final class LabelData implements LabelInterface {
060    
061            /** ???タのカラ?号 {@value}        */
062            public static final int CLM                     = 0 ;
063            /** ???タのカラ?号 {@value}        */
064            public static final int SNAME           = 1 ;
065            /** ???タのカラ?号 {@value}        */
066            public static final int LNAME           = 2 ;
067            /** ???タのカラ?号 {@value}        */
068            public static final int DESCRIPTION     = 3 ;
069            /** ???タのカラ? {@value}  */
070            public static final int DATA_SIZE       = 4 ;
071            /** リソース読み込みのために?利用 4.3.5.7 (2009/03/22) */
072            public static final int FG_LOAD         = 4 ;
073    
074            private final String    key                     ;               // ?
075            private final String    label           ;               // 名称(長)
076            private final String    shortLabel      ;               // 名称(HTML短)
077            private final String    longLabel       ;               // 名称(HTML長)
078            private final String    description     ;               // 概要説?
079            private final boolean   official        ;               // リソース??から作?されたかど?
080            private final boolean   isFormat        ;               // メ?ージフォーマット対象かど? 4.0.0.0 (2007/10/17)
081            private final String    rawShortLabel;          // 名称(未変換短) 4.3.8.0 (2009/08/01)
082            private final boolean   isFormatDesc;           // 概要がフォーマット対象?4.3.7.6 (2009/07/15)
083    
084            /**
085             * null LabelData オブジェクトを作?します?
086             * こ?オブジェクト???リソース上に存在しな??合に使用され?
087             * null ??を表す?LabelData オブジェクトです?
088             *
089             * @param       inkey   キー??
090             */
091            LabelData( final String inkey ) {
092                    key                     = inkey.intern() ;
093                    label           = key ;         // 名称(長)
094                    shortLabel      = key ;         // 名称(HTML短)
095                    longLabel       = key ;         // 名称(HTML長)
096                    description     = ""  ;         // 概要説?
097                    official        = false;        // 非正?
098                    isFormat        = false;        // 非フォーマッ?4.0.0.0 (2007/10/17)
099                    rawShortLabel = key;    // 名称(未変換短) 4.3.8.0 (2009/08/01)
100                    isFormatDesc = false;   // 概要フォーマッ?4.3.7.6 (2009/07/15)
101            }
102    
103            /**
104             * 配???の??タを?に、LabelDataオブジェクトを構築します?
105             * こ?コンストラクタは、他?パッケージから呼び出せな???
106             * パッケージプライベ?トにしておきます?
107             * こ?コンストラクタは??リソースファイルを想定して?す?
108             *
109             * @og.rev 5.4.0.1 (2011/11/01) SNAME、概要説明?rawShortLabel 関係?処?修正
110             *
111             * @param       data    CLM,SNAME,LNAME,DESCRIPTION
112             */
113            LabelData( final String[] data ) {
114                    key                     = data[CLM].intern() ;                                                  // ?
115                    label           = StringUtil.nval2( data[LNAME],"" ) ;                  // 名称(HTML長)
116                    description     = data[DESCRIPTION] ;                                                   // 概要説?
117                    official        = true;                                                                                 // 正?
118                    isFormat = ( label.indexOf( '{' ) >= 0 ) ;                   // 4.0.0.0 (2007/10/17)
119    //              isFormatDesc = ( description.indexOf( '{' ) >= 0 ); // 4.3.7.6 (2009/07/15)
120                    String title = null;
121    
122                    if( description == null || description.length() == 0 ) {
123                            isFormatDesc = false;
124                            // 5.4.0.1 (2011/11/01) title と label が間違って??SNAME が存在する場?
125    //                      title     = StringUtil.htmlFilter( title ) ;
126                            title     = StringUtil.htmlFilter( label ) ;
127    
128                            // 概要説明がな??合?、そのままラベルを使用する?
129                            longLabel = label;
130                    }
131                    else {
132                            isFormatDesc = ( description.indexOf( '{' ) >= 0 );          // 5.1.8.0 (2010/07/01) nullポインタの参?外し対?
133                            title        = StringUtil.htmlFilter( description ) ;
134    
135                            // 概要説明がある場合?、ツールチップにDESCRIPTIONを表示する?
136                            longLabel = "<span title=\""
137    //                                                      + StringUtil.htmlFilter( description )
138                                                            + title
139                                                            + "\">"
140                                                            + label
141                                                            + "</span>" ;
142                    }
143    
144                    String sname = data[SNAME];             // 名称(HTML短)
145                    if( sname == null || sname.length() == 0 ) {
146                            // SNAME がな??合?、longLabel を使用する?
147                            shortLabel    = longLabel;
148    //                      rawShortLabel = longLabel;      // 4.3.8.0 (2009/08/01)
149                            rawShortLabel = label;          // 5.4.0.1 (2011/11/01) longLabel を使?、ツールチップが?されるため?
150                    }
151                    else {
152                            // SNAME が存在する場合???ルチップにdescriptionかlabelを使用する?
153    //                      String title = ( description == null || description.length() == 0 ) ? label : description ;
154                            shortLabel = "<span title=\""
155    //                                                      + StringUtil.htmlFilter( title )
156                                                            + title
157                                                            + "\">"
158                                                            + sname
159                                                            + "</span>" ;
160                            rawShortLabel = sname; // 4.3.8.0 (2009/08/01)
161                    }
162            }
163    
164            /**
165             * ラベルオブジェクト?キーを返します?
166             *
167             * @return      ラベルオブジェクト?キー
168             */
169            public String getKey() { return key; }
170    
171            /**
172             * ラベルオブジェクト?名称を返します?
173             * これは??上? LNAME(名称(長))に該当します?
174             *
175             * @return      ラベルオブジェクト?名称(短)
176             */
177            public String getLabel() { return label; }
178    
179            /**
180             * ラベルオブジェクト?名称(短)を返します?
181             * 概要説明がな??合でかつ??上?SNAMEが未設定?場合??
182             * LNAME が返されます?SNAMEが設定されて?場合??
183             * ??ルチップにLNAME が表示されます?
184             * 概要説明が存在する場合?、ツールチップに概要説明が
185             * 表示されます?
186             *
187             * @return      ラベルオブジェクト?名称(短)
188             */
189            public String getShortLabel() { return shortLabel; }
190    
191            /**
192             * ラベルオブジェクト?名称(長)を返します?
193             * 概要説明が存在する場合?、ツールチップに概要説明が
194             * 表示されます?
195             *
196             * @return      ラベルオブジェクト?名称(長)
197             * @see #getLongLabel( String )
198             */
199            public String getLongLabel() { return longLabel; }
200    
201            /**
202             * ラベルインターフェースの名称(長)を返します?
203             * ??ルチップに表示するタイトル属?(概要説?を置き換えます?
204             * null の場合?、既存?getLongLabel()を返します?
205             *
206             * @param       title   ??ルチップに表示するタイトル属?
207             *
208             * @return      ラベルインターフェースの名称(長)
209             * @see #getLongLabel()
210             */
211            public String getLongLabel( final String title ) {
212                    final String tipsLabel ;
213                    if( title == null ) {
214                            tipsLabel = longLabel;
215                    }
216                    else {
217                            tipsLabel = "<span title=\""
218                                                            + StringUtil.htmlFilter( title )
219                                                            + "\">"
220                                                            + label
221                                                            + "</span>" ;
222                    }
223                    return tipsLabel ;
224            }
225    
226            /**
227             * ラベルインターフェースの引数付きメ?ージを返します?
228             * メ?ージの引数部?、文字?配?を適用して、MessageFormat
229             * で変換した結果を返します?(MessageData でのみ有効です?)
230             *
231             * @og.rev 4.0.0.0 (2007/10/17) メ?ージリソース統合に伴??MessageDataより移?
232             * @og.rev 4.3.8.0 (2009/08/01) 引数にHTMLサニタイジング処?
233             * @og.rev 5.0.0.2 (2009/09/15) サニタイジング処???
234             *
235             * @param       vals    メ?ージの引数(??配?)
236             *
237             * @return      ラベルインターフェースの引数付きメ?ージ
238             */
239            public String getMessage( final String[] vals ) {
240    //              return label ;
241                    final String rtn ;
242    //      5.0.0.2 (2009/09/15)
243    //              // 4.3.8.0 valsに対してサニタイジングフィルタをかける
244    //              if( vals != null && vals.length > 0){
245    //                      for( int i=0; i<vals.length; i++ ){
246    //                              vals[i] = StringUtil.htmlFilter( vals[i] );
247    //                      }
248    //              }
249    
250                    String[] args = ( vals == null ) ? new String[0] : vals ;
251                    if( isFormat ) {
252                            rtn = MessageFormat.format( label,(Object[])args );
253                    }
254                    else {
255                            StringBuilder buf = new StringBuilder();
256                            buf.append( label );
257                            for( int i=0; i<args.length; i++ ) {
258                                    if( args[i] != null && ! args[i].equals( label ) ) {
259                                            buf.append( " " ).append( args[i] );
260                                    }
261                            }
262                            rtn = buf.toString();
263                    }
264                    return rtn ;
265            }
266    
267            /**
268             * ラベルオブジェクト?概要説明を返します?
269             * 概要説明が存在する場合?、ラベルの??ルチップに
270             * 概要説明が表示されます?
271             *
272             * @return      ラベルオブジェクト?概要説?
273             */
274            public String getDescription() { return description; }
275    
276            /**
277             * ラベルオブジェクト?概要説明を返します?
278             * こ?メソ?では{0},{1}...をパラメータで置換します?
279             *
280             * @og.rev 4.3.7.6 (2009/07/15) 新規作?
281             * @og.rev 4.3.8.0 (2009/08/01) 引数にHTMLサニタイジング処?
282             * @og.rev 5.0.0.2 (2009/09/15) サニタイジング処???
283             * @og.rev 5.4.0.1 (2011/11/01) {}が存在しな??合?単に概要を出?
284             *
285             * @param       vals    メ?ージの引数(??配?)
286             *
287             * @return      ラベルオブジェクト?概要説?
288             */
289            public String getDescription( final String[] vals ) {
290                    final String rtn ;
291    
292    //              5.0.0.2 (2009/09/15)
293    //              // 4.3.8.0 valsに対してサニタイジングフィルタをかける
294    //              if( vals != null && vals.length > 0){
295    //                      for( int i=0; i<vals.length; i++ ){
296    //                              vals[i] = StringUtil.htmlFilter( vals[i] );
297    //                      }
298    //              }
299    
300                    String[] args = ( vals == null ) ? new String[0] : vals ;
301                    if( isFormatDesc ) {
302                            rtn = MessageFormat.format( description,(Object[])args );
303                    }
304                    else {
305    //                      StringBuilder buf = new StringBuilder();
306    //                      buf.append( description );
307    //                      // Descriptionでは{}が存在しな??合?単に概要を出?
308    //                      // for( int i=0; i<args.length; i++ ) {
309    //                      //      if( args[i] != null && ! args[i].equals( description ) ) {
310    //                      //              buf.append( " " ).append( args[i] );
311    //                      //      }
312    //                      // }
313    //                      rtn = buf.toString();
314    
315                            // 5.4.0.1 (2011/11/01) {}が存在しな??合?単に概要を出?・・・ なら?直接セ?に変更
316                            rtn = description;
317                    }
318                    return rtn ;
319            }
320    
321            /**
322             * リソース??から作?されたかど?を返します?
323             * 正式な場合?、true / リソースになく?独自に作?された?合?、false になります?
324             *
325             * @return      リソース??から作?されたかど?
326             */
327            public boolean isOfficial() { return official; }
328    
329            /**
330             * ラベルオブジェクト?名称(短)をspanタグを付けな?態で返します?
331             * SNAMEが未設定?場合?、LNAME が返されます?
332             *
333             * @og.rev 4.3.8.0 (2009/08/01) 追?
334             *
335             * @return      ラベルオブジェクト?名称(短)にspanタグを付けな??
336             */
337            public String getRawShortLabel() { return rawShortLabel; }
338    
339            /**
340             * オブジェクト?識別子として?詳細なユーザー??を返します?
341             *
342             * @return  詳細なユーザー??
343             */
344            @Override
345            public String toString() {
346                    StringBuilder rtn = new StringBuilder( HybsSystem.BUFFER_MIDDLE );
347                    rtn.append( "CLM :" ).append( key );
348                    rtn.append( " SNAME :" ).append( shortLabel );
349                    rtn.append( " LNAME :" ).append( longLabel );
350                    rtn.append( " DESCRIPTION :" ).append( description ).append( HybsSystem.CR );
351                    return rtn.toString();
352            }
353    }