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