001/* 002 * Copyright (c) 2017 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.fukurou.fileexec; 017 018import java.nio.file.Path; 019 020/** 021 * システムのベースフォルダ基準で、各種パスを管理するクラスです。 022 * 023 *<pre> 024 * 本システムでは、ベースフォルダを基準として、各種管理フォルダを規定しています。 025 * それらのパスオブジェクトを管理します。 026 * 027 *</pre> 028 * 029 * <table border="2" cellspacing="0" cellpadding="2" rules="all" style="font-family: monospace;"> 030 * <caption>各種管理フォルダの規定</caption> 031 * <tr><th>フォルダ </th><th>説明</th></tr> 032 * <tr><td>BASE_PATH </td><td>基本となるフォルダパス</td></tr> 033 * <tr><td>SUB_PATH </td><td>ベースパスの下位のサブパス。これがスキャン対象になる。</td></tr> 034 * <tr><td>WORK_PATH </td><td>中間パス。サブパスのファイルを一旦このワークに移動してから、取込処理を行います</td></tr> 035 * <tr><td>OK_PATH </td><td>処理が成功した場合のファイルの移動先</td></tr> 036 * <tr><td>NG_PATH </td><td>処理が失敗した場合のファイルの移</td></tr> 037 *</table> 038 * 039 * @og.rev 7.0.0.0 (2017/07/07) 新規作成 040 * 041 * @version 7.0 042 * @author Kazuhiko Hasegawa 043 * @since JDK1.8, 044 */ 045public final class BasePath { 046 private static final XLogger LOGGER= XLogger.getLogger( BasePath.class.getName() ); // ログ出力 047 048 /** BASEフォルダの相対パスの処理フォルダ(WORK)の初期値 {@value} */ 049 public static final String DEF_WORK_DIR = "work" ; 050 /** BASEフォルダの相対パスの処理済フォルダ(正常)の初期値 {@value} */ 051 public static final String DEF_OK_DIR = "bkup_ok" ; 052 /** BASEフォルダの相対パスの処理済フォルダ(異常)の初期値 {@value} */ 053 public static final String DEF_NG_DIR = "bkup_ng" ; 054 055 /** ベースパス */ 056 public final Path BASE_PATH ; 057 058 /** サブパス(実際にスキャンを行うトップパス) */ 059 public final Path SUB_PATH ; 060 061 /** 処理フォルダ(WORK)のパス */ 062 public final Path WORK_PATH ; 063 /** 処理済フォルダ(正常)のパス */ 064 public final Path OK_PATH ; 065 /** 処理済フォルダ(異常)のパス */ 066 public final Path NG_PATH ; 067 068 /** 069 * フォルダを指定して、オブジェクトを作成します。 070 * 071 * DIR_BASE,DIR_SUB,DIR_WORK,DIR_BKUP_OK,DIR_BKUP_NG の順にセットされます。 072 * 指定されていない(null)の場合は、初期設定を使用します。 073 * 074 * @param dirs フォルダ配列 075 */ 076 public BasePath( final String... dirs ) { 077 BASE_PATH = FileUtil.readPath( dirs[0] ); // ベースフォルダのチェック 078 079 SUB_PATH = dirs[1] == null || dirs[1].isEmpty() 080 ? BASE_PATH 081 : FileUtil.readPath( dirs[0] , dirs[1] ); 082 083 WORK_PATH = dirs[2] == null || dirs[2].isEmpty() 084 ? FileUtil.writePath( dirs[0] , DEF_WORK_DIR ) 085 : FileUtil.writePath( dirs[2] ); 086 087 OK_PATH = dirs[3] == null || dirs[3].isEmpty() 088 ? FileUtil.writePath( dirs[0] , DEF_OK_DIR ) 089 : FileUtil.writePath( dirs[3] ); 090 091 NG_PATH = dirs[4] == null || dirs[4].isEmpty() 092 ? FileUtil.writePath( dirs[0] , DEF_NG_DIR ) 093 : FileUtil.writePath( dirs[4] ); 094 095 LOGGER.debug( () -> "[BasePath] BASE_PATH=" + BASE_PATH 096 + " , SUB_PATH=" + SUB_PATH 097 + " , WORK_PATH=" + WORK_PATH 098 + " , OK_PATH=" + OK_PATH 099 + " , NG_PATH=" + NG_PATH ); 100 } 101}