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.table;
017
018 import java.util.Locale;
019 import java.util.Map;
020
021 import org.opengion.hayabusa.db.AbstractTableFilter;
022 import org.opengion.hayabusa.db.DBTableModel;
023
024 import org.opengion.fukurou.util.ErrorMessage;
025 import org.opengion.fukurou.util.StringUtil;
026
027 /**
028 * TableFilter_UPPER は、TableFilter インターフェースを継承した、DBTableModel 処ç�?”¨の
029 * 実è£?‚¯ラスですã?
030 *
031 * ここでは、指定ã? カラãƒ?KEY_CLMS) に対して、データを大æ–?—化しますã?
032 * カラãƒ??、CSV形式でæŒ?®šする事としã?DBTableModel にæŒ?®šã?カラãƒ?�Œなければ無視しますã?
033 *
034 * パラメータは、tableFilterタグの keys, vals にそれぞれ記述するかã?BODY 部にCSS形式で記述しますã?
035 * 【パラメータã€?
036 * {
037 * KEY_CLMS : AA,BB,CC ; ãƒ??タを大æ–?—化したã�?‚«ラãƒ?��をã?CSV形式でæŒ?®šしますã?
038 * }
039 *
040 * @og.formSample
041 * ●形式ï¼?
042 * â‘?<og:tableFilter classId="UPPER" keys="KEY_CLMS" vals='"TABLE_NAME,CLM"' />
043 *
044 * ② <og:tableFilter classId="UPPER" >
045 * {
046 * KEY_CLMS : TABLE_NAME,CLM ;
047 * }
048 * </og:tableFilter>
049 *
050 * @og.rev 5.5.5.0 (2012/07/28) 新規追åŠ?
051 * @og.rev 5.6.6.0 (2013/07/05) keys の整合æ?チェãƒ?‚¯を追åŠ?
052 *
053 * @version 0.9.0 2000/10/17
054 * @author Kazuhiko Hasegawa
055 * @since JDK1.1,
056 */
057 public class TableFilter_UPPER extends AbstractTableFilter {
058 //* こã?プログラãƒ??VERSIONæ–?—å?を設定しますã? {@value} */
059 private static final String VERSION = "5.6.6.1 (2013/07/12)" ;
060
061 /**
062 * keys の整合æ?チェãƒ?‚¯を行うための初期設定を行いますã?
063 *
064 * @og.rev 5.6.6.1 (2013/07/12) keys の整合æ?チェãƒ?‚¯対å¿?
065 *
066 * @param keysMap keys の整合æ?チェãƒ?‚¯を行うための Map
067 */
068 @Override
069 protected void init( final Map<String,String> keysMap ) {
070 keysMap.put( "KEY_CLMS" , "大æ–?—化したã�?‚«ラãƒ?��をã?CSV形式でæŒ?®? );
071 }
072
073 /**
074 * DBTableModel処ç�?‚’実行しますã?
075 *
076 * @return 処ç�?µ�果のDBTableModel
077 */
078 public DBTableModel execute() {
079 DBTableModel table = getDBTableModel(); // 5.5.2.6 (2012/05/25) インターフェースにgetterメソãƒ?ƒ‰追åŠ?
080
081 String[] keyClms = StringUtil.csv2Array( getValue( "KEY_CLMS" ) );
082
083 if ( keyClms == null || keyClms.length == 0 ) { return table; } // KEY_CLMSがã?存在しなかったã?
084
085 int[] keyNos = new int[keyClms.length];
086 int lastNo = 0;
087 for ( int i = 0; i < keyNos.length; i++ ) {
088 int no = table.getColumnNo( keyClms[i], false ); // 存在しなã�??合ã?ã€?1 を返すã€?
089 if( no >=0 ) { keyNos[lastNo++] = no; } // -1 でなければ、keyNos に設定するã??ˆ前づã‚?¼?
090 }
091
092 if( lastNo == 0 ) { return table; } // 対象のカラãƒ?�Œ、すべて存在しなかったã?
093
094 int rowCnt = table.getRowCount();
095 for( int row=0; row<rowCnt; row++ ) {
096 try {
097 for( int j=0; j<lastNo; j++ ) {
098 int col = keyNos[j];
099 String val = table.getValue( row,col );
100 if( val != null ) {
101 val = val.toUpperCase( Locale.JAPAN );
102 table.setValueAt( val,row,col );
103 }
104 }
105 }
106 catch( RuntimeException ex ) {
107 ErrorMessage errMessage = makeErrorMessage( "TableFilter_UPPER Error",ErrorMessage.NG );
108 errMessage.addMessage( row+1,ErrorMessage.NG,ex.getMessage() );
109 errMessage.addMessage( row+1,ErrorMessage.NG,"KEY_CLMS=[" + StringUtil.array2csv( keyClms ) + "]" );
110 errMessage.addMessage( row+1,ErrorMessage.NG,"row=[" + row + "]" );
111 }
112 }
113
114 return table;
115 }
116 }