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.system.DateSet;                                                     // 6.4.2.0 (2016/01/29)
024import org.opengion.fukurou.xml.OGElement;
025import org.opengion.fukurou.xml.OGAttributes;
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     = DateSet.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 = "6.3.9.1 (2015/11/27)" ;
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        // 6.3.9.1 (2015/11/27) Variables should start with a lowercase character(PMD)
056        private List<JspConvertEntity> commentROWS ;
057        private boolean isNULL ;
058
059        /**
060         * コンストラクター
061         *
062         * インスタンス構築時に、タグ名(key)とファイル名(names)を指定します。
063         *
064         * @og.rev 6.3.9.1 (2015/11/27) コンストラクタを用意して、KEY,NAME をセットするように変更します。
065         */
066        public JspCreate_COMMENT() {
067                super( ":comment" , "query,result,update,entry" );
068        }
069
070        /**
071         * 初期化メソッド
072         *
073         * 内部で使用する JspConvertEntity の リスト のマップを受け取り、初期化を行います。
074         * @og.rev 5.2.1.0 (2010/10/01) 名前空間を、og 決め打ちから、名前空間指定無しに変更します。
075         * @og.rev 5.6.1.2 (2013/02/22) 処理対象のファイル名を指定するように変更します。
076         *
077         * @param       master  JspConvertEntityのリストのマップ
078         */
079        @Override
080        protected void init( final Map<String,List<JspConvertEntity>> master ) {
081                commentROWS = master.get("COMMENT");                                            // 6.3.9.1 (2015/11/27)
082                isNULL = !isNotEmpty( commentROWS );                                            // 6.3.9.1 (2015/11/27)
083        }
084
085        /**
086         * JSPに出力するタグの内容を作成します。
087         * 引数より作成前のタグの属性内容を確認するする事が出来ます。
088         *
089         * @og.rev 5.2.1.0 (2010/10/01) メソッドの引数を、OGAttributes から OGElement に変更します。
090         * @og.rev 5.2.1.0 (2010/10/01) 名前空間を、og 決め打ちから、引数を使用するように変更します。
091         * @og.rev 5.6.1.2 (2013/02/22) XML処理するように変更します。
092         * @og.rev 5.6.8.0 (2013/09/06) 日付はフォーマット変換します。author と text は更新しません。
093         *
094         * @param ele OGElementエレメントオブジェクト
095         * @param       nameSpace       このドキュメントのnameSpace( og とか mis とか )
096         *
097         * @return      変換された文字列
098         * @og.rtnNotNull
099         * @throws Throwable 変換時のエラー
100         */
101        @Override
102        protected String execute( final OGElement ele , final String nameSpace )  throws Throwable {
103                if( isNULL ) { return ""; }                                                                                                     // 6.3.9.1 (2015/11/27)
104
105                // この OGElement の階層の深さを探ります。
106                // ele.getText( para ) とすることでXML全体を階層表示できる。
107        //      int para = ele.getParentCount();
108
109                final JspConvertEntity ENTITY = commentROWS.get(0);                                                     // 6.3.9.1 (2015/11/27)
110
111                final OGAttributes attri = ele.getOGAttributes();
112
113                // 5.6.8.0 (2013/09/06) 日付はフォーマット変換します。author は、あれば元の値を使います。
114                final String dtFmt  = StringUtil.nval( attri.getVal( "date"   ) , DEF_DATE_FORMAT );
115                final String author = StringUtil.nval( attri.getVal( "author" ) , DEF_AUTHOR_NAME );
116
117                attri.setUseCR( true );
118                attri.setVal( "system"  , ENTITY.getNmSys()     );
119                attri.setVal( "pgid"    , ENTITY.getPgid()      );
120                attri.setVal( "title"   , ENTITY.getNmpg()      );
121                attri.setVal( "date"    , DateSet.getDate( dtFmt ) );                           // 5.6.8.0 (2013/09/06)
122                attri.setVal( "author"  , author        );                                                                      // 5.6.8.0 (2013/09/06)
123                attri.setVal( "version" , "001"                         );
124
125                return ele.getText( 0 );
126        }
127}