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 * 特定のHTMLタグのエスケープ文字を元のタグに戻して表示するクラスです。
025 *
026 * HTMLレンデラーで、HTMLタグ('<' や '>')が('<' や '>' に)変換
027 * されますが、この FILTERでは、特定の変換済みタグを元のHTMLに戻す処理を行います。
028 * 現時点では、<u> , </u> , <br /> の3種類です。
029 * これは、帳票システムで、データに含まれるHTMLを変換しないと、HTMLのレイアウトが
030 * 崩れる為、3.7.0.1 (2005/01/31) で、帳票データのHTMLエスケープ処理を導入しました。
031 * この時点で、セル内の改行を表す <br> も、エスケープされる為、3.7.1.1 (2005/05/31)にて
032 * <br>のみ、そのまま元に戻す処理が入っています。
033 * 今回は、指定のデータに下線を引く <u> タグと、今後もこのような変換対象が現れる
034 * 可能性を考慮して、既存のレンデラーに実装しました。
035 * 現状の帳票システムでは、エンジンのレンデラー経由で変換され、HTML可されているため、
036 * カラムリソース(システムIDがGE)に逆変換したいカラムをこの FILTER レンデラーで
037 * 登録すれば、元に戻すことが可能になります。
038 *
039 * クロスサイトスクリプティング問題に対応するフィールドに対して
040 * 定義することにより、エスケープ処理を行います。
041 *
042 * このクラスは、不変オブジェクトとして、共有されます。
043 *
044 * @og.rev 3.8.1.1 (2005/11/21) 新規追加
045 * @og.group データ表示
046 *
047 * @version  4.0
048 * @author   Kazuhiko Hasegawa
049 * @since    JDK5.0,
050 */
051public class Renderer_FILTER extends AbstractRenderer {
052        /** このプログラムのVERSION文字列を設定します。   {@value} */
053        private static final String VERSION = "6.4.2.0 (2016/01/29)" ;
054
055        private static final CellRenderer DB_CELL = new Renderer_FILTER();
056        private static final String[] KEYS = { "<u>"      ,"</u>","<br/>" };
057        private static final String[] VALS = { "<u>"            ,"</u>"          ,"<br/>"       };
058
059        /**
060         * デフォルトコンストラクター
061         *
062         * @og.rev 6.4.2.0 (2016/01/29) PMD refactoring. Each class should declare at least one constructor.
063         */
064        public Renderer_FILTER() { super(); }           // これも、自動的に呼ばれるが、空のメソッドを作成すると警告されるので、明示的にしておきます。
065
066        /**
067         * 各オブジェクトから自分のインスタンスを返します。
068         * 自分自身をキャッシュするのか、新たに作成するのかは、各サブクラスの実装に
069         * まかされます。
070         *
071         * @param       clm     DBColumnオブジェクト
072         *
073         * @return      CellRendererオブジェクト
074         * @og.rtnNotNull
075         */
076        public CellRenderer newInstance( final DBColumn clm ) {
077                return DB_CELL;
078        }
079
080        /**
081         * データの表示用文字列を返します。
082         *
083         * @param   value 入力値
084         *
085         * @return  データの表示用文字列
086         * @og.rtnNotNull
087         */
088        @Override
089        public String getValue( final String value ) {
090                String val = ( value == null ) ? "" : value;
091
092                for( int i=0; i<KEYS.length; i++ ) {
093                        val = StringUtil.replace( val,KEYS[i],VALS[i] );
094                }
095
096                return val;
097        }
098}