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.develop; 017 018import java.util.List; 019import java.util.Map; 020import java.util.Calendar; 021 022import org.opengion.hayabusa.develop.AbstractJspCreate; 023import org.opengion.hayabusa.develop.JspConvertEntity; 024import org.opengion.fukurou.xml.OGElement; 025import org.opengion.fukurou.xml.OGAttributes; 026import org.opengion.fukurou.util.HybsDateUtil; 027import org.opengion.fukurou.util.StringUtil; // 5.6.8.0 (2013/09/06) 028 029/** 030 * query.jspの<og:comment>タグを作成します。 031 * comment タグは、既存の 032 * 033 * ●使用例 034 * <og:comment 035 * system = ENTITY.getNmSys() 036 * pgid = ENTITY.getPgid() 037 * title = ENTITY.getNmpg() 038 * date = HybsDateUtil.getDate( "yyyy/MM/dd" ) 039 * author = "Auto Create" 040 * text = "" 041 * version = "001" 042 * /> 043 * 044 * @og.rev 5.6.1.2 (2013/02/22) 文字列連結から、XML処理するように変更します。 045 * 046 * @author Administrator 047 * 048 */ 049public class JspCreate_COMMENT extends AbstractJspCreate { 050 //* このプログラムのVERSION文字列を設定します。 {@value} */ 051 private static final String VERSION = "5.6.8.0 (2013/09/06)" ; 052 053 private static final String DEF_DATE_FORMAT = "yyyy/MM/dd" ; // 5.6.8.0 (2013/09/06) 054 private static final String DEF_AUTHOR_NAME = "Auto Create" ; // 5.6.8.0 (2013/09/06) 055 056 private List<JspConvertEntity> COMMENT_ROWS ; 057 private boolean IS_NULL ; 058 059 /** 060 * 初期化メソッド 061 * 062 * 内部で使用する JspConvertEntity の リスト のマップを受け取り、初期化を行います。 063 * @og.rev 5.2.1.0 (2010/10/01) 名前空間を、og 決め打ちから、名前空間指定無しに変更します。 064 * @og.rev 5.6.1.2 (2013/02/22) 処理対象のファイル名を指定するように変更します。 065 * 066 * @param master JspConvertEntityのリストのマップ 067 */ 068 @Override 069 protected void init( final Map<String,List<JspConvertEntity>> master ) { 070 COMMENT_ROWS = master.get("COMMENT"); 071 IS_NULL = !isNotEmpty( COMMENT_ROWS ); 072 KEY = ":comment"; // 5.2.1.0 (2010/10/01) 名前空間指定無し 073 NAME = "query,result,update,entry"; 074 } 075 076 /** 077 * ファイル名から、処理対象かどうかを判断します。 078 * 079 * @og.rev 5.6.1.2 (2013/02/22) 処理対象のファイル名を指定するため、廃止します。 080 * 081 * @param name 処理対象のファイル名 082 * 083 * @return 処理対象なら true/ そうでなければ、false 084 */ 085// @Override 086// protected boolean isExecute( final String name ) { 087// return ( name != null && name.indexOf( "index" ) < 0 && name.indexOf( "forward" ) < 0 ); 088// } 089 090 /** 091 * JSPに出力するタグの内容を作成します。 092 * 引数より作成前のタグの属性内容を確認するする事が出来ます。 093 * 094 * @og.rev 5.2.1.0 (2010/10/01) メソッドの引数を、OGAttributes から OGElement に変更します。 095 * @og.rev 5.2.1.0 (2010/10/01) 名前空間を、og 決め打ちから、引数を使用するように変更します。 096 * @og.rev 5.6.1.2 (2013/02/22) XML処理するように変更します。 097 * @og.rev 5.6.8.0 (2013/09/06) 日付はフォーマット変換します。author と text は更新しません。 098 * 099 * @param ele OGElementエレメントオブジェクト 100 * @param nameSpace このドキュメントのnameSpace( og とか mis とか ) 101 * 102 * @return 変換された文字列 103 * @throws Throwable 変換時のエラー 104 */ 105 @Override 106 protected String execute( final OGElement ele , final String nameSpace ) throws Throwable { 107 if( IS_NULL ) { return ""; } 108 109 // この OGElement の階層の深さを探ります。 110 // ele.getText( para ) とすることでXML全体を階層表示できる。 111 // int para = ele.getParentCount(); 112 113 JspConvertEntity ENTITY = COMMENT_ROWS.get(0); 114 115 OGAttributes attri = ele.getOGAttributes(); 116 117 // 5.6.8.0 (2013/09/06) 日付はフォーマット変換します。author は、あれば元の値を使います。 118 String dtFmt = StringUtil.nval( attri.getVal( "date" ) , DEF_DATE_FORMAT ); 119 String author = StringUtil.nval( attri.getVal( "author" ) , DEF_AUTHOR_NAME ); 120 121 attri.setUseCR( true ); 122 attri.setVal( "system" , ENTITY.getNmSys() ); 123 attri.setVal( "pgid" , ENTITY.getPgid() ); 124 attri.setVal( "title" , ENTITY.getNmpg() ); 125// attri.setVal( "date" , toDay() ); 126// attri.setVal( "date" , HybsDateUtil.getDate( "yyyy/MM/dd" ) ); // 5.6.1.2 (2013/02/22) 127// attri.setVal( "author" , "Auto Create" ); 128 attri.setVal( "date" , HybsDateUtil.getDate( dtFmt ) ); // 5.6.8.0 (2013/09/06) 129 attri.setVal( "author" , author ); // 5.6.8.0 (2013/09/06) 130// attri.setVal( "text" , "" ); // 5.6.8.0 (2013/09/06) 131 attri.setVal( "version" , "001" ); 132 133 return ele.getText( 0 ); 134 } 135 136 /** 137 * JSPに出力するタグの内容を作成します。 138 * 引数より作成前のタグの属性内容を確認するする事が出来ます。 139 * 140 * @og.rev 5.2.1.0 (2010/10/01) メソッドの引数を、OGAttributes から OGElement に変更します。 141 * @og.rev 5.2.1.0 (2010/10/01) 名前空間を、og 決め打ちから、引数を使用するように変更します。 142 * 143 * @param ele OGElementエレメントオブジェクト 144 * @param nameSpace このドキュメントのnameSpace( og とか mis とか ) 145 * 146 * @return 変換された文字列 147 * @throws Throwable 変換時のエラー 148 */ 149// @Override 150// protected String execute( final OGElement ele , final String nameSpace ) throws Throwable { 151// if( IS_NULL ) { return ""; } 152// 153// String ns = (nameSpace.length() == 0) ? "" : nameSpace + ":" ; // 5.2.1.0 (2010/10/01) 名前空間 154// 155// JspConvertEntity ENTITY = COMMENT_ROWS.get(0); 156// 157// // TODO Auto-generated method stub 158// //書き出す文字列を作成開始。 159// StringBuilder sbTub = new StringBuilder(); 160// sbTub.append( "<" ).append( ns ).append( "comment").append( CR ); 161// sbTub.append( "\tsystem = \"" ).append( ENTITY.getNmSys() ).append( "\"" ).append( CR ); 162// sbTub.append( "\tpgid = \"" ).append( ENTITY.getPgid() ).append( "\"" ).append( CR ); 163// sbTub.append( "\ttitle = \"" ).append( ENTITY.getNmpg() ).append( "\"" ).append( CR ); 164// sbTub.append( "\tdate = \"" ).append( toDay() ).append( "\"" ).append( CR ); 165// sbTub.append( "\tauthor = \"" ).append( "Auto Create" ).append( "\"" ).append( CR ); 166// sbTub.append( "\ttext = \"" ).append( "" ).append( "\"" ).append( CR ); 167// sbTub.append( "\tversion = \"" ).append( "001" ).append( "\"" ).append( CR ); 168// sbTub.append( "/>" ).append( CR ); 169// return sbTub.toString(); 170// } 171 172 /** 173 * 現在の日付(yyyy/MM/dd)を取得。 174 * 175 * @return 現在の日付 176 */ 177// private String toDay(){ 178// //インスタンス化 179// Calendar now = Calendar.getInstance(); 180// 181// int year = now.get(Calendar.YEAR); 182// int mm = now.get(Calendar.MONTH) + 1; 183// int dd = now.get(Calendar.DATE); 184// 185// String month = String.valueOf( mm ); 186// if (mm < 10){ 187// month = "0" + month ; 188// } 189// String day = String.valueOf( dd ); 190// if (dd < 10){ 191// day = "0" + day ; 192// } 193// return year + "/" + month + "/" + day; 194// } 195}