001    /*
002     * Copyright (c) 2009 The openGion Project.
003     *
004     * Licensed under the Apache License, Version 2.0 (the "License");
005     * you may not use this file except in compliance with the License.
006     * You may obtain a copy of the License at
007     *
008     *     http://www.apache.org/licenses/LICENSE-2.0
009     *
010     * Unless required by applicable law or agreed to in writing, software
011     * distributed under the License is distributed on an "AS IS" BASIS,
012     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
013     * either express or implied. See the License for the specific language
014     * governing permissions and limitations under the License.
015     */
016    package org.opengion.fukurou.process;
017    
018    import org.opengion.fukurou.util.Argument;
019    import org.opengion.fukurou.util.HybsFileFilter;
020    import org.opengion.fukurou.util.LogWriter;
021    
022    import java.io.File;
023    import java.util.Map ;
024    import java.util.LinkedHashMap ;
025    import java.util.Stack;
026    
027    /**
028     * Process_FileSearch は、指定ã?フォルãƒ?»¥下ã?ファイルをä¸?¦§する、FirstProcess
029     * インターフェースと、ChainProcess インターフェースの実è£?‚¯ラスですã?
030     *
031     * æŒ?®šã?条件に合è?するファイルを検索しã?LineModel のサブクラスであるã€?
032     * FileLineModel オブジェクトを作æ?して、下流に渡しますã?
033     * FileLineModel オブジェクトには、ファイル属æ?(Level,File,Length,Modify)
034     * が設定されますã?
035     *
036     * 引数æ–?­—å?中にスペã?スを含ã‚??合ã?、ダブルコーãƒ??ション("") で括って下さã�??
037     * 引数æ–?­—å?の ã€?』ã?前後には、スペã?スは挟めません。å¿?�šã€?key=value の様に
038     * 繋げてくださいã€?
039     *
040     * @og.formSample
041     *  Process_FileSearch -start=d:/ -suffix=jsp
042     *
043     *     -start=開始フォルãƒ?        ?š検索を開始するフォルãƒ?
044     *   [ -prefix=接頭è¾?           ] ?šFile?¥?¥?¥?¥,View?¥?¥?¥?¥,など、指定ã?接頭辞で始まるファイルを検索
045     *   [ -unprefix=不接頭è¾?       ] ?šFile?¥?¥?¥?¥,View?¥?¥?¥?¥,など、指定ã?接頭辞で始まらなã�?ƒ•ァイルを検索
046     *   [ -suffix=接尾è¾?           ] ??txt,.java,.jsp.... など、指定ã?接尾辞で終わるファイルを検索
047     *   [ -unsuffix=不接尾è¾?       ] ??txt,.java,.jsp.... など、指定ã?接尾辞で終わらなã�?ƒ•ァイルを検索
048     *   [ -instr=部åˆ?–‡字å?         ] ?šファイル名とä¸??する部åˆ?–‡字å?を指å®?
049     *   [ -uninstr=不部åˆ?–‡字å?     ] ?šファイル名とä¸??しな部åˆ?–‡字å?を指å®?
050     *   [ -equals=ä¸??              ] ?šファイル名とä¸??するæ–?­—å?(大æ–?­—小文字ã?区別しなã�?を指å®?
051     *   [ -notequals=不ä¸??         ] ?šファイル名とä¸??しなã�?–‡字å?(大æ–?­—小文字ã?区別しなã�?を指å®?
052     *   [ -match=正規表現           ] ?šファイル名とä¸??する正規表現を指å®?
053     *   [ -unmatch=正規表現         ] ?šファイル名とä¸??しなã�?­£規表現を指å®?
054     *   [ -modify=YYYYMMDD          ] ?š指定日付け以降に変更されたファイルを検索
055     *             YYYYMMDD   : YYYYMMDD 形式でのæŒ?®š日の 00:00:00 を基準時刻
056     *             TODAY      : 実行日の 00:00:00 を基準時刻
057     *             YESTERDAY  : 実行日前日の 00:00:00 を基準時刻
058     *             LAST_WEEK  : 実行日の先é?(7日å‰? 00:00:00 を基準時刻
059     *             MONTH      : 実行月の 1日 00:00:00 を基準時刻
060     *             LAST_MONTH : 実行前月ã? 同日 00:00:00 を基準時刻
061     *             LAST_YEAR  : 実行前年の 同月同日 00:00:00 を基準時刻
062     *   [ -useDIR=[false/true]      ] ?š判定をファイルã�?�‘でなくã?ãƒ?‚£レクトリでも行うかどã�?�‹を指å®?初期値:false)
063     *   [ -larger=サイズ(Byte)      ] ?šファイルの大きさが指定ã?バイト数と同じか大きいファイルを検索
064     *   [ -smaller=サイズ(Byte)     ] ?šファイルの大きさが指定ã?バイト数より小さã�?ƒ•ァイルを検索
065     *   [ -isHidden=[true/false]    ] ?štrue:HIDDENファイルのみ検索/false:NORMALファイルのみ検索(初期値:null)
066     *   [ -maxLevel=æœ?¤§階層数      ] ?šディレクトリの階層を下がる最大数(初期値:256)
067     *   [ -useLineCnt=行数計ç®?     ] ?šファイルの行数をカウントするかどã�?�‹を指å®?初期値:false)
068     *   [ -useMD5=MD5計算å?         ] ?šファイルのMD5計算を行うかどã�?�‹を指å®?初期値:false)
069     *   [ -useOmitCmnt=[false/true] ] ?šコメント部åˆ?‚’削除した行数とæ–?­—数計算を行うかどã�?�‹を指å®?初期値:false)
070     *   [ -encode=エンコード名      ] ?šコメント削除時ã?æ–?­—数計算で利用するファイルのエンコーãƒ?初期値:JISAutoDetect)
071     *   [ -inPath=入力å?通パス      ] ?šBIKO作æ?用のファイルパスから削除する部åˆ?æ–?­—数のみ)
072     *   [ -outPath=出力追åŠ?ƒ‘ス     ] ?šBIKO作æ?用のファイルパスに追åŠ?�™る部åˆ?
073     *   [ -display=[false/true]     ] ?štrueは、検索状況を表示しまã�?初期値:false)
074     *   [ -debug=[false/true]       ] ?šデバッグæƒ??を標準å?力に表示する(true)かしなã�?false)ã�?初期値:false[表示しない])
075     *
076     * @version  4.0
077     * @author   Kazuhiko Hasegawa
078     * @since    JDK5.0,
079     */
080    public class Process_FileSearch extends AbstractProcess
081                                                                    implements FirstProcess , ChainProcess {
082    
083            private Stack<FileListStack>      dirs            = null;
084            private File                    file            = null;
085            private HybsFileFilter  filter          = null;
086            private FileLineModel   newData         = null;
087            private int                             level           = 1;
088    
089            private String                  startDir        = null;
090            private int                             maxLevel        = 256;
091            private int                             inCount         = 0;
092            private int                             outCount        = 0;
093            private int                             inPathLen       = 0;            // 4.2.3.0 (2008/05/26) BIKOæ¬?”¨
094            private String                  outPath         = null;         // 4.3.1.1 (2008/08/23) BIKOæ¬?”¨
095            private boolean                 display         = false;        // 表示しなã�?
096            private boolean                 debug           = false;        // 5.7.3.0 (2014/02/07) ãƒ?ƒ�ãƒ?‚°æƒ??
097    
098            private static final Map<String,String> mustProparty   ;          // ?»プロパティ?½å¿??チェãƒ?‚¯用 Map
099            private static final Map<String,String> usableProparty ;          // ?»プロパティ?½整合æ?チェãƒ?‚¯ Map
100    
101            static {
102                    mustProparty = new LinkedHashMap<String,String>();
103                    mustProparty.put( "start",      "検索を開始するフォルãƒ?å¿??)" );
104    
105                    usableProparty = new LinkedHashMap<String,String>();
106                    usableProparty.put( "prefix",   "File?¥?¥?¥?¥,View?¥?¥?¥?¥,など、指定ã?接頭辞で始まるファイルを検索" );
107                    usableProparty.put( "unprefix", "File?¥?¥?¥?¥,View?¥?¥?¥?¥,など、指定ã?接頭辞で始まらなã�?ƒ•ァイルを検索" );
108                    usableProparty.put( "suffix",   ".txt,.java,.jsp.... など、指定ã?接尾辞で終わるファイルを検索" );
109                    usableProparty.put( "unsuffix", ".txt,.java,.jsp.... など、指定ã?接尾辞で終わらなã�?ƒ•ァイルを検索" );
110                    usableProparty.put( "instr",    "ファイル名とä¸??する部åˆ?–‡字å?を指å®? );
111                    usableProparty.put( "uninstr",  "ファイル名とä¸??しなã�?ƒ¨åˆ?–‡字å?を指å®? );
112                    usableProparty.put( "equals",   "ファイル名とä¸??するæ–?­—å?(大æ–?­—小文字ã?区別しなã�?を指å®? );
113                    usableProparty.put( "notequals",        "ファイル名とä¸??しなã�?–‡字å?(大æ–?­—小文字ã?区別しなã�?を指å®? );
114                    usableProparty.put( "match",    "ファイル名とä¸??する正規表現を指å®? );
115                    usableProparty.put( "unmatch",  "ファイル名とä¸??しなã�?­£規表現を指å®? );
116                    usableProparty.put( "modify",   "æŒ?®š日付け以降に変更されたファイルを検索" +
117                                            CR + "YYYYMMDD   : YYYYMMDD 形式でのæŒ?®š日の 00:00:00 を基準時刻" +
118                                            CR + "TODAY      : 実行日の 00:00:00 を基準時刻" +
119                                            CR + "YESTERDAY  : 実行日前日の 00:00:00 を基準時刻" +
120                                            CR + "LAST_WEEK  : 実行日の先é?(7日å‰? 00:00:00 を基準時刻" +
121                                            CR + "MONTH      : 実行月の 1日 00:00:00 を基準時刻" +
122                                            CR + "LAST_MONTH : 実行前月ã? 同日 00:00:00 を基準時刻" +
123                                            CR + "LAST_YEAR  : 実行前年の 同月同日 00:00:00 を基準時刻"
124                    );
125                    usableProparty.put( "useDIR"    ,"判定をファイルã�?�‘でなくã?ãƒ?‚£レクトリでも行うかどã�?�‹を指å®?初期値:false)" );
126                    usableProparty.put( "larger"    ,"ファイルの大きさが指定ã?バイト数と同じか大きいファイルを検索" );
127                    usableProparty.put( "smaller"   ,"ファイルの大きさが指定ã?バイト数より小さã�?ƒ•ァイルを検索" );
128                    usableProparty.put( "isHidden"  ,"true:HIDDENファイルのみ検索/false:NORMALファイルのみ検索(初期値:null)" );
129                    usableProparty.put( "maxLevel"  ,"ãƒ?‚£レクトリの階層を下がる最大数(初期値:256)" );
130                    usableProparty.put( "useLineCnt","ファイルの行数をカウントするかどã�?�‹を指å®?初期値:false)" );
131                    usableProparty.put( "useMD5"    ,"ファイルのMD5計算を行うかどã�?�‹を指å®?初期値:false)" );               // 5.7.2.1 (2014/01/17)
132                    usableProparty.put( "useOmitCmnt" ,"コメント部åˆ?‚’削除した行数とæ–?­—数計算を行うかどã�?�‹を指å®?初期値:false)" );             // 5.7.4.0 (2014/03/07)
133                    usableProparty.put( "encode"    ,"コメント削除時ã?æ–?­—数計算で利用するファイルのエンコーãƒ?初期値:JISAutoDetect)" );    // 5.7.4.0 (2014/03/07)
134                    usableProparty.put( "inPath"    ,"BIKO作æ?用のファイルパスから削除する部åˆ?æ–?­—数のみ)" );
135                    usableProparty.put( "outPath"   ,"BIKO作æ?用のファイルパスに追åŠ?�™る部åˆ? );
136                    usableProparty.put( "display"   ,"trueは、検索状況を表示しまã�?初期値:false)" );
137                    usableProparty.put( "debug"             ,"ãƒ?ƒ�ãƒ?‚°æƒ??を標準å?力に表示する(true)かしなã�?false)ã�? +
138                                                                                    CR + "(初期値:false:表示しなã�?" );                // 5.7.3.0 (2014/02/07) ãƒ?ƒ�ãƒ?‚°æƒ??
139            }
140    
141            /**
142             * ãƒ?ƒ•ォルトコンストラクターã€?
143             * こã?クラスは、動çš?½œæ?されますã?ãƒ?ƒ•ォルトコンストラクターでã€?
144             * super クラスに対して、å¿?¦�な初期化を行っておきますã?
145             *
146             */
147            public Process_FileSearch() {
148                    super( "org.opengion.fukurou.process.Process_FileSearch",mustProparty,usableProparty );
149            }
150    
151            /**
152             * プロセスの初期化を行いますã?初めにä¸?º¦ã�?�‘、呼び出されますã?
153             * 初期処ç�?ファイルオープンã€?¼¤?¢オープンç­?に使用しますã?
154             *
155             * @og.rev 4.2.2.0 (2008/05/10) 行数カウントã?使用有無
156             * @og.rev 4.3.1.1 (2008/08/23) BIKO æ¬?�«outPath 属æ?を追åŠ?�—ますã?
157             * @og.rev 5.1.2.0 (2010/01/01) useDIR 属æ?を追åŠ?�—ますã?
158             * @og.rev 5.7.2.1 (2014/01/17) useMD5 属æ?を追åŠ?�—ますã?
159             * @og.rev 5.7.4.0 (2014/03/07) useOmitCmnt,encode 属æ?を追åŠ?�—ますã?
160             * @og.rev 5.7.4.3 (2014/03/28) larger,smaller属æ?を文字å?に変更
161             * @og.rev 5.7.5.0 (2014/04/04) isHidden属æ?を追åŠ?�—ますã?
162             *
163             * @param   paramProcess ãƒ??タベã?スの接続å?æƒ??などを持ってã�?‚‹オブジェクãƒ?
164             */
165            public void init( final ParamProcess paramProcess ) {
166                    Argument arg = getArgument();
167    
168                    startDir                = arg.getProparty("start" );
169    
170                    String inPath   = arg.getProparty("inPath");
171                    if( inPath != null ) { inPathLen = inPath.length(); }
172    
173                    String prefix   = arg.getProparty("prefix");
174                    String unprefix = arg.getProparty("unprefix");          // 5.1.2.0 (2010/01/01) 追åŠ?
175                    String suffix   = arg.getProparty("suffix");
176                    String unsuffix = arg.getProparty("unsuffix");          // 5.1.2.0 (2010/01/01) 追åŠ?
177                    String instr    = arg.getProparty("instr");
178                    String uninstr  = arg.getProparty("uninstr");           // 5.1.2.0 (2010/01/01) 追åŠ?
179                    String equals   = arg.getProparty("equals");
180                    String notequals= arg.getProparty("notequals");         // 5.1.2.0 (2010/01/01) 追åŠ?
181                    String match    = arg.getProparty("match");
182                    String unmatch  = arg.getProparty("unmatch");
183                    String modify   = arg.getProparty("modify");
184                    String larger   = arg.getProparty("larger");
185                    String smaller  = arg.getProparty("smaller");
186                    String isHidden = arg.getProparty("isHidden");          // 5.7.5.0 (2014/04/04) 追åŠ?
187                    maxLevel                = arg.getProparty("maxLevel",maxLevel);
188                    outPath                 = arg.getProparty("outPath");
189                    // 4.2.2.0 (2008/05/10) 行数カウントã?使用有無
190                    boolean useLineCnt      = arg.getProparty( "useLineCnt",false );
191                    // 5.7.2.1 (2014/01/17) ファイルのMD5の計算有無
192                    boolean useMD5          = arg.getProparty( "useMD5",false );
193                    // 5.7.4.0 (2014/03/07) コメント部åˆ?‚’削除した行数とæ–?­—数計算を行うかどã�?�‹
194                    boolean useOmitCmnt     = arg.getProparty( "useOmitCmnt",false );
195                    // 5.7.4.0 (2014/03/07) コメント削除時ã?æ–?­—数計算で利用するファイルのエンコーãƒ?初期値:JISAutoDetect)
196                    String encode   = arg.getProparty( "encode" , "JISAutoDetect" );
197    
198                    // 5.1.2.0 (2010/01/01) 判定をãƒ?‚£レクトリでも行うかどã�?�‹
199                    boolean useDIR = arg.getProparty( "useDIR",false );
200    
201                    display = arg.getProparty("display",display);
202    //              if( display ) { println( startDir ); }                                  // 4.0.0 (2005/01/31)
203                    debug   = arg.getProparty("debug",debug);                               // 5.7.3.0 (2014/02/07) ãƒ?ƒ�ãƒ?‚°æƒ??
204    //              if( debug ) { println( arg.toString() ); }                              // 5.7.3.0 (2014/02/07) ãƒ?ƒ�ãƒ?‚°æƒ??
205    
206                    // 5.1.2.0 (2010/01/01) 反転処ç�??引数追åŠ?
207                    filter = new HybsFileFilter( useDIR );                                  // 5.1.2.0 (2010/01/01) 判定をãƒ?‚£レクトリでも行うかどã�?�‹
208                    filter.startsWith( prefix   , false);
209                    filter.startsWith( unprefix , true );
210                    filter.endsWith( suffix   , false);
211                    filter.endsWith( unsuffix , true );
212                    filter.instr( instr   , false);
213                    filter.instr( uninstr , true );
214                    filter.fileEquals( equals   , false);
215                    filter.fileEquals( notequals , true );
216                    filter.matches( match   , false);
217                    filter.matches( unmatch , true );
218    //              filter.unMatches( unmatch );                    // 5.1.2.0 (2010/01/01) 反転処ç�??、matches の 反転引数で対å¿?
219                    filter.lastModified( modify );
220                    // 5.7.4.3 (2014/03/28) larger,smaller属æ?を文字å?に変更
221    //              if( larger  != null ) { filter.isLarger( Integer.parseInt( larger ) ); }
222    //              if( smaller != null ) { filter.isSmaller( Integer.parseInt( smaller ) ); }
223                    filter.isLarger( larger );
224                    filter.isSmaller( smaller );
225                    filter.isHidden( isHidden );                    // 5.7.5.0 (2014/04/04) 追åŠ?
226    
227                    File tempFile = new File( startDir );
228                    if( display ) { println( "start=[" + tempFile + "]" ); }                // 5.7.3.0 (2014/02/07)
229                    if( tempFile.isDirectory() ) {
230                            dirs = new Stack<FileListStack>();
231                            File[] fileList = tempFile.listFiles( filter );
232                            dirs.push( new FileListStack( fileList, level ) );
233                    }
234                    else {
235                            dirs = new Stack<FileListStack>();
236                            File[] fileList = new File[] { tempFile };
237                            dirs.push( new FileListStack( fileList, level ) );
238                    }
239    
240    //              newData = new FileLineModel();
241    //              newData = new FileLineModel( useLineCnt );                      // 4.2.2.0 (2008/05/10)
242    //              newData = new FileLineModel( useLineCnt,useMD5 );       // 5.7.2.1 (2014/01/17)
243                    newData = new FileLineModel( useLineCnt,useMD5,useOmitCmnt );   // 5.7.4.0 (2014/03/07)
244                    newData.setEncode( encode );
245            }
246    
247            /**
248             * こã?ãƒ??タの処ç�?�«おいて、次の処ç�?�Œ出来るかどã�?�‹を問ã�?�ˆわせますã?
249             * こã?呼び出し1回毎に、次のãƒ??タを取得する準備を行いますã?
250             *
251             * @og.rev 5.3.8.0 (2011/08/01) 処ç�?¸­の状態を表示するための println を追åŠ?
252             *
253             * @return      処ç�?�§きる:true / 処ç�?�§きなã�?false
254             */
255            public boolean next() {
256                    while( !dirs.empty() ) {
257                            FileListStack fStack = dirs.pop();
258    
259                            level = fStack.getLevel();
260                            if( level > maxLevel ) { continue; }
261    
262                            File[] fileList = fStack.getFileList();
263                            if( fileList == null ) { continue; }
264    
265                            int address = fStack.getAddress();
266                            for( ; address < fileList.length; address++ ) {
267                                    inCount++ ;
268                                    if( fileList[address].isDirectory() ) {
269    //                                      if( display ) { println( fileList[address].getAbsolutePath() ); }               // 5.3.8.0 (2011/08/01)
270                                            if( debug ) { println( "file Add=" + fileList[address].getAbsolutePath() ); }                   // 5.7.3.0 (2014/02/07) ãƒ?ƒ�ãƒ?‚°æƒ??
271                                            File[] newList = fileList[address].listFiles( filter );
272                                            dirs.push( new FileListStack( newList,level+1) );
273                                    }
274                                    else {
275                                            file = fileList[address];
276                                            if( debug ) { println( "file=" + file ); }                      // 5.7.3.0 (2014/02/07) ãƒ?ƒ�ãƒ?‚°æƒ??
277                                            fStack.setAddress( address+1 );
278                                            dirs.push( fStack );
279                                            return true;
280                                    }
281                            }
282                    }
283                    return false;
284            }
285    
286            /**
287             * æœ??にã€?行データである LineModel を作æ?しまã�?
288             * FirstProcess は、次ã€?�¨処ç�?‚’チェインしてã�?��æœ??の行データã‚?
289             * 作æ?して、後続ã? ChainProcess クラスに処ç�?ƒ‡ータを渡しますã?
290             *
291             * @og.rev 4.2.3.0 (2008/05/26) BIKO æ¬?�«展開ファイル名を記述しますã?
292             * @og.rev 4.3.1.1 (2008/08/23) BIKO æ¬?�«outPath 属æ?を追åŠ?�—ますã?
293             *
294             * @param       rowNo   処ç�?¸­の行番号
295             *
296             * @return      処ç�?¤‰換後ã?LineModel
297             */
298            public LineModel makeLineModel( final int rowNo ) {
299                    outCount++ ;
300                    newData.setFileVals( level,file );
301    
302                    // 4.3.1.1 (2008/08/23)
303                    String biko = null;
304                    // 4.2.3.0 (2008/05/26) BIKO æ¬?¿½åŠ?
305                    if( inPathLen > 0 ) {
306                            biko = file.getAbsolutePath().substring( inPathLen );
307    //                      newData.setBiko( biko );
308                    }
309    
310                    if( outPath != null ) {
311                            if( biko == null ) {
312                                    biko = outPath + file.getName() ;
313                            }
314                            else {
315                                    biko = outPath + biko ;
316                            }
317                    }
318                    if( biko != null ) {
319                            newData.setBiko( biko );
320                    }
321    
322                    newData.setRowNo( rowNo );
323    
324    //              if( display ) { println( newData.dataLine() ); }                // 5.1.2.0 (2010/01/01) display の条件変更
325    
326                    return newData;
327            }
328    
329            /**
330             * 引数の LineModel をå?ç�?�™るメソãƒ?ƒ‰ですã?
331             * 変換処ç�?¾Œã? LineModel を返しますã?
332             * 後続å?ç�?‚’行わなã�??å�?ãƒ??タのフィルタリングを行う場å�?はã€?
333             * null ãƒ??タを返しますã?つまりã?null ãƒ??タは、後続å?ç�?‚’行わなã�?
334             * フラグの代わりにも使用してã�?�¾すã?
335             * なおã?変換処ç�?¾Œã? LineModel と、オリジナルの LineModel がã?
336             * 同ä¸?�‹、コピã?(クローン)かã?、各処ç�?ƒ¡ソãƒ?ƒ‰å†?�§決めてã�?�¾すã?
337             * ドキュメントに明記されてã�?�ªã�??合ã?、副作用が問題になるå?合ã?ã€?
338             * å�??ç�?�”とに自åˆ?�§コピã?(クローン)して下さã�??
339             *
340             * @param       data    オリジナルのLineModel
341             *
342             * @return      処ç�?¤‰換後ã?LineModel
343             */
344            public LineModel action( final LineModel data ) {
345                    LineModel rtn = null;
346    
347                    final FileLineModel fileData ;
348                    if( data instanceof FileLineModel ) {
349                            fileData = (FileLineModel)data ;
350                    }
351                    else {
352                            String errMsg = "ãƒ??タã�?FileLineModel オブジェクトではありませんã€? + CR ;
353                            throw new RuntimeException( errMsg );
354                    }
355    
356                    if( debug ) { println( "Before:" + data.dataLine() ); }         // 5.1.2.0 (2010/01/01) display の条件変更
357    
358                    File inFile = fileData.getFile() ;
359                    File[] fileList = inFile.listFiles( filter );
360    
361                    if( fileList != null && fileList.length > 0 ) {
362                            rtn = data;
363                    }
364    
365                    if( display && rtn != null ) { println( rtn.dataLine() ); }             // 5.1.2.0 (2010/01/01) display の条件変更
366                    return rtn ;
367            }
368    
369            /**
370             * プロセスの終äº?‚’行いますã?æœ?¾Œにä¸?º¦ã�?�‘、呼び出されますã?
371             * 終äº??ç�?ファイルクローズã€?¼¤?¢クローズç­?に使用しますã?
372             *
373             * @param   isOK トã?タルで、OKã�?�£たかどã�?�‹[true:成功/false:失敗]
374             */
375            public void end( final boolean isOK ) {
376                    dirs            = null;
377                    file            = null;
378                    filter          = null;
379                    newData         = null;
380            }
381    
382            /**
383             * プロセスの処ç�?µ�果のレポã?ト表現を返しますã?
384             * 処ç�??ログラãƒ?��、å?力件数、å?力件数などのæƒ??ですã?
385             * こã?æ–?­—å?をそのまま、標準å?力に出すことで、結果レポã?トと出来るよã�?�ª
386             * 形式で出してくださいã€?
387             *
388             * @return   処ç�?µ�果のレポã?ãƒ?
389             */
390            public String report() {
391                    String report = "[" + getClass().getName() + "]" + CR
392                                    + TAB + "Start Folder : " + startDir  + CR
393                                    + TAB + "Search Count : " + inCount   + CR
394                                    + TAB + "Output Count : " + outCount ;
395    
396                    return report ;
397            }
398    
399            /**
400             * こã?クラスの使用方法を返しますã?
401             *
402             * @return      こã?クラスの使用方æ³?
403             */
404            public String usage() {
405                    StringBuilder buf = new StringBuilder();
406    
407                    buf.append( "Process_FileSearch は、指定ã?フォルãƒ?»¥下ã?ファイルをä¸?¦§する、FirstProcess"      ).append( CR );
408                    buf.append( "インターフェースと、ChainProcess インターフェースの実è£?‚¯ラスですã?"                    ).append( CR );
409                    buf.append( CR );
410                    buf.append( "æŒ?®šã?条件に合è?するファイルを検索しã?ファイル属æ?(Level,File,Length,Modify)"     ).append( CR );
411                    buf.append( "をå?に、LineModelを作æ?しã?下流に渡しますã?"                                                                      ).append( CR );
412                    buf.append( CR );
413                    buf.append( "引数æ–?­—å?中に空白を含ã‚??合ã?、ダブルコーãƒ??ション(\"\") で括って下さã�??" ).append( CR );
414                    buf.append( "引数æ–?­—å?の ã€?』ã?前後には、空白は挟めません。å¿?�šã€?key=value の様に"             ).append( CR );
415                    buf.append( "繋げてくださいã€?                                                                                                                              ).append( CR );
416                    buf.append( CR );
417                    buf.append( "  -start=開始フォルãƒ?   ?š検索を開始するフォルãƒ?                                                                       ).append( CR );
418                    buf.append( "[ -prefix=接頭è¾?       ]?šFile?¥?¥?¥?¥,View?¥?¥?¥?¥,などの接頭辞で始まるファイル"                      ).append( CR );
419                    buf.append( "[ -unprefix=不接頭è¾?   ]?šFile?¥?¥?¥?¥,View?¥?¥?¥?¥,などの接頭辞で始まらなã�?ƒ•ァイル"            ).append( CR );
420                    buf.append( "[ -suffix=接尾è¾?       ]??txt,.java,.jsp.... などの接尾辞で終わるファイル"            ).append( CR );
421                    buf.append( "[ -unsuffix=不接尾è¾?   ]??txt,.java,.jsp.... などの接尾辞で終わらなã�?ƒ•ァイル"  ).append( CR );
422                    buf.append( "[ -instr=部åˆ?–‡字å?     ]?šファイル名とä¸??する部åˆ?–‡字å?"                                 ).append( CR );
423                    buf.append( "[ -uninstr=不部åˆ?–‡字å? ]?šファイル名とä¸??しな部åˆ?–‡字å?"                                                  ).append( CR );
424                    buf.append( "[ -equals=ä¸??          ]?šファイル名とä¸??するæ–?­—å?(大æ–?­—小文字ã?区別しなã�?"     ).append( CR );
425                    buf.append( "[ -notequals=不ä¸??     ]?šファイル名とä¸??しなã�?–‡字å?(大æ–?­—小文字ã?区別しなã�?"    ).append( CR );
426                    buf.append( "[ -match=正規表現       ]?šファイル名とä¸??する正規表現"                                                       ).append( CR );
427                    buf.append( "[ -unmatch=正規表現     ]?šファイル名とä¸??しなã�?­£規表現"                                                     ).append( CR );
428                    buf.append( "[ -modify=YYYYMMDD      ]?š指定日付け以降に変更されたファイル"                                            ).append( CR );
429                    buf.append( "          YYYYMMDD   : YYYYMMDD 形式でのæŒ?®š日の 00:00:00 を基準時刻"                          ).append( CR );
430                    buf.append( "          TODAY      : 実行日の 00:00:00 を基準時刻"                                                          ).append( CR );
431                    buf.append( "          YESTERDAY  : 実行日前日の 00:00:00 を基準時刻"                                                       ).append( CR );
432                    buf.append( "          LAST_WEEK  : 実行日の先é?(7日å‰? 00:00:00 を基準時刻"                                 ).append( CR );
433                    buf.append( "          MONTH      : 実行月の 1日 00:00:00 を基準時刻"                                                      ).append( CR );
434                    buf.append( "          LAST_MONTH : 実行前月ã? 同日 00:00:00 を基準時刻"                                             ).append( CR );
435                    buf.append( "          LAST_YEAR  : 実行前年の 同月同日 00:00:00 を基準時刻"                                 ).append( CR );
436                    buf.append( "[ -useDIR=[false/true]  ]?š判定をãƒ?‚£レクトリ名も含めて行うかどã�?�‹(初期値:false)"   ).append( CR );
437                    buf.append( "[ -larger=サイズ(Byte)  ]?š大きさが指定ã?バイト数と同じか大きいファイル"                   ).append( CR );
438                    buf.append( "[ -smaller=サイズ(Byte) ]?š大きさが指定ã?バイト数より小さã�?ƒ•ァイル"                               ).append( CR );
439                    buf.append( "[ -isHidden=[false/true]]?štrue:HIDDENのみ検索/false:NORMALのみ検索(初期値:null)"    ).append( CR );
440                    buf.append( "[ -maxLevel=æœ?¤§階層数  ]?šディレクトリの階層を下がる最大数(初期値:256)"                        ).append( CR );
441                    buf.append( "[ -useLineCnt=行数計ç®? ]?šファイルの行数をカウントするかどã�?�‹(初期値:false)"              ).append( CR );
442                    buf.append( "[ -useMD5=MD5計算å?     ]?šファイルのMD5計算を行うかどã�?�‹を指å®?初期値:false)"     ).append( CR );
443                    buf.append( "[ -inPath=入力å?通パス  ]?šBIKO作æ?用のファイルパスから削除するæ–?­—å?"                               ).append( CR );
444                    buf.append( "[ -outPath=出力追åŠ?ƒ‘ス ]?šBIKO作æ?用のファイルパスに追åŠ?�™る文字å?"                               ).append( CR );
445                    buf.append( "[ -display=[false/true] ]?štrueは、検索状況を表示(初期値:false)"                                      ).append( CR );
446                    buf.append( "[ -debug=[false/true]   ]?štrueは、デバッグ状況を表示(初期値:false)"                            ).append( CR );
447                    buf.append( CR ).append( CR );
448                    buf.append( getArgument().usage() ).append( CR );
449    
450                    return buf.toString();
451            }
452    
453            /**
454             * こã?クラスは、main メソãƒ?ƒ‰から実行できませんã€?
455             *
456             * @param       args    コマンド引数配å?
457             */
458            public static void main( final String[] args ) {
459                    LogWriter.log( new Process_FileSearch().usage() );
460            }
461    
462            /**
463             * こã?クラスはファイルをスタãƒ?‚¯を使用して展開する場合ã?
464             * 個ã?の状態を保持する為のクラスですã?
465             *
466             * @version  4.0
467             * @author   Kazuhiko Hasegawa
468             * @since    JDK5.0,
469             */
470            private static final class FileListStack {
471                    private int address ;
472                    private final File[] files;
473                    private final int level;
474    
475                    /**
476                     * コンストラクター
477                     * 初期値を設定しますã?
478                     * ファイルの配å?につã�?�¦は、コピã?せずそã?ままå†?ƒ¨配å?にセãƒ?ƒˆしてã�?�¾すã?
479                     *
480                     * @param files File[] ファイルの配å?(ファイルリスãƒ?
481                     * @param       level   レベル(æŒ?®šã?startフォルãƒ?�‹らã?階層数)
482                     */
483                    FileListStack( final File[] files,final int level ) {
484                            this.files   = files;
485                            this.address = 0;
486                            this.level   = level;
487                    }
488    
489                    /**
490                     * ファイルリストã?アドレスを設定しますã?
491                     * スタãƒ?‚¯から取り出した後ã?配å?を前回ã?続きからサーチするå?合に使用しますã?
492                     *
493                     * @param       address ファイルリストã?アドレス
494                     */
495                    void setAddress( final int address ) {
496                            this.address = address;
497                    }
498    
499                    /**
500                     * ファイルリストã?アドレスを取りå?しますã?
501                     *
502                     * @return      ファイルリストã?アドレス
503                     */
504                    int getAddress() {
505                            return address;
506                    }
507    
508                    /**
509                     * ファイルリストを取り出しますã?
510                     * ファイルの配å?につã�?�¦は、コピã?せずそã?ままå†?ƒ¨配å?を返してã�?�¾すã?
511                     *
512                     * @return File[] ファイルリスãƒ?
513                     */
514                    File[] getFileList() {
515                            return files;
516                    }
517    
518                    /**
519                     * 階層レベルを取りå?しますã?
520                     *
521                     * @return      レベル
522                     */
523                    int getLevel() {
524                            return level;
525                    }
526            }
527    }