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.db.AbstractRenderer; 019import org.opengion.hayabusa.db.CellRenderer; 020import org.opengion.hayabusa.db.DBColumn; 021import org.opengion.fukurou.util.StringUtil; 022 023/** 024 * NBSP レンデラーは、内部のスペースを、  という文字列に置き換えます。 025 * これは、文字列にスペースが含まれている場合、  と言うコードにエスケープすることで、 026 * HTML 上で、連続したスペースを表示します。 027 * 通常、PRE レンデラーで表示するなどの方法もありますが、NBSP でないとスペースに 028 * ならない場合(たとえば、プルダウンメニューのオプション文字列など)に対応できます。 029 * また、レンデラーパラメータに、数字を指定すれば、その文字数で強制的に Fill埋めするため、 030 * 固定長の表示にも使用できます。 031 * これにより、連続するスペースを、そのまま表示することが出来ます。 032 * 033 * カラムの表示に必要な属性は, DBColumn オブジェクト より取り出します。 034 * このクラスは、DBColumn オブジェクト毎に1つ作成されます。 035 * 036 * @og.rev 3.7.1.0 (2005/04/26) 新規追加 037 * @og.group データ表示 038 * 039 * @version 0.9.0 2000/10/17 040 * @author Kazuhiko Hasegawa 041 * @since JDK5.0, 042 */ 043public class Renderer_NBSP extends AbstractRenderer { 044 //* このプログラムのVERSION文字列を設定します。 {@value} */ 045 private static final String VERSION = "4.0.0.0 (2005/08/31)" ; 046 047 private final int dataSize ; 048 049 /** 050 * デフォルトコンストラクター。 051 * このコンストラクターで、基本オブジェクトを作成します。 052 * 053 */ 054 public Renderer_NBSP() { 055 dataSize = 0; 056 } 057 058 /** 059 * デフォルトコンストラクター。 060 * 061 * @param clm DBColumnオブジェクト 062 */ 063 private Renderer_NBSP( final DBColumn clm ) { 064 String tmp = clm.getRendererParam(); 065 if( tmp == null || tmp.length() == 0 ) { dataSize = 0; } 066 else { 067 dataSize = Integer.parseInt( tmp ) ; 068 } 069 } 070 071 /** 072 * 各オブジェクトから自分のインスタンスを返します。 073 * 自分自身をキャッシュするのか、新たに作成するのかは、各サブクラスの実装に 074 * まかされます。 075 * 076 * @param clm DBColumnオブジェクト 077 * 078 * @return CellRendererオブジェクト 079 */ 080 public CellRenderer newInstance( final DBColumn clm ) { 081 return new Renderer_NBSP( clm ); 082 } 083 084 /** 085 * データの表示用文字列を返します。 086 * 087 * ここでは、内部のスペースを、  という文字列に置き換えます。 088 * これにより、HTML 上で、連続したスペースを表示できます。 089 * また、レンデラーパラメータに、数字を指定すれば、その文字数で強制的に Fill埋めするため、 090 * 固定長の表示にも使用できます。 091 * 092 * @param value 入力値 093 * 094 * @return データの表示用文字列 095 */ 096 @Override 097 public String getValue( final String value ) { 098 String rtn = ( value == null ) ? "" : value ; 099 100 if( dataSize > 0 ) { 101 rtn = StringUtil.stringFill( rtn,dataSize,"Windows-31J" ); 102 } 103 104 return StringUtil.replace( rtn," "," " ); 105 } 106}