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.common.HybsSystem;
019import org.opengion.hayabusa.db.AbstractEditor;
020import org.opengion.hayabusa.db.CellEditor;
021import org.opengion.hayabusa.db.DBColumn;
022import org.opengion.fukurou.util.XHTMLTag;
023import org.opengion.fukurou.util.Attributes;
024
025import java.util.Map;                                                                                   // 7.4.2.0 (2021/05/08)
026
027/**
028 * UPLOAD2 エディターは、ドラッグ&ドロップでファイルアップロードを行う場合に
029 * 使用する編集用クラスです。
030 *
031 * 行ごとの対応も、ファイル名の書き換えもサポートしていません。
032 * 現状できるのは、filetemp/ログインID フォルダに、そのままのファイル名で
033 * アップロードするだけです。
034 *
035 *  カラムの表示に必要な属性は, DBColumn オブジェクト より取り出します。
036 * このクラスは、DBColumn オブジェクト毎に1つ作成されます。
037 *
038 * 編集パラメータに指定できる項目は、『;』で
039 *  width=300px;                                                初期値
040 *  height=180px;                                               初期値
041 *  CALL_JSP=/common/dragFiles.jsp;             初期値
042 *  UPLOAD_DIR=                                                 初期値 (filetemp/{@USER.ID})
043 *
044 *
045 * @og.rev 7.4.2.0 (2021/05/08) 新規追加
046 *
047 * @og.group データ編集
048 *
049 * @version  7.4
050 * @author   Kazuhiko Hasegawa
051 * @since    JDK11.0,
052 */
053public class Editor_UPLOAD2 extends AbstractEditor {
054        /** このプログラムのVERSION文字列を設定します。 {@value} */
055        private static final String VERSION = "7.4.2.0 (2021/05/08)" ;
056
057        private static final String JSP = HybsSystem.sys( "JSP" ) ;
058
059        private static final String CALL_JSP   = "/common/dragFiles.jsp" ;
060//      private static final String UPLOAD_DIR = "" ;           // 指定がない場合は、デフォルト( filetemp/{@USER.ID} )               8.0.0.0 (2021/07/31) 未使用
061                                                                                                                // dragFiles.jsp 内で、設定。jsp/ 以下のフォルダを指定
062
063        private static final String DEF_WIDTH  = "300px" ;
064//      private static final String DEF_HEIGHT = "180px" ;
065        private static final String DEF_HEIGHT = "135px" ;      // 8.0.1.0 (2021/10/29)
066
067//      private  String         name;
068
069        /**
070         * デフォルトコンストラクター。
071         * このコンストラクターで、基本オブジェクトを作成します。
072         *
073         */
074        public Editor_UPLOAD2() { super(); }            // これも、自動的に呼ばれるが、空のメソッドを作成すると警告されるので、明示的にしておきます。
075
076        /**
077         * DBColumnオブジェクトを指定したprivateコンストラクター。
078         *
079         * @og.rev 7.4.2.0 (2021/05/08) optionAttributesが使えるように修正。
080         *
081         * @param       clm     DBColumnオブジェクト
082         */
083        private Editor_UPLOAD2( final DBColumn clm ) {
084                super( clm );
085
086                final String name = clm.getName();
087
088                final Attributes attri = clm.getEditorAttributes()
089                                        .set( "width"   , DEF_WIDTH  )                  // 初期値として渡したい
090                                        .set( "height"  , DEF_HEIGHT );
091
092                // 7.4.2.0 (2021/05/08)
093                String srcURL = JSP + CALL_JSP ;
094                final String param = clm.getEditorParam();
095                if( param != null ) {
096                        final Map<String,String> prmMap = attri.getParamMap( param );           // param をMapに分解した物
097
098                        attri.set( "width"  , prmMap.get( "width"  )  );        // width 指定があれば使う
099                        attri.set( "height" , prmMap.get( "height" ) );         // width 指定があれば使う
100
101                        final String callJsp = prmMap.get( "CALL_JSP" ) ;
102                        if( callJsp != null && !callJsp.isEmpty() ) { srcURL = JSP + callJsp ; }
103
104                        final String urlOpt  = prmMap.get( "UPLOAD_DIR" ) ;
105                        if( urlOpt != null && !urlOpt.isEmpty() ) { srcURL += "?UPLOAD_DIR=" + urlOpt ; }
106                }
107
108                attributes = new Attributes()
109                                        .set( "name"    , name  )
110                                        .set( "id"              , name  )
111                                        .set( "src"             , srcURL  )
112                //                      .set( "width"   , "300px" )                     // 初期値として渡したい
113                //                      .set( "height"  , "180px" )
114                //                      .set( clm.getEditorAttributes() );      // #addAttributes( Attributes ) の代替え
115                                        .set( attri );                                          // #addAttributes( Attributes ) の代替え
116
117                tagBuffer.add( XHTMLTag.iframe( attributes , "" ) );
118        }
119
120        /**
121         * 各オブジェクトから自分のインスタンスを返します。
122         * 自分自身をキャッシュするのか、新たに作成するのかは、各サブクラスの実装に
123         * まかされます。
124         *
125         * @og.rev 7.4.2.0 (2021/05/08) ドラッグ&ドロップのファイルアップロードを追加
126         *
127         * @param       clm     DBColumnオブジェクト
128         *
129         * @return      CellEditorオブジェクト
130         * @og.rtnNotNull
131         */
132        public CellEditor newInstance( final DBColumn clm ) {
133                return new Editor_UPLOAD2( clm );
134        }
135        /**
136         * データの編集用文字列を返します。
137         *
138         * @og.rev 7.4.2.0 (2021/05/08) ドラッグ&ドロップのファイルアップロードを追加
139         *
140         * @param       value 値
141         *
142         * @return      データの編集用文字列
143         * @og.rtnNotNull
144         */
145        public String getValue( final String value ) {
146                return tagBuffer.makeTag();
147        }
148
149        /**
150         * name属性を変えた、データ表示/編集用のHTML文字列を作成します。
151         * テーブル上の name に 行番号を付加して、名前_行番号 で登録するキーを作成し,
152         * リクエスト情報を1つ毎のフィールドで処理できます。
153         *
154         * @og.rev 7.4.2.0 (2021/05/08) ドラッグ&ドロップのファイルアップロードを追加
155         *
156         * @param       row   行番号
157         * @param       value 値
158         *
159         * @return      データ表示/編集用の文字列
160         * @og.rtnNotNull
161         */
162        public String getValue( final int row,final String value ) {
163                return tagBuffer.makeTag();
164        }
165}