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; 021 022/** 023 * XXXX レンデラーは、パラメータで指定された XXXXフォーマットに対して、 024 * 値を変換します。たとえば、郵便番号や、電話番号など、ハイフン編集や、日付や 025 * 時刻などの / や : 編集を行います。 026 * 例) 1234567 XXX-XXXX ⇒ 123-4567 027 * 例) 1234567890 (XXX)-XXX-XXXX ⇒ (123)-456-7890 028 * 例) 20060715 XXXX/XX/XX ⇒ 2006/07/15 029 * 030 * XXXX フォーマットよりデータが少ない場合は、以下表示されません。 031 * XXXX-XXXX の場合に、データが4桁の場合は、ハイフンは含まれません。 032 * 033 * フォーマットの初期値はXXXXXXXXXXXXXXXXXXXXです。 034 * 035 * カラムの表示に必要な属性は, DBColumn オブジェクト より取り出します。 036 * このクラスは、DBColumn オブジェクト毎に1つ作成されます。 037 * 038 * @og.group データ表示 039 * 040 * @version 4.0 041 * @author Kazuhiko Hasegawa 042 * @since JDK5.0, 043 */ 044public class Renderer_XXXX extends AbstractRenderer { 045 //* このプログラムのVERSION文字列を設定します。 {@value} */ 046 private static final String VERSION = "4.0.0.0 (2005/08/31)" ; 047 048 private final String form ; 049 050 /** 051 * デフォルトコンストラクター。 052 * このコンストラクターで、基本オブジェクトを作成します。 053 * 054 * @og.rev 3.1.1.1 (2003/04/03) 各オブジェクトから自分のインスタンスを返すファクトリメソッドを追加。 055 * 056 */ 057 public Renderer_XXXX() { 058 form = "XXXXXXXXXXXXXXXXXXXX"; 059 } 060 061 /** 062 * デフォルトコンストラクター。 063 * 064 * @param clm DBColumnオブジェクト 065 */ 066 private Renderer_XXXX( final DBColumn clm ) { 067 String tmp = clm.getRendererParam(); 068 if( tmp == null || tmp.length() == 0 ) { tmp = "XXXXXXXXXXXXXXXXXXXX"; } 069 form = tmp ; 070 } 071 072 /** 073 * 各オブジェクトから自分のインスタンスを返します。 074 * 自分自身をキャッシュするのか、新たに作成するのかは、各サブクラスの実装に 075 * まかされます。 076 * 077 * @param clm DBColumnオブジェクト 078 * 079 * @return CellRendererオブジェクト 080 */ 081 public CellRenderer newInstance( final DBColumn clm ) { 082 return new Renderer_XXXX( clm ); 083 } 084 085 /** 086 * データの表示用文字列を返します。 087 * 088 * @param value 入力値 089 * 090 * @return データの表示用文字列 091 */ 092 @Override 093 public String getValue( final String value ) { 094 if( value == null ) { return ""; } 095 096 char[] formChar = form.toCharArray(); 097 char[] valChar = value.toCharArray(); 098 099 StringBuilder buf = new StringBuilder( formChar.length ); 100 int j = 0; 101 for( int i=0; i<formChar.length && j<valChar.length; i++ ) { 102 if( formChar[i] == 'X' ) { 103 buf.append( valChar[j++] ); 104 } 105 else { 106 buf.append( formChar[i] ); 107 } 108 } 109 110 return buf.toString(); 111 } 112}