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.AbstractEditor;
019import org.opengion.hayabusa.db.CellEditor;
020import org.opengion.hayabusa.db.DBColumn;
021import org.opengion.fukurou.util.XHTMLTag;
022import org.opengion.fukurou.util.StringUtil;
023
024/**
025 * HTMLタグを含むデータを編集する場合に使用するエディタークラスです。
026 *
027 * データベースに対して、加工なしデータを登録しています。HTMLタグを
028 * 含むデータは、DBTypeのチェックにより、通常は登録できません。
029 * これは、クロスサイトスクリプティング対策の為です。DBTypeを指定する
030 * ことで、HTMLタグの登録が可能になります。
031 * しかし、エンジンでは、検索時処理を優先させる為、検索時には加工して
032 * いません。つまり、HTMLタグを含むデータをそのまま表示させると、HTMLの
033 * コードと解釈され、レイアウトが崩れることになります。
034 * HTMLエディターは、データのHTMLタグをエスケープすることで、表示上は、
035 * HTMLコードがそのまま表示/編集できる状態にします。
036 *
037 * カラムの表示に必要な属性は, DBColumn オブジェクト より取り出します。
038 * このクラスは、DBColumn オブジェクト毎に1つ作成されます。
039 *
040 * @og.rev 2.1.1.1 (2002/11/15) HTML エディターを新規追加しました。
041 * @og.group データ編集
042 *
043 * @version  4.0
044 * @author       Kazuhiko Hasegawa
045 * @since    JDK5.0,
046 */
047public class Editor_HTML extends AbstractEditor {
048        //* このプログラムのVERSION文字列を設定します。   {@value} */
049        private static final String VERSION = "4.0.0.0 (2005/08/31)" ;
050
051        /**
052         * デフォルトコンストラクター。
053         * このコンストラクターで、基本オブジェクトを作成します。
054         *
055         * @og.rev 3.1.1.1 (2003/04/03) 各オブジェクトから自分のインスタンスを返すファクトリメソッドを追加。
056         *
057         */
058        public Editor_HTML() {
059                // 4.3.4.4 (2009/01/01)
060//              super();
061        }
062
063        /**
064         * コンストラクター。
065         *
066         * @og.rev 3.1.1.1 (2003/04/03) 各オブジェクトから自分のインスタンスを返すファクトリメソッドを追加。
067         * @og.rev 3.5.6.0 (2004/06/18) XHTMLTag の 内部配列 INPUT_KEY を隠蔽します。
068         *
069         * @param       clm     DBColumnオブジェクト
070         */
071        private Editor_HTML( final DBColumn clm ) {
072                super( clm );
073                tagBuffer.add( XHTMLTag.inputAttri( attributes ) );
074        }
075
076        /**
077         * 各オブジェクトから自分のインスタンスを返します。
078         * 自分自身をキャッシュするのか、新たに作成するのかは、各サブクラスの実装に
079         * まかされます。
080         *
081         * @og.rev 3.1.1.1 (2003/04/03) 各オブジェクトから自分のインスタンスを返すファクトリメソッドを追加。
082         * @og.rev 3.1.2.1 (2003/04/10) synchronized を、削除します。
083         *
084         * @param       clm     DBColumnオブジェクト
085         *
086         * @return      CellEditorオブジェクト
087         */
088        public CellEditor newInstance( final DBColumn clm ) {
089                return new Editor_HTML( clm );
090        }
091
092        /**
093         * データの編集用文字列を返します。
094         *
095         * @param       value 入力値
096         *
097         * @return      データの編集用文字列
098         */
099        @Override
100        public String getValue( final String value ) {
101                return super.getValue( StringUtil.htmlFilter( value ) );
102        }
103
104        /**
105         * name属性を変えた、データ表示/編集用のHTML文字列を作成します。
106         * テーブル上の name に 行番号を付加して、名前_行番号 で登録するキーを作成し,
107         * リクエスト情報を1つ毎のフィールドで処理できます。
108         *
109         * @og.rev 2.0.0.3 (2002/09/26) optionAttributes 属性に "$i" を使うとその行数に置き換る機能を追加。
110         *
111         * @param       row   行番号
112         * @param       value 入力値
113         *
114         * @return      データ表示/編集用の文字列
115         */
116        @Override
117        public String getValue( final int row,final String value ) {
118                return super.getValue( row, StringUtil.htmlFilter( value ) );
119        }
120}