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;
020
021import org.opengion.hayabusa.develop.AbstractJspCreate;
022import org.opengion.hayabusa.develop.JspConvertEntity;
023import org.opengion.fukurou.xml.OGElement;
024import org.opengion.fukurou.xml.OGAttributes;
025import org.opengion.fukurou.util.HybsDateUtil;
026import org.opengion.fukurou.util.StringUtil;                    // 5.6.8.0 (2013/09/06)
027
028/**
029 * query.jspの<og:comment>タグを作成します。
030 * comment タグは、既存の
031 *
032 * ●使用例
033 *      <og:comment
034 *          system   = ENTITY.getNmSys() 
035 *          pgid     = ENTITY.getPgid()  
036 *          title    = ENTITY.getNmpg()  
037 *          date     = HybsDateUtil.getDate( "yyyy/MM/dd" ) 
038 *          author   = "Auto Create"     
039 *          text     = ""                
040 *          version  = "001"             
041 *      />
042 *
043 * @og.rev 5.6.1.2 (2013/02/22) 文字列連結から、XML処理するように変更します。
044 *
045 * @author Administrator
046 *
047 */
048public class JspCreate_COMMENT extends AbstractJspCreate {
049        //* このプログラムのVERSION文字列を設定します。   {@value} */
050        private static final String VERSION = "5.6.8.0 (2013/09/06)" ;
051
052        private static final String DEF_DATE_FORMAT = "yyyy/MM/dd" ;            // 5.6.8.0 (2013/09/06)
053        private static final String DEF_AUTHOR_NAME = "Auto Create" ;           // 5.6.8.0 (2013/09/06)
054
055        private List<JspConvertEntity> COMMENT_ROWS ;
056        private boolean IS_NULL ;
057
058        /**
059         * 初期化メソッド
060         *
061         * 内部で使用する JspConvertEntity の リスト のマップを受け取り、初期化を行います。
062         * @og.rev 5.2.1.0 (2010/10/01) 名前空間を、og 決め打ちから、名前空間指定無しに変更します。
063         * @og.rev 5.6.1.2 (2013/02/22) 処理対象のファイル名を指定するように変更します。
064         *
065         * @param       master  JspConvertEntityのリストのマップ
066         */
067        @Override
068        protected void init( final Map<String,List<JspConvertEntity>> master ) {
069                COMMENT_ROWS = master.get("COMMENT");
070                IS_NULL = !isNotEmpty( COMMENT_ROWS );
071                KEY  = ":comment";              // 5.2.1.0 (2010/10/01) 名前空間指定無し
072                NAME = "query,result,update,entry";
073        }
074
075        /**
076         * JSPに出力するタグの内容を作成します。
077         * 引数より作成前のタグの属性内容を確認するする事が出来ます。
078         *
079         * @og.rev 5.2.1.0 (2010/10/01) メソッドの引数を、OGAttributes から OGElement に変更します。
080         * @og.rev 5.2.1.0 (2010/10/01) 名前空間を、og 決め打ちから、引数を使用するように変更します。
081         * @og.rev 5.6.1.2 (2013/02/22) XML処理するように変更します。
082         * @og.rev 5.6.8.0 (2013/09/06) 日付はフォーマット変換します。author と text は更新しません。
083         *
084         * @param ele OGElementエレメントオブジェクト
085         * @param       nameSpace       このドキュメントのnameSpace( og とか mis とか )
086         *
087         * @return      変換された文字列
088         * @throws Throwable 変換時のエラー
089         */
090        @Override
091        protected String execute( final OGElement ele , final String nameSpace )  throws Throwable {
092                if( IS_NULL ) { return ""; }
093
094                // この OGElement の階層の深さを探ります。
095                // ele.getText( para ) とすることでXML全体を階層表示できる。
096        //      int para = ele.getParentCount();
097
098                JspConvertEntity ENTITY = COMMENT_ROWS.get(0);
099
100                OGAttributes attri = ele.getOGAttributes();
101
102                // 5.6.8.0 (2013/09/06) 日付はフォーマット変換します。author は、あれば元の値を使います。
103                String dtFmt  = StringUtil.nval( attri.getVal( "date"   ) , DEF_DATE_FORMAT );
104                String author = StringUtil.nval( attri.getVal( "author" ) , DEF_AUTHOR_NAME );
105
106                attri.setUseCR( true );
107                attri.setVal( "system"  , ENTITY.getNmSys()     );
108                attri.setVal( "pgid"    , ENTITY.getPgid()      );
109                attri.setVal( "title"   , ENTITY.getNmpg()      );
110                attri.setVal( "date"    , HybsDateUtil.getDate( dtFmt ) );                              // 5.6.8.0 (2013/09/06)
111                attri.setVal( "author"  , author        );                                                                      // 5.6.8.0 (2013/09/06)
112                attri.setVal( "version" , "001"                         );
113
114                return ele.getText( 0 );
115        }
116}