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.hayabusa.db; 017 018import org.opengion.hayabusa.common.HybsSystem; 019import org.opengion.fukurou.util.StringFormat; 020import org.opengion.fukurou.util.StringUtil; 021 022/** 023 * 動的プルダウンなどで利用されるイベントカラムの各種情報を保持するための 024 * 管理クラスです。 025 * 026 * 内容を置き換えるカラム(子カラム)の名前をキーに、イベントカラム(親カラム)や、 027 * イベント発行時の処理URL等を管理します。 028 * 029 * これらの情報は、ColumnTagやSelectTag、ViewFormTagなどで登録され、その結果を 030 * JavaScriptのコードとして出力します。(common/eventColumn.jsp) 031 * 032 * ここで出力された情報をイベント発行時に、JavaScriptが参照し、処理URLに渡す 033 * ことで、動的な項目の入れ替えを実現しています。 034 * 035 * @og.rev 5.1.7.0 (2010/06/01) 新規追加 036 * @og.rev 5.9.0.1 (2015/09/11) アンダースコア対応 037 * 038 * @version 4.0 039 * @author Hiroki Nakamura 040 * @since JDK5.0, 041 */ 042public class DBEventColumn { 043 044 private static final String EVENT_COLUMN_URL = HybsSystem.sys( "JSP" ) + "/" + HybsSystem.sys( "EVENT_COLUMN_URL" ); 045 046 final String name; // 内容を置き換えるカラム(子カラム) 047 final String evCol; // イベントカラム(親カラム・カンマ区切り) 048 final String eventUrl; // イベント発行時の処理URL 049 final String renderer; // 子カラムのレンデラー 050 final String editor; // 子カラムのエディター 051 final String rendParam; // 子カラムの表示パラメーター 052 final String editParam; // 子カラムの編集パラメーター 053 054 /** 055 * 初期情報を含んだ新規オブジェクトを作成します。 056 * 057 * @param name 内容を置き換えるカラム(子カラム) 058 * @param evCol イベントカラム(親カラム・カンマ区切り) 059 * @param eventUrl イベント発行時の処理URL 060 * @param renderer 子カラムのレンデラー 061 * @param editor 子カラムのエディター 062 * @param rendParam 子カラムの表示パラメーター 063 * @param editParam 子カラムの編集パラメーター 064 */ 065 public DBEventColumn( final String name, final String evCol, final String eventUrl, 066 final String renderer, final String editor, final String rendParam, final String editParam ) { 067 this.name = name; 068 this.evCol = evCol; 069 // 5.1.9.0 (2010/08/01) 動的プルダウン不具合対応 070 this.eventUrl = ( eventUrl != null && eventUrl.length() > 0 ) ? eventUrl : EVENT_COLUMN_URL; 071 this.renderer = renderer; 072 this.editor = editor; 073 this.rendParam = rendParam; 074 this.editParam = editParam; 075 } 076 077 /** 078 * 内容を置き換えるカラム(子カラム)を返します。 079 * 080 * @return 内容を置き換えるカラム(子カラム) 081 */ 082 public String getName() { return name; } 083 084 /** 085 * イベントカラム(親カラム・カンマ区切り)を返します。 086 * 087 * @return イベントカラム(親カラム・カンマ区切り) 088 */ 089 public String getEventColumn() { return evCol; } 090 091 /** 092 * イベント発行時の処理URLを返します。 093 * 094 * @og.rev 5.1.8.0 (2010/07/01) getEventUrl ⇒ getEventURL に変更 095 * 096 * @return イベント発行時の処理URL 097 */ 098// public String getEventUrl() { return eventUrl; } 099 public String getEventURL() { return eventUrl; } 100 101 /** 102 * 子カラムのレンデラーを返します。 103 * 104 * @return 子カラムのレンデラー 105 */ 106 public String getRenderer() { return renderer; } 107 108 /** 109 * 子カラムのエディターを返します。 110 * 111 * @return 子カラムのエディター 112 */ 113 public String getEditor() { return editor; } 114 115 /** 116 * 子カラムの表示パラメーターを返します。 117 * 118 * @og.rev 5.9.0.1 (2015/09/11) アンダースコア対応 119 * 120 * @return 子カラムの表示パラメーター 121 */ 122 public String getRendParam() { 123 StringFormat sf = new StringFormat( 124 rendParam 125// ,"{@" + evCol.replace( ",", "}:{@" ) + "}" 126 ,"{@" + evColReplace(evCol).replace( ",", "}:{@" ) + "}" 127 ,name ); 128 return sf.format(); 129 } 130 131 /** 132 * 子カラムの編集パラメーターを返します。 133 * 134 * @og.rev 5.9.0.1 (2015/09/11) アンダースコア対応 135 * 136 * @return 子カラムの編集パラメーター 137 */ 138 public String getEditParam() { 139 StringFormat sf = new StringFormat( 140 editParam 141// ,"{@" + evCol.replace( ",", "}:{@" ) + "}" 142 ,"{@" + evColReplace(evCol).replace( ",", "}:{@" ) + "}" 143 ,name ); 144 return sf.format(); 145 } 146 147 /** 148 * カンマ区切りのカラム名から先頭のアンダースコアを外します。 149 * 150 * @og.rev 5.9.0.1 (2015/09/11) 新規作成 151 * 152 * @param inStr カンマ区切りイベントカラム 153 * @return 先頭アンダースコアを外したカンマ区切り文字列 154 */ 155 private String evColReplace( final String inStr ){ 156 final String[] to; 157 if( inStr != null && inStr.indexOf( ',' ) >= 0 ) { 158 to = StringUtil.csv2Array( inStr, ',' ); 159 } 160 else { 161 to = new String[] { inStr }; 162 } 163 164 165 for( int i = 0; i < to.length; i++ ) { 166 if( to[i].charAt( 0 ) == '_'){ 167 to[i] = to[i].substring( 1 ); 168 } 169 } 170 171 return org.opengion.fukurou.util.StringUtil.array2csv(to); 172 } 173}