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     */
016    package org.opengion.plugin.column;
017    
018    import org.opengion.fukurou.util.Attributes;
019    import org.opengion.fukurou.util.XHTMLTag;
020    
021    import org.opengion.hayabusa.common.HybsSystem;
022    import org.opengion.hayabusa.common.HybsSystemException;
023    
024    import org.opengion.hayabusa.db.AbstractEditor;
025    import org.opengion.hayabusa.db.CellEditor;
026    import org.opengion.hayabusa.db.DBColumn;
027    import org.opengion.hayabusa.db.DBColumnConfig;
028    import org.opengion.hayabusa.resource.ResourceFactory;
029    import org.opengion.hayabusa.resource.ResourceManager;
030    import org.opengion.hayabusa.resource.LabelData;
031    
032    import java.util.Locale ;
033    
034    /**
035     * 動的カラãƒ??Entryカラãƒ?‚’ç·¨é›?™ã‚‹å?åˆã«ä½¿ç”¨ã™ã‚‹ã‚¨ãƒ?‚£ã‚¿ãƒ¼ã‚¯ãƒ©ã‚¹ã§ã™ã?
036     *
037     * Editor_ENTCLM ã¯ã€Editor_EntryColumn ã®ç•¥ã§ã€Editor_COLUMN.java ã‚?
038     * 強化ã—ãŸå½¢ã§ä½œæ?ã—ã¾ã™ã?
039     * ã“れã¯ã€å¼•æ•°ã®å€¤ã‚’キーã«ã€DBColumn ã‚’å‹•çš?«ä½œæ?ã™ã‚‹æ©Ÿè?ã«ãªã‚Šã¾ã™ã?
040     *
041     * Editor_COLUMN ã¨ã®é•ã„ã¯ã€ã“ã¡ã‚‰ã?ã€è¡Œã§ã¯ãªãã?Entryå½¢å¼ã?カラãƒ?‚’
042     * 作æ?ã™ã‚‹ã¨ã“ã‚ã§ã™ã?ã¤ã¾ã‚Šã?行番å·ã¯ã€?–¢ä¿‚ã‚りã¾ã›ã‚“ã€?
043     * 通常ã¯ã€ã‚«ãƒ©ãƒ?__è¡Œç•ªå· ã‚’ã‚­ãƒ¼ã¨ã™ã‚‹ãƒ?‚­ã‚¹ãƒˆãƒ•ィールドãªã©ã‚?
044     * 出力ã—ã¾ã™ãŒã€Editor_ENTCLM ã¯ã€åå‰ãã®ã‚‚ã?をキーã¨ã™ã‚‹
045     * ãƒ?‚­ã‚¹ãƒˆãƒ•ィールドãªã©ã‚’å?力ã—ã¾ã™ã?
046     * ã‚ã¨ã€ã‚«ãƒ©ãƒ?¼•æ•°(:ã§åŒºåˆ?‚‰ã‚ŒãŸå€¤)ãŒä½¿ãˆã¾ã™ã?
047     * 通常ã¯ã€å?(Value)ã«ã€ã‚«ãƒ©ãƒ?ã®ã¿ã‚’ã‚»ãƒ?ƒˆã—ã¾ã™ãŒã€ã‚³ãƒ­ãƒ³(:)ã§ã€?
048     * 区åˆ?£ã¦ãƒ‘ラメータを渡ã›ã¾ã™ã?
049     *
050     * カラãƒ?:値:must:Length:Label:Editor:DBType:EditParam ã®é ?•ªã§ã™ã?
051     *
052     * ã‚³ãƒ­ãƒ³ã®æ•°ã?‘åˆ?›¢ã—ã¾ã™ãŒã€æ•°ã¯å°‘ãªãã¦ã‚‚良ã?Œä¸¦ã³é ??ã€å¿??ã§ã™ã?
053     *
054     * 通常ã€ã“ã®ã¾ã¾ã§ã¯ã€ãƒªã‚½ãƒ¼ã‚¹ã«å­˜åœ¨ã™ã‚‹ã“ã¨ãŒå‰æã§ã™ãŒã€?
055     * ç·¨é›?ƒ‘ラメータã«ã€SAVE=TRUE ã¨ã?†ã‚­ãƒ¼ãƒ¯ãƒ¼ãƒ‰ã‚’ã‚»ãƒ?ƒˆã™ã‚‹ã¨ã€?
056     * 個ã?ã«ä½œæ?ã—ãŸå€¤ã‚’å?ã«ã€ResourceManager ã«ã€å‹•çš?«ä½œæ?ã—ãŸ
057     * LabelData を追åŠ?™ã‚‹æ©Ÿè?ã‚’æŒãŸã›ã¾ã™ã?
058     * ã“ã?ã€LabelData ã¯ã€??常ã®LabelDataLoaderã®ãƒ—ã?ルã§ã¯ãªãã?
059     * ResourceManagerã§ã€å?別ã«ç®¡ç?•れるãŸã‚ã€ç‰¹æ®Šãªæ–¹æ³•を使ã‚ãªã?¨
060     * 値をå–りå?ã™ã“ã¨ã¯ã§ãã¾ã›ã‚“ã€?
061     * ã“ã?キャãƒ?‚·ãƒ¥ã•れãŸãƒ©ãƒ™ãƒ«ã‚’用ã?‚‹ã“ã¨ã§ã€columnCheckã®ã‚¨ãƒ©ãƒ¼ãƒ¡ãƒ?‚»ãƒ¼ã‚¸
062     * ã®ãƒ©ãƒ™ãƒ«ã‚’å‹•çš?«æ›¸ãæ›ãˆãŸãƒ©ãƒ™ãƒ«ã§è¡¨ç¤ºã™ã‚‹ã“ã¨ãŒã§ãã¾ã™ã?
063     *
064     * ã•らã«ã€ç·¨é›?ƒ‘ラメータã«ã€QUERY=・・・・ ã¨ã?†ã‚­ãƒ¼ãƒ¯ãƒ¼ãƒ‰ã‚’
065     * ã‚»ãƒ?ƒˆã™ã‚‹ã¨ã€ãã®SQLåˆ?‚’実行ã—ã¦ã€ã‚³ãƒ¼ãƒ‰ãƒªã‚½ãƒ¼ã‚¹ã‚’作æ?ã—ã¾ã™ã?
066     * ã“ã¡ã‚‰ã?ã€SAVE=TRUE ã®å ´åˆã?ã¿å®Ÿè¡Œã•れã?コードリソースã®ã‚­ãƒ£ãƒ?‚·ãƒ¥ã«
067     * ã‚»ãƒ?ƒˆã•れã¾ã™ã?
068     *
069     * ã“ã?エãƒ?‚£ã‚¿ã¯eventColumnã«å¯¾å¿œã—ã¦ã?¾ã›ã‚“ã€?
070     *
071     * カラãƒ??表示ã«å¿?¦ãªå±žæ?ã¯, DBColumn オブジェクãƒ?よりå–り出ã—ã¾ã™ã?
072     * ã“ã?クラスã¯ã€DBColumn オブジェクト毎ã«?‘ã¤ä½œæ?ã•れã¾ã™ã?
073     * @og.group �?タ編�
074     *
075     * @og.rev 5.4.2.2 (2011/12/14) æ–°è¦è¿½åŠ??
076     *
077     * @version  4.0
078     * @author       Kazuhiko Hasegawa
079     * @since    JDK5.0,
080     */
081    public class Editor_ENTCLM extends AbstractEditor {
082            //* ã“ã?プログラãƒ??VERSIONæ–?­—å?を設定ã—ã¾ã™ã?       {@value} */
083            private static final String VERSION = "5.4.3.4 (2012/01/12)" ;
084    
085            private final String    lang ;
086            private final boolean   isSave ;
087            private final String    codeQuery ;
088            private final boolean   addNoValue ;            // 5.4.2.3 (2011/12/22)
089    
090            /**
091             * ãƒ?ƒ•ォルトコンストラクターã€?
092             * ã“ã?コンストラクターã§ã€åŸºæœ¬ã‚ªãƒ–ジェクトを作æ?ã—ã¾ã™ã?
093             *
094             * @og.rev 5.4.2.3 (2011/12/22) addNoValue 属æ?を追åŠ?—ã¾ã™ã?
095             */
096            public Editor_ENTCLM() {
097    //              super();
098                    lang            = null;
099                    isSave          = false;
100                    codeQuery       = null;
101                    addNoValue      = false;                // 5.4.2.3 (2011/12/22)
102            }
103    
104            /**
105             * ãƒ?ƒ•ォルトコンストラクターã€?
106             *
107             * @og.rev 5.4.2.3 (2011/12/22) addNoValue 属æ?を追åŠ?—ã¾ã™ã?
108             *
109             * @param       clm     DBColumnオブジェク�
110             */
111            private Editor_ENTCLM( final DBColumn clm ) {
112            //      super( clm );
113                    name = clm.getName();           // ã“ã“ã§ã?†åå‰ã¯ã€ã‚ªãƒªã‚¸ãƒŠãƒ«ãªã®ã§ã€å‹•çš?«ä½œæ?ã™ã‚‹ã¨ãã«ã¯ä½¿ç”¨ã—ãªã??
114                    lang = clm.getLang();
115                    addNoValue = clm.isAddNoValue() ;               // 5.4.2.3 (2011/12/22)
116    
117                    String orgParam = clm.getEditorParam();
118                    if( orgParam != null ) {
119                            String upParam = orgParam.toUpperCase(Locale.JAPAN);
120                            // ç·¨é›?ƒ‘ラメータã«ã€SAVE=TRUE ã¨ã?†ã‚­ãƒ¼ãƒ¯ãƒ¼ãƒ‰ãŒã‚ã‚‹ã‹ã©ã?‹ã®ãƒã‚§ãƒ?‚¯
121                            isSave = ( upParam.indexOf( "SAVE=TRUE" ) >= 0 );
122    
123                            // QUERY= ã®ã‚­ãƒ¼ãƒ¯ãƒ¼ãƒ‰ãŒã‚れã°ã€ã‚³ãƒ¼ãƒ‰ãƒªã‚½ãƒ¼ã‚¹ã®æ¤œç´¢ç”¨SQLã¨ãªã‚‹ã?(ãƒ‘ãƒ©ãƒ¡ãƒ¼ã‚¿ã®æ®‹ã‚Šã™ã¹ã¦)
124                            int adrs = upParam.indexOf( "QUERY=" );
125                            codeQuery = ( adrs >= 0 ) ? orgParam.substring( adrs+6,orgParam.length() ) : null;
126                    }
127                    else {
128                            isSave    = false;
129                            codeQuery = null;
130                    }
131            }
132    
133            /**
134             * å?‚ªãƒ–ジェクトã‹ã‚‰è?åˆ??インスタンスを返ã—ã¾ã™ã?
135             * 自åˆ??身をキャãƒ?‚·ãƒ¥ã™ã‚‹ã®ã‹ã?æ–°ãŸã«ä½œæ?ã™ã‚‹ã®ã‹ã?ã€å„サブクラスã®å®Ÿè£?«
136             * ã¾ã‹ã•れã¾ã™ã?
137             *
138             * @param       clm     DBColumnオブジェク�
139             *
140             * @return      CellEditorオブジェク�
141             */
142            public CellEditor newInstance( final DBColumn clm ) {
143                    return new Editor_ENTCLM( clm );
144            }
145    
146            /**
147             * ãƒ??ã‚¿ã®ç·¨é›?”¨æ–?­—å?ã‚’è¿”ã—ã¾ã™ã?
148             *
149             * 通常ã¯ã€å?(Value)ã«ã€ã‚«ãƒ©ãƒ?ã®ã¿ã‚’ã‚»ãƒ?ƒˆã—ã¾ã™ãŒã€ã‚³ãƒ­ãƒ³(:)ã§ã€?
150             * 区åˆ?£ã¦ãƒ‘ラメータを渡ã›ã¾ã™ã?
151             *
152             * カラãƒ?:値:must:Length:Label:Editor:DBType:EditParam ã®é ?•ªã§ã™ã?
153             *
154             * ã‚³ãƒ­ãƒ³ã®æ•°ã?‘åˆ?›¢ã—ã¾ã™ãŒã€æ•°ã¯å°‘ãªãã¦ã‚‚良ã?Œä¸¦ã³é ??ã€å¿??ã§ã™ã?
155             *
156             * @og.rev 5.4.2.3 (2011/12/22) addNoValue 属æ?を追åŠ?—ã¾ã™ã?
157             * @og.rev 5.4.3.4 (2012/01/12) official フラグをセãƒ?ƒˆã—ã¾ã™ã?パラメータã«ãƒ©ãƒ™ãƒ«è¿½åŠ?
158             *
159             * @param       value 入力å?
160             *
161             * @return      ãƒ??ã‚¿ã®è¡¨ç¤ºç”¨æ–?­—å?
162             */
163            @Override
164            public String getValue( final String value ) {
165                    // å…ˆé?æ–?­—㌠コロン(:)ã®å ´åˆã?ã€ã‚«ãƒ©ãƒ?ãŒçœç•¥ã•れã¦ã?‚‹ã®ã§ã€ã‚¨ãƒ©ãƒ¼
166                    if( value == null || value.isEmpty() || value.charAt(0) == ':'  ) {
167                            String errMsg = "æŒ?®šã?カラãƒ??値ãŒè¨­å®šã•れã¦ã?¾ã›ã‚“ã€?
168                                                    + HybsSystem.CR
169                                                    + "  name=[" + name + "]"
170                                                    + "  value=[" + value + "]";
171                            throw new HybsSystemException( errMsg );
172                    }
173    
174                    ResourceManager resource = ResourceFactory.newInstance( lang ) ;
175                    String[] vals = value.split( ":" , 8 );         // ?˜å?割ã—ã¾ã™ã?
176    
177                    String key    = vals[0];                                                                        // é…å??ã?ã€ã‚«ãƒ©ãƒ?
178                    String val    = (vals.length >= 2) ? vals[1] : null;         // é…å??‘ã?ã€å?
179                    String must   = (vals.length >= 3) ? vals[2] : null;         // é…å??’ã?ã€must
180                    String len    = (vals.length >= 4) ? vals[3] : null;         // é…å??“ã?ã€Length
181                    String lbl    = (vals.length >= 5) ? vals[4] : null;         // é…å??”ã?ã€Label
182                    String edit   = (vals.length >= 6) ? vals[5] : null;         // é…å??•ã?ã€Editor
183                    String dbtype = (vals.length >= 7) ? vals[6] : null;         // é…å??–ã?ã€DBType
184                    String edPrm  = (vals.length >= 8) ? vals[7] : null;         // é…å??—ã?ã€EditParam
185    
186                    boolean isMust = "1".equalsIgnoreCase( must ) || "true".equalsIgnoreCase( must ) ;      // mustãŒè¨­å®šã•れã¦ã?‚‹ã‹ã©ã?‹
187                    // キーã«å¯¾å¿œã™ã‚‹DBColumnãŒãªã‘れã°ã€null ãŒè¿”ã•れるã€?
188                    DBColumn dbColumn = resource.getDBColumn( key );
189    
190                    // DBColumnConfig ã§å€¤ã®ã‚»ãƒ?ƒˆ
191                    DBColumnConfig config = (dbColumn != null) ? dbColumn.getConfig() : new DBColumnConfig( key );
192    
193                    // 5.4.3.4 (2012/01/12) official フラグをセãƒ?ƒˆã—ã¾ã™ã?
194                    config.setOfficial( true );
195    
196                    // 5.4.2.3 (2011/12/22) addNoValue 属æ?を追åŠ?
197                    config.setAddNoValue( addNoValue );
198    
199                    String mstChStr = "";
200                    if( isMust ) {                  // é…å??’ã?ã€must
201                            Attributes editAttri = config.getEditorAttributes();
202                            if( editAttri == null ) { editAttri = new Attributes(); }
203                            editAttri.add( "class","must" );
204                            config.setEditorAttributes( editAttri );
205    
206                            // must æŒ?®šã?å ´åˆã«ã€ãƒã‚§ãƒ?‚¯ç”¨ã®hidden を作æ?ã—ã¾ã™ã?
207                            mstChStr = XHTMLTag.hidden( HybsSystem.MUST_KEY + "must", key );
208                    }
209                    if( len != null && !len.isEmpty() ) {                   // é…å??“ã?ã€Length
210                            config.setMaxlength( len );
211                    }
212                    // 5.4.3.4 (2012/01/12) パラメータã«ãƒ©ãƒ™ãƒ«è¿½åŠ?
213                    if( lbl != null && !lbl.isEmpty() ) {                   // é…å??”ã?ã€Label
214                            LabelData labelData = resource.getLabelData( lbl ) ;
215                            config.setLabelData( labelData );
216    //                      if( isSave ) {  // isSave ã?true ã§ã€ã‚»ãƒ¼ãƒ–ã™ã‚‹ã?
217    ////                    resource.setLabelData( key,labelData );
218    //                              resource.setLabel( key,lbl );
219    //                      }
220                    }
221                    if( edit != null && !edit.isEmpty() ) {                 // é…å??•ã?ã€Editor
222                            config.setEditor( edit );
223                    }
224                    if( dbtype != null && !dbtype.isEmpty() ) {             // é…å??–ã?ã€DBType
225                            config.setDbType( dbtype );
226                    }
227                    if( edPrm != null && !edPrm.isEmpty() ) {               // é…å??—ã?ã€EditParam
228                            config.setEditorParam( edPrm );
229                    }
230    
231                    // å‹•çš„ãªã‚³ãƒ¼ãƒ‰ãƒªã‚½ãƒ¼ã‚¹ã®ä½œæ?
232                    if( codeQuery != null && isSave ) {
233                            config.setCodeData( resource.getCodeData( key,codeQuery ) );
234                    }
235    
236                    dbColumn = new DBColumn( config );
237                    if( isSave ) {  // isSave ã?true ã§ã€ã‚»ãƒ¼ãƒ–ã™ã‚‹ã?
238                            resource.setDBColumn( key,dbColumn );
239                    }
240    
241                    // val 㨠must ã¯ã€ã‚­ãƒ£ãƒ?‚·ãƒ¥ã•れã?DBColumn ã¨åˆ¥ã«ã€æ¯Žå›žç•°ãªã‚‹ã‚±ãƒ¼ã‚¹ã‚’想定ã—ã¾ã™ã?
242                    return dbColumn.getEditorValue( val ) + mstChStr;
243            }
244    
245            /**
246             * ã“ã?クラスã§ã¯ã€Entryå½¢å¼ã?ç·¨é›?”¨ã®æ–?­—å?を作æ?ã—ã¾ã™ã?
247             * よã£ã¦ã€è¡Œç•ªå·ã‚’付加ã—ã¾ã›ã‚“ã€?
248             *
249             * @param       row   行番å·
250             * @param       value 入力å?
251             *
252             * @return      ãƒ??タ表示/ç·¨é›?”¨ã®æ–?­—å?
253             */
254            @Override
255            public String getValue( final int row,final String value ) {
256                    return getValue( value );
257            }
258    }