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.hayabusa.servlet; 017 018import java.io.File; 019import java.io.IOException; 020import java.io.PrintWriter; 021import java.lang.reflect.Field; 022import java.net.URL; 023import java.util.Enumeration; 024import java.util.Map; 025import java.util.jar.JarEntry; 026import java.util.jar.JarFile; 027 028import javax.servlet.ServletContext; 029import javax.servlet.ServletException; 030import javax.servlet.http.HttpServlet; 031import javax.servlet.http.HttpServletRequest; 032import javax.servlet.http.HttpServletResponse; 033import javax.servlet.http.HttpSession; 034 035import org.opengion.fukurou.db.ConnectionFactory; 036import org.opengion.fukurou.util.Attributes; 037import org.opengion.fukurou.util.HybsEntry; 038import org.opengion.fukurou.util.StringUtil; 039import org.opengion.fukurou.util.Closer ; // 5.5.2.6 (2012/05/25) 040import org.opengion.hayabusa.common.BuildNumber; 041import org.opengion.hayabusa.common.HybsSystem; 042import org.opengion.hayabusa.common.SystemManager; 043import org.opengion.hayabusa.common.SystemParameter; 044import org.opengion.hayabusa.common.UserSummary; 045 046/** 047 * サーバー管理情報を取得するAdminサーブレットです。 048 * 049 * 引数(URL)に応じて、サーバーの状態結果を返します。 050 * 一般には、http://サーバー:ポート/システムID/jsp/admin?COMMAND=コマンド の 051 * 形式のURL でアクセスします。 052 * 053 * ・COMMAND=infomation 054 * 【サーバー情報】 055 * OS情報 = Windows 7 Service Pack 1 056 * サーバー名 = 10374232-0004 ( 172.27.26.192 ) 057 * サーブレット = Apache Tomcat/7.0.42 058 * TOMCAT_HOME = C:/opengionV6/uap/bin//../../apps/tomcat7.0.42 059 * JDKバージョン = Java HotSpot(TM) Server VM 23.25-b01 060 * JAVA_HOME = C:/opengionV6/apps/jdk170u25/jre 061 * 062 * 【実行環境】 063 * REAL_PATH = C:/opengionV6/uap/webapps/gf/ 064 * バージョンNo = 6.0.0.0 Release6 Builds (2013233) 065 * 作成日時 = 2013/08/21 14:57:29 066 * 067 * 【ログイン情報】 068 * ログイン人数 = 2 名 ( 明細情報 ) 069 * 070 * 【メモリ情報】 071 * 空きメモリ = 15977 [KByte] 072 * 合計メモリ = 32448 [KByte] 073 * 使用率 = 50 [%] 074 * 075 * ・COMMAND=close 076 * リソース情報のキャッシュを全てクリアします。 077 * 078 * ・COMMAND=loginUser 079 * 現在のログインユーザーの明細情報を表示します。 080 * SORT=[JNAME,ID,ROLES,IPADDRESS,LOGINTIME] ソートキー 081 * DIREC=[true,false] true:昇順/false:降順 082 * 083 * ・COMMAND=plugin 084 * 現在のプラグインのバージョン情報を表示します。 085 * 086 * ・COMMAND=systemResource 087 * 現在のシステムリソースの設定情報を表示します。 088 * 089 * ・COMMAND=AccessStop 090 * アクセスストップフィルターの制御(停止、許可)を行います。 091 * 092 * @og.rev 3.5.3.0 (2003/10/27) Admin JSP を Servlet化して、エンジンと共に供給します。 093 * @og.rev 4.0.0.0 (2005/08/31) プラグインのバージョン情報の表示機能を追加 094 * @og.group その他機能 095 * 096 * @version 4.0 097 * @author Kazuhiko Hasegawa 098 * @since JDK5.0, 099 */ 100public final class HybsAdmin extends HttpServlet { 101 private static final long serialVersionUID = 400020050131L ; // 4.0.0.0 (2005/01/31) 102 103 private static final String CR = HybsSystem.CR ; 104 105 private static final String JSP = HybsSystem.sys( "JSP" ); // jspフォルダの正規パス 106 107 private static final String HEADER = 108 "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>" + CR + 109 "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\"" + CR + 110 " \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">" + CR + 111 "<html xmlns=\"http://www.w3.org/1999/xhtml\" >" + CR + 112 "<head>" + CR + 113 " <meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\" />" + CR + 114 " <meta http-equiv=\"Content-Style-Type\" content=\"text/css\" />" + CR + 115 " <link rel=\"stylesheet\" href=\"" + JSP + "/common/default.css\" type=\"text/css\" />" + CR + 116 " <link rel=\"stylesheet\" href=\"" + JSP + "/custom/custom.css\" type=\"text/css\" />" + CR + 117 " <title>Hybs Admin</title>" + CR + 118 "</head>" + CR; 119 120 // 3.5.3.1 (2003/10/31) User情報のテーブルの設定を、システムリソース より行う。 121 private static final String TABLE_HEADER = getTableHeaderTag() ; 122 123 private static final String OS_INFO = HybsSystem.sys( "OS_INFO" ); // Windows 7 Service Pack 1 124 private static final String SERVER_INFO = HybsSystem.sys( "SERVER_INFO" ); // 10374232-0004 ( 200.1.50.239 ) 125 private static final String SERVLET_INFO = HybsSystem.sys( "SERVLET_INFO" ); // Apache Tomcat/7.0.39 126 private static final String REAL_PATH = HybsSystem.sys( "REAL_PATH" ); // C:/opengion/uap/webapps/gf/ 127 private static final String TOMCAT_HOME = HybsSystem.sys( "TOMCAT_HOME" ); // C:/opengion/apps/tomcat5.5.17 128 private static final String JDK_INFO = HybsSystem.sys( "JDK_INFO" ); // Java HotSpot(TM) Server VM 23.25-b01 129 private static final String JAVA_HOME = HybsSystem.sys( "JAVA_HOME" ); // C:/opengion/apps/jdk170u25/jre 130 private static final String ENGINE_INFO = HybsSystem.sys( "ENGINE_INFO" ); // 5.6.6.0 Release5 Builds (2013182) 131 132 // 5.6.6.0 (2013/07/05) getLoginUser( String,boolean ) で、指定するキーを配列で持っておきます。 133 // キーは、SystemManager.getRunningUserSummary 処理内で大文字化されるため、この配列は、表示用と兼用します。 134 private static final String[] USER_KEYS = new String[] { "ID","Jname","Roles","IPAddress","LoginTime","LastAccess","LastGamenNm" }; 135 136 /** 137 * GET メソッドが呼ばれたときに実行します。 138 * 139 * @og.rev 3.5.3.1 (2003/10/31) 機能ごとにメソッドを呼び出すように修正します。 140 * @og.rev 3.5.4.1 (2003/12/01) getAdminLink() メソッドを追加 141 * 142 * @param req HttpServletRequestオブジェクト 143 * @param res HttpServletResponseオブジェクト 144 * 145 * @throws ServletException サーブレット関係のエラーが発生した場合、throw されます。 146 * @throws IOException 入出力エラーが発生したとき 147 */ 148 @Override 149 public void doGet( final HttpServletRequest req, final HttpServletResponse res) 150 throws ServletException, IOException { 151 152 res.setContentType( "text/html; charset=UTF-8" ); 153 PrintWriter out = res.getWriter(); 154 155 String command = req.getParameter( "COMMAND" ); 156 157 out.println( HEADER ); 158 out.println("<body>"); 159 160 out.print("<h2>"); 161 out.print( req.getServerName() ); 162 out.print( ":" ); 163 out.print( req.getServerPort() ); 164 out.print( req.getContextPath() ); 165 out.println("</h2>"); 166 167 if( "infomation".equalsIgnoreCase( command ) ) { 168 out.print( getInfomation() ); 169 } 170 else if( "close".equalsIgnoreCase( command ) ) { 171 out.print( getCloseMessage( req.getSession() ) ); 172 } 173 else if( "loginUser".equalsIgnoreCase( command ) ) { 174 String sort = req.getParameter( "sort" ); 175 String direc = req.getParameter( "direc" ); 176 boolean dir = (direc == null) ? true : Boolean.valueOf( direc ).booleanValue(); 177 out.print( getLoginUser(sort,dir) ); 178 } 179 else if( "plugin".equalsIgnoreCase( command ) ) { 180 out.print( getPlugInInfo() ); 181 } 182 else if( "taglib".equalsIgnoreCase( command ) ) { 183 out.print( getTaglibInfo() ); 184 } 185 else if( "systemResource".equalsIgnoreCase( command ) ) { 186 out.print( getSystemResource() ); 187 } 188 else if( "AccessStop".equalsIgnoreCase( command ) ) { 189 out.print( getAccessStop() ); 190 } 191 else { 192 out.print( getAdminLink() ); // 3.5.4.1 (2003/12/01) 追加 193 } 194 195 out.println("</body></html>"); 196 } 197 198 /** 199 * infomation 情報を作成します。 200 * 201 * @og.rev 3.5.3.1 (2003/10/31) 機能ごとにメソッドを呼び出すように修正します。 202 * @og.rev 5.6.7.3 (2013/08/23) TOMCAT_WORKは、TOMCAT_HOME に置き換えます。 203 * 204 * @return infomation情報 205 */ 206 private String getInfomation() { 207 // 4.0.0 (2005/01/31) ログイン数の取得方法の変更。 208 int loginCount = SystemManager.getRunningCount() ; 209 210 int freeMemory = (int)( Runtime.getRuntime().freeMemory()/1024 ) ; 211 int totalMemory = (int)( Runtime.getRuntime().totalMemory()/1024 ); 212 int useMemoryRatio = ((totalMemory - freeMemory) * 100 )/totalMemory ; 213 214 StringBuilder rtn = new StringBuilder( HybsSystem.BUFFER_MIDDLE ); 215 216 rtn.append( "<table border = \"0px\" >" ).append( CR ); 217 tableTr1( rtn,"サーバー情報" ); 218 tableTr( rtn,"OS情報" , OS_INFO ); 219 tableTr( rtn,"サーバー名" , SERVER_INFO ); 220 tableTr( rtn,"サーブレット" , SERVLET_INFO ); 221 tableTr( rtn,"TOMCAT_HOME" , TOMCAT_HOME ); // 5.6.7.3 (2013/08/23) 222 tableTr( rtn,"JDKバージョン", JDK_INFO ); 223 tableTr( rtn,"JAVA_HOME" , JAVA_HOME ); 224 225 tableTr1( rtn,"実行環境" ); 226 tableTr( rtn,"REAL_PATH" , REAL_PATH ); 227 tableTr( rtn,"バージョンNo" , ENGINE_INFO ); 228 tableTr( rtn,"作成日時" , BuildNumber.TIMESTAMP ); 229 230 tableTr1( rtn,"ログイン情報" ); 231 tableTr( rtn,"ログイン人数" , String.valueOf( loginCount )," 名 ","( <a href=\"admin?COMMAND=loginUser\">明細情報</a> )" ); 232 233 tableTr1( rtn,"メモリ情報" ); 234 tableTr( rtn,"空きメモリ" , String.valueOf( freeMemory ) , " [KByte]" ); 235 tableTr( rtn,"合計メモリ" , String.valueOf( totalMemory ) , " [KByte]" ); 236 tableTr( rtn,"使用率" , String.valueOf( useMemoryRatio ) , " [%]" ); 237 238 rtn.append( "</table>" ).append( CR ); 239 rtn.append( CR ); 240 241 rtn.append( "<table width=\"50%\" frame=\"box\" border = \"1px\" cellspacing=\"0px\" cellpadding=\"0px\" >" ).append( CR ); 242 rtn.append( " <tr><td align=\"center\" width=\"" ).append( useMemoryRatio ).append( "%\" bgcolor=\"red\" >" ).append( CR ); 243 rtn.append( useMemoryRatio ).append( "%</td>" ).append( CR ); 244 rtn.append( " <td align=\"center\">" ).append( 100-useMemoryRatio ).append( "%</td>" ).append( CR ); 245 rtn.append( " </tr>" ).append( CR ); 246 rtn.append( "</table>" ).append( CR ); 247 248 rtn.append( "<hr />" ).append( CR ); 249 rtn.append( "<pre>" ).append( CR ); 250 rtn.append( ConnectionFactory.information() ).append( CR ); 251 rtn.append( "</pre>" ).append( CR ); 252 253 return rtn.toString(); 254 } 255 256 /** 257 * infomation 情報を作成します。 258 * 259 * @og.rev 5.6.6.0 (2013/07/05) </td></tr>漏れ追加 260 * @og.rev 5.6.7.3 (2013/08/23) 前後に、【】を付けます。 261 * 262 * @param buf 情報登録用のStringBuilder(出力と同じオブジェクト) 263 * @param key キー 264 * 265 * @return infomation情報 266 */ 267 private StringBuilder tableTr1( final StringBuilder buf, final String key ) { 268 buf.append( "<tr><td colspan=\"4\"><b>【" ).append( key ).append( "】</b></td></tr>" ).append( CR ); // 【】追加 269 return buf ; 270 } 271 272 /** 273 * infomation 情報を作成します。 274 * 275 * @og.rev 5.6.6.0 (2013/07/05) 最初の td に、全角スペース2個 追加 276 * 277 * @param buf 情報登録用のStringBuilder(出力と同じオブジェクト) 278 * @param key キー 279 * @param val 値の可変長引数 280 * 281 * @return infomation情報 282 */ 283 private StringBuilder tableTr( final StringBuilder buf, final String key, final String... val ) { 284 buf.append( "<tr><td width=\"20px\"> </td><td>" ).append( key ).append( "</td><td> = </td><td>" ); // 段を作成する為に、width指定 追加 285 for( int i=0; i<val.length; i++ ) { 286 buf.append( val[i] ); 287 } 288 buf.append( "</td></tr>" ).append( CR ); 289 return buf ; 290 } 291 292 /** 293 * close 情報を作成します。 294 * 295 * @og.rev 3.5.3.1 (2003/10/31) 機能ごとにメソッドを呼び出すように修正します。 296 * @og.rev 3.6.0.0 (2004/09/17) CalendarFactory.clear() を追加します。 297 * @og.rev 4.0.0.0 (2005/01/31) Cleanable インターフェースによる初期化処理 298 * @og.rev 4.1.0.2 (2008/01/29) UserInfoをsessionから消去する(超暫定対応) 299 * @og.rev 5.6.6.0 (2013/07/05) UserSummary の削除処理は、SystemManager から行う。 300 * 301 * @param session HttpSessionオブジェクト 302 * 303 * @return close情報 304 */ 305 private String getCloseMessage( final HttpSession session ) { 306 307 // 4.0.0 (2005/01/31) Cleanable インターフェースによる初期化処理 308 SystemManager.allClear( false ) ; 309 310 ServletContext context = session.getServletContext(); 311 Map<String,String> param = SystemParameter.makeSystemParameter( context ); 312 HybsSystem.setInitialData( param ); // 4.0.0 (2005/01/31) 313 314 // 5.6.6.0 (2013/07/05) UserSummary の削除処理は、SystemManager から行う。 315 SystemManager.removeSession( session ) ; 316 317 String rtn = "<pre>" 318 + "キャッシュ情報をクリアーしました。" 319 + CR 320 + "ユーザー情報の初期化に関しては、ブラウザを閉じて、再ログインが必要です。" 321 + CR 322 + ConnectionFactory.information() 323 + "</pre>" ; 324 return rtn ; 325 } 326 327 /** 328 * loginUser 情報を作成します。 329 * 330 * @og.rev 3.5.3.1 (2003/10/31) 機能ごとにメソッドを呼び出すように修正します。 331 * @og.rev 3.8.5.3 (2006/08/07) ユーザー情報をソートするためのキー情報を追加 332 * @og.rev 3.8.7.0 (2006/12/15) USER.LASTACCESS情報を追加します。 333 * @og.rev 4.0.0.0 (2005/01/31) DBColumn の 属性(CLS_NM)から、DBTYPEに変更 334 * @og.rev 4.4.0.1 (2009/08/08) 最終ログイン画面名称を追加 335 * @og.rev 5.6.6.0 (2013/07/05) table作成処理を、変更します。 336 * 337 * @param sort ソートするキー項目を指定 338 * @param direc ソートする方向 [true:昇順/false:降順] 339 * 340 * @return loginUser情報 341 */ 342 private String getLoginUser( final String sort,final boolean direc ) { 343 // 4.0.0 (2005/01/31) ログイン数の取得方法の変更。 344 int loginCount = SystemManager.getRunningCount() ; 345 346 // 4.0.0 (2005/01/31) 347 UserSummary[] userInfos = SystemManager.getRunningUserSummary( sort,direc ); 348 349 StringBuilder rtn = new StringBuilder( HybsSystem.BUFFER_MIDDLE ); 350 351 rtn.append( "現在 " ).append( loginCount ).append( " 名の方がログイン中です。" ); 352 rtn.append( CR ); 353 354 rtn.append( "<table " ).append( TABLE_HEADER ).append( " >" ).append( CR ); 355 rtn.append( " <thead><tr><th>No</th>" ); 356 357 // 5.6.6.0 (2013/07/05) table作成処理を、変更します。 358 for( String sortKey : USER_KEYS ) { 359 rtn.append( " <th><a href=\"?COMMAND=loginUser&sort=" ).append( sortKey ) 360 .append( "&direc=" ).append( !direc ) 361 .append( "\">" ).append( sortKey ).append( "</a></th>" ); 362 } 363 364 rtn.append( " </tr></thead>" ).append( CR ); 365 rtn.append( " <colgroup class=\"S9\" />" ).append( CR ); 366 rtn.append( " <colgroup class=\"X\" span=\"6\" />" ).append( CR ); 367 rtn.append( CR ); 368 369 for( int i=0; i<userInfos.length; i++ ) { 370 UserSummary userInfo = userInfos[i] ; 371 rtn.append( " <tr class=\"row_" ).append( i%2 ).append( "\" >" ).append( CR ); 372 rtn.append( " <td>" ).append( String.valueOf( i+1 ) ).append( "</td>" ).append( CR ); 373 rtn.append( " <td>" ).append( userInfo.getUserID() ).append( "</td>" ).append( CR ); 374 rtn.append( " <td>" ).append( userInfo.getJname() ).append( "</td>" ).append( CR ); 375 rtn.append( " <td>" ).append( userInfo.getRoles() ).append( "</td>" ).append( CR ); 376 rtn.append( " <td>" ).append( userInfo.getIPAddress() ).append( "</td>" ).append( CR ); 377 rtn.append( " <td>" ).append( HybsSystem.getDate( userInfo.getLoginTime() ) ).append( "</td>" ).append( CR ); 378 rtn.append( " <td>" ).append( userInfo.getAttribute( "LASTACCESS") ).append( "</td>" ).append( CR ); 379 rtn.append( " <td>" ).append( StringUtil.nval( userInfo.getAttribute( "LASTGAMENNM"), "" ) ).append( "</td>" ).append( CR ); // 4.4.0.1 (2009/08/08) 380 rtn.append( " </tr>" ).append( CR ); 381 } 382 rtn.append( "</table>" ).append( CR ); 383 384 return rtn.toString() ; 385 } 386 387 /** 388 * PlugIn 情報を作成します。 389 * 390 * @og.rev 4.0.0.0 (2005/08/31) 新規作成 391 * @og.rev 5.6.6.0 (2013/07/05) "DBConstValue","Daemon","JspCreate" を、追加します。 392 * 393 * @return PlugIn情報 394 */ 395 private String getPlugInInfo() { 396 397 String[] pluginType = new String[] { 398 "Query","Renderer","Editor","DBType","ViewForm", 399 "TableReader","TableWriter","TableFilter","ChartWriter","CalendarQuery", 400 "DBConstValue","Daemon","JspCreate" // 5.6.6.0 (2013/07/05) 追加 401 } ; 402 403 ClassInfo info = new ClassInfo(); 404 405 for( int j=0; j<pluginType.length; j++ ) { 406 String type = pluginType[j] ; 407 HybsEntry[] names = HybsSystem.sysEntry( type + "_" ); 408 for( int i=0; i<names.length; i++ ) { 409 String key = names[i].getKey().substring( type.length()+1 ); 410 String clsName = names[i].getValue(); 411 info.addLine( type,key,clsName ); 412 } 413 } 414 return info.getClassInfoData() ; 415 } 416 417 /** 418 * Taglib 情報を作成します。 419 * 420 * @og.rev 4.0.0.0 (2006/01/31) 新規作成 421 * @og.rev 5.3.6.0 (2011/06/01) Taglib クラス名の求め方を変更します。(jar版のみ) 422 * @og.rev 5.5.2.6 (2012/05/25) JarFile を、Closer#zipClose( ZipFile ) メソッドを利用して、close します。 423 * 424 * @return Taglib情報 425 */ 426 private String getTaglibInfo() { 427 ClassInfo info = new ClassInfo(); 428 429 // 5.5.2.6 (2012/05/25) findbugs対応 430 JarFile jarFile = null; 431 try { 432 ClassLoader loader = Thread.currentThread().getContextClassLoader(); 433 Enumeration<URL> enume = loader.getResources( "org/opengion/hayabusa/taglib/" ); // 4.3.3.6 (2008/11/15) Generics警告対応 434 while( enume.hasMoreElements() ) { 435 URL url = enume.nextElement(); // 4.3.3.6 (2008/11/15) Generics警告対応 436 // jar:file:/実ディレクトリ または、file:/実ディレクトリ 437 String dir = url.getFile(); 438 if( "jar".equals( url.getProtocol() ) ) { 439 // dir = file:/G:/webapps/gf/WEB-INF/lib/hayabusa4.0.0.jar!/org/opengion/hayabusa/taglib 形式です。 440 String jar = dir.substring(dir.indexOf( ':' )+1,dir.lastIndexOf( '!' )); 441 // jar = /G:/webapps/gf/WEB-INF/lib/hayabusa4.0.0.jar 形式に切り出します。 442 jarFile = new JarFile( jar ); 443 Enumeration<JarEntry> en = jarFile.entries() ; // 4.3.3.6 (2008/11/15) Generics警告対応 444 while( en.hasMoreElements() ) { 445 JarEntry ent = en.nextElement(); // 4.3.3.6 (2008/11/15) Generics警告対応 446 String file = ent.getName(); 447 if( ! ent.isDirectory() && file.endsWith( "Tag.class" ) ) { 448 String type = "Taglib"; 449 // 5.3.6.0 (2011/06/01) Taglib クラス名の求め方を変更します。(jar版のみ) 450 String key = file.substring( file.lastIndexOf( '/' )+1,file.length()-6 ); // -6 は、.class 分 451 String clsName = file.replace( '/','.' ).substring( 0,file.length()-6 ); 452 info.addLine( type,key,clsName ); 453 } 454 } 455 Closer.zipClose( jarFile ); // 5.5.2.6 (2012/05/25) findbugs対応 456 jarFile = null; // 正常終了時に、close() が2回呼ばれるのを防ぐため。 457 } 458 else { 459 // dir = /G:/webapps/gf/WEB-INF/classes/org/opengion/hayabusa/taglib/ 形式です。 460 File fileObj = new File( dir ); 461 File[] list = fileObj.listFiles(); 462 for( int i=0; i<list.length; i++ ) { 463 String file = list[i].getName() ; 464 if( list[i].isFile() && file.endsWith( "Tag.class" ) ) { 465 String type = "Taglib"; 466 String key = file.substring( 0,file.length()-6 ); 467 String clsName = "org.opengion.hayabusa.taglib." + key ; 468 info.addLine( type,key,clsName ); 469 } 470 } 471 } 472 } 473 } 474 catch( IOException ex ) { 475 String errMsg = "taglibファイル読み取りストリームを失敗しました。" 476 + CR + ex.getMessage(); 477 throw new RuntimeException( errMsg,ex ); 478 } 479 finally { 480 Closer.zipClose( jarFile ); // 5.5.2.6 (2012/05/25) findbugs対応 481 } 482 483 return info.getClassInfoData() ; 484 } 485 486 /** 487 * クラス情報を表示するためのデータを管理します。 488 * ここでは、引数に渡された、分類(Classify)、名称(Key Name)、クラス名(Class Name)、 489 * バージョン(Version)情報をテーブル形式で表示します。 490 * バージョン情報は、クラス名から、インスタンスを作成して、private static final String VERSION 491 * フィールドの値を読み取ります。 492 * 493 * @og.rev 4.0.0.0 (2006/01/31) 新規作成 494 */ 495 private static final class ClassInfo { 496 private final StringBuilder rtn = new StringBuilder( HybsSystem.BUFFER_MIDDLE ); 497 private int cnt = 0; 498 499 /** 500 * コンストラクター 501 * 502 * @og.rev 4.0.0.0 (2006/01/31) 新規作成 503 */ 504 public ClassInfo() { 505 rtn.append( "<table " ).append( TABLE_HEADER ).append( " >" ).append( CR ); 506 rtn.append( " <thead><tr><th>No</th><th>Classify</th><th>Key Name</th><th>Class Name</th><th>Version</th></tr></thead>" ).append( CR ); 507 rtn.append( " <colgroup class=\"S9\" />" ).append( CR ); 508 rtn.append( " <colgroup class=\"X\" />" ).append( CR ); 509 rtn.append( " <colgroup class=\"X\" />" ).append( CR ); 510 rtn.append( " <colgroup class=\"X\" />" ).append( CR ); 511 rtn.append( " <colgroup class=\"X\" />" ).append( CR ); 512 rtn.append( " <colgroup class=\"X\" />" ).append( CR ); 513 rtn.append( CR ); 514 } 515 516 /** 517 * テーブル表示用のデータを追加します。 518 * 519 * @og.rev 4.0.0.0 (2006/01/31) 新規作成 520 * 521 * @param type タイプ属性 522 * @param key キー属性 523 * @param clsName クラス名(このクラス名からインスタンス化します。) 524 */ 525 public void addLine( final String type, final String key, final String clsName ) { 526 String version = getFieldValue( clsName ); 527 528 boolean isCustom = version.compareTo( BuildNumber.VERSION_NO ) > 0 529 || version.indexOf( "Pache" ) >= 0 530 || version.indexOf( "Nightly" ) >= 0 ; 531 532 String trType = isCustom ? "warning" : String.valueOf( cnt%2 ); 533 534 rtn.append( " <tr class=\"row_" ).append( trType ).append( "\" >" ).append( CR ); 535 rtn.append( " <td>" ).append( cnt++ ).append( "</td>" ).append( CR ); 536 rtn.append( " <td>" ).append( type ).append( "</td>" ).append( CR ); 537 rtn.append( " <td>" ).append( key ).append( "</td>" ).append( CR ); 538 rtn.append( " <td>" ).append( clsName ).append( "</td>" ).append( CR ); 539 rtn.append( " <td>" ).append( version ).append( "</td>" ).append( CR ); 540 rtn.append( " </tr>" ).append( CR ); 541 } 542 543 /** 544 * すべての内部のデータを文字列化して返します。 545 * 546 * @og.rev 4.0.0.0 (2006/01/31) 新規作成 547 * 548 * @return 作成されたテーブルデータ 549 */ 550 public String getClassInfoData() { 551 rtn.append( "</table>" ).append( CR ); 552 return rtn.toString() ; 553 } 554 555 /** 556 * 指定のオブジェクトの VERSION staticフィールドの値を取得します。 557 * 558 * @og.rev 4.0.0.0 (2005/08/31) 新規作成 559 * 560 * @param clsName 指定のクラスを表す名称 561 * @return VERSION staticフィールドの値(エラー時は、そのメッセージ) 562 */ 563 private String getFieldValue( final String clsName ) { 564 String rtn ; 565 try { 566 Object obj = HybsSystem.newInstance( clsName ); 567 Field fld = obj.getClass().getDeclaredField( "VERSION" ) ; 568 // privateフィールドの取得には、accessibleフラグを trueにする必要があります。 569 fld.setAccessible( true ); 570 571 rtn = (String)fld.get( null ); 572 } 573 catch( Throwable ex ) { 574 rtn = ex.getMessage(); 575 } 576 return rtn ; 577 } 578 } 579 580 /** 581 * systemResource 情報を作成します。 582 * 583 * @og.rev 3.5.3.1 (2003/10/31) 機能ごとにメソッドを呼び出すように修正します。 584 * @og.rev 4.0.0.0 (2005/01/31) DBColumn の 属性(CLS_NM)から、DBTYPEに変更 585 * 586 * @return systemResource情報 587 */ 588 private String getSystemResource() { 589 StringBuilder rtn = new StringBuilder( HybsSystem.BUFFER_MIDDLE ); 590 591 rtn.append( "<table " ).append( TABLE_HEADER ).append( " >" ).append( CR ); 592 rtn.append( " <thead><tr><th>No</th><th>Key</th><th>Value</th></tr></thead>" ).append( CR ); 593 rtn.append( " <colgroup class=\"S9\" />" ).append( CR ); 594 rtn.append( " <colgroup class=\"X\" span=\"2\" />" ).append( CR ); 595 rtn.append( CR ); 596 597 String[][] str = HybsSystem.getSystemResourceData(); 598 for( int i=0; i<str[0].length; i++ ) { 599 rtn.append( " <tr class=\"row_" ).append( i%2 ).append( "\" >" ).append( CR ); 600 rtn.append( " <td>" ).append( String.valueOf( i+1 ) ).append( "</td>" ).append( CR ); 601 rtn.append( " <td>" ).append( str[0][i] ).append( "</td>" ).append( CR ); 602 rtn.append( " <td>" ).append( str[1][i] ).append( "</td>" ).append( CR ); 603 rtn.append( " </tr>" ).append( CR ); 604 } 605 rtn.append( "</table>" ).append( CR ); 606 607 return rtn.toString(); 608 } 609 610 /** 611 * AccessStop 情報を作成します。 612 * 613 * @og.rev 3.5.3.1 (2003/10/31) 機能ごとにメソッドを呼び出すように修正します。 614 * @og.rev 4.0.0.0 (2007/11/29) AccessStopFilter#getStopFilter() ⇒ isStopFilter() に変更 615 * 616 * @return AccessStop情報 617 */ 618 private String getAccessStop() { 619 620 boolean flag = org.opengion.hayabusa.filter.AccessStopFilter.isStopFilter(); 621 flag = !flag ; 622 623 final String rtn ; 624 if( flag ) { 625 rtn = "Webアプリケーションのサービスを停止します。"; 626 } 627 else { 628 rtn = "Webアプリケーションのサービスを開始します。"; 629 } 630 org.opengion.hayabusa.filter.AccessStopFilter.setStopFilter( flag ); 631 632 return rtn ; 633 } 634 635 /** 636 * admin リンク情報を作成します。 637 * 簡易メソッドなので、国際化対応していません。 638 * 639 * @og.rev 3.5.4.1 (2003/12/01) 新規作成 640 * @og.rev 5.1.1.2 (2009/12/10) 画面IDを変更 641 * @og.rev 5.6.3.4 (2013/04/26) クイックリファレンス 画面を追加 642 * 643 * @return アドミンリンク情報 644 */ 645 private String getAdminLink() { 646 StringBuilder rtn = new StringBuilder( HybsSystem.BUFFER_MIDDLE ); 647 648 rtn.append( "<table><tr>" ).append( CR ); 649 rtn.append( "<td width=\"10px\"/>" ).append( CR ); 650 rtn.append( "<td>[<a href=\"admin?COMMAND=infomation\" target=\"RESULT\" >状況表示</a>]</td>" ).append( CR ); 651 rtn.append( "<td width=\"10px\"/>" ).append( CR ); 652 rtn.append( "<td>[<a href=\"admin?COMMAND=close\" target=\"RESULT\" >プール削除</a>]</td>" ).append( CR ); 653 rtn.append( "<td width=\"10px\"/><td>" ).append( CR ); 654 rtn.append( "[<a href=\"admin?COMMAND=loginUser\" target=\"RESULT\" >ログインユーザー</a>]</td>" ).append( CR ); 655 rtn.append( "<td width=\"10px\"/><td>" ).append( CR ); 656 rtn.append( "[<a href=\"admin?COMMAND=plugin\" target=\"RESULT\" >プラグイン情報</a>]</td>" ).append( CR ); 657 rtn.append( "<td width=\"10px\"/><td>" ).append( CR ); 658 rtn.append( "[<a href=\"admin?COMMAND=taglib\" target=\"RESULT\" >タグリブ情報</a>]</td>" ).append( CR ); 659 rtn.append( "<td width=\"10px\"/><td>" ).append( CR ); 660 rtn.append( "[<a href=\"common/quickReference.html\" target=\"RESULT\" >クイックリファレンス</a>]</td>" ).append( CR ); // 5.6.3.4 (2013/04/26) 661 rtn.append( "<td width=\"10px\"/><td>" ).append( CR ); 662 rtn.append( "[<a href=\"admin?COMMAND=systemResource\" target=\"RESULT\" >システムリソース</a>]</td>" ).append( CR ); 663 rtn.append( "<td width=\"10px\"/><td>" ).append( CR ); 664 rtn.append( "[<a href=\"common/gamen/01_ADMIN/parameter.jsp?GAMENID=01_ADMIN\" target=\"RESULT\" >Parameter</a>]</td>" ).append( CR ); 665 rtn.append( "</tr></table>" ).append( CR ); 666 667 return rtn.toString(); 668 } 669 670 /** 671 * DBTableModel から テーブルのタグ文字列を作成して返します。 672 * 673 * @og.rev 3.5.3.1 (2003/10/31) User情報のテーブルの設定を、システムリソース より行う。 674 * @og.rev 5.2.2.0 (2010/11/01) SystemData 見直し漏れの対応。 675 * 676 * @return テーブルのタグ文字列 677 */ 678 private static String getTableHeaderTag() { 679 Attributes attri = new Attributes(); 680 attri.set( "id" ,"viewTable" ); // 3.6.0.5 (2004/10/18) 681 attri.set( "summary" ,"layout" ); // サマリー 682 683 return attri.getAttribute(); 684 } 685}