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.hayabusa.develop;
017
018 import java.util.Map;
019 import java.util.List;
020
021 import org.opengion.fukurou.xml.JspParserFilter;
022 import org.opengion.fukurou.xml.OGDocument;
023 import org.opengion.fukurou.xml.OGElement;
024 import org.opengion.fukurou.xml.OGNode;
025
026 import org.opengion.fukurou.util.FileUtil;
027
028 /**
029 * コンストラクタに引数で与えられた?スタ??タ??を?に、特定?JSPタグ??を生成する基底クラス?
030 * マスタ??タ??はGF92のNMSYORIカラ??種別毎にJspConvertEntityオブジェクトに事前に準備する?がある?
031 *
032 * ?
033 * JspConvertEntity e = new JspConvertEntity("RESULT");
034 * e.setTableName("GF92");
035 * e.setColumnName("NMSYORI");
036 *
037 *
038 * 継承先?クラスのexecuteメソ?では、引数のマスタ??タ??からJSPタグの??を生成する??実?ます?
039 *
040 * @author Takeshi.Takada
041 *
042 */
043 public abstract class AbstractJspCreate implements JspParserFilter {
044
045 /** 出力?のシス?に応じた改行コー?*/
046 public static final String CR = System.getProperty("line.separator");
047
048 /** タブを定数化しておきます? */
049 public static final String T1 = "\t" ; // 5.6.4.4 (2013/05/31) タブを定数化しておきます?
050 public static final String T2 = "\t\t" ; // 5.6.4.4 (2013/05/31) タブを定数化しておきます?
051 public static final String T3 = "\t\t\t" ; // 5.6.4.4 (2013/05/31) タブを定数化しておきます?
052
053 // 5.6.1.2 (2013/02/22) 初期値を設定?NAME は、?のファイル名をカンマ区??で与えられるよ?想定を変更?
054 protected String KEY = null;
055 protected String NAME = "";
056
057 /**
058 * ファイル名から?処?象かど?を判断します?
059 * ファイル名?、拡張子なし?ファイル?index,query,result,・・・)などになります?
060 * 先に?して?ファイル名と部???するかど?で判定します?
061 *
062 * @og.rev 5.6.1.2 (2013/02/22) NAME は、?のファイル名をカンマ区??で与えられるよ?変更?
063 *
064 * @param name 処?象のファイル?
065 *
066 * @return 処?象な?true/ そうでなければ、false
067 */
068 protected boolean isExecute( final String name ) {
069 return NAME.contains( FileUtil.getBaseName( name ) ) ;
070 }
071
072 /**
073 * 初期化メソ?
074 *
075 * ?で使用する JspConvertEntity の List のマップを受け取り、?期化を行います?
076 *
077 * @param master JspConvertEntityのリスト?マッ?
078 */
079 abstract protected void init( final Map<String,List<JspConvertEntity>> master );
080
081 /**
082 * JSPに出力するタグの?を作?します?
083 * 引数より作?前?タグの属??を確認するする事が出来ます?
084 *
085 * @og.rev 5.2.1.0 (2010/10/01) メソ?の引数を?OGAttributes から OGElement に変更します?
086 *
087 * @param ele エレメントオブジェク?
088 * @param nameSpace こ?ドキュメント?nameSpace( og と?mis と?)
089 *
090 * @return 変換された文字?
091 * @throws Throwable 変換時?エラー
092 */
093 abstract protected String execute( final OGElement ele , final String nameSpace ) throws Throwable ;
094
095 /**
096 * ドキュメントオブジェク?を変換します?
097 *
098 * 引数に null が設定された場合も、正常に処?行います?(return null とする)
099 * 後続??行いたくな??合にも?null を返します?
100 *
101 * @og.rev 5.2.1.0 (2010/10/01) メソ?の引数を?OGAttributes から OGElement に変更します?
102 *
103 * @param doc 処?行う ドキュメントオブジェク?
104 *
105 * @return 処?た結果の ドキュメントオブジェク?
106 * @see org.opengion.fukurou.xml.JspParserFilter#filter( OGDocument )
107 */
108 @Override
109 public OGDocument filter( final OGDocument doc ) {
110 if( doc == null ) { return doc; }
111 OGDocument rtndoc = doc;
112
113 String name = doc.getFilename();
114 if( isExecute( name ) && KEY != null ) {
115 try {
116 String nameSpace = doc.getNameSpace();
117 String key = (KEY.indexOf( ':' ) == 0 ) ? nameSpace + KEY : KEY ;
118
119 List<OGElement> list = doc.getElementList( key );
120 for( OGElement ele : list ) {
121 OGNode newNode = new OGNode( execute( ele,nameSpace ) ); // 5.2.1.0 (2010/10/01)
122 rtndoc.changeNode( ele,newNode );
123 }
124 } catch ( Throwable th ) {
125 th.printStackTrace();
126 }
127 }
128 return rtndoc;
129 }
130
131 /**
132 * 引数のリストを連結文字?で連結した文字?を作?して返します?
133 *
134 * @param list 処?行うドキュメントリス?
135 * @param sep 連結する区???
136 *
137 * @return 連結された??
138 */
139 protected String chainChar( final List<String> list , final String sep ){
140 StringBuilder buf = new StringBuilder();
141
142 for( String st : list ) {
143 if( buf.length() > 0 ) {
144 buf.append( sep ) ;
145 }
146 buf.append( st ) ;
147 }
148 return buf.toString();
149 }
150
151 /**
152 * ??Listオブジェクトが null でなく?かつ、空でな?、判定する?
153 *
154 * @og.rev 5.2.1.0 (2010/10/01) 新規追?
155 *
156 * @param list 、判定するListオブジェク?
157 *
158 * @return nullでなく?かつ、空でな??合?true
159 */
160 protected boolean isNotEmpty( final List<JspConvertEntity> list ) {
161 return ( list != null && !list.isEmpty() ) ;
162 }
163 }