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タグ('<' や '>')が('&lt;' や '&gt;' に)変換 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 // 7.0.1.0 (2018/10/15) XHTML → HTML5 対応(空要素の、"/>" 止めを、">" に変更します)。 057// private static final String[] KEYS = { "<u>" ,"</u>","<br/>" }; 058// private static final String[] VALS = { "<u>" ,"</u>" ,"<br/>" }; 059 private static final String[] KEYS = { "<u>" ,"</u>","<br/>" ,"<br>" }; 060 private static final String[] VALS = { "<u>" ,"</u>" ,"<br/>" ,"<br>" }; 061 062 /** 063 * デフォルトコンストラクター 064 * 065 * @og.rev 6.4.2.0 (2016/01/29) PMD refactoring. Each class should declare at least one constructor. 066 */ 067 public Renderer_FILTER() { super(); } // これも、自動的に呼ばれるが、空のメソッドを作成すると警告されるので、明示的にしておきます。 068 069 /** 070 * 各オブジェクトから自分のインスタンスを返します。 071 * 自分自身をキャッシュするのか、新たに作成するのかは、各サブクラスの実装に 072 * まかされます。 073 * 074 * @param clm DBColumnオブジェクト 075 * 076 * @return CellRendererオブジェクト 077 * @og.rtnNotNull 078 */ 079 public CellRenderer newInstance( final DBColumn clm ) { 080 return DB_CELL; 081 } 082 083 /** 084 * データの表示用文字列を返します。 085 * 086 * @param value 入力値 087 * 088 * @return データの表示用文字列 089 * @og.rtnNotNull 090 */ 091 @Override 092 public String getValue( final String value ) { 093 String val = ( value == null ) ? "" : value; 094 095 for( int i=0; i<KEYS.length; i++ ) { 096 val = StringUtil.replace( val,KEYS[i],VALS[i] ); 097 } 098 099 return val; 100 } 101}