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 org.opengion.fukurou.system.OgRuntimeException ;                         // 6.4.2.0 (2016/01/29)
019import java.io.File;
020import java.io.IOException;
021import java.io.PrintWriter;
022import java.lang.reflect.Field;
023import java.net.URL;
024import java.util.Enumeration;
025import java.util.Map;
026import java.util.concurrent.ConcurrentMap;                                                      // 6.4.3.3 (2016/03/04)
027import java.util.jar.JarEntry;
028import java.util.jar.JarFile;
029
030import javax.servlet.ServletContext;
031import javax.servlet.ServletException;
032import javax.servlet.http.HttpServlet;
033import javax.servlet.http.HttpServletRequest;
034import javax.servlet.http.HttpServletResponse;
035import javax.servlet.http.HttpSession;
036
037import org.opengion.fukurou.db.ConnectionFactory;
038import org.opengion.fukurou.util.Attributes;
039import org.opengion.fukurou.util.HybsEntry;
040import org.opengion.fukurou.util.StringUtil;
041import org.opengion.fukurou.fileexec.MainProcess;                                       // 7.2.5.0 (2020/06/01)
042import org.opengion.fukurou.system.BuildNumber;                                         // 6.4.2.0 (2016/01/29) hayabusa.common.BuildNumber → fukurou.system.BuildNumber に移動
043import org.opengion.fukurou.system.Closer ;                                                     // 5.5.2.6 (2012/05/25)
044import org.opengion.hayabusa.common.HybsSystem;
045import org.opengion.hayabusa.common.SystemManager;
046import org.opengion.hayabusa.common.SystemParameter;
047import org.opengion.hayabusa.common.UserSummary;
048import static org.opengion.fukurou.system.HybsConst.CR ;                        // 6.1.0.0 (2014/12/26)
049import static org.opengion.fukurou.system.HybsConst.BUFFER_MIDDLE;      // 6.1.0.0 (2014/12/26) refactoring
050
051import org.opengion.hayabusa.resource.ResourceFactory;                          // 5.9.1.0 (2015/10/02)
052import org.opengion.hayabusa.resource.UserInfo;                                         // 5.9.1.0 (2015/10/02)
053
054import javax.servlet.ServletRegistration;                                                       // 6.3.4.0 (2015/08/01)
055import javax.servlet.FilterRegistration;                                                        // 6.3.4.0 (2015/08/01)
056import javax.servlet.annotation.WebServlet;                                                     // 7.3.0.0 (2021/01/06)
057
058/**
059 * サーバー管理情報を取得するAdminサーブレットです。
060 *
061 * 引数(URL)に応じて、サーバーの状態結果を返します。
062 * 一般には、http://サーバー:ポート/システムID/jsp/admin?COMMAND=コマンド の
063 * 形式のURL でアクセスします。
064 *
065 *  ・COMMAND=infomation
066 *     【サーバー情報】
067 *        OS情報      = Windows 7 Service Pack 1 x86 (32)
068 *        サーバー名    = 10374232-0004 ( 172.27.26.164 )
069 *        サーブレット  = Apache Tomcat/8.0.22
070 *        TOMCAT_HOME   = C:\opengionV6\apps\tomcat8.0.22
071 *        JDKバージョン = Java HotSpot(TM) Server VM 1.8.0_45-b15
072 *        JAVA_HOME     = C:\opengionV6\apps\jdk180u45\jre
073 *     【実行環境】
074 *        REAL_PATH     = C:/opengionV6/uap/webapps/gf/
075 *        バージョンNo  = openGion 6.2.4.0 Release6 Builds (2015142)
076 *        作成日時      = 2015/05/22 15:31:53
077 *     【ログイン情報】
078 *        ログイン人数  = 2 名 ( 明細情報 )
079 *     【メモリ情報】
080 *        空きメモリ    = 129 [MByte]
081 *        合計メモリ    = 209 [MByte]
082 *        使用率        = 38 [%]
083 *     【ディスク情報】
084 *
085 *  ・COMMAND=close
086 *       リソース情報のキャッシュを全てクリアします。
087 *
088 *  ・COMMAND=loginUser
089 *       現在のログインユーザーの明細情報を表示します。
090 *       SORT=[JNAME,ID,ROLES,IPADDRESS,LOGINTIME] ソートキー
091 *       DIREC=[true,false] true:昇順/false:降順
092 *  ・COMMAND=systemResource
093 *       現在のシステムリソースの設定情報を表示します。
094 *
095 *  ・COMMAND=AccessStop&stop=[true/false]
096 *       アクセスストップフィルターの制御(停止、許可)を行います。
097 *  ・common/gamen/01_ADMIN/parameter.jsp
098 *       現在のシステムリソースの設定情報を表示します。
099 *
100 *  ・common/gamen/01_ADMIN/systemInfo.jsp
101 *       システム定数のシステム起動情報を表示します。
102 *
103 *    ※ 7.1.0.0 (2020/01/20)
104 *  ・common/gamen/01_ADMIN/logLink.jsp
105 *       Tomcatのlogを表示します。
106 *
107 *    ※ 7.1.0.0 (2020/01/20)
108 *  ・common/gamen/01_ADMIN/serviceRestart.jsp
109 *       Tomcatのサービスを再起動(停止―開始)します。
110 *
111 * @og.rev 3.5.3.0 (2003/10/27) Admin JSP を Servlet化して、エンジンと共に供給します。
112 * @og.rev 4.0.0.0 (2005/08/31) プラグインのバージョン情報の表示機能を追加
113 * @og.group その他機能
114 *
115 * @version  4.0
116 * @author   Kazuhiko Hasegawa
117 * @since    JDK5.0,
118 */
119@WebServlet( "/jsp/admin" )
120public final class HybsAdmin extends HttpServlet {
121        private static final long serialVersionUID = 624120150522L ;    // 6.2.4.1 (2015/05/22)
122
123        private static final String JSP = HybsSystem.sys( "JSP" );                                              // jspフォルダの正規パス
124
125        private static final long MB = 1024*1024 ;                                              // 6.2.4.1 (2015/05/22)
126        private static final long GB = 1024*1024*1024 ;                                 // 6.2.4.1 (2015/05/22)
127
128        // 7.0.1.0 (2018/10/15) XHTML → HTML5 対応
129        private static final String HEADER =
130                "<!DOCTYPE html>"                                                                                                                                                       + CR +
131                "<html class=\"headtype-query\">"                                                                                                                       + CR +
132                "<head>"                                                                                                                                                                        + CR +
133                "       <meta charset=\"UTF-8\" >"                                                                                                                              + CR +
134                "       <meta http-equiv=\"X-UA-Compatible\" content=\"IE=edge\" >"                                                             + CR +
135                "       <link rel=\"stylesheet\" href=\"" + JSP + "/common/default.css\" type=\"text/css\" >"   + CR +
136                "       <link rel=\"stylesheet\" href=\"" + JSP + "/custom/custom.css\" type=\"text/css\" >"    + CR +
137                "       <title>Hybs Admin</title>"                                                                                                                              + CR +
138                "</head>"                                                                                                                                                                       + CR;
139
140        // 3.5.3.1 (2003/10/31) User情報のテーブルの設定を、システムリソース より行う。
141        private static final String TABLE_HEADER = getTableHeaderTag() ;
142
143        // 5.6.6.0 (2013/07/05) getLoginUser( String,boolean ) で、指定するキーを配列で持っておきます。
144        // キーは、SystemManager.getRunningUserSummary 処理内で大文字化されるため、この配列は、表示用と兼用します。
145        private static final String[] USER_KEYS = { "ID","Jname","Roles","IPAddress","LoginTime","LastAccess","LastGamenNm" };
146
147        // 6.3.6.1 (2015/08/28) <table> 枠の指定と、</table> の static final String 化
148        private static final String TABLE_WAKU  = "<table style=\"margin: 0px 0px 0px 20px;\" frame=\"box\" border=\"1px\" cellspacing=\"0px\" cellpadding=\"0px\" " ;
149        private static final String TABLE_END   = "</table>" + CR ;
150
151        // 7.0.1.0 (2018/10/15) XHTML → HTML5 対応(空要素の、"/>" 止めを、">" に変更します)。
152        private static final String COMMON_MESSAGE =
153                        "【共通メッセージを表示する場合は、このテキストフィールドに入力してください。】<br>"   + CR +
154                        "<form method=\"GET\" action=\"" + JSP + "/admin\" target=\"RESULT\" >"                                 + CR +
155                        "    <input name=\"message\" size=\"50\" >"                                                                                             + CR +
156                        "    <button type=\"submit\" name=\"type\" value=\"set\"   >Set</button>"                               + CR +
157                        "    <button type=\"submit\" name=\"type\" value=\"clear\" >Clear</button>"                             + CR +
158                        "    <input type=\"hidden\" name=\"COMMAND\" value=\"commonMessage\" >"                                 + CR +
159                        "</form><br><br>"                                                                                                                                               + CR ;
160
161        // 7.1.0.0 (2020/01/27) static で定義しておきます。
162        private static final String[] PLUGIN_TYPE = new String[] {
163                                "Query","Renderer","Editor","DBType","ViewForm",
164                                "TableReader","TableWriter","TableFilter","ChartWriter","CalendarQuery",
165                                "DBConstValue","Daemon","JspCreate"                                     // 5.6.6.0 (2013/07/05) 追加
166        } ;
167
168        // 7.1.0.0 (2020/01/27) static で定義しておきます。
169        private static final String TD_CMD = "  <td>  [<a href=\"" + JSP + "/admin?COMMAND=" ;
170        private static final String TD_QREF= "  <td>  [<a href=\"" + JSP + "/common/quickReference.html" ;              // クイックリファレンス 専用
171        private static final String TD_GMN = "  <td>  [<a href=\"" + JSP + "/common/gamen/01_ADMIN/" ;
172        private static final String YESNO  = "\" onclick=\"return confirm( '実行してよろしいでしょうか?' );" ;
173        private static final String TGT    = "\" target=\"RESULT\" >" ;
174        private static final String END_TD = "</a>]</td>" + CR ;
175
176        private static final String INFOMATION          = TD_CMD + "infomation"                 + TGT + "状況表示"                  + END_TD ;
177        private static final String CLOSE                       = TD_CMD + "close"                              + TGT + "プール削除"                        + END_TD ;
178        private static final String LOGIN_USER          = TD_CMD + "loginUser"                  + TGT + "ログインユーザー"            + END_TD ;
179        private static final String QUICK_REFERENCE     = TD_QREF                                               + TGT + "クイックリファレンス"            + END_TD ;
180        private static final String SYSTEM_RESOURCE     = TD_CMD + "systemResource"             + TGT + "システムリソース"                      + END_TD ;
181        private static final String PARAMETER           = TD_GMN + "parameter.jsp?GAMENID=01_ADMIN" + TGT + "パラメータ"+ END_TD ;
182        private static final String LOGLINK                     = TD_GMN + "logLink.jsp"                + TGT + "ログ"                           + END_TD ;
183        private static final String SERVICE_RESTART     = TD_GMN + "serviceRestart.jsp" + YESNO + TGT + "サービス再起動" + END_TD ;
184
185        private static final String PLUGIN                      = TD_CMD + "plugin"                             + TGT + "プラグイン情報"             + END_TD ;
186        private static final String TAGLIB                      = TD_CMD + "taglib"                             + TGT + "タグリブ情報"              + END_TD ;
187        private static final String REGISTRATION        = TD_CMD + "registrationInfo"   + TGT + "Servlet/Filter"        + END_TD ;
188        private static final String SYSTEM_INFO         = TD_GMN + "systemInfo.jsp"             + TGT + "システム状況"                        + END_TD ;
189        private static final String ACCESS_STOP         = "<td colspan=\"2\">  アクセス制限"
190                                                                                                                + "[<a href=\"" + JSP + "/admin?COMMAND=AccessStop&stop=true"   + TGT + "停止</a>]/"
191                                                                                                                + "[<a href=\"" + JSP + "/admin?COMMAND=AccessStop&stop=false"  + TGT + "開始" + END_TD ;
192
193        // 7.2.6.0 (2020/06/30) StringBuilderの連結部見直し
194        private static final String TD_TD = "</td><td>" ;                       // tdの終了とtdの開始を連結したもの
195        private static final String TD_TR = "</td></tr>" + CR ;         // tdの終了とtrの終了を連結したもの
196
197
198        /**
199         * fileexecのMainProcess の処理が起動しているかどうかを表示。
200         *
201         * @og.rev 7.2.5.0 (2020/06/01) fileexecのMainProcess の処理が起動しているかどうかを表示
202         *
203         * @return      fileexecの起動情報
204         * @og.rtnNotNull
205         */
206        public static String fileExecCmnt() {
207                final boolean isStart = MainProcess.isStarted();
208                return "ファイル取込(" + ( isStart ? "起動中" : "停止中" ) + ")  " ;
209
210//              return "<td colspan=\"2\">  ファイル取込("
211//                                      + ( isStart ? "起動中" : "停止中" ) + ") "
212//                                      + "[<a href=\"" + JSP + "/admin?COMMAND=fileexec&start=" + !isStart + TGT               // 他の admin もJSP が必要なはず。
213//                                      + "<b>" + ( isStart ? "待機する" : "実行する" )  + "</b>" + END_TD
214//                                      + "<td>  起動するには、システム定数で、パラメータID=USE_FILEEXEC を、true に登録してください。(要[プール削除])</td>" ;
215        }
216
217        /**
218         * GET メソッドが呼ばれたときに実行します。
219         *
220         * @og.rev 3.5.3.1 (2003/10/31) 機能ごとにメソッドを呼び出すように修正します。
221         * @og.rev 3.5.4.1 (2003/12/01) getAdminLink() メソッドを追加
222         * @og.rev 6.3.8.0 (2015/09/11) AccessStop を外部から制御できるように、コマンドと状態を受けるようにする。
223         * @og.rev 5.9.1.0 (2015/10/02) UserInfoセット機能追加
224         * @og.rev 6.3.8.3 (2015/10/03) Servlet/Filter 情報を作成。
225         * @og.rev 6.3.9.1 (2015/11/27) 3項演算子を || or &amp;&amp; で簡素化できる(PMD)。
226         * @og.rev 6.4.4.1 (2016/03/18) application オブジェクトに関連付ける 共通メッセージを設定します。
227//       * @og.rev 7.2.5.0 (2020/06/01) fileexecのMainProcess の処理が起動しているかどうかを表示
228         *
229         * @param       req     HttpServletRequestオブジェクト
230         * @param       res     HttpServletResponseオブジェクト
231         *
232         * @throws ServletException サーブレット関係のエラーが発生した場合、throw されます。
233         * @throws IOException 入出力エラーが発生したとき
234         */
235        @Override
236        public void doGet( final HttpServletRequest req, final HttpServletResponse res)
237                                                                throws ServletException, IOException {
238
239                req.setCharacterEncoding( "UTF-8" );                                                            // 6.4.4.1 (2016/03/18)
240                res.setContentType( "text/html; charset=UTF-8" );
241                final PrintWriter out = res.getWriter();
242
243                final String command = req.getParameter( "COMMAND" );
244
245                out.println( HEADER );
246                out.println( "<body>" );
247
248//              out.print("<h2>");
249                out.print("<div style=\"font-size:1.5em;\">");
250                out.print( req.getServerName() );
251                out.print( ":" );
252                out.print( req.getServerPort() );
253                out.print( req.getContextPath() );
254//              out.println("</h2>");
255                out.println("</div>");
256
257                if( "infomation".equalsIgnoreCase( command ) ) {
258                        out.print( getInfomation() );
259                }
260                else if( "close".equalsIgnoreCase( command ) ) {
261                        out.print( getCloseMessage( req.getSession() ) );
262                }
263                else if( "loginUser".equalsIgnoreCase( command ) ) {
264                        final String sort  = req.getParameter( "sort" );
265                        final String direc = req.getParameter( "direc" );
266                        // 6.3.9.1 (2015/11/27) 3項演算子を || or && で簡素化できる(PMD)。
267                        final boolean dir = direc == null || Boolean.parseBoolean( direc );                             // 6.3.9.1 (2015/11/27)
268
269                        out.print( COMMON_MESSAGE );                                    // 6.4.4.1 (2016/03/18)
270                        out.print( getLoginUser(sort,dir) );
271                }
272                // 6.4.4.1 (2016/03/18) application オブジェクトに関連付ける 共通メッセージを設定します。
273                else if( "commonMessage".equalsIgnoreCase( command ) ) {
274                        final String type    = req.getParameter( "type" );
275                        final String message = req.getParameter( "message" );
276                        out.print( setCommonMessage( type , message , req.getSession() ) );
277                }
278                else if( "plugin".equalsIgnoreCase( command ) ) {
279                        out.print( getPlugInInfo() );
280                }
281                else if( "taglib".equalsIgnoreCase( command ) ) {
282                        out.print( getTaglibInfo() );
283                }
284                else if( "systemResource".equalsIgnoreCase( command ) ) {
285                        out.print( getSystemResource() );
286                }
287                // 6.3.8.0 (2015/09/11) AccessStop を外部から制御できるように、コマンドと状態を受けるようにする。
288                else if( "AccessStop".equalsIgnoreCase( command ) ) {
289                        out.print( getAccessStop( req.getParameter( "stop" ) ) );       // 6.3.8.0 (2015/09/11)
290                }
291                // 5.9.1.0 (2015/10/02) UserInfoセット機能追加
292                else if( "UserInfo".equalsIgnoreCase( command ) ){ // 5.9.1.0 (2015/10/02)
293                        out.print( setUserinfo( req ) );
294                }
295                // 6.3.8.3 (2015/10/03) Servlet/Filter 情報を作成。
296                else if( "registrationInfo".equalsIgnoreCase( command ) ) {
297                        out.print( getRegistrationMessage( req.getSession() ) );
298                }
299//              else if( "fileexec".equalsIgnoreCase( command ) ) {             // 7.2.5.0 (2020/06/01)
300//                      out.print( getFileExecInfo( req.getParameter( "start" ) ) );
301//              }
302                else {
303                        out.print( getAdminLink() );            // 3.5.4.1 (2003/12/01) 追加
304                }
305
306                out.println("</body></html>");
307        }
308
309        /**
310         * infomation 情報を作成します。
311         *
312         * @og.rev 3.5.3.1 (2003/10/31) 機能ごとにメソッドを呼び出すように修正します。
313         * @og.rev 5.6.7.3 (2013/08/23) TOMCAT_WORKは、TOMCAT_HOME に置き換えます。
314         * @og.rev 6.2.4.1 (2015/05/22) ディスク容量を求めます。
315         * @og.rev 6.3.6.1 (2015/08/28) <table> 枠の指定と、</table> の static final String 化
316         * @og.rev 6.3.9.0 (2015/11/06) 整数値演算なので、Math.round 不要
317         * @og.rev 6.5.0.1 (2016/10/21) ENGINE_INFO は、直接、BuildNumber から取得する。
318         * @og.rev 7.0.1.0 (2018/10/15) XHTML → HTML5 対応(空要素の、"/>" 止めを、">" に変更します)。
319         * @og.rev 7.1.0.0 (2020/01/20) OFFICE_HOME,EXT_DIR,SYS_LOG_URL,LOGS_DIR 環境変数の追加。
320         *
321         * @return      infomation情報
322         * @og.rtnNotNull
323         */
324        private String getInfomation() {
325                // 4.0.0 (2005/01/31) ログイン数の取得方法の変更。
326                final int loginCount = SystemManager.getRunningCount() ;
327
328                final long freeMemory     = Runtime.getRuntime().freeMemory()/MB ;                                      // 6.3.9.0 (2015/11/06) 整数値演算なので、Math.round 不要
329                final long totalMemory    = Runtime.getRuntime().totalMemory()/MB;                                      // 6.3.9.0 (2015/11/06) 整数値演算なので、Math.round 不要
330                final long useMemoryRatio = (totalMemory-freeMemory)*100/totalMemory ;                          // 6.3.9.0 (2015/11/06) 整数値演算なので、Math.round 不要
331                final String bgCls = useMemoryRatio <= 50 ? "OK" : useMemoryRatio <= 80 ? "CAUT" : "NG" ;       // 6.9.7.0 (2018/05/14) PMD Useless parentheses.
332
333                final StringBuilder rtn = new StringBuilder( BUFFER_MIDDLE );
334
335                rtn.append( "<table border = \"0px\" >" );
336//              // 7.1.0.0 (2020/01/20) static定義をやめて、getInfomation() メソッド内で都度呼びます。
337                tableTr1( rtn,"サーバー情報" );
338                tableTr(  rtn,"OS情報"                    , BuildNumber.OS_INFO );                // 6.5.0.1 (2016/10/21)
339                tableTr(  rtn,"サーバー名"                  , HybsSystem.sys( "SERVER_INFO"  ) );   // 10759278-0002
340                tableTr(  rtn,"サーブレット"                 , HybsSystem.sys( "SERVLET_INFO" ) );   // Apache Tomcat/9.0.30
341                tableTr(  rtn,"TOMCAT_HOME"             , HybsSystem.sys( "TOMCAT_HOME"  ) );   // C:/opengionV7/apps/tomcat9.0.30
342                tableTr(  rtn,"  ログフォルダ"      , HybsSystem.sys( "TOMCAT_LOGS"  ) );   // C:/opengionV7/apps/tomcat9.0.30/logs
343                tableTr(  rtn,"JDKバージョン"              , BuildNumber.JDK_INFO             );   // OpenJDK 64-Bit Server VM 11.0.5+10-LTS
344                tableTr(  rtn,"JAVA_HOME"               , HybsSystem.sys( "JAVA_HOME"    ) );   // C:/opengionV7/apps/jdk11.0.5_10
345                tableTr(  rtn,"  拡張フォルダ"       , HybsSystem.sys( "EXT_DIR"      ) );   // C:/opengionV7/uap/bin/../../apps/endorsed7.0.5
346                tableTr(  rtn,"OFFICE_HOME"             , HybsSystem.sys( "OFFICE_HOME"  ) );   // C:/opengionV7/uap/bin/../../apps/LibreOffice_6.3.4
347
348//              // 7.1.0.0 (2020/01/20) static定義をやめて、getInfomation() メソッド内で都度呼びます。
349                tableTr1( rtn,"実行環境" );
350                tableTr(  rtn,"サービス起動"         , HybsSystem.sys( "IS_SERVICE"   ) , " [ " , HybsSystem.sys( "SERVICE_NAME" ) , " ] " );        // true [ サービス名 ]
351                tableTr(  rtn,"REAL_PATH"               , HybsSystem.sys( "REAL_PATH"    ) );   // C:/opengionV7/uap/webapps/gf/
352                tableTr(  rtn,"バージョンNo"               , BuildNumber.ENGINE_INFO          );   // openGion 7.1.0.0 Release7 Builds (26324783)
353                tableTr(  rtn,"作成日時"            , BuildNumber.TIMESTAMP            );   // 2020/01/20 11:23:37
354
355                tableTr1( rtn,"ログイン情報" );
356                tableTr(  rtn,"ログイン人数"         , String.valueOf( loginCount )," 名 ","( <a href=\"admin?COMMAND=loginUser\">明細情報</a> )" );
357
358                tableTr1( rtn,"メモリ情報" );
359                tableTr(  rtn,"空きメモリ"                   , String.valueOf( freeMemory     ) , " [MByte]" );      // 6.2.4.1 (2015/05/22) 単位を MB に変更
360                tableTr(  rtn,"合計メモリ"                   , String.valueOf( totalMemory    ) , " [MByte]" );      // 6.2.4.1 (2015/05/22) 単位を MB に変更
361                tableTr(  rtn,"使用率"                     , String.valueOf( useMemoryRatio ) , " [%]"    );
362                rtn.append( TABLE_END )
363                        // 6.2.4.1 (2015/05/22) default.css で、memory、disc、discTD を定義
364                        .append( TABLE_WAKU ).append( "width=\"300px\" >" ).append( CR )
365                        .append( "\t<tr><td class=\"memory " ).append( bgCls ).append( "\" style=\"width:" )
366                        .append( useMemoryRatio ).append( "%;\" >" ).append( useMemoryRatio ).append( "%</td>" )
367                        .append( "<td class=\"BIT\">" ).append( 100-useMemoryRatio ).append( "%</td></tr>" ).append( CR )
368                        .append( TABLE_END )
369
370                        // 6.2.4.1 (2015/05/22) ディスク容量を求めます。
371                        .append( "<table border=\"0px\" >" ).append( CR );
372                tableTr1( rtn,"ディスク情報" );
373                rtn.append( TABLE_END )
374                        .append( TABLE_WAKU ).append( "width=\"500px\" >" ).append( CR )
375                        .append( "<th>名前</th><th>合計サイズ</th><th>空き領域</th><th>使用率</th></tr>" ).append( CR ).append( CR );
376
377                final File[] driv = File.listRoots();
378                for( final File file : driv ) {
379                        // 6.3.9.0 (2015/11/06) 整数値演算なので、Math.round 不要
380                        final long total        = file.getTotalSpace()/GB ;                                             // パーティションのサイズ
381                        final long usable       = file.getUsableSpace()/GB ;                                    // 仮想マシンが利用できるバイト数
382                        tableTr2( rtn, file.getPath() , total , usable );                                       // ディスク容量専用3
383                }
384                rtn.append( TABLE_END )
385
386                // information
387                        .append( "<hr>" ).append( CR )                                                                          // 7.0.1.0 (2018/10/15) XHTML → HTML5
388                        .append( "<pre>" ).append( CR )
389                        .append( ConnectionFactory.information() ).append( CR )
390                        .append( "</pre>" ).append( CR );
391
392                return rtn.toString();
393        }
394
395        /**
396         * infomation 情報を作成します。
397         *
398         * @og.rev 5.6.6.0 (2013/07/05) &lt;/td&gt;&lt;/tr&gt;漏れ追加
399         * @og.rev 5.6.7.3 (2013/08/23) 前後に、【】を付けます。
400         *
401         * @param       buf     情報登録用のStringBuilder
402         * @param       key     キー
403         *
404         * @return      infomation情報(入力bufと同じオブジェクト)
405         * @og.rtnNotNull
406         */
407        private StringBuilder tableTr1( final StringBuilder buf, final String key ) {
408                return buf.append( "\t<tr><td colspan=\"4\"><b>【" )
409                                .append( key ).append( "】</b></td></tr>" )
410                                .append( CR );  // 【】追加
411        }
412
413        /**
414         * infomation 情報を作成します。
415         *
416         * @og.rev 5.6.6.0 (2013/07/05) 最初の td に、全角スペース2個 追加
417         *
418         * @param       buf     情報登録用のStringBuilder
419         * @param       key     キー
420         * @param       val     値の可変長引数
421         *
422         * @return      infomation情報(入力bufと同じオブジェクト)
423         * @og.rtnNotNull
424         */
425        private StringBuilder tableTr( final StringBuilder buf, final String key, final String... val ) {
426                buf.append( "\t<tr><td width=\"20px\"> </td><td>" ).append( key ).append( "</td><td> = </td><td>" );                    // 段を作成する為に、width指定 追加
427                for( int i=0; i<val.length; i++ ) {
428                        buf.append( val[i] );
429                }
430//              return buf.append( "</td></tr>" ).append( CR );
431                return buf.append( TD_TR );
432        }
433
434        /**
435         * infomation 情報を作成します。
436         *
437         * @og.rev 6.2.4.1 (2015/05/22) ディスク容量専用
438         * @og.rev 6.2.4.2 (2015/05/29) total が 0 の場合の対応
439         * @og.rev 7.2.6.0 (2020/06/30) StringBuilderの連結部見直し
440         *
441         * @param       buf     情報登録用のStringBuilder
442         * @param       name    ドライブ名
443         * @param       total   パーティションのサイズ(GB)
444         * @param       usable  仮想マシンが利用できるサイズ(GB)
445         *
446         * @return      infomation情報(入力bufと同じオブジェクト)
447         * @og.rtnNotNull
448         */
449        private StringBuilder tableTr2( final StringBuilder buf, final String name, final long total, final long usable ) {
450                final long useRatio = total == 0L ? 0L : (total-usable)*100/total ;                     // 6.3.9.0 (2015/11/06) findBugs
451
452                final String bgCls = useRatio <= 50 ? "OK" : useRatio <= 80 ? "CAUT" : useRatio <= 95 ? "WARN" : "NG" ;                 // 6.9.7.0 (2018/05/14) PMD Useless parentheses.
453
454//              return buf.append( "\t<tr><td class=\"BIT\">" ).append( name ).append( "</td>" )
455//                      .append( "<td class=\"S9\" >" ).append( total  ).append( " GB</td>" )
456//                      .append( "<td class=\"S9\" >" ).append( usable ).append( " GB</td>" ).append( CR )
457//                      .append( "\t\t<td class=\"discTD\" ><span class=\"disc " ).append( bgCls )
458//                      .append( "\" style=\"width:" ).append( useRatio ).append( "%;\" >" )
459//                      .append( useRatio ).append( "%</span> </td></tr>" ).append( CR );
460
461                // 7.2.6.0 (2020/06/30) StringBuilderの連結部見直し
462                return buf.append( "\t<tr><td class=\"BIT\">"   )
463                        .append( name           ).append( "</td><td class=\"S9\" >" )
464                        .append( total          ).append( " GB</td><td class=\"S9\" >" )
465                        .append( usable         ).append( " GB</td>" ).append( CR )
466                        .append( "\t\t<td class=\"discTD\" ><span class=\"disc " )
467                        .append( bgCls          ).append( "\" style=\"width:" )
468                        .append( useRatio       ).append( "%;\" >" )
469                        .append( useRatio       ).append( "%</span> </td></tr>" ).append( CR );
470        }
471
472        /**
473         * close 情報を作成します。
474         *
475         * @og.rev 3.5.3.1 (2003/10/31) 機能ごとにメソッドを呼び出すように修正します。
476         * @og.rev 3.6.0.0 (2004/09/17) CalendarFactory.clear() を追加します。
477         * @og.rev 4.0.0.0 (2005/01/31) Cleanable インターフェースによる初期化処理
478         * @og.rev 4.1.0.2 (2008/01/29) UserInfoをsessionから消去する(超暫定対応)
479         * @og.rev 5.6.6.0 (2013/07/05) UserSummary の削除処理は、SystemManager から行う。
480         * @og.rev 6.3.7.0 (2015/09/04) ファイナライズを呼び出します。
481         * @og.rev 7.2.9.4 (2020/11/20) PMD:Do not explicitly trigger a garbage collection.
482         *
483         * @param       session HttpSessionオブジェクト
484         *
485         * @return      close情報
486         * @og.rtnNotNull
487         */
488        private String getCloseMessage( final HttpSession session ) {
489
490                // 4.0.0 (2005/01/31) Cleanable インターフェースによる初期化処理
491                SystemManager.allClear( false ) ;
492
493                final ServletContext context = session.getServletContext();
494                final Map<String,String> param = SystemParameter.makeSystemParameter( context );
495                HybsSystem.setInitialData( param );                     // 4.0.0 (2005/01/31)
496
497                // 5.6.6.0 (2013/07/05) UserSummary の削除処理は、SystemManager から行う。
498                SystemManager.removeSession( session ) ;
499
500                // 6.3.7.0 (2015/09/04) ファイナライズを呼び出します。
501                // 7.2.9.4 (2020/11/20) PMD:Do not explicitly trigger a garbage collection.
502//              System.runFinalization();
503//      //      System.gc();                                    // 取りあえず、GCは呼びません。
504
505                return "<pre>"
506                        + "キャッシュ情報をクリアしました。"                                                                                    + CR
507                        + "ユーザー情報の初期化に関しては、ブラウザを閉じて、再ログインが必要です。"        + CR
508                        + ConnectionFactory.information()
509                        + "</pre>" ;
510        }
511
512        /**
513         * loginUser 情報を作成します。
514         *
515         * @og.rev 3.5.3.1 (2003/10/31) 機能ごとにメソッドを呼び出すように修正します。
516         * @og.rev 3.8.5.3 (2006/08/07) ユーザー情報をソートするためのキー情報を追加
517         * @og.rev 3.8.7.0 (2006/12/15) USER.LASTACCESS情報を追加します。
518         * @og.rev 4.0.0.0 (2005/01/31) DBColumn の 属性(CLS_NM)から、DBTYPEに変更
519         * @og.rev 4.4.0.1 (2009/08/08) 最終ログイン画面名称を追加
520         * @og.rev 5.6.6.0 (2013/07/05) table作成処理を、変更します。
521         * @og.rev 6.3.6.1 (2015/08/28) <table> 枠の指定と、</table> の static final String 化
522         * @og.rev 5.9.1.2 (2015/10/23) 自己終了警告対応
523         * @og.rev 7.0.4.0 (2019/05/31) colgroup 廃止
524         * @og.rev 7.2.6.0 (2020/06/30) StringBuilderの連結部見直し
525         *
526         * @param       sort    ソートするキー項目を指定
527         * @param       direc   ソートする方向 [true:昇順/false:降順]
528         *
529         * @return      loginUser情報
530         * @og.rtnNotNull
531         */
532        private String getLoginUser( final String sort,final boolean direc ) {
533                // 4.0.0 (2005/01/31) ログイン数の取得方法の変更。
534                final int loginCount = SystemManager.getRunningCount() ;
535
536                // 4.0.0 (2005/01/31)
537                final UserSummary[] userInfos = SystemManager.getRunningUserSummary( sort,direc );
538
539                final StringBuilder rtn = new StringBuilder( BUFFER_MIDDLE )
540                        .append( "現在 "   ).append( loginCount   ).append( " 名の方がログイン中です。" ).append( CR )
541                        .append( "<table " ).append( TABLE_HEADER ).append( " >" )
542                        .append( "<thead><tr><th>No</th>" );
543
544                // 5.6.6.0 (2013/07/05) table作成処理を、変更します。
545                for( final String sortKey : USER_KEYS ) {
546                        rtn.append( "<th><a href=\"?COMMAND=loginUser&sort=" ).append( sortKey )
547                                .append( "&direc=" ).append( !direc )
548                                .append( "\">" ).append( sortKey ).append( "</a></th>" );
549                }
550
551                // 7.0.4.0 (2019/05/31) colgroup 廃止
552                rtn.append( "</tr></thead>" ).append( CR )
553                        .append( CR );
554
555//              for( int i=0; i<userInfos.length; i++ ) {
556//                      final UserSummary userInfo = userInfos[i] ;
557//                      rtn.append( " <tr class=\"row_" ).append( i%2 ).append( "\" >" )
558//                              .append( "<td class='S9'>" ).append( String.valueOf( i+1 )      ).append( "</td>"       )               // 7.0.4.0 (2019/05/31)
559//                              .append( "<td>" ).append( userInfo.getUserID()                          ).append( "</td>"       )
560//                              .append( "<td>" ).append( userInfo.getJname()                           ).append( "</td>"       )
561//                              .append( "<td>" ).append( userInfo.getRoles()                           ).append( "</td>"       )
562//                              .append( "<td>" ).append( userInfo.getIPAddress()                       ).append( "</td>"       )
563//                              .append( "<td>" ).append( HybsSystem.getDate( userInfo.getLoginTime() ) ).append( "</td>" )
564//                              .append( "<td>" ).append( userInfo.getAttribute( "LASTACCESS" )                 ).append( "</td>" )
565//                              .append( "<td>" ).append( StringUtil.nval( userInfo.getAttribute( "LASTGAMENNM" ), "" ) ).append( "</td>" )     // 4.4.0.1 (2009/08/08)
566//                              .append( " </tr>" ).append( CR );
567//              }
568
569                // 7.2.6.0 (2020/06/30) StringBuilderの連結部見直し
570                for( int i=0; i<userInfos.length; i++ ) {
571                        final UserSummary userInfo = userInfos[i] ;
572                        rtn.append( " <tr class=\"row_" ).append( i%2 )
573                                .append( "\" ><td class='S9'>" ).append( String.valueOf( i+1 )  )               // 7.0.4.0 (2019/05/31)
574                                .append( TD_TD ).append( userInfo.getUserID()                   )
575                                .append( TD_TD ).append( userInfo.getJname()                    )
576                                .append( TD_TD ).append( userInfo.getRoles()                    )
577                                .append( TD_TD ).append( userInfo.getIPAddress()                )
578                                .append( TD_TD ).append( HybsSystem.getDate( userInfo.getLoginTime() ) )
579                                .append( TD_TD ).append( userInfo.getAttribute( "LASTACCESS" )                  )
580                                .append( TD_TD ).append( StringUtil.nval( userInfo.getAttribute( "LASTGAMENNM" ), "" ) )        // 4.4.0.1 (2009/08/08)
581                                .append( TD_TR );
582                }
583                return rtn.append( TABLE_END ).toString();
584        }
585
586        /**
587         * PlugIn 情報を作成します。
588         *
589         * @og.rev 4.0.0.0 (2005/08/31) 新規作成
590         * @og.rev 5.6.6.0 (2013/07/05) "DBConstValue","Daemon","JspCreate" を、追加します。
591         * @og.rev 7.1.0.0 (2020/01/27) pluginType をstatic で定義しておきます。
592         *
593         * @return      PlugIn情報
594         * @og.rtnNotNull
595         */
596        private String getPlugInInfo() {
597                final ClassInfo info = new ClassInfo();
598
599                for( int j=0; j<PLUGIN_TYPE.length; j++ ) {
600                        final String type = PLUGIN_TYPE[j] ;
601                        final HybsEntry[] names = HybsSystem.sysEntry( type + "_" );
602                        for( int i=0; i<names.length; i++ ) {
603                                final String key                = names[i].getKey().substring( type.length()+1 );
604                                final String clsName    = names[i].getValue();
605                                info.addLine( type,key,clsName );
606                        }
607                }
608                return info.getClassInfoData() ;
609        }
610
611        /**
612         * Taglib 情報を作成します。
613         *
614         * @og.rev 4.0.0.0 (2006/01/31) 新規作成
615         * @og.rev 5.3.6.0 (2011/06/01) Taglib クラス名の求め方を変更します。(jar版のみ)
616         * @og.rev 5.5.2.6 (2012/05/25) JarFile を、Closer#zipClose( ZipFile ) メソッドを利用して、close します。
617         * @og.rev 6.8.5.1 (2018/01/15) ファイル名は、##バージョン番号を変換しておく必要がある。
618         *
619         * @return      Taglib情報
620         * @og.rtnNotNull
621         */
622        private String getTaglibInfo() {
623                final ClassInfo info = new ClassInfo();
624
625                // 5.5.2.6 (2012/05/25) findbugs対応
626                JarFile jarFile = null;
627                try {
628                        final ClassLoader loader = Thread.currentThread().getContextClassLoader();
629                        final Enumeration<URL> enume = loader.getResources( "org/opengion/hayabusa/taglib/" );          // 4.3.3.6 (2008/11/15) Generics警告対応
630                        while( enume.hasMoreElements() ) {
631                                final URL url = enume.nextElement();            // 4.3.3.6 (2008/11/15) Generics警告対応
632                                // jar:file:/実ディレクトリ または、file:/実ディレクトリ
633                                final String dir = url.getFile().replaceAll( "%23%23","##" );   // 6.8.5.1 (2018/01/15)
634                                if( "jar".equals( url.getProtocol() ) ) {
635                                        // dir = file:/G:/webapps/gf/WEB-INF/lib/hayabusa4.0.0.jar!/org/opengion/hayabusa/taglib 形式です。
636                                        final String jar = dir.substring(dir.indexOf( ':' )+1,dir.lastIndexOf( '!' ));
637                                        // jar = /G:/webapps/gf/WEB-INF/lib/hayabusa4.0.0.jar 形式に切り出します。
638                                        jarFile = new JarFile( jar );
639                                        final Enumeration<JarEntry> en = jarFile.entries() ;            // 4.3.3.6 (2008/11/15) Generics警告対応
640                                        while( en.hasMoreElements() ) {
641                                                final JarEntry ent = en.nextElement();          // 4.3.3.6 (2008/11/15) Generics警告対応
642                                                final String file = ent.getName();
643                                                if( ! ent.isDirectory() && file.endsWith( "Tag.class" ) ) {
644                                                        final String type               = "Taglib_jar";
645                                                        // 5.3.6.0 (2011/06/01) Taglib クラス名の求め方を変更します。(jar版のみ)
646                                                        final String key                = file.substring( file.lastIndexOf( '/' )+1,file.length()-6 );  // -6 は、.class 分
647                                                        final String clsName    = file.replace( '/','.' ).substring( 0,file.length()-6 );
648                                                        info.addLine( type,key,clsName );
649                                                }
650                                        }
651                                        Closer.zipClose( jarFile );             // 5.5.2.6 (2012/05/25) findbugs対応
652                                        jarFile = null;                                 // 正常終了時に、close() が2回呼ばれるのを防ぐため。
653                                }
654                                else {
655                                        // dir = /G:/webapps/gf/WEB-INF/classes/org/opengion/hayabusa/taglib/ 形式です。
656                                        final File[] list = new File( dir ).listFiles();
657                                        // 6.3.9.0 (2015/11/06) null になっている可能性がある(findbugs)
658                                        if( list != null ) {
659                                                for( final File file : list ) {
660                                                        final String name = file.getName() ;
661                                                        if( file.isFile() && name.endsWith( "Tag.class" ) ) {
662                                                                final String type               = "Taglib_file";
663                                                                final String key                = name.substring( 0,name.length()-6 );
664                                                                final String clsName    = "org.opengion.hayabusa.taglib." + key ;
665                                                                info.addLine( type,key,clsName );
666                                                        }
667                                                }
668                                        }
669                                }
670                        }
671                }
672                catch( final IOException ex ) {
673                        final String errMsg = "taglibファイル読み取りストリームを失敗しました。"
674                                        + CR + ex.getMessage();
675                        throw new OgRuntimeException( errMsg,ex );
676                }
677                finally {
678                        Closer.zipClose( jarFile );             // 5.5.2.6 (2012/05/25) findbugs対応
679                }
680
681                return info.getClassInfoData() ;
682        }
683
684        /**
685         * クラス情報を表示するためのデータを管理します。
686         * ここでは、引数に渡された、分類(Classify)、名称(Key Name)、クラス名(Class Name)、
687         * バージョン(Version)情報をテーブル形式で表示します。
688         * バージョン情報は、クラス名から、インスタンスを作成して、private static final String VERSION
689         * フィールドの値を読み取ります。
690         *
691         * @og.rev 4.0.0.0 (2006/01/31) 新規作成
692         * @og.rev 7.0.4.0 (2019/05/31) colgroup 廃止
693         * @og.rev 7.1.0.0 (2020/01/27) ヘッダー部分をstatic で定義しておきます。
694         */
695        private static final class ClassInfo {
696                private static final String HEADER =
697                        "<table " + TABLE_HEADER + " >" + CR +
698                        "       <thead><tr><th>No</th><th>Classify</th><th>Key Name</th><th>Class Name</th><th>Version</th></tr></thead>" + CR ;
699
700                private final StringBuilder rtn = new StringBuilder( BUFFER_MIDDLE );
701                private int cnt;
702
703                /**
704                 * コンストラクター
705                 *
706                 * @og.rev 4.0.0.0 (2006/01/31) 新規作成
707                 * @og.rev 5.9.1.2 (2015/10/23) 自己終了警告対応
708                 * @og.rev 7.1.0.0 (2020/01/27) ヘッダー部分をstatic で定義しておきます。
709                 */
710                public ClassInfo() {
711                        rtn.append( HEADER );                   // 7.1.0.0 (2020/01/27)
712                }
713
714                /**
715                 * テーブル表示用のデータを追加します。
716                 *
717                 * @og.rev 4.0.0.0 (2006/01/31) 新規作成
718                 * @og.rev 7.0.4.0 (2019/05/31) colgroup 廃止
719                 * @og.rev 7.2.6.0 (2020/06/30) StringBuilderの連結部見直し
720                 *
721                 * @param       type    タイプ属性
722                 * @param       key     キー属性
723                 * @param       clsName クラス名(このクラス名からインスタンス化します。)
724                 */
725                public void addLine( final String type, final String key, final String clsName ) {
726                        final String version    = getFieldValue( clsName );
727
728                        final boolean isCustom =   version.compareTo( BuildNumber.VERSION_NO ) > 0
729                                                                        || version.indexOf( "Pache"   ) >= 0
730                                                                        || version.indexOf( "Nightly" ) >= 0 ;
731
732                        final String trType = isCustom ? "warning" : String.valueOf( cnt%2 );
733
734//                      rtn.append( "<tr class=\"row_" ).append( trType ).append( "\" >" )
735//                              .append( "<td class='S9'>"      ).append( cnt++         ).append( "</td>" )                     // 7.0.4.0 (2019/05/31)
736//                              .append( "<td>"                         ).append( type          ).append( "</td>" )
737//                              .append( "<td>"                         ).append( key           ).append( "</td>" )
738//                              .append( "<td>"                         ).append( clsName       ).append( "</td>" )
739//                              .append( "<td>"                         ).append( version       ).append( "</td>" )
740//                              .append( "</tr>" ).append( CR );
741
742                        // 7.2.6.0 (2020/06/30) StringBuilderの連結部見直し
743                        rtn.append( "<tr class=\"row_" ).append( trType )
744                                .append( "\" ><td class='S9'>"  ).append( cnt++         )                       // 7.0.4.0 (2019/05/31)
745                                .append( TD_TD ).append( type   )
746                                .append( TD_TD ).append( key            )
747                                .append( TD_TD ).append( clsName        )
748                                .append( TD_TD ).append( version        )
749                                .append( TD_TR );
750                }
751
752                /**
753                 * すべての内部のデータを文字列化して返します。
754                 *
755                 * @og.rev 4.0.0.0 (2006/01/31) 新規作成
756                 * @og.rev 6.3.6.1 (2015/08/28) <table> 枠の指定と、</table> の static final String 化
757                 *
758                 * @return      作成されたテーブルデータ
759                 * @og.rtnNotNull
760                 */
761                public String getClassInfoData() {
762                        return rtn.append( TABLE_END ).toString();
763                }
764
765                /**
766                 * 指定のオブジェクトの  VERSION staticフィールドの値を取得します。
767                 *
768                 * @og.rev 4.0.0.0 (2005/08/31) 新規作成
769                 * @og.rev 6.4.3.3 (2016/03/04) HybsSystem#newInstance(String) ではなく、直接Class#forName(String)から、求めます。
770                 *
771                 * @param       clsName 指定のクラスを表す名称
772                 * @return      VERSIONフィールドの値(エラー時は、そのメッセージ)
773                 */
774                private String getFieldValue( final String clsName ) {
775                        String rtn ;
776                        try {
777                                final Field fld = Class.forName( clsName ).getDeclaredField( "VERSION" ) ;
778
779                                // privateフィールドの取得には、accessibleフラグを trueにする必要があります。
780                                fld.setAccessible( true );
781
782                                rtn = (String)fld.get( null );
783                        }
784                        catch( final Throwable ex ) {
785                                rtn = ex.getMessage();
786                        }
787                        return rtn ;
788                }
789        }
790
791        /**
792         * systemResource 情報を作成します。
793         *
794         * @og.rev 3.5.3.1 (2003/10/31) 機能ごとにメソッドを呼び出すように修正します。
795         * @og.rev 4.0.0.0 (2005/01/31) DBColumn の 属性(CLS_NM)から、DBTYPEに変更
796         * @og.rev 6.3.6.1 (2015/08/28) <table> 枠の指定と、</table> の static final String 化
797         * @og.rev 5.9.1.2 (2015/10/23) 自己終了警告対応
798         * @og.rev 6.4.3.3 (2016/03/04) 配列返しではなく、Map を返します。
799         * @og.rev 7.0.4.0 (2019/05/31) colgroup 廃止
800         * @og.rev 7.2.6.0 (2020/06/30) StringBuilderの連結部見直し
801         *
802         * @return      systemResource情報
803         * @og.rtnNotNull
804         */
805        private String getSystemResource() {
806                final StringBuilder rtn = new StringBuilder( BUFFER_MIDDLE )
807                        .append( "<table " ).append( TABLE_HEADER ).append( " >" ).append( CR )
808                        .append( "<thead><tr><th>No</th><th>Key</th><th>Value</th></tr></thead>" ).append( CR )
809                        .append( CR );
810
811                // 6.4.3.3 (2016/03/04) 配列返しではなく、Map を返します。
812                final ConcurrentMap<String,String> rscMap = HybsSystem.getSystemResourceMap();
813                int i=0;
814//              for( final Map.Entry<String,String> entry : rscMap.entrySet() ) {
815//                      rtn.append( "<tr class=\"row_" ).append( i%2 ).append( "\" >" ).append( CR )
816//                              .append( "<td class='S9'>" ).append( ++i        ).append( "</td>" )             // 7.0.4.0 (2019/05/31)
817//                              .append( "<td>" ).append( entry.getKey()        ).append( "</td>" )
818//                              .append( "<td>" ).append( entry.getValue()      ).append( "</td>" )
819//                              .append( "</tr>" ).append( CR );
820//              }
821                // 7.2.6.0 (2020/06/30) StringBuilderの連結部見直し
822                for( final Map.Entry<String,String> entry : rscMap.entrySet() ) {
823                        rtn.append( "<tr class=\"row_" ).append( i%2 )
824                                .append( "\" ><td class='S9'>" ).append( ++i )          // 7.0.4.0 (2019/05/31)
825                                .append( TD_TD ).append( entry.getKey()         )
826                                .append( TD_TD ).append( entry.getValue()       )
827                                .append( TD_TR );
828                }
829                return rtn.append( TABLE_END ).toString();
830        }
831
832        /**
833         * AccessStop 情報を作成します。
834         *
835         * @og.rev 3.5.3.1 (2003/10/31) 機能ごとにメソッドを呼び出すように修正します。
836         * @og.rev 4.0.0.0 (2007/11/29) AccessStopFilter#getStopFilter() ⇒ isStopFilter() に変更
837         * @og.rev 6.1.1.0 (2015/01/17) パッケージを import するのと、ロジック見直し。
838         * @og.rev 6.3.8.0 (2015/09/11) AccessStop を外部から制御できるように、コマンドと状態を受けるようにする。
839         * @og.rev 7.1.0.0 (2020/01/20) 本物のサービスと混同しないようにメッセージを変更します。
840         *
841         * @param       isStop          true:停止/false:実行
842         * @return      AccessStop情報
843         * @og.rtnNotNull
844         */
845        private String getAccessStop( final String isStop ) {
846                final boolean flag = Boolean.parseBoolean( isStop );            // 6.3.8.0 (2015/09/11)
847
848                return flag ? "Webアプリケーションへのアクセスを停止します。"
849                                        : "Webアプリケーションへのアクセスを開始します。";
850        }
851
852//      /**
853//       * fileexecのMainProcess 情報を作成します。
854//       *
855//       * @og.rev 7.2.5.0 (2020/06/01) fileexecのMainProcess の処理が起動しているかどうかを表示
856//       *
857//       * @param       isStart         true:実行/false停止:
858//       * @return      fileexec情報
859//       * @og.rtnNotNull
860//       */
861//      private String getFileExecInfo( final String isStart ) {
862//              final String reload = "<script>parent.QUERY.location.reload(true);</script>" ;
863//
864//              final String msg ;
865//
866//              if( Boolean.parseBoolean( isStart ) ) {
867//                      MainProcess.start();
868//                      msg = "ファイル取込処理を実行しました。";
869//              }
870//              else {
871//                      MainProcess.shutdown( false );  // 再実行できるようにしておきます。
872//                      msg = "ファイル取込処理を停止しました。";
873//              }
874//
875//              return msg + reload;
876//      }
877
878        /**
879         * application オブジェクトに関連付ける 共通メッセージを設定します。
880         *
881         * 取り出しは、errorMessageタグで行います。これは、個々のrequest.jsp に組み込まれている
882         * メッセージなので、ここで登録したメッセージは、同時に、すべてのアクセスしているユーザーが
883         * 見ることになります。
884         *
885         * @og.rev 6.4.4.1 (2016/03/18) application オブジェクトに関連付ける 共通メッセージを設定します。
886         * @og.rev 6.8.5.0 (2018/01/09) 共通メッセージで、strongタグのバグ修正と、class="common_msg" 追加。
887         * @og.rev 7.0.1.0 (2018/10/15) XHTML → HTML5 対応(空要素の、"/>" 止めを、">" に変更します)。
888         *
889         * @param       type    [set/clear] を指定します。
890         * @param       message 共通メッセージを指定します。
891         * @param       session HttpSessionオブジェクト
892         *
893         * @return      Servlet/Filter情報
894         * @og.rtnNotNull
895         */
896        private String setCommonMessage( final String type , final String message , final HttpSession session ) {
897                final ServletContext context = session.getServletContext();
898
899                String rtMsg = "";
900                if( "set".equalsIgnoreCase( type ) && message != null && message.length() > 0 ) {
901                        rtMsg = "<strong class=\"common_msg\">" + message + "</strong><br>";                            // 7.0.1.0 (2018/10/15)
902                        context.setAttribute( HybsSystem.COMMON_MSG_KEY,rtMsg );
903                }
904                else if( "get".equalsIgnoreCase( type ) ) {
905                        rtMsg = (String)context.getAttribute( HybsSystem.COMMON_MSG_KEY );
906                }
907                else if( "clear".equalsIgnoreCase( type ) ) {
908                        context.removeAttribute( HybsSystem.COMMON_MSG_KEY );
909                }
910
911                return rtMsg;
912        }
913
914        /**
915         * Servlet/Filter 情報を作成します。
916         *
917         * @og.rev 6.3.8.3 (2015/10/03) Servlet/Filter 情報を作成。
918         * @og.rev 5.9.1.2 (2015/10/23) 自己終了警告対応
919         * @og.rev 7.0.4.0 (2019/05/31) colgroup 廃止
920         * @og.rev 7.2.6.0 (2020/06/30) StringBuilderの連結部見直し
921         *
922         * @param       session HttpSessionオブジェクト
923         *
924         * @return      Servlet/Filter情報
925         * @og.rtnNotNull
926         */
927        private String getRegistrationMessage( final HttpSession session ) {
928                final StringBuilder rtn = new StringBuilder( BUFFER_MIDDLE )
929                        // 速度よりソースの見易さ
930                        .append( "<table " ).append( TABLE_HEADER ).append( " >" )
931                        .append( "<thead><tr><th>No</th><th>Type</th><th>Key</th><th>Class</th><th>Mappings</th></tr></thead>" )
932                        .append( CR );
933
934                int no = 0;
935                final ServletContext context = session.getServletContext();
936                for( final ServletRegistration reg : context.getServletRegistrations().values() ) {
937//                      // 速度よりソースの見易さ
938//                      rtn.append( "<tr class=\"row_" ).append( no%2 ).append( "\" >" )
939//                              .append( "<td class='S9'>" ).append( String.valueOf( ++no ) ).append( "</td>" )         // 7.0.4.0 (2019/05/31)
940//                              .append( "<td>Servlet</td>" )
941//                              .append( "<td>" ).append( reg.getName()                 ).append( "</td>" )
942//                              .append( "<td>" ).append( reg.getClassName()    ).append( "</td>" )
943//                              .append( "<td>" ).append( reg.getMappings()             ).append( "</td>" )
944//                              .append( "</tr>" ).append( CR );
945                        // 7.2.6.0 (2020/06/30) StringBuilderの連結部見直し
946                        rtn.append( "<tr class=\"row_" ).append( no%2 )
947                                .append( "\" ><td class='S9'>" ).append( String.valueOf( ++no ) )               // 7.0.4.0 (2019/05/31)
948                                .append( TD_TD ).append( "Servlet"                      )
949                                .append( TD_TD ).append( reg.getName()          )
950                                .append( TD_TD ).append( reg.getClassName()     )
951                                .append( TD_TD ).append( reg.getMappings()      )
952                                .append( TD_TR );
953                }
954
955                for( final FilterRegistration reg : context.getFilterRegistrations().values() ) {
956//                      // 速度よりソースの見易さ
957//                      rtn.append( "<tr class=\"row_" ).append( no%2 ).append( "\" >" )
958//                              .append( "<td class='S9'>" ).append( String.valueOf( ++no )       ).append( "</td>" )   // 7.0.4.0 (2019/05/31)
959//                              .append( "<td>Filter</td>" )
960//                              .append( "<td>" ).append( reg.getName()                           ).append( "</td>" )
961//                              .append( "<td>" ).append( reg.getClassName()              ).append( "</td>" )
962//                              .append( "<td>" ).append( reg.getUrlPatternMappings() ).append( "</td>" )
963//                              .append( "</tr>" ).append( CR );
964                        // 7.2.6.0 (2020/06/30) StringBuilderの連結部見直し
965                        rtn.append( "<tr class=\"row_" ).append( no%2 )
966                                .append( "\" ><td class='S9'>" ).append( String.valueOf( ++no ) )       // 7.0.4.0 (2019/05/31)
967                                .append( TD_TD ).append( "Filter"                                               )
968                                .append( TD_TD ).append( reg.getName()                                  )
969                                .append( TD_TD ).append( reg.getClassName()                             )
970                                .append( TD_TD ).append( reg.getUrlPatternMappings()    )
971                                .append( TD_TR );
972                }
973                return rtn.append( TABLE_END ).toString();
974        }
975
976        /**
977         * admin リンク情報を作成します。
978         * 簡易メソッドなので、国際化対応していません。
979         *
980         * @og.rev 3.5.4.1 (2003/12/01) 新規作成
981         * @og.rev 5.1.1.2 (2009/12/10) 画面IDを変更
982         * @og.rev 5.6.3.4 (2013/04/26) クイックリファレンス 画面を追加
983         * @og.rev 6.3.6.1 (2015/08/28) <table> 枠の指定と、</table> の static final String 化
984         * @og.rev 6.3.8.0 (2015/09/11) AccessStop を外部から制御できるように、コマンドと状態を受けるようにする。
985         * @og.rev 6.9.2.1 (2018/03/12) リンクが横に長くなってきたので、2段に折り返します。
986         * @og.rev 7.0.0.1 (2018/10/09) 一旦、[プラグイン情報],[タグリブ情報],[Servlet/Filter情報],[システム状況] を削除します。
987         * @og.rev 7.0.1.0 (2018/10/15) XHTML → HTML5 対応(空要素の、"/>" 止めを、">" に変更します)。
988         * @og.rev 7.1.0.0 (2020/01/20) logLink.jsp 、serviceRestart.jsp 追加。AccessStopのON/OFF追加
989         * @og.rev 7.1.0.0 (2020/01/27) static で定義しておきます。
990         *
991         * @return      アドミンリンク情報
992         * @og.rtnNotNull
993         */
994        private String getAdminLink() {
995                // 7.1.0.0 (2020/01/20) AccessStopのON/OFF追加
996                final String accessStop = "true".equalsIgnoreCase( System.getProperty( "AccessStopFilter" ) )
997                                                                                ? ACCESS_STOP : "" ;
998
999                // 7.1.0.0 (2020/01/20) logLink.jsp 、serviceRestart.jsp 追加
1000                final String serviceRestart = "true".equalsIgnoreCase( HybsSystem.sys( "IS_SERVICE" ) )
1001                                                                                ? SERVICE_RESTART : "" ;
1002
1003                // 7.1.0.0 (2020/01/27) static で定義しておきます。
1004                return new StringBuilder( BUFFER_MIDDLE )
1005                        .append( "<style> body { overflow-y: hidden; } </style>" )                              //
1006                        .append( "<table><tr>"   ).append( CR )
1007                        .append( INFOMATION              )
1008                        .append( CLOSE                   )
1009                        .append( LOGIN_USER              )
1010                        .append( QUICK_REFERENCE )
1011                        .append( SYSTEM_RESOURCE )
1012                        .append( PARAMETER               )
1013                        .append( LOGLINK                 )
1014                        .append( serviceRestart  )
1015//                      .append( "</tr>" ).append( CR ).append( "<tr><td /><td />" ).append( CR )
1016                        .append( "</tr>" ).append( CR ).append( "<tr><td />" ).append( CR )     // 7.2.5.0 (2020/06/01)
1017                        .append( PLUGIN                  )
1018                        .append( TAGLIB                  )
1019                        .append( REGISTRATION    )
1020                        .append( SYSTEM_INFO     )
1021                        .append( accessStop              )
1022        //              .append( fileExecCmnt()  )              // 7.2.5.0 (2020/06/01)
1023                        .append( "</tr>" ).append( TABLE_END )
1024                        .toString();
1025        }
1026
1027        /**
1028         * DBTableModel から テーブルのタグ文字列を作成して返します。
1029         *
1030         * @og.rev 3.5.3.1 (2003/10/31) User情報のテーブルの設定を、システムリソース より行う。
1031         * @og.rev 5.2.2.0 (2010/11/01) SystemData 見直し漏れの対応。
1032         *
1033         * @return      テーブルのタグ文字列
1034         * @og.rtnNotNull
1035         */
1036        private static String getTableHeaderTag() {
1037                // 6.1.1.0 (2015/01/17) Attributesの連結記述
1038                return new Attributes()
1039                                        .set( "id"              ,"viewTable"    )               // 3.6.0.5 (2004/10/18)
1040                                        .set( "summary" ,"layout"               )               // サマリー
1041                                        .getAttribute();
1042        }
1043
1044        /**
1045         * userInfo 情報をセットします。
1046         * 現状、このメソッドではLANGのみ設定可能です。
1047         * (予約語以外のセットはuserInfoタグで行う)
1048         *
1049         * LANGではuserInfoを切り替えた後にユーザのGUIInfoを再ロードします。
1050         *
1051         * @og.rev 5.9.1.0 (2015/10/02) 新規作成
1052         *
1053         * @param       req     HttpServletRequestオブジェクト
1054         * @return      結果情報
1055         */
1056        private String setUserinfo( final HttpServletRequest req ) {
1057                final HttpSession session = req.getSession();
1058                final UserInfo userInfo = (UserInfo)(session.getAttribute( HybsSystem.USERINFO_KEY ));
1059
1060                final String infoLang = req.getParameter( "LANG" );
1061
1062                String rtn = null ;
1063                if( userInfo != null && infoLang != null && infoLang.length() > 0) {
1064                        userInfo.setLang( infoLang );
1065                        ResourceFactory.newInstance( userInfo.getLang() ).makeGUIInfos( userInfo );
1066                        rtn = "User language : " + infoLang;
1067                }
1068
1069                if( rtn == null || rtn.length() == 0 ) {
1070                        rtn = "Error";
1071                }
1072
1073                return rtn ;
1074        }
1075}