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.taglib;
017
018 import org.opengion.hayabusa.common.HybsSystem;
019 import org.opengion.hayabusa.common.HybsSystemException;
020 import org.opengion.fukurou.util.StringUtil;
021
022 import static org.opengion.fukurou.util.StringUtil.nval ;
023
024 import org.opengion.fukurou.util.Shell;
025
026 import java.io.File;
027
028 /**
029 * ãƒã‚¤ãƒ?‚£ãƒ–ãªãƒ—ãƒã‚»ã‚¹ã‚’作æ?ã—ã?ãƒãƒƒãƒãƒ•ァイルã‚?‚¢ãƒ—リケーションを起動ã™ã‚‹ã‚¿ã‚°ã§ã™ã?
030 *
031 * プãƒã‚»ã‚¹ã®çŠ¶æ…‹ã«å¿œã˜ã¦ã€ä¸‹è¨˜ã?リターンコードãŒå¾—られã¾ã™ã?
032 *
033 * SHELL.RTN_CODE = 0 : æ£å¸¸ (ペã?ã‚¸ã®æ®‹ã‚Šã‚’評価ã™ã‚‹ã€?
034 * SHELL.RTN_CODE = 1 : 処ç?¸ (ペã?ã‚¸ã®æ®‹ã‚Šã‚’評価ã™ã‚‹ã€?
035 * SHELL.RTN_CODE = 9 : å–æ¶? (ペã?ã‚¸ã®æ®‹ã‚Šã‚’評価ã™ã‚‹ã€?
036 * SHELL.RTN_CODE = -1 : 異常終äº?ペã?ã‚¸ã®æ®‹ã‚Šã®å‡¦ç?‚’行ã‚ãªã??)
037 *
038 * 異常終äº??å ´åˆã?ã€ã“ã®ã‚¿ã‚°ä»¥é™ã?処ç?‚’䏿¢ã—ã¾ã™ã?
039
040 * wait 属æ?を使用ã—ã¦ã€å?ç??終äº?‚’å¾?Ÿãšã«ã€å¾©å¸°ã™ã‚‹ã“ã¨ã‚‚å?æ¥ã¾ã™ã?ã“ã?å ´åˆã?ã€?
041 * SHELL.RTN_CODE = 1 ã¨ãªã‚Šã?ãã?ã¾ã¾ã€å?ç??継続ã•れã¾ã™ã?ã“ã?SHELL.RTN_CODE ã¯ã€?
042 * リクエスト変数ã«ã‚»ãƒ?ƒˆã•れã¦ã?¾ã™ã?ã§ã€ãã®ã¾ã¾ã€value ã‚¿ã‚°ã§ã€å–å¾—å¯èƒ½ã§ã™ã?
043 *
044 * action 属æ?ã«æŒ?®šã§ãるアクションåã?ã€ä»¥ä¸‹ã?ã¨ãŠã‚Šã§ã™ã?
045 *
046 * RUN Shellオブジェクトを生æ?/実行ã—ã¾ã™ã?(ã‚»ãƒ?‚·ãƒ§ãƒ³ã«ç™»éŒ²ã—ã¾ã›ã‚“ã€?
047 * SET Shellオブジェクトを生æ?/実行ã—ã€ã‚»ãƒ?‚·ãƒ§ãƒ³ã«ç™»éŒ²ã—ã¾ã™ã?
048 * ã™ã§ã«ã‚»ãƒ?‚·ãƒ§ãƒ³ã«ç™»éŒ²æ¸ˆã¿ã®ShellオブジェクトãŒå®Ÿè¡Œä¸ã®å ´åˆã?ã€??ä¸çµŒéŽã‚’å?告ã—ã¾ã™ã?
049 * GET ã‚»ãƒ?‚·ãƒ§ãƒ³ã«ç™»éŒ²ã•れã¦ã?‚‹ Shellオブジェクトを呼ã³å‡ºã—ã¾ã™ã?
050 * ã‚»ãƒ?‚·ãƒ§ãƒ³ã«ç™»éŒ²ã•れã¦ã?ªã??åˆã?ã€ç•°å¸¸çµ‚äº?«ãªã‚Šã¾ã™ã?
051 * REMOVE ã‚»ãƒ?‚·ãƒ§ãƒ³ã‹ã‚‰ã€Shellオブジェクトを削除ã—ã¾ã™ã?
052 * ShellãŒå®Ÿè¡Œä¸ã®å ´åˆã?強制終äº?—ã¾ã™ã?
053 *
054 * @og.formSample
055 * â—å½¢å¼ï¼?lt;og:shell program="…" />
056 * â—body?šãªã?
057 *
058 * â—Tag定義??
059 * <og:shell
060 * program â—‹ã?TAG】シェルファイルを実行ã™ã‚‹æ™‚ã«å¼•ãæ¸¡ã™ã‚³ãƒžãƒ³ãƒ?å¿??)ã€?
061 * useBatch ã€TAG】BATCHプãƒã‚»ã‚¹ã‚’実行ã™ã‚‹ã?ã‹ã©ã?‹[true/false]を指定ã—ã¾ã?åˆæœŸå€¤:false)
062 * wait ã€TAG】ã?ãƒã‚»ã‚¹ã®çµ‚äº?‚’å¾?¤ã‹ã©ã?‹[true/false]を指定ã—ã¾ã?åˆæœŸå€¤:true[å¾?¤])
063 * timeout ã€TAG】ã?ãƒã‚»ã‚¹ã®å®Ÿè¡Œå?ç??タイãƒ?‚¢ã‚¦ãƒˆã‚’è¨å®šã—ã¾ã?(åˆæœŸå€¤:SHELL_TIMEOUT[=3600])
064 * stdout ã€TAGã€‘å®Ÿè¡Œçµæžœã‚’標準å?力ã«å‡ºåŠ›ã™ã‚‹ã‹ã©ã?‹[true/false]を指定ã—ã¾ã?åˆæœŸå€¤:false)
065 * stderr ã€TAGã€‘å®Ÿè¡Œçµæžœã‚’エラー出力ã«å‡ºåŠ›ã™ã‚‹ã‹ã©ã?‹[true/false]を指定ã—ã¾ã?åˆæœŸå€¤:false)
066 * info ã€TAG】インフォメーションæƒ??ã‚’å?力ã™ã‚‹ã‹ã©ã?‹[true/false]を指定ã—ã¾ã?åˆæœŸå€¤:false)
067 * action ã€TAG】アクション(RUN,SET,GET,REMOVE)ã‚’ã‚»ãƒ?ƒˆã—ã¾ã?åˆæœŸå€¤:RUN)
068 * workDir ã€TAG】作æ¥ãƒ?‚£ãƒ¬ã‚¯ãƒˆãƒªã‚’指定ã—ã¾ã?åˆæœŸå€¤:Java仮想マシンã®ä½œæ¥ãƒ?‚£ãƒ¬ã‚¯ãƒˆãƒª)
069 * envKeys ã€TAG】環å¢?¤‰æ•°ã®ã‚ーをC?³?¶å½¢å¼ã§æŒ?®šã—ã¾ã?åˆæœŸå€¤:ç¾çжã®Java仮想マシンã®ç’°å¢?
070 * envVals ã€TAG】環å¢?¤‰æ•°ã®å€¤ã‚’ï¼£?³?¶å½¢å¼ã§æŒ?®šã—ã¾ã?åˆæœŸå€¤:ç¾çжã®Java仮想マシンã®ç’°å¢?
071 * display ã€TAG】å?ç?µæžœã‚’ç”»é¢ã«è¡¨ç¤ºã™ã‚‹ã‹ã©ã?‹[true/false]æŒ?®šã—ã¾ã?åˆæœŸå€¤:true)
072 * debug ã€TAG】デãƒãƒƒã‚°æƒ??ã‚’å?力ã™ã‚‹ã‹ã©ã?‹[true/false]を指定ã—ã¾ã?åˆæœŸå€¤:false)
073 * />
074 *
075 * â—使用ä¾?
076 * <og:shell
077 * program = "プãƒã‚°ãƒ©ãƒ? dir /S ã‚??abc.bat ãªã©
078 * action = "アクション" [RUN/SET/GET/REMOVE]
079 * useBatch = "ãƒãƒƒãƒä½¿ç”¨" ãƒãƒƒãƒ?¼štrue/false (åˆæœŸå€¤:false)
080 * wait = "終äº?¾?¡" 処ç?µ‚äº?¾ã§å¾?¤:true/å¾?Ÿãªã?false (åˆæœŸå€¤:true)
081 * stdout = "標準å?力使用" 標準å?力使用:true/未使用:false (åˆæœŸå€¤:false)
082 * stderr = "エラー出力使用" エラー出力使用:true/未使用:false (åˆæœŸå€¤:false)
083 * info = "状態表示" シェルã®çŠ¶æ…‹è¡¨ç¤º:true/未使用:false (åˆæœŸå€¤:false)
084 * />
085 *
086 * <og:value command="GET" key="SHELL.RTN_CODE" />
087 *
088 * @og.group ãã?他部å“?
089 *
090 * @version 4.0
091 * @author Kazuhiko Hasegawa
092 * @since JDK5.0,
093 */
094 public class ShellTag extends CommonTagSupport {
095 //* ã“ã?プãƒã‚°ãƒ©ãƒ??VERSIONæ–?—å?ã‚’è¨å®šã—ã¾ã™ã? {@value} */
096 private static final String VERSION = "4.0.0.0 (2007/10/18)" ;
097
098 private static final long serialVersionUID = 400020071018L ;
099
100 /** action å¼•æ•°ã«æ¸¡ã™äº‹ã?出æ¥ã‚?コマンãƒ? 実è¡?{@value} */
101 public static final String ACT_RUN = "RUN" ;
102 /** action å¼•æ•°ã«æ¸¡ã™äº‹ã?出æ¥ã‚?コマンãƒ? 登録 {@value} */
103 public static final String ACT_SET = "SET" ;
104 /** action å¼•æ•°ã«æ¸¡ã™äº‹ã?出æ¥ã‚?コマンãƒ? å–å¾?{@value} */
105 public static final String ACT_GET = "GET" ;
106 /** action å¼•æ•°ã«æ¸¡ã™äº‹ã?出æ¥ã‚?コマンãƒ? 削除 {@value} */
107 public static final String ACT_REMOVE = "REMOVE" ;
108
109 /** action å¼•æ•°ã«æ¸¡ã™äº‹ã?出æ¥ã‚?コマンãƒ?リスãƒ? */
110 private static final String[] ACTION_LIST = new String[] {
111 ACT_RUN , ACT_SET , ACT_GET , ACT_REMOVE };
112
113 private String program = null;
114 private boolean useBatch = false; // BATCHプãƒã‚»ã‚¹ã‚’実行ã™ã‚‹ã?ã‹ã©ã?‹(åˆæœŸå€¤:false)
115 private boolean stdout = false; // 標準å?ã‚’å?力ã™ã‚‹ã‹ã©ã?‹(åˆæœŸå€¤:false)
116 private boolean stderr = false; // エラー出力を出力ã™ã‚‹ã‹ã©ã?‹(åˆæœŸå€¤:false)
117 private boolean wait = true; // プãƒã‚»ã‚¹ã®çµ‚äº?‚’å¾?¤(true)/å¾?Ÿãªã?false) (åˆæœŸå€¤:true)
118 private boolean info = false; // インフォメーションをå?力ã™ã‚‹ã‹ã©ã?‹(åˆæœŸå€¤:false)
119 private boolean display = true; // 処ç?µæžœã‚’ç”»é¢ã«è¡¨ç¤ºã™ã‚‹ã‹ã©ã?‹(åˆæœŸå€¤:true)
120 private String action = ACT_RUN;
121 private File workDir = null;
122 private String[] envKeys = null;
123 private String[] envVals = null;
124
125 private static final String RTN_CODE = "SHELL.RTN_CODE" ;
126
127 // 3.6.1.0 (2005/01/05) タイãƒ?‚¢ã‚¦ãƒˆæ™‚é–“ã‚’è¨å®?
128 private int timeout = HybsSystem.sysInt( "SHELL_TIMEOUT" );
129
130 /**
131 * Taglibã®çµ‚äº?‚¿ã‚°ãŒè¦‹ã¤ã‹ã£ãŸã¨ãã«å‡¦ç?™ã‚?doEndTag() ã‚?オーãƒã?ライドã—ã¾ã™ã?
132 *
133 * @og.rev 3.1.1.2 (2003/04/04) Tomcat4.1 対応ã?release2() ã‚?doEndTag()ã§å‘¼ã¶ã€?
134 * @og.rev 3.1.9.0 (2003/05/16) Shell ã¸ã® stdout 㨠stderr ã®å–å¾—è¨å®šã?å»?¢ã€‚ShellTag ã§ã¯ã€æœ‰åйã€?
135 * @og.rev 3.3.3.0 (2003/07/09) ãƒ?ƒãƒ?‚°æ™‚ã?表示ãƒã‚¸ãƒ?‚¯ã‚’追åŠ??
136 *
137 * @return 後続å?ç??æŒ?¤º
138 */
139 @Override
140 public int doEndTag() {
141 debugPrint(); // 4.0.0 (2005/02/28)
142
143 int rtnCode = actionExec( action );
144
145 if( isDebug() ) {
146 jspPrint( "Return Code=[" + rtnCode + "]" );
147 }
148
149 setRequestAttribute( RTN_CODE, String.valueOf( rtnCode ) );
150
151 // rtnCode = 0 : æ£å¸¸ (ペã?ã‚¸ã®æ®‹ã‚Šã‚’評価ã™ã‚‹ã€?
152 // rtnCode = 1 : 処ç?¸ (ペã?ã‚¸ã®æ®‹ã‚Šã‚’評価ã™ã‚‹ã€?
153 // rtnCode = 9 : å–æ¶? (ペã?ã‚¸ã®æ®‹ã‚Šã‚’評価ã™ã‚‹ã€?
154 // rtnCode = -1 : 異常終äº?ペã?ã‚¸ã®æ®‹ã‚Šã®å‡¦ç?‚’行ã‚ãªã??)
155
156 if( rtnCode >= 0 ) {
157 return(EVAL_PAGE); // ペã?ã‚¸ã®æ®‹ã‚Šã‚’評価ã™ã‚‹ã€?
158 }
159 else {
160 return(SKIP_PAGE); // ペã?ã‚¸ã®æ®‹ã‚Šã®å‡¦ç?‚’行ã‚ãªã??
161 }
162 }
163
164 /**
165 * タグリブオブジェクトをリリースã—ã¾ã™ã?
166 * ã‚ャãƒ?‚·ãƒ¥ã•れã¦å†åˆ©ç”¨ã•れるã?ã§ã€ãƒ•ィールドã?åˆæœŸè¨å®šã‚’行ã„ã¾ã™ã?
167 *
168 * @og.rev 2.0.0.4 (2002/09/27) カスタãƒ?‚¿ã‚°ã® release() メソãƒ?ƒ‰ã‚’ã?追åŠ?
169 * @og.rev 3.1.1.2 (2003/04/04) Tomcat4.1 対応ã?release2() ã‚?doEndTag()ã§å‘¼ã¶ã€?
170 * @og.rev 3.1.9.0 (2003/05/16) action コマンド追�
171 * @og.rev 3.3.3.0 (2003/07/09) action コマンドã?å‹•ãã‚’ä¿®æ£ã€?
172 * @og.rev 3.6.0.1 (2004/09/29) display 属æ?を追åŠ?
173 * @og.rev 3.6.1.0 (2005/01/05) timeout 属æ?を追åŠ?
174 *
175 */
176 @Override
177 protected void release2() {
178 super.release2();
179 program = null;
180 useBatch = false; // BATCHプãƒã‚»ã‚¹ã‚’実行ã™ã‚‹ã?ã‹ã©ã?‹(åˆæœŸå€¤:false)
181 stdout = false; // 標準å?ã‚’å?力ã™ã‚‹ã‹ã©ã?‹(åˆæœŸå€¤:false)
182 stderr = false; // エラー出力を出力ã™ã‚‹ã‹ã©ã?‹(åˆæœŸå€¤:false)
183 wait = true; // プãƒã‚»ã‚¹ã®çµ‚äº?‚’å¾?¤(true)/å¾?Ÿãªã?false) (åˆæœŸå€¤:true)
184 action = ACT_RUN;
185 info = false;
186 display = true; // 3.6.0.1 (2004/09/29)
187 timeout = HybsSystem.sysInt( "SHELL_TIMEOUT" );
188 }
189
190 /**
191 * アクションを実行ã—ã¾ã™ã?
192 *
193 * アクションã¯,æŒ?®šã?アクションコマンドã«å¯¾å¿œã™ã‚‹å?ç?‚’入力データã«
194 * 対ã—ã¦è¡Œã„ã¾ã™ã?[RUN/SET/GET/REMOVE]
195 *
196 * @og.rev 3.1.9.0 (2003/05/16) æ–°è¦è¿½åŠ?
197 *
198 * @param action アクションコマンãƒ?public static final 宣è¨?•れã¦ã?‚‹æ–?—å?)
199 *
200 * @return リターンコーãƒ? 0:æ£å¸¸ 1:å®Ÿè¡Œä¸ 9:å–æ¶? -1:異常終äº?
201 */
202 private int actionExec( final String action ) {
203 int rtnCode = 1;
204 if( ACT_RUN.equals( action ) ) { rtnCode = shellRun(); }
205 else if( ACT_SET.equals( action ) ) { rtnCode = shellSet(); }
206 else if( ACT_GET.equals( action ) ) { rtnCode = shellGet(); }
207 else if( ACT_REMOVE.equals( action ) ) { rtnCode = shellRemove(); }
208
209 return rtnCode ;
210 }
211
212 /**
213 * Shell オブジェクトを新è¦ä½œæ?ã—ã¾ã™ã?
214 *
215 * @og.rev 3.3.3.0 (2003/07/09) æ–°è¦è¿½åŠ?
216 * @og.rev 3.6.1.0 (2005/01/05) タイãƒ?‚¢ã‚¦ãƒˆæ™‚é–“ã‚’è¨å®?
217 *
218 * @return Shellオブジェク�
219 */
220 private Shell makeShell() {
221 Shell shell = new Shell();
222 shell.setCommand( program,useBatch );
223 shell.setWait( wait );
224 shell.setTimeout( timeout ); // 3.6.1.0 (2005/01/05)
225 shell.setWorkDir( workDir );
226 shell.setEnvP( makeEnvpArray( envKeys,envVals ) );
227
228 if( isDebug() ) {
229 jspPrint( shell.getCommand() + HybsSystem.BR );
230 }
231
232 return shell ;
233 }
234
235 /**
236 * ç’°å¢?¤‰æ•°è¨å®šç”¨ã®æ–?—å?é…å?を作æ?ã—ã¾ã™ã?
237 * ã“れã¯ã€ã‚ーé…å?ã¨å€¤é…å?ã‚’ã?key=value ã¨ã?†æ–?—å?ã«ã—ã¦ã€??列を返ã—ã¾ã™ã?
238 *
239 * @og.rev 3.3.3.0 (2003/07/09) æ–°è¦è¿½åŠ?
240 * @og.rev 3.6.0.0 (2004/09/22) 引数ã®ã‚ーã€å?ãŒnull ç‰ã?å ´åˆã?ã€?•·ã•ï¼é?列を返ã—ã¾ã™ã?
241 *
242 * @param keys ç’°å¢?¤‰æ•°ã®ã‚ーé…å?
243 * @param vals ç’°å¢?¤‰æ•°ã®å€¤é…å?
244 *
245 * @return ç’°å¢?¤‰æ•°è¨å®šç”¨ã®æ–?—å?é…å?(ã‚ー=å€¤ã®æ–?—å?ã‚’é?列ã«ã‚»ãƒ?ƒˆ)
246 */
247 private String[] makeEnvpArray( final String[] keys, final String[] vals ) {
248 if( keys == null || keys.length == 0 || vals == null || vals.length == 0 ) {
249 return new String[0];
250 }
251
252 if( keys.length != vals.length ) {
253 String errMsg = "ã‚ーã¨ãƒãƒªãƒ¥ãƒ¼ã®å€‹æ•°ãŒç•°ãªã‚Šã¾ã™ã?"
254 + HybsSystem.CR
255 + " keys.length=[" + keys.length + "] vals.length=[" + vals.length + "]"
256 + HybsSystem.CR
257 + " keys=" + StringUtil.array2csv( keys )
258 + HybsSystem.CR
259 + " vals=" + StringUtil.array2csv( vals ); // 5.1.8.0 (2010/07/01) errMsg ä¿®æ£
260 throw new HybsSystemException( errMsg );
261 }
262
263 String[] envp = new String[keys.length];
264 for( int i=0; i<envp.length; i++ ) {
265 envp[i] = keys[i] + "=" + vals[i] ;
266 }
267
268 return envp ;
269 }
270
271 /**
272 * RUN アクションを実行ã—ã¾ã™ã?
273 *
274 * Shellオブジェクトを生æ?/実行ã—ã¾ã™ã?(ã‚»ãƒ?‚·ãƒ§ãƒ³ã«ç™»éŒ²ã—ã¾ã›ã‚“ã€?
275 *
276 * @og.rev 3.1.9.0 (2003/05/16) æ–°è¦è¿½åŠ?
277 * @og.rev 3.3.3.0 (2003/07/09) Shell オブジェクトをã€makeShell() メソãƒ?ƒ‰ã‚ˆã‚Šä½œæ?ã—ã¾ã™ã?
278 *
279 * @return リターンコーãƒ? 0:æ£å¸¸ 1:å®Ÿè¡Œä¸ 9:å–æ¶? -1:異常終äº?
280 */
281 private int shellRun() {
282 Shell shell = makeShell();
283 int rtnCode = shell.exec(); // 0 ã¯æ£å¸¸çµ‚äº?‚’示ã?
284 shellView( shell );
285
286 return rtnCode ;
287 }
288
289 /**
290 * SET アクションを実行ã—ã¾ã™ã?
291 *
292 * Shellオブジェクトを生æ?/実行ã—ã€ã‚»ãƒ?‚·ãƒ§ãƒ³ã«ç™»éŒ²ã—ã¾ã™ã?
293 * wait ç‰ã§Shellã®çµ‚äº?‚’å¾?Ÿãªã?–¹å¼ã§ã¯ã€æœ‰ç”¨ã§ã™ã?
294 *
295 * @og.rev 3.1.9.0 (2003/05/16) æ–°è¦è¿½åŠ?
296 *
297 * @return リターンコーãƒ? 0:æ£å¸¸ 1:å®Ÿè¡Œä¸ 9:å–æ¶? -1:異常終äº?
298 */
299 private int shellSet() {
300 final int rtnCode;
301
302 Shell shell = (Shell)getSessionAttribute( HybsSystem.SHELL_KEEP_KEY );
303 if( shell == null || shell.isEnd() ) {
304 shell = makeShell();
305 rtnCode = shell.exec(); // 0 ã¯æ£å¸¸çµ‚äº?‚’示ã?
306 setSessionAttribute( HybsSystem.SHELL_KEEP_KEY,shell );
307 }
308 else {
309 rtnCode = shell.exitValue();
310 }
311 shellView( shell );
312
313 return rtnCode ;
314 }
315
316 /**
317 * GET アクションを実行ã—ã¾ã™ã?
318 *
319 * ã‚»ãƒ?‚·ãƒ§ãƒ³ã«ç™»éŒ²ã•れã¦ã?‚‹ Shellオブジェクトを呼ã³å‡ºã—ã¾ã™ã?
320 *
321 * @og.rev 3.1.9.0 (2003/05/16) æ–°è¦è¿½åŠ?
322 * @og.rev 3.3.3.0 (2003/07/09) アクション時ã?å†?®¹ã‚’å?力ã—ã¾ã™ã?
323 *
324 * @return リターンコーãƒ? 0:æ£å¸¸ 1:å®Ÿè¡Œä¸ 9:å–æ¶? -1:異常終äº?
325 */
326 private int shellGet() {
327 int rtnCode = 0;
328
329 Shell shell = (Shell)getSessionAttribute( HybsSystem.SHELL_KEEP_KEY );
330 if( shell != null ) { rtnCode = shell.exitValue(); }
331 shellView( shell );
332
333 return rtnCode ;
334 }
335
336 /**
337 * REMOVE アクションを実行ã—ã¾ã™ã?
338 *
339 * ã‚»ãƒ?‚·ãƒ§ãƒ³ã‹ã‚‰ã€Shellオブジェクトを削除ã—ã¾ã™ã?
340 * Shell ãŒå®Ÿè¡Œä¸ãªã‚‰ã?ã€å¼·åˆ¶çµ‚äº?•ã›ã¾ã™ã?
341 *
342 * @og.rev 3.1.9.0 (2003/05/16) æ–°è¦è¿½åŠ?
343 * @og.rev 3.3.3.0 (2003/07/09) アクション時ã?å†?®¹ã‚’å?力ã—ã¾ã™ã?
344 *
345 * @return リターンコーãƒ? 0:æ£å¸¸ 1:å®Ÿè¡Œä¸ 9:å–æ¶? -1:異常終äº?
346 */
347 private int shellRemove() {
348 int rtnCode = 0;
349
350 Shell shell = (Shell)getSessionAttribute( HybsSystem.SHELL_KEEP_KEY );
351 if( shell != null ) {
352 shell.destroy();
353 rtnCode = shell.exitValue();
354 }
355 shellView( shell );
356
357 removeSessionAttribute( HybsSystem.SHELL_KEEP_KEY );
358
359 return rtnCode ;
360 }
361
362 /**
363 * シェルã®å®Ÿè¡Œå?容をã?ç”»é¢ã«è¡¨ç¤ºã—ã¾ã™ã?
364 *
365 * @og.rev 3.3.3.0 (2003/07/09) æ–°è¦è¿½åŠ?
366 * @og.rev 3.6.0.1 (2004/09/29) display 属æ?ã‚’è?æ…®
367 * @og.rev 4.0.0.0 (2007/10/18) メãƒ?‚»ãƒ¼ã‚¸ãƒªã‚½ãƒ¼ã‚¹çµ±å? getResource().getMessage â‡?getResource().getLabel )
368 *
369 * @param shell シェルオブジェク�
370 */
371 private void shellView( final Shell shell ) {
372 if( shell == null ) {
373 // MSG0066=処ç??å˜åœ¨ã—ã¦ã?¾ã›ã‚“ã€?
374 // jspPrint( getResource().getMessage( "MSG0066" ) );
375 jspPrint( getResource().getLabel( "MSG0066" ) );
376 return ;
377 }
378
379 int rtnCode = shell.exitValue();
380
381 final String msg ;
382 switch( rtnCode ) {
383 case Shell.OK : msg = "MSG0063"; break; // MSG0063=完äº?—ã¾ã—ãŸã€?
384 case Shell.RUNNING : msg = "MSG0067"; break; // MSG0067=処ç??実行ä¸ã§ã™ã?
385 case Shell.CANCEL : msg = "MSG0069"; break; // MSG0069=処ç?‚’ã‚ャンセルã—ã¾ã—ãŸã€?
386 // case Shell.ERROR : msg = "MSG0068"; break; // MSG0068=処ç??実行ä¸ã«ã‚¨ãƒ©ãƒ¼ãŒç™ºç”Ÿã—ã¾ã—ãŸã€?
387 default : msg = "MSG0068"; break; // MSG0068=処ç??実行ä¸ã«ã‚¨ãƒ©ãƒ¼ãŒç™ºç”Ÿã—ã¾ã—ãŸã€?
388 }
389
390 // 3.6.0.1 (2004/09/29) display 属æ?ã‚’è?æ…®(display=true ã‹ã?ERROR ã®å ´åˆã?表示)
391 if( display || rtnCode == Shell.ERROR ) {
392 // jspPrint( getResource().getMessage( msg ) + HybsSystem.BR );
393 jspPrint( getResource().getLabel( msg ) + HybsSystem.BR );
394 }
395
396 if( info ) {
397 jspPrint( shell.toString() );
398 }
399 if( stdout ) {
400 jspPrint( StringUtil.htmlFilter( shell.getStdoutData() ) );
401 }
402 if( stderr ) {
403 jspPrint( "<div class=\"row_mark\">" );
404 jspPrint( StringUtil.htmlFilter( shell.getStderrData() ) );
405 jspPrint( "</div>" );
406 }
407 }
408
409 /**
410 * ã€TAG】シェルファイルを実行ã™ã‚‹æ™‚ã«å¼•ãæ¸¡ã™ã‚³ãƒžãƒ³ãƒ‰ã?
411 *
412 * @og.tag シェルファイルを実行ã™ã‚‹æ™‚ã«å¼•ãæ¸¡ã™ã‚³ãƒžãƒ³ãƒ?
413 *
414 * @param val シェルコマン�
415 */
416 public void setProgram( final String val ) {
417 program = getRequestParameter( val );
418 }
419
420 /**
421 * ã€TAG】BATCHプãƒã‚»ã‚¹ã‚’実行ã™ã‚‹ã?ã‹ã©ã?‹[true/false]を指定ã—ã¾ã?åˆæœŸå€¤:false)ã€?
422 *
423 * @og.tag
424 * BATCHファイルã®å®Ÿè¡Œã¨ã€EXEファイルã®å®Ÿè¡Œã§ã¯ã€cmd.exe 経由ã™ã‚‹ã?
425 * ã©ã?‹ã€åˆ¤æ–ãŒå¿?¦ã§ã™ã?true(BATCHプãƒã‚»ã‚¹)ã§ã¯ã€cmd.exe 経由ã§å®Ÿè¡Œã?
426 * false(EXEファイル)ã§ã¯ã€ç›´æŽ¥å®Ÿè¡Œã—ã¾ã™ã?
427 * åˆæœŸå€¤ã¯ã€false(EXEファイル)ã§ã™ã?
428 *
429 * @param flag BATCHプãƒã‚»ã‚¹ã‚’実行ã™ã‚‹ã?ã‹ã©ã?‹ [true:BATCHプãƒã‚»ã‚¹/false:EXEファイル]
430 */
431 public void setUseBatch( final String flag ) {
432 useBatch = nval( getRequestParameter( flag ),useBatch );
433 }
434
435 /**
436 * ã€TAGã€‘å®Ÿè¡Œçµæžœã‚’標準å?力ã«å‡ºåŠ›ã™ã‚‹ã‹ã©ã?‹[true/false]を指定ã—ã¾ã?åˆæœŸå€¤:false)ã€?
437 *
438 * @og.tag å®Ÿè¡Œçµæžœã®æ¨™æº–å?力を出力ã™ã‚‹ã‹ã©ã?‹(åˆæœŸå€¤:false)
439 *
440 * @param flag å®Ÿè¡Œçµæžœã®æ¨™æº–å?åŠ?[true:出力ã™ã‚?false:ã—ãªã„]
441 */
442 public void setStdout( final String flag ) {
443 stdout = nval( getRequestParameter( flag ),stdout );
444 }
445
446 /**
447 * ã€TAGã€‘å®Ÿè¡Œçµæžœã‚’エラー出力ã«å‡ºåŠ›ã™ã‚‹ã‹ã©ã?‹[true/false]を指定ã—ã¾ã?åˆæœŸå€¤:false)ã€?
448 *
449 * @og.tag å®Ÿè¡Œçµæžœã®ã‚¨ãƒ©ãƒ¼å‡ºåŠ›ã‚’å‡ºåŠ›ã™ã‚‹ã‹ã©ã?‹(åˆæœŸå€¤:false)
450 *
451 * @param flag å®Ÿè¡Œçµæžœã®ã‚¨ãƒ©ãƒ¼å‡ºåŠ?[true:出力ã™ã‚?false:ã—ãªã„]
452 */
453 public void setStderr( final String flag ) {
454 stderr = nval( getRequestParameter( flag ),stderr );
455 }
456
457 /**
458 * ã€TAG】ã?ãƒã‚»ã‚¹ã®çµ‚äº?‚’å¾?¤ã‹ã©ã?‹[true/false]を指定ã—ã¾ã?åˆæœŸå€¤:true[å¾?¤])ã€?
459 *
460 * @og.tag プãƒã‚»ã‚¹ã®çµ‚äº?‚’å¾?¤(true)/å¾?Ÿãªã?false) (åˆæœŸå€¤:true)
461 *
462 * @param flag プãƒã‚»ã‚¹ã®çµ‚äº?true:å¾?¤/false:å¾?Ÿãªã?
463 */
464 public void setWait( final String flag ) {
465 wait = nval( getRequestParameter( flag ),wait );
466 }
467
468 /**
469 * ã€TAG】ã?ãƒã‚»ã‚¹ã®å®Ÿè¡Œå?ç??タイãƒ?‚¢ã‚¦ãƒˆã‚’è¨å®šã—ã¾ã?
470 * (åˆæœŸå€¤:SHELL_TIMEOUT[={@og.value org.opengion.hayabusa.common.SystemData#SHELL_TIMEOUT}])ã€?
471 *
472 * @og.tag
473 * ゼãƒ(0) ã®å ´åˆã?ã€å‰²ã‚Šè¾¼ã¿ãŒå?ã‚‹ã¾ã§å¾?¡ã¤ã¥ã‘ã¾ã™ã?
474 * ãã?å ´åˆã?確実ã«çµ‚äº?•ã›ã‚‹æ‰‹æ®µã‚’用æ„ã—ã¦ãŠã‹ãªã?¨ã€ã„ã¤ã¾ã§å¾?£ã¦ã‚‚以下ã?処ç?Œ
475 * 実行ã•れãªã?ãƒ?ƒƒãƒ‰ãƒãƒ?‚¯)状態ã«ãªã£ã¦ã—ã¾ã?¾ã™ã?
476 * (åˆæœŸå€¤:シスãƒ?ƒ 定数ã®SHELL_TIMEOUT[={@og.value org.opengion.hayabusa.common.SystemData#SHELL_TIMEOUT}])ã€?
477 *
478 * @og.rev 3.6.1.0 (2005/01/05) æ–°è¦è¿½åŠ?
479 *
480 * @param tout タイãƒ?‚¢ã‚¦ãƒˆæ™‚é–?ç§? ゼãƒã¯ã€ç„¡åˆ¶é™?
481 * @see org.opengion.hayabusa.common.SystemData#SHELL_TIMEOUT
482 */
483 public void setTimeout( final String tout ) {
484 timeout = nval( getRequestParameter( tout ),timeout );
485 }
486
487 /**
488 * ã€TAG】インフォメーションæƒ??ã‚’å?力ã™ã‚‹ã‹ã©ã?‹[true/false]を指定ã—ã¾ã?åˆæœŸå€¤:false)ã€?
489 *
490 * @og.tag インフォメーションæƒ??ã‚’å?力ã™ã‚‹ã‹ã©ã?‹(åˆæœŸå€¤:false)
491 *
492 * @og.rev 3.1.9.0 (2003/05/16) æ–°è¦è¿½åŠ?
493 *
494 * @param flag インフォメーションæƒ?? [true:出力ã™ã‚?false:ã—ãªã„]
495 */
496 public void setInfo( final String flag ) {
497 info = nval( getRequestParameter( flag ),info );
498 }
499
500 /**
501 * ã€TAG】å?ç?µæžœã‚’ç”»é¢ã«è¡¨ç¤ºã™ã‚‹ã‹ã©ã?‹[true/false]æŒ?®šã—ã¾ã?åˆæœŸå€¤:true)ã€?
502 *
503 * @og.tag
504 * 処ç?µæžœãŒã?異常ã§ãªã??åˆã?ã¿ã€ã“ã®æ©Ÿè?ãŒæœ‰åйã«ãªã‚Šã¾ã™ã?
505 * å?¨®å‡¦ç?‚’連続ã§è¡Œã†å ´åˆã?æœ?¾Œã«ã‚¨ãƒ©ãƒ¼ãŒç™ºç”Ÿã—ãŸã«ã‚‚ã‹ã‹ã‚らãšã€?
506 * å…ˆã«æ£å¸¸çµ‚äº?—ã¦ã?‚‹å ´åˆã«ã€ä¸è¦ãªãƒ¡ãƒ?‚»ãƒ¼ã‚¸ã‚’å?ã™ã¨ã€ç´›ã‚‰ã‚ã—ã?‚ºã§ã™ã?
507 *
508 * @og.rev 3.6.0.1 (2004/09/29) æ–°è¦è¿½åŠ?
509 *
510 * @param flag 処ç?µæžœã‚’ç”»é¢ã«è¡¨ç¤ºã™ã‚‹ã‹ã©ã?‹ [true:出力ã™ã‚?false:ã—ãªã„]
511 */
512 public void setDisplay( final String flag ) {
513 display = nval( getRequestParameter( flag ),display );
514 }
515
516 /**
517 * ã€TAG】アクション(RUN,SET,GET,REMOVE)ã‚’ã‚»ãƒ?ƒˆã—ã¾ã?åˆæœŸå€¤:RUN)ã€?
518 *
519 * @og.tag
520 * アクションã¯,HTMLã‹ã‚‰(get/post)æŒ?®šã•れã¾ã™ã?ã§,ACT_xxx ã§è¨å®šã•れる
521 * フィールド定数値ã®ã?¥ã‚Œã‹ã‚’ã?æŒ?®šã§ãã¾ã™ã?
522 *
523 * RUN Shellオブジェクトを生æ?/実行ã—ã¾ã™ã?(ã‚»ãƒ?‚·ãƒ§ãƒ³ã«ç™»éŒ²ã—ã¾ã›ã‚“ã€?
524 * SET Shellオブジェクトを生æ?/実行ã—ã€ã‚»ãƒ?‚·ãƒ§ãƒ³ã«ç™»éŒ²ã—ã¾ã™ã?
525 * GET ã‚»ãƒ?‚·ãƒ§ãƒ³ã«ç™»éŒ²ã•れã¦ã?‚‹ Shellオブジェクトを呼ã³å‡ºã—ã¾ã™ã?
526 * REMOVE ã‚»ãƒ?‚·ãƒ§ãƒ³ã‹ã‚‰ã€Shellオブジェクトを削除ã—ã¾ã™ã?
527 * ShellãŒå®Ÿè¡Œä¸ã®å ´åˆã?強制終äº?—ã¾ã™ã?
528 *
529 * @og.rev 3.1.9.0 (2003/05/16) æ–°è¦è¿½åŠ?
530 * @og.rev 3.5.6.2 (2004/07/05) æ–?—å?ã®é€£çµã«StringBuilderを使用ã—ã¾ã™ã?
531 *
532 * @param act アクション(åˆæœŸå€¤ã¯ã€RUN ã§ã™ã?)
533 * @see <a href="../../../../constant-values.html#org.opengion.hayabusa.taglib.ShellTag.ACT_RUN">アクション定数</a>
534 */
535 public void setAction( final String act ) {
536 action = nval( getRequestParameter( act ),action );
537 if( !check( action, ACTION_LIST ) ) {
538 StringBuilder errMsg = new StringBuilder( HybsSystem.BUFFER_MIDDLE );
539 errMsg.append( "æŒ?®šã?アクションã¯å®Ÿè¡Œã§ãã¾ã›ã‚“。アクションエラー" );
540 errMsg.append( HybsSystem.CR );
541 errMsg.append( "action=[" ).append( action ).append( "] " );
542 errMsg.append( HybsSystem.CR );
543 for( int i=0; i<ACTION_LIST.length; i++ ) {
544 errMsg.append( " | " );
545 errMsg.append( ACTION_LIST[i] );
546 }
547 errMsg.append( " | " );
548 throw new HybsSystemException( errMsg.toString() );
549 }
550 }
551
552 /**
553 * ã€TAG】作æ¥ãƒ?‚£ãƒ¬ã‚¯ãƒˆãƒªã‚’指定ã—ã¾ã?åˆæœŸå€¤:Java仮想マシンã®ä½œæ¥ãƒ?‚£ãƒ¬ã‚¯ãƒˆãƒª)ã€?
554 *
555 * @og.tag
556 * シェルを実行ã™ã‚‹ã?作æ¥ãƒ?‚£ãƒ¬ã‚¯ãƒˆãƒªã‚’指定ã—ã¾ã™ã?
557 * çµ¶å¯¾ãƒ‘ã‚¹ã§æŒ?®šã™ã‚‹ã“ã¨ã‚‚ã?ç›¸å¯¾ãƒ‘ã‚¹ã§æŒ?®šã™ã‚‹ã“ã¨ã‚‚å?æ¥ã¾ã™ã?
558 * 相対パスã®å ´åˆã?ã€ãƒ‰ã‚ュメントã?ースã®ç‰©ç?ƒ‘スãŒåŸºæº–ã«ãªã‚Šã¾ã™ã?
559 * (ãã?JSPファイル自身ã®ãƒ?‚£ãƒ¬ã‚¯ãƒˆãƒªãŒåŸºæº–ã§ã¯ã‚りã¾ã›ã‚“ã€?
560 * æŒ?®šã—ãªã??åˆã?ã€ã“ã®Java仮想マシンã®ä½œæ¥ãƒ?‚£ãƒ¬ã‚¯ãƒˆãƒªã§å®Ÿè¡Œã•れã¾ã™ã?
561 *
562 * @og.rev 3.3.3.0 (2003/07/09) æ–°è¦è¿½åŠ?
563 *
564 * @param dir 作æ¥ãƒ?‚£ãƒ¬ã‚¯ãƒˆãƒª
565 */
566 public void setWorkDir( final String dir ) {
567 String work = HybsSystem.url2dir( getRequestParameter( dir ) );
568 workDir = new File( work );
569 if( ! workDir.isDirectory() ) {
570 String errMsg = "æŒ?®šã?作æ¥ãƒ?‚£ãƒ¬ã‚¯ãƒˆãƒªã¯ã€ä½¿ç”¨ã§ãã¾ã›ã‚“ã€?
571 + HybsSystem.CR
572 + "workDir=[" + workDir + "] "
573 + HybsSystem.CR ;
574 throw new HybsSystemException( errMsg );
575 }
576 }
577
578 /**
579 * ã€TAG】環å¢?¤‰æ•°ã®ã‚ーをC?³?¶å½¢å¼ã§æŒ?®šã—ã¾ã?åˆæœŸå€¤:ç¾çжã®Java仮想マシンã®ç’°å¢?ã€?
580 *
581 * @og.tag
582 * シェル実行時ã®ç’°å¢?¤‰æ•°ã®ã‚ーをã??£?³?¶Vå½¢å¼ã§æŒ?®šã—ã¾ã™ã?
583 * æŒ?®šãŒãªã??åˆã?ã€ç¾çжã®Java仮想マシンã®ç’°å¢?Œå¼•ãç¶™ãŒã‚Œã¾ã™ã?
584 * envVals ã¨å¯¾å¿œã—ã¦ã?ªã‘れã°ãªã‚Šã¾ã›ã‚“ã€?
585 * åˆ?§£æ–¹æ³•ã?ã€CSV変数をå?ã«åˆ?§£ã—ã¦ã‹ã‚‰ã€getRequestParameter ã§å€¤ã‚’å–å¾—ã—ã¾ã™ã?
586 * ã“ã†ã—ãªã?¨ãƒ??タ自身ã«ã‚«ãƒ³ãƒžã‚’æŒã£ã¦ã?‚‹å ´åˆã«åˆ?§£ã‚’ミスる為ã§ã™ã?
587 *
588 * @og.rev 3.3.3.0 (2003/07/09) æ–°è¦è¿½åŠ?
589 * @og.rev 3.5.6.2 (2004/07/05) CommonTagSupport#getCSVParameter を使用
590 *
591 * @param keys ç’°å¢?¤‰æ•°ã®ã‚ー
592 */
593 public void setEnvKeys( final String keys ) {
594 envKeys = getCSVParameter( keys );
595 }
596
597 /**
598 * ã€TAG】環å¢?¤‰æ•°ã®å€¤ã‚’ï¼£?³?¶å½¢å¼ã§æŒ?®šã—ã¾ã?åˆæœŸå€¤:ç¾çжã®Java仮想マシンã®ç’°å¢?ã€?
599 *
600 * @og.tag
601 * シェル実行時ã®ç’°å¢?¤‰æ•°ã®å€¤ã‚’ã??£?³?¶Vå½¢å¼ã§æŒ?®šã—ã¾ã™ã?
602 * æŒ?®šãŒãªã??åˆã?ã€ç¾çжã®Java仮想マシンã®ç’°å¢?Œå¼•ãç¶™ãŒã‚Œã¾ã™ã?
603 * envKeys ã¨å¯¾å¿œã—ã¦ã?ªã‘れã°ãªã‚Šã¾ã›ã‚“ã€?
604 * åˆ?§£æ–¹æ³•ã?ã€CSV変数をå?ã«åˆ?§£ã—ã¦ã‹ã‚‰ã€getRequestParameter ã§å€¤ã‚’å–å¾—ã—ã¾ã™ã?
605 * ã“ã†ã—ãªã?¨ãƒ??タ自身ã«ã‚«ãƒ³ãƒžã‚’æŒã£ã¦ã?‚‹å ´åˆã«åˆ?§£ã‚’ミスる為ã§ã™ã?
606 *
607 * @og.rev 3.3.3.0 (2003/07/09) æ–°è¦è¿½åŠ?
608 * @og.rev 3.5.6.2 (2004/07/05) CommonTagSupport#getCSVParameter を使用
609 *
610 * @param vals ç’°å¢?¤‰æ•°ã®ã‚ー
611 */
612 public void setEnvVals( final String vals ) {
613 envVals = getCSVParameter( vals );
614 }
615
616 /**
617 * ã“ã?オブジェクトã?æ–?—å?表ç¾ã‚’è¿”ã—ã¾ã™ã?
618 * 基本çš?«ãƒ?ƒãƒ?‚°ç›®çš?«ä½¿ç”¨ã—ã¾ã™ã?
619 *
620 * @return ã“ã?ã‚¯ãƒ©ã‚¹ã®æ–?—å?表ç¾
621 */
622 @Override
623 public String toString() {
624 return org.opengion.fukurou.util.ToString.title( this.getClass().getName() )
625 .println( "VERSION" ,VERSION )
626 .println( "program" ,program )
627 .println( "useBatch" ,useBatch )
628 .println( "stdout" ,stdout )
629 .println( "stderr" ,stderr )
630 .println( "wait" ,wait )
631 .println( "info" ,info )
632 .println( "display" ,display )
633 .println( "action" ,action )
634 .println( "ACTION_LIST" ,ACTION_LIST )
635 .println( "workDir" ,workDir )
636 .println( "envKeys" ,envKeys )
637 .println( "envVals" ,envVals )
638 .println( "timeout" ,timeout )
639 .println( "Other..." ,getAttributes().getAttribute() )
640 .fixForm().toString() ;
641 }
642 }