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 = "6.0.4.0 (2014/11/28)" ; 046 047 private final int dataSize ; 048 049 /** 050 * デフォルトコンストラクター。 051 * このコンストラクターで、基本オブジェクトを作成します。 052 * 053 */ 054 public Renderer_NBSP() { 055 super(); // 6.4.1.1 (2016/01/16) PMD refactoring. It is a good practice to call super() in a constructor 056 dataSize = 0; 057 } 058 059 /** 060 * デフォルトコンストラクター。 061 * 062 * @param clm DBColumnオブジェクト 063 */ 064 private Renderer_NBSP( final DBColumn clm ) { 065 super(); // 6.4.1.1 (2016/01/16) PMD refactoring. It is a good practice to call super() in a constructor 066 final String tmp = clm.getRendererParam(); 067 if( tmp == null || tmp.isEmpty() ) { dataSize = 0; } 068 else { 069 dataSize = Integer.parseInt( tmp ) ; 070 } 071 } 072 073 /** 074 * 各オブジェクトから自分のインスタンスを返します。 075 * 自分自身をキャッシュするのか、新たに作成するのかは、各サブクラスの実装に 076 * まかされます。 077 * 078 * @param clm DBColumnオブジェクト 079 * 080 * @return CellRendererオブジェクト 081 * @og.rtnNotNull 082 */ 083 public CellRenderer newInstance( final DBColumn clm ) { 084 return new Renderer_NBSP( clm ); 085 } 086 087 /** 088 * データの表示用文字列を返します。 089 * 090 * ここでは、内部のスペースを、  という文字列に置き換えます。 091 * これにより、HTML 上で、連続したスペースを表示できます。 092 * また、レンデラーパラメータに、数字を指定すれば、その文字数で強制的に Fill埋めするため、 093 * 固定長の表示にも使用できます。 094 * 095 * @param value 入力値 096 * 097 * @return データの表示用文字列 098 * @og.rtnNotNull 099 */ 100 @Override 101 public String getValue( final String value ) { 102 String rtn = ( value == null ) ? "" : value ; 103 104 if( dataSize > 0 ) { 105 rtn = StringUtil.stringFill( rtn,dataSize,"Windows-31J" ); 106 } 107 108 return StringUtil.replace( rtn," "," " ); 109 } 110 111 /** 112 * データ出力用の文字列を作成します。 113 * ファイル等に出力する形式を想定しますので、HTMLタグを含まない 114 * データを返します。 115 * 基本は、#getValue( String ) をそのまま返します。 116 * 117 * @og.rev 6.0.4.0 (2014/11/28) データ出力用のレンデラー 118 * 119 * @param value 入力値 120 * 121 * @return データ出力用の文字列 122 * @og.rtnNotNull 123 * @see #getValue( String ) 124 */ 125 @Override 126 public String getWriteValue( final String value ) { 127 return value==null ? "" : value; 128 } 129}