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 * YMD レンデラーは、カラムのデータを日付(月/日)表示する場合に使用するクラスです。
024 * 元の文字列の5,6桁目を月として、7,8桁目を日として表示します。
025 *
026 * このクラスは、不変オブジェクトとして、共有されます。
027 *
028 * @og.group データ表示
029 *
030 * @og.rev 4.3.7.1 (2009/06/08) 新規作成
031 *
032 * @version  4.0
033 * @author   Takahashi Masakazu
034 * @since    JDK5.0,
035 */
036public class Renderer_MD extends AbstractRenderer {
037        //* このプログラムのVERSION文字列を設定します。   {@value} */
038        private static final String VERSION = "5.5.8.1 (2012/11/05)" ;
039
040        private static final CellRenderer dbCell = new Renderer_MD() ;
041
042        /**
043         * 各オブジェクトから自分のインスタンスを返します。
044         * 自分自身をキャッシュするのか、新たに作成するのかは、各サブクラスの実装に
045         * まかされます。
046         *
047         * @param       clm     DBColumnオブジェクト
048         *
049         * @return      CellRendererオブジェクト
050         */
051        public CellRenderer newInstance( final DBColumn clm ) {
052                return dbCell;
053        }
054
055        /**
056         * データの表示用文字列を返します。
057         * ここでは、null か ゼロ文字列の場合は、ゼロ文字列を返します。
058         * 4ケタ以外の8ケタ以下のデータなど、正常に処理できなかった場合は、エラー表示を行います。
059         * 元が8ケタ以上の場合は先頭から8文字をYYYYMMDD として、MM/DD を返します。
060         * 4ケタの場合は、MMDD を、MM/DD として返します。
061         *
062         * @og.rev 5.5.7.2 (2012/10/09) 処理ロジックの見直し
063         * @og.rev 5.5.8.1 (2012/11/05) コロンをスラッシュに修正、8文字以上の処理
064         *
065         * @param   value 入力値
066         *
067         * @return  データの表示用文字列
068         */
069        @Override
070        public String getValue( final String value ) {
071                if( value == null || value.length() == 0 ) { return ""; }
072
073                String rtn = value;
074
075                char[] ch1 = new char[5];
076                if( rtn.length() == 4 ) {
077                        ch1[0] = rtn.charAt(0);
078                        ch1[1] = rtn.charAt(1);
079                        ch1[2] = '/' ; // 5.5.8.1 (2012/11/05)
080                        ch1[3] = rtn.charAt(2);
081                        ch1[4] = rtn.charAt(3);
082
083                        rtn = new String( ch1 );
084                }
085                else if( rtn.length() >= 8 ) {
086                        ch1[0] = rtn.charAt(4);
087                        ch1[1] = rtn.charAt(5);
088                        ch1[2] = '/' ; // 5.5.8.1 (2012/11/05)
089                        ch1[3] = rtn.charAt(6);
090                        ch1[4] = rtn.charAt(7);
091
092                        rtn = new String( ch1 );
093                }
094                else {
095                        rtn = "<span class=\"error\">" + value + "</span>";
096                }
097                return rtn;
098        }
099}