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
066//      private  String         name;
067
068        /**
069         * デフォルトコンストラクター。
070         * このコンストラクターで、基本オブジェクトを作成します。
071         *
072         */
073        public Editor_UPLOAD2() { super(); }            // これも、自動的に呼ばれるが、空のメソッドを作成すると警告されるので、明示的にしておきます。
074
075        /**
076         * DBColumnオブジェクトを指定したprivateコンストラクター。
077         *
078         * @og.rev 7.4.2.0 (2021/05/08) optionAttributesが使えるように修正。
079         *
080         * @param       clm     DBColumnオブジェクト
081         */
082        private Editor_UPLOAD2( final DBColumn clm ) {
083                super( clm );
084
085                final String name = clm.getName();
086
087                final Attributes attri = clm.getEditorAttributes()
088                                        .set( "width"   , DEF_WIDTH  )                  // 初期値として渡したい
089                                        .set( "height"  , DEF_HEIGHT );
090
091                // 7.4.2.0 (2021/05/08)
092                String srcURL = JSP + CALL_JSP ;
093                final String param = clm.getEditorParam();
094                if( param != null ) {
095                        final Map<String,String> prmMap = attri.getParamMap( param );           // param をMapに分解した物
096
097                        attri.set( "width"  , prmMap.get( "width"  )  );        // width 指定があれば使う
098                        attri.set( "height" , prmMap.get( "height" ) );         // width 指定があれば使う
099
100                        final String callJsp = prmMap.get( "CALL_JSP" ) ;
101                        if( callJsp != null && !callJsp.isEmpty() ) { srcURL = JSP + callJsp ; }
102
103                        final String urlOpt  = prmMap.get( "UPLOAD_DIR" ) ;
104                        if( urlOpt != null && !urlOpt.isEmpty() ) { srcURL += "?UPLOAD_DIR=" + urlOpt ; }
105                }
106
107                attributes = new Attributes()
108                                        .set( "name"    , name  )
109                                        .set( "id"              , name  )
110                                        .set( "src"             , srcURL  )
111                //                      .set( "width"   , "300px" )                     // 初期値として渡したい
112                //                      .set( "height"  , "180px" )
113                //                      .set( clm.getEditorAttributes() );      // #addAttributes( Attributes ) の代替え
114                                        .set( attri );                                          // #addAttributes( Attributes ) の代替え
115
116                tagBuffer.add( XHTMLTag.iframe( attributes , "" ) );
117        }
118
119        /**
120         * 各オブジェクトから自分のインスタンスを返します。
121         * 自分自身をキャッシュするのか、新たに作成するのかは、各サブクラスの実装に
122         * まかされます。
123         *
124         * @og.rev 7.4.2.0 (2021/05/08) ドラッグ&ドロップのファイルアップロードを追加
125         *
126         * @param       clm     DBColumnオブジェクト
127         *
128         * @return      CellEditorオブジェクト
129         * @og.rtnNotNull
130         */
131        public CellEditor newInstance( final DBColumn clm ) {
132                return new Editor_UPLOAD2( clm );
133        }
134        /**
135         * データの編集用文字列を返します。
136         *
137         * @og.rev 7.4.2.0 (2021/05/08) ドラッグ&ドロップのファイルアップロードを追加
138         *
139         * @param       value 値
140         *
141         * @return      データの編集用文字列
142         * @og.rtnNotNull
143         */
144        public String getValue( final String value ) {
145                return tagBuffer.makeTag();
146        }
147
148        /**
149         * name属性を変えた、データ表示/編集用のHTML文字列を作成します。
150         * テーブル上の name に 行番号を付加して、名前_行番号 で登録するキーを作成し,
151         * リクエスト情報を1つ毎のフィールドで処理できます。
152         *
153         * @og.rev 7.4.2.0 (2021/05/08) ドラッグ&ドロップのファイルアップロードを追加
154         *
155         * @param       row   行番号
156         * @param       value 値
157         *
158         * @return      データ表示/編集用の文字列
159         * @og.rtnNotNull
160         */
161        public String getValue( final int row,final String value ) {
162                return tagBuffer.makeTag();
163        }
164}