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 * HHM レンデラーは、カラムのデータを時:分に分けて表示する場合に 024 * 使用するクラスです。 025 * HMレンデラーと異なり、元の値は、「分」であり、それを、時間:分 に 026 * 分解表示します。 027 * 028 * カラムの表示に必要な属性は, DBColumn オブジェクト より取り出します。 029 * このクラスは、DBColumn オブジェクト毎に1つ作成されます。 030 * 031 * @og.group データ表示 032 * @og.rev 6.0.2.3 (2014/10/10) 新規作成 033 * 034 * @version 5.0 035 * @author Kazuhiko Hasegawa 036 * @since JDK6.0, 037 */ 038public class Renderer_HHM extends AbstractRenderer { 039 /** このプログラムのVERSION文字列を設定します。 {@value} */ 040 private static final String VERSION = "6.4.2.0 (2016/01/29)" ; 041 042 private static final CellRenderer DB_CELL = new Renderer_HHM() ; // 5.6.5.1 (2013/06/14) 043 044 /** 045 * デフォルトコンストラクター 046 * 047 * @og.rev 6.4.2.0 (2016/01/29) PMD refactoring. Each class should declare at least one constructor. 048 */ 049 public Renderer_HHM() { super(); } // これも、自動的に呼ばれるが、空のメソッドを作成すると警告されるので、明示的にしておきます。 050 051 /** 052 * 各オブジェクトから自分のインスタンスを返します。 053 * 自分自身をキャッシュするのか、新たに作成するのかは、各サブクラスの実装に 054 * まかされます。 055 * 056 * @param clm DBColumnオブジェクト 057 * 058 * @return CellRendererオブジェクト 059 * @og.rtnNotNull 060 */ 061 public CellRenderer newInstance( final DBColumn clm ) { 062 return DB_CELL; 063 } 064 065 /** 066 * データの表示用文字列を返します。 067 * ここでは、null か ゼロ文字列の場合は、ゼロ文字列を返します。 068 * HMレンデラーと異なり、元の値は、「分」であり、それを、時間:分 に 069 * 分解表示します。 070 * 数値化して、60 で割り算しますので、数値化できない場合は、エラーになります。 071 * 072 * @og.rev 6.0.2.3 (2014/10/10) 新規追加 073 * @og.rev 6.0.2.4 (2014/10/17) 分が、1桁の場合、XX:X 表記になってしまうバグを修正 074 * @og.rev 6.0.4.0 (2014/11/28) ロジックの共通化 075 * 076 * @param value 入力値 077 * 078 * @return データの表示用文字列 079 */ 080 @Override 081 public String getValue( final String value ) { 082 return getValue( value , true ); 083 084 } 085 086 /** 087 * データ出力用の文字列を作成します。 088 * ファイル等に出力する形式を想定しますので、HTMLタグを含まない 089 * データを返します。 090 * 基本は、#getValue( String ) をそのまま返します。 091 * 092 * @og.rev 6.0.4.0 (2014/11/28) データ出力用のレンデラー 093 * 094 * @param value 入力値 095 * 096 * @return データ出力用の文字列 097 * @see #getValue( String ) 098 */ 099 @Override 100 public String getWriteValue( final String value ) { 101 return getValue( value , false ); 102 } 103 104 /** 105 * データ表示用/出力用の文字列を作成します。 106 * 第二引数の isView == true で、データ表示用文字列を、false で 107 * データ出力用の文字列を作成します。 108 * 処理の共通化を行うためのメソッドです。 109 * 110 * @og.rev 6.0.4.0 (2014/11/28) ロジックの共通化 111 * 112 * @param value 入力値 113 * @param isView データ表示用かどうか(true:表示用/false:出力用) 114 * 115 * @return データ表示用/出力用の文字列 116 * @og.rtnNotNull 117 * @see #getValue( String ) 118 */ 119 private String getValue( final String value , final boolean isView ) { 120 if( value == null || value.isEmpty() ) { return ""; } 121 122 String rtn = value; // 初期値:isView = false の時の値 123 try { 124 final int val = Integer.parseInt( value ); 125 final int mm = val % 60; 126 127 rtn = val/60 + ":" + (mm<10 ? "0" + mm : mm) ; // 時:分 128 } 129 catch( final NumberFormatException ex ) { 130 if( isView ) { 131 rtn = "<span class=\"error\">" + value + "</span>"; 132 } 133 } 134 135 return rtn; 136 } 137}