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 private final String rawLongLabel; // 名称(未変換長) 5.6.8.2 (2013/09/20)
084
085 /**
086 * null LabelData オブジェクトを作æ?しますã?
087 * こã?オブジェクトã?ã€?¼¤?¢リソース上に存在しなã�??合に使用されã‚?
088 * null æƒ??を表すã?LabelData オブジェクトですã?
089 *
090 * @og.rev 5.6.8.2 (2013/09/20) rawLongLabel対å¿?
091 *
092 * @param inkey キーæƒ??
093 */
094 LabelData( final String inkey ) {
095 key = inkey.intern() ;
096 label = key ; // 名称(長)
097 shortLabel = key ; // 名称(HTML短)
098 longLabel = key ; // 名称(HTML長)
099 description = "" ; // 概要説æ˜?
100 official = false; // 非正å¼?
101 isFormat = false; // 非フォーマッãƒ?4.0.0.0 (2007/10/17)
102 rawShortLabel = key; // 名称(未変換短) 4.3.8.0 (2009/08/01)
103 isFormatDesc = false; // 概要フォーマッãƒ?4.3.7.6 (2009/07/15)
104 rawLongLabel = key; // 名称(未変換長)5.6.8.2 (2013/09/20)
105 }
106
107 /**
108 * 配å?æ–?—å?のãƒ??タをå?に、LabelDataオブジェクトを構築しますã?
109 * こã?コンストラクタは、他ã?パッケージから呼び出せなã�?‚ˆã�?�«ã€?
110 * パッケージプライベã?トにしておきますã?
111 * こã?コンストラクタはã€?¼¤?¢リソースファイルを想定してã�?�¾すã?
112 *
113 * @og.rev 5.4.0.1 (2011/11/01) SNAME、概要説明ã?rawShortLabel 関係ã?処ç�?‚’修正
114 * @og.rev 5.6.8.2 (2013/09/20) rawLongLabel対å¿?
115 *
116 * @param data CLM,SNAME,LNAME,DESCRIPTION
117 */
118 LabelData( final String[] data ) {
119 key = data[CLM].intern() ; // é ?›®
120 label = StringUtil.nval2( data[LNAME],"" ) ; // 名称(HTML長)
121 description = data[DESCRIPTION] ; // 概要説æ˜?
122 official = true; // 正å¼?
123 isFormat = ( label.indexOf( '{' ) >= 0 ) ; // 4.0.0.0 (2007/10/17)
124 // isFormatDesc = ( description.indexOf( '{' ) >= 0 ); // 4.3.7.6 (2009/07/15)
125 String title = null;
126
127 rawLongLabel = label; // 名称(未変換長)5.6.8.2 (2013/09/20)
128 if( description == null || description.length() == 0 ) {
129 isFormatDesc = false;
130 // 5.4.0.1 (2011/11/01) title と label が間違ってã�?‚‹ã€?SNAME が存在する場å�?
131 // title = StringUtil.htmlFilter( title ) ;
132 title = StringUtil.htmlFilter( label ) ;
133
134 // 概要説明がなã�??合ã?、そのままラベルを使用するã€?
135 longLabel = label;
136 }
137 else {
138 isFormatDesc = ( description.indexOf( '{' ) >= 0 ); // 5.1.8.0 (2010/07/01) nullポインタの参ç?外し対ç?
139 title = StringUtil.htmlFilter( description ) ;
140
141 // 概要説明がある場合ã?、ツールチップにDESCRIPTIONを表示するã€?
142 longLabel = "<span title=\""
143 // + StringUtil.htmlFilter( description )
144 + title
145 + "\">"
146 + label
147 + "</span>" ;
148 }
149
150 String sname = data[SNAME]; // 名称(HTML短)
151 if( sname == null || sname.length() == 0 ) {
152 // SNAME がなã�??合ã?、longLabel を使用するã€?
153 shortLabel = longLabel;
154 // rawShortLabel = longLabel; // 4.3.8.0 (2009/08/01)
155 rawShortLabel = label; // 5.4.0.1 (2011/11/01) longLabel を使ã�?�¨、ツールチップがåŠ?‘³されるためã?
156 }
157 else {
158 // SNAME が存在する場合ã?ãƒ??ルチップにdescriptionかlabelを使用するã€?
159 // String title = ( description == null || description.length() == 0 ) ? label : description ;
160 shortLabel = "<span title=\""
161 // + StringUtil.htmlFilter( title )
162 + title
163 + "\">"
164 + sname
165 + "</span>" ;
166 rawShortLabel = sname; // 4.3.8.0 (2009/08/01)
167 }
168 }
169
170 /**
171 * ラベルオブジェクトã?キーを返しますã?
172 *
173 * @return ラベルオブジェクトã?キー
174 */
175 public String getKey() { return key; }
176
177 /**
178 * ラベルオブジェクトã?名称を返しますã?
179 * これはã€?¼¤?¢上ã? LNAME(名称(長))に該当しますã?
180 *
181 * @return ラベルオブジェクトã?名称(短)
182 */
183 public String getLabel() { return label; }
184
185 /**
186 * ラベルオブジェクトã?名称(短)を返しますã?
187 * 概要説明がなã�??合でかつ?¤?¢上ã?SNAMEが未設定ã?場合ã?ã€?
188 * LNAME が返されますã?SNAMEが設定されてã�?‚‹場合ã?ã€?
189 * ãƒ??ルチップにLNAME が表示されますã?
190 * 概要説明が存在する場合ã?、ツールチップに概要説明が
191 * 表示されますã?
192 *
193 * @return ラベルオブジェクトã?名称(短)
194 */
195 public String getShortLabel() { return shortLabel; }
196
197 /**
198 * ラベルオブジェクトã?名称(長)を返しますã?
199 * 概要説明が存在する場合ã?、ツールチップに概要説明が
200 * 表示されますã?
201 *
202 * @return ラベルオブジェクトã?名称(長)
203 * @see #getLongLabel( String )
204 */
205 public String getLongLabel() { return longLabel; }
206
207 /**
208 * ラベルインターフェースの名称(長)を返しますã?
209 * ãƒ??ルチップに表示するタイトル属æ?(概要説æ˜?を置き換えますã?
210 * null の場合ã?、既存ã?getLongLabel()を返しますã?
211 *
212 * @param title ãƒ??ルチップに表示するタイトル属æ?
213 *
214 * @return ラベルインターフェースの名称(長)
215 * @see #getLongLabel()
216 */
217 public String getLongLabel( final String title ) {
218 final String tipsLabel ;
219 if( title == null ) {
220 tipsLabel = longLabel;
221 }
222 else {
223 tipsLabel = "<span title=\""
224 + StringUtil.htmlFilter( title )
225 + "\">"
226 + label
227 + "</span>" ;
228 }
229 return tipsLabel ;
230 }
231
232 /**
233 * ラベルインターフェースの引数付きメãƒ?‚»ージを返しますã?
234 * メãƒ?‚»ージの引数部åˆ?�«、文字å?配å?を適用して、MessageFormat
235 * で変換した結果を返しますã?(MessageData でのみ有効ですã?)
236 *
237 * @og.rev 4.0.0.0 (2007/10/17) メãƒ?‚»ージリソース統合に伴ã�??MessageDataより移è¡?
238 * @og.rev 4.3.8.0 (2009/08/01) 引数にHTMLサニタイジング処ç�?
239 * @og.rev 5.0.0.2 (2009/09/15) サニタイジング処ç�?‚’ã‚?‚�ã‚?
240 *
241 * @param vals メãƒ?‚»ージの引数(æ–?—å?配å?)
242 *
243 * @return ラベルインターフェースの引数付きメãƒ?‚»ージ
244 */
245 public String getMessage( final String[] vals ) {
246 // return label ;
247 final String rtn ;
248 // 5.0.0.2 (2009/09/15)
249 // // 4.3.8.0 valsに対してサニタイジングフィルタをかける
250 // if( vals != null && vals.length > 0){
251 // for( int i=0; i<vals.length; i++ ){
252 // vals[i] = StringUtil.htmlFilter( vals[i] );
253 // }
254 // }
255
256 String[] args = ( vals == null ) ? new String[0] : vals ;
257 if( isFormat ) {
258 rtn = MessageFormat.format( label,(Object[])args );
259 }
260 else {
261 StringBuilder buf = new StringBuilder();
262 buf.append( label );
263 for( int i=0; i<args.length; i++ ) {
264 if( args[i] != null && ! args[i].equals( label ) ) {
265 buf.append( " " ).append( args[i] );
266 }
267 }
268 rtn = buf.toString();
269 }
270 return rtn ;
271 }
272
273 /**
274 * ラベルオブジェクトã?概要説明を返しますã?
275 * 概要説明が存在する場合ã?、ラベルのãƒ??ルチップに
276 * 概要説明が表示されますã?
277 *
278 * @return ラベルオブジェクトã?概要説æ˜?
279 */
280 public String getDescription() { return description; }
281
282 /**
283 * ラベルオブジェクトã?概要説明を返しますã?
284 * こã?メソãƒ?ƒ‰では{0},{1}...をパラメータで置換しますã?
285 *
286 * @og.rev 4.3.7.6 (2009/07/15) 新規作æ?
287 * @og.rev 4.3.8.0 (2009/08/01) 引数にHTMLサニタイジング処ç�?
288 * @og.rev 5.0.0.2 (2009/09/15) サニタイジング処ç�?‚’ã‚?‚�ã‚?
289 * @og.rev 5.4.0.1 (2011/11/01) {}が存在しなã�??合ã?単に概要を出åŠ?
290 *
291 * @param vals メãƒ?‚»ージの引数(æ–?—å?配å?)
292 *
293 * @return ラベルオブジェクトã?概要説æ˜?
294 */
295 public String getDescription( final String[] vals ) {
296 final String rtn ;
297
298 // 5.0.0.2 (2009/09/15)
299 // // 4.3.8.0 valsに対してサニタイジングフィルタをかける
300 // if( vals != null && vals.length > 0){
301 // for( int i=0; i<vals.length; i++ ){
302 // vals[i] = StringUtil.htmlFilter( vals[i] );
303 // }
304 // }
305
306 String[] args = ( vals == null ) ? new String[0] : vals ;
307 if( isFormatDesc ) {
308 rtn = MessageFormat.format( description,(Object[])args );
309 }
310 else {
311 // StringBuilder buf = new StringBuilder();
312 // buf.append( description );
313 // // Descriptionでは{}が存在しなã�??合ã?単に概要を出åŠ?
314 // // for( int i=0; i<args.length; i++ ) {
315 // // if( args[i] != null && ! args[i].equals( description ) ) {
316 // // buf.append( " " ).append( args[i] );
317 // // }
318 // // }
319 // rtn = buf.toString();
320
321 // 5.4.0.1 (2011/11/01) {}が存在しなã�??合ã?単に概要を出åŠ?・・・ ならã?直接セãƒ?ƒˆに変更
322 rtn = description;
323 }
324 return rtn ;
325 }
326
327 /**
328 * リソース?¤?¢から作æ?されたかどã�?�‹を返しますã?
329 * 正式な場合ã?、true / リソースになくã?独自に作æ?されたå?合ã?、false になりますã?
330 *
331 * @return リソース?¤?¢から作æ?されたかどã�?�‹
332 */
333 public boolean isOfficial() { return official; }
334
335 /**
336 * ラベルオブジェクトã?名称(長)をそのままの形で返しますã?
337 * ??iscription等を付けなã�?
338 *
339 * @og.rev 5.6.8.2 (2009/08/01) 追åŠ?
340 *
341 * @return ラベルオブジェクトã?名称(長)そã?ままの状æ…?
342 */
343 public String getRawLongLabel() { return rawLongLabel; }
344
345 /**
346 * ラベルオブジェクトã?名称(短)をspanタグを付けなã�?ж態で返しますã?
347 * SNAMEが未設定ã?場合ã?、LNAME が返されますã?
348 *
349 * @og.rev 4.3.8.0 (2009/08/01) 追åŠ?
350 *
351 * @return ラベルオブジェクトã?名称(短)にspanタグを付けなã�?жæ…?
352 */
353 public String getRawShortLabel() { return rawShortLabel; }
354
355 /**
356 * オブジェクトã?識別子として?Œ詳細なユーザーæƒ??を返しますã?
357 *
358 * @return 詳細なユーザーæƒ??
359 */
360 @Override
361 public String toString() {
362 StringBuilder rtn = new StringBuilder( HybsSystem.BUFFER_MIDDLE );
363 rtn.append( "CLM :" ).append( key );
364 rtn.append( " SNAME :" ).append( shortLabel );
365 rtn.append( " LNAME :" ).append( longLabel );
366 rtn.append( " DESCRIPTION :" ).append( description ).append( HybsSystem.CR );
367 return rtn.toString();
368 }
369 }