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.FileUtil;
020    import org.opengion.fukurou.util.FileString;
021    import org.opengion.fukurou.util.Closer ;
022    import org.opengion.fukurou.util.StringUtil ;
023    import org.opengion.fukurou.util.LogWriter;
024    
025    import java.util.Map ;
026    import java.util.LinkedHashMap ;
027    import java.util.List ;
028    import java.util.ArrayList ;
029    import java.util.Locale ;                               // 5.7.3.2 (2014/02/28) ignoreCase が実è£?�•れてã�?�ªかったã?
030    import java.util.regex.Pattern;                 // 5.7.3.2 (2014/02/28) regexを利用する場å�?
031    import java.util.regex.Matcher;                 // 5.7.3.2 (2014/02/28) regexを利用する場å�?
032    
033    import java.io.File;
034    import java.io.PrintWriter;
035    import java.io.BufferedReader;
036    import java.io.IOException;
037    
038    /**
039     * Process_GrepChange は、上流から受け取っã�?FileLineModelから、語句ã‚?
040     * 置換するã?ChainProcess インターフェースの実è£?‚¯ラスですã?
041     *
042     * Process_Grep との違いは、チェãƒ?‚¯するファイルのコピã?ã‚?キーワードが存在
043     * しなくとã‚?作æ?することと、検索キーに正規表現が使えなã�??è¤?•°行置き換えが
044     * 出来なã�?�“とですã?
045     *
046     * keywordFile より、置換する語句を含ã‚?‚­ーと値のペアー(タブ区åˆ?‚Š)を読取りã€?
047     * 対象とする語句を置換しますã?
048     * keywordFile に、タブが含まれなã�?¡Œや、å?頭にタブが存在してã�?‚‹場合ã?ã€?
049     * そã?行を読み飛ã?しますã?またã?区åˆ?‚Šタブã?何å?存在しても構いませんã€?
050     * 置換文å­?値)は、\t の特殊文字が使用できますã?
051     * こã? GrepChange では、語句に、正規表現は使用できません。正規表現のキーワーãƒ?
052     * ã‚?–‡字å?をè¤?•°行ã?æ–?­—å?と置き換える場合ã?、Process_Grep を使用してくださいã€?
053     * こã?プログラãƒ?�§は、上流から受け取っã�?FileLineModel のファイルに対してã€?
054     * 置き換えた結果もã?同じファイルにセーブしますã?
055     * å…??ファイルを保存したい場合ã?、予めバックアãƒ??を取得しておいてくださいã€?
056     * -inEncode は、å?力ファイルのエンコード指定になりますã?
057     * -outEncode は、å?力ファイルのエンコードや、キーワードファイルの
058     * エンコード指定になりますã?(keywordFile は、å¿?�š 出力ファイルと同じエンコードですã?)
059     * これらã?エンコードが無æŒ?®šã?場合ã?、System.getProperty("file.encoding") で
060     * 求まるå?を使用しますã?
061     *
062     * 5.7.3.2 (2014/02/28)
063     * -regex=true でã€?½·?°?œー??¾žに正規表現を利用できますã?具体的には、String#replaceAll(String,String) 
064     * を利用して置換しますã?
065     * 通常の置換å?ç�??、indexOf で見つけて、StringBuilder#replace(int,int,String) を繰り返して処ç�?�—てã�?�¾すã?
066     * -ignoreCase=true で、検索?·?°?œー??¾žに大æ–?­—小文字を区別しなã�??ç�?�Œ可能ですã?
067     *
068     * 上流ã?ロセスでは、Name 属æ?として、ã?File』を持ち、å?は、Fileオブジェクãƒ?
069     * である、Process_FileSearch を使用するのがã?便利ですã?それ以外ã?クラスã‚?
070     * 使用する場合でもã?Name属æ?と、File オブジェクトを持つ LineModel を受け渡ã�?
071     * できれば、使用可能ですã?
072     *
073     * 引数æ–?­—å?中にスペã?スを含ã‚??合ã?、ダブルコーãƒ??ション("") で括って下さã�??
074     * 引数æ–?­—å?の ã€?』ã?前後には、スペã?スは挟めません。å¿?�šã€?key=value の様に
075     * 繋げてくださいã€?
076     *
077     *  Process_GrepChange -keyword=検索æ–?­—å? -ignoreCase=true -outfile=OUTFILE -encode=UTF-8
078     *
079     *    -keywordFile=キーワーãƒ?   ?š置換する語句を含ã‚?‚­ーと値のペアー(タブ区åˆ?‚Š)
080     *   [-ignoreCase=[false/true] ] ?š検索時に大æ–?­—小文字を区別しなã�?true)かどã�?�‹(初期値:false[区別する])
081     *   [-regex=[false/true]      ] ?šキ?°?œー??¾žに正規表現を利用する(true)かどã�?�‹(初期値:false[利用しない])
082     *   [-isChange=置換可否       ] ?š置換å?ç�?‚’実施する(true)かどã�?�‹(初期値:置換する[true])
083     *   [-inEncode=入力エンコーãƒ?] ?šå?力ファイルのエンコードタイãƒ?
084     *   [-outEncode=出力エンコード] ?šå?力ファイルã‚?‚­ーワードファイルのエンコードタイãƒ?
085     *   [-display=[false/true]    ] ?š結果を標準å?力に表示する(true)かしなã�?false)ã�?初期値:false[表示しない])
086     *   [-debug=[false/true]      ] ?šデバッグæƒ??を標準å?力に表示する(true)かしなã�?false)ã�?初期値:false[表示しない])
087     *
088     * @version  4.0
089     * @author   Kazuhiko Hasegawa
090     * @since    JDK5.0,
091     */
092    public class Process_GrepChange extends AbstractProcess implements ChainProcess {
093            private String[]        keyword = null;
094            private String[]        change  = null;
095            private Pattern[]       pattern = null;                 // 5.7.3.2 (2014/02/28) ?·?°?œー??¾žに正規表現を利用する場å�?
096            private boolean         ignoreCase      = false;
097            private boolean         regex           = false;        // 5.7.3.2 (2014/02/28) ?·?°?œー??¾žに正規表現を利用するかどã�?�‹
098            private boolean         isChange        = true;         // 5.1.2.0 (2010/01/01) 置換するかどã�?�‹を指定可能にする
099            private String          inEncode        = null;
100            private String          outEncode       = null;
101            private boolean         display         = false;        // 表示しなã�?
102            private boolean         debug           = false;        // 5.7.3.0 (2014/02/07) ãƒ?ƒ�ãƒ?‚°æƒ??
103    
104            private int             inCount         = 0;
105            private int             findCount       = 0;
106            private int             cngCount        = 0;
107    
108            private static final Map<String,String> mustProparty   ;          // ?»プロパティ?½å¿??チェãƒ?‚¯用 Map
109            private static final Map<String,String> usableProparty ;          // ?»プロパティ?½整合æ?チェãƒ?‚¯ Map
110    
111            static {
112                    mustProparty = new LinkedHashMap<String,String>();
113                    mustProparty.put( "keywordFile",        "置換する語句を含ã‚?‚­ーと値のペアー(タブ区åˆ?‚Š)(å¿??)" );
114    
115                    usableProparty = new LinkedHashMap<String,String>();
116                    usableProparty.put( "ignoreCase",       "検索時に大æ–?­—小文字を区別しなã�?true)かどã�?�‹ã€? +
117                                                                                    CR + "(初期値:区別する[false])" );
118                    usableProparty.put( "regex",            "?·?°?œー??¾žに正規表現を利用する(true)かどã�?�‹ã€? +
119                                                                                    CR + "(初期値:利用しない[false])" );       // 5.7.3.2 (2014/02/28)
120                    usableProparty.put( "isChange",         "置換å?ç�?‚’実施する(true)かどã�?�‹" +
121                                                                                    CR + "(初期値:置換する[true])" );
122                    usableProparty.put( "inEncode",         "入力ファイルのエンコードタイãƒ? );
123                    usableProparty.put( "outEncode",        "出力ファイルã‚?‚­ーワードファイルのエンコードタイãƒ? );
124                    usableProparty.put( "display",          "結果を標準å?力に表示する(true)かしなã�?false)ã�? +
125                                                                                    CR + "(初期値:false:表示しなã�?" );
126                    usableProparty.put( "debug",    "ãƒ?ƒ�ãƒ?‚°æƒ??を標準å?力に表示する(true)かしなã�?false)ã�? +
127                                                                                    CR + "(初期値:false:表示しなã�?" );                // 5.7.3.0 (2014/02/07) ãƒ?ƒ�ãƒ?‚°æƒ??
128            }
129    
130            /**
131             * ãƒ?ƒ•ォルトコンストラクターã€?
132             * こã?クラスは、動çš?½œæ?されますã?ãƒ?ƒ•ォルトコンストラクターでã€?
133             * super クラスに対して、å¿?¦�な初期化を行っておきますã?
134             *
135             */
136            public Process_GrepChange() {
137                    super( "org.opengion.fukurou.process.Process_GrepChange",mustProparty,usableProparty );
138            }
139    
140            /**
141             * プロセスの初期化を行いますã?初めにä¸?º¦ã�?�‘、呼び出されますã?
142             * 初期処ç�?ファイルオープンã€?¼¤?¢オープンç­?に使用しますã?
143             *
144             * @og.rev 5.1.2.0 (2010/01/01) 置換するかどã�?�‹を指定可能にする(isChange)属æ?追åŠ?
145             * @og.rev 5.7.3.2 (2014/02/28) debug の表示とã€?½·?°?œー??¾žã? \t の使用、trim() å»?­¢、ignoreCase の実è£??regex の追åŠ?
146             *
147             * @param   paramProcess ãƒ??タベã?スの接続å?æƒ??などを持ってã�?‚‹オブジェクãƒ?
148             */
149            public void init( final ParamProcess paramProcess ) {
150                    Argument arg = getArgument();
151    
152                    String keywordFile = arg.getProparty("keywordFile" );
153                    ignoreCase      = arg.getProparty("ignoreCase",ignoreCase);
154                    regex           = arg.getProparty("regex",regex);                               // 5.7.3.2 (2014/02/28) 
155                    isChange        = arg.getProparty("isChange",isChange);                 // 5.1.2.0 (2010/01/01)
156                    inEncode        = arg.getProparty("inEncode",System.getProperty("file.encoding"));
157                    outEncode       = arg.getProparty("outEncode",System.getProperty("file.encoding"));
158                    display         = arg.getProparty("display",display);
159                    debug           = arg.getProparty("debug",debug);                               // 5.7.3.0 (2014/02/07) ãƒ?ƒ�ãƒ?‚°æƒ??
160    //              if( debug ) { println( arg.toString() ); }                                      // 5.7.3.0 (2014/02/07) ãƒ?ƒ�ãƒ?‚°æƒ??
161    
162                    FileString fs = new FileString();
163                    fs.setFilename( keywordFile );
164                    fs.setEncode( outEncode );
165    //              String[] lines = fs.getValue( "\n" );
166                    String[] lines = fs.getValue( CR );                                     // 5.7.3.2 (2014/02/28) \n でなくã?CR としますã?
167                    int len = lines.length;
168                    if( len == 0 ) {
169                            String errMsg = "keywordFile のå†?®¹ã�?読み取れませんでしたã€?" + keywordFile + "]" ;
170                            throw new RuntimeException( errMsg );
171                    }
172    
173                    println( "keywordFile をã?" + len + "件読み取りましたã€? );
174                    List<String> keyList = new ArrayList<String>( len );
175                    List<String> cngList = new ArrayList<String>( len );
176    
177                    for( int i=0; i<len; i++ ) {
178            //              String line = lines[i].trim();
179                            String line = lines[i];
180                            int indx = line.indexOf( '\t' );
181                            if( indx <= 0 ) { continue ; }       // TAB がå?頭ã‚??存在しなã�?¡Œã?読み飛ã?すã?
182                            // 5.7.3.2 (2014/02/28) debug の表示とã€?½·?°?œー??¾žã? \t の使用、trim() å»?­¢
183    //                      keyList.add( line.substring( 0,indx ).trim() );
184    //                      String cng = line.substring( indx+1 ).trim();
185                            String key = line.substring( 0,indx );
186                            String cng = line.substring( indx+1 );
187    
188                            if( ignoreCase ) { key = key.toUpperCase(Locale.JAPAN); }       // 5.7.3.2 (2014/02/28) ignoreCase の実è£?¼�れ
189    
190                            if( debug ) { println( "[" + key + "]⇒[" + cng + "]" ); }
191    
192    //                      key = StringUtil.replace( key,"\\n",CR );               // 5.7.3.2 (2014/02/28) ?·?°?œー??¾žに \n は使えなã�??
193                            key = StringUtil.replace( key,"\\t","\t" );
194    
195    //                      cng = StringUtil.replace( cng,"\\n",CR );               // 5.7.3.2 (2014/02/28) ?·?°?œー??¾žに \n は使えなã�??
196                            cng = StringUtil.replace( cng,"\\t","\t" );
197    
198                            keyList.add( key );
199                            cngList.add( cng );
200                    }
201                    keyword = keyList.toArray( new String[keyList.size()] );
202                    change  = cngList.toArray( new String[cngList.size()] );
203    
204                    // 5.7.3.2 (2014/02/28) regex=true の場合ã?処ç�?
205                    if( regex ) {
206                            pattern = new Pattern[keyword.length];
207                            for( int i=0; i<keyword.length; i++ ) {
208                                    pattern[i] = (ignoreCase) ? Pattern.compile( keyword[i],Pattern.CASE_INSENSITIVE )
209                                                                                      : Pattern.compile( keyword[i] ) ;
210                            }
211                    }
212            }
213    
214            /**
215             * プロセスの終äº?‚’行いますã?æœ?¾Œにä¸?º¦ã�?�‘、呼び出されますã?
216             * 終äº??ç�?ファイルクローズã€?¼¤?¢クローズç­?に使用しますã?
217             *
218             * @param   isOK トã?タルで、OKã�?�£たかどã�?�‹[true:成功/false:失敗]
219             */
220            public void end( final boolean isOK ) {
221                    // ここでは処ç�?‚’行いませんã€?
222            }
223    
224            /**
225             * 引数の LineModel をå?ç�?�™るメソãƒ?ƒ‰ですã?
226             * 変換処ç�?¾Œã? LineModel を返しますã?
227             * 後続å?ç�?‚’行わなã�??å�?ãƒ??タのフィルタリングを行う場å�?はã€?
228             * null ãƒ??タを返しますã?つまりã?null ãƒ??タは、後続å?ç�?‚’行わなã�?
229             * フラグの代わりにも使用してã�?�¾すã?
230             * なおã?変換処ç�?¾Œã? LineModel と、オリジナルの LineModel がã?
231             * 同ä¸?�‹、コピã?(クローン)かã?、各処ç�?ƒ¡ソãƒ?ƒ‰å†?�§決めてã�?�¾すã?
232             * ドキュメントに明記されてã�?�ªã�??合ã?、副作用が問題になるå?合ã?ã€?
233             * å�??ç�?�”とに自åˆ?�§コピã?(クローン)して下さã�??
234             *
235             * @og.rev 4.0.0.0 (2007/11/28) メソãƒ?ƒ‰の戻りå?をチェãƒ?‚¯しますã?
236             * @og.rev 5.1.2.0 (2010/01/01) 置換するかどã�?�‹を指定可能にする(isChange)属æ?追åŠ?
237             * @og.rev 5.7.2.2 (2014/01/24) エラー時にãƒ??タもå?力しますã?
238             * @og.rev 5.7.3.2 (2014/02/28) debug の表示と、ignoreCase の実è£?
239             *
240             * @param       data    オリジナルのLineModel
241             *
242             * @return      処ç�?¤‰換後ã?LineModel
243             */
244            public LineModel action( final LineModel data ) {
245                    inCount++ ;
246                    final FileLineModel fileData ;
247                    if( data instanceof FileLineModel ) {
248                            fileData = (FileLineModel)data ;
249                    }
250                    else {
251                            String errMsg = "ãƒ??タã�?FileLineModel オブジェクトではありませんã€? + CR ;
252                            throw new RuntimeException( errMsg );
253                    }
254    
255    
256                    File org = fileData.getFile() ;
257                    String orgName = org.getPath();
258                    if( ! org.isFile() ) { return data; }
259    
260                    if( debug ) { println( "File:" + org ); }               // 5.1.2.0 (2010/01/01) display の条件変更
261    
262                    BufferedReader reader = FileUtil.getBufferedReader( org,inEncode );
263    //              File            tempFile  = new File( org.getPath() + "_temp" );
264    //              PrintWriter     tempWrt   = FileUtil.getPrintWriter( tempFile,outEncode );
265                    File            tempFile  = null;
266                    PrintWriter     tempWrt   = null;
267    
268                    // 5.1.2.0 (2010/01/01) 置換するå?合ã?前å?ç�?
269                    if( isChange ) {
270                            tempFile  = new File( orgName + "_temp" );
271                            tempWrt   = FileUtil.getPrintWriter( tempFile,outEncode );
272                    }
273    
274                    boolean nextFlag  = false;
275    
276                    try {
277                            String line ;
278                            int    lineNo = 0;
279                            while((line = reader.readLine()) != null) {
280                                    lineNo++ ;
281                                    // 5.7.3.2 (2014/02/28) regex 対å¿?
282                                    if( regex ) {
283                                            for( int i=0; i<pattern.length; i++ ) {
284                                                    Matcher mt = pattern[i].matcher( line );
285                                                    nextFlag = mt.matches();
286                                                    if( nextFlag ) {
287                                                            findCount++ ;
288                                                            if( display ) { println( orgName + ":" + lineNo + ":" + keyword[i] + ":" + line ); }
289                                                            if( isChange ) {
290                                                                    line = mt.replaceAll( change[i] );
291                                                                    cngCount++ ;
292                                                            }
293                                                    }
294                                            }
295                                    }
296                                    else {
297                                            StringBuilder buf = new StringBuilder( line );
298            //                              boolean foundFlag = false;              // 行単位に初期化するã?
299                                            for( int i=0; i<keyword.length; i++ ) {
300                                                    // 5.7.3.2 (2014/02/28) ignoreCase 対応ã?
301            //                                      int indx = buf.indexOf( keyword[i] );
302                                                    int indx = (ignoreCase) ? buf.toString().toUpperCase(Locale.JAPAN).indexOf( keyword[i] )
303                                                                                                    : buf.indexOf( keyword[i] ) ;
304    
305                                                    // 置換対象発見ã?行å?力用に見つかれば、true にするã€?
306                                                    if( indx >= 0 ) {
307            //                                              foundFlag = true;
308                                                            nextFlag  = true;               // ?‘度でも見つかれば、true にセãƒ?ƒˆ
309                                                            if( display ) { println( orgName + ":" + lineNo + ":" + keyword[i] + ":" + line ); }
310                                                            findCount++ ;
311                                                    }
312                                                    // 置換対象が見つかってもã?isChange=true でなければ、置換å?ç�??行わなã�??
313                                                    if( isChange ) {
314                                                            while( indx >= 0 ) {
315                                                                    buf.replace( indx,indx+keyword[i].length(),change[i] );
316                                                                    // 5.7.3.2 (2014/02/28) ignoreCase 対応ã?
317            //                                                      indx = buf.indexOf( keyword[i],indx+change[i].length() );
318                                                                    int nxt = indx+change[i].length();
319                                                                    indx = (ignoreCase) ? buf.toString().toUpperCase(Locale.JAPAN).indexOf( keyword[i],nxt )
320                                                                                                            : buf.indexOf( keyword[i],nxt );
321    
322                    //                                              nextFlag = true;                        // キーワードが存在したファイルã€?
323                                                                    cngCount++ ;
324    //                                                              findCount++ ;
325                                                            }
326                                                    }
327                                            }
328                                            line = buf.toString();
329                                    }
330                                    // 5.1.2.0 (2010/01/01) 置換するå?合ã?処ç�?
331                                    if( isChange ) {
332    //                                      tempWrt.println( buf.toString() );
333                                            tempWrt.println( line );                                // 5.7.3.2 (2014/02/28) regexで出力を共有する為ã€?
334                                    }
335                            }
336                    }
337                    catch ( IOException ex ) {
338                            String errMsg = "処ç�?¸­にエラーが発生しましたã€?" + data.getRowNo() + "]件目" + CR
339    //                                              + data.toString() ;
340                                                    +       "data=[" + data.dataLine() + "]" + CR ;         // 5.7.2.2 (2014/01/24) エラー時にãƒ??タもå?力しますã?
341                            throw new RuntimeException( errMsg,ex );
342                    }
343                    finally {
344                            Closer.ioClose( reader );
345                            Closer.ioClose( tempWrt );
346                    }
347    
348                    // 5.1.2.0 (2010/01/01) 置換するå?合ã?処ç�?
349                    if( isChange ) {
350                            if( nextFlag ) {
351                                    if( !org.delete() ) {
352                                            String errMsg = "æ‰?®šã?ファイルを削除できませんでしたã€?" + org + "]" + CR
353                                                            +       "data=[" + data.dataLine() + "]" + CR ;         // 5.7.2.2 (2014/01/24) エラー時にãƒ??タもå?力しますã?
354                                            throw new RuntimeException( errMsg );
355                                    }
356                                    if( !tempFile.renameTo( org ) ) {
357                                            String errMsg = "æ‰?®šã?ファイルをリネã?ãƒ?�§きませんでしたã€?" + tempFile + "]" + CR
358                                                            +       "data=[" + data.dataLine() + "]" + CR ;         // 5.7.2.2 (2014/01/24) エラー時にãƒ??タもå?力しますã?
359                                            throw new RuntimeException( errMsg );
360                                    }
361                            }
362                            else {
363                                    if( !tempFile.delete() ) {
364                                            String errMsg = "æ‰?®šã?ファイルを削除できませんでしたã€?" + tempFile + "]" + CR
365                                                            +       "data=[" + data.dataLine() + "]" + CR ;         // 5.7.2.2 (2014/01/24) エラー時にãƒ??タもå?力しますã?
366                                            throw new RuntimeException( errMsg );
367                                    }
368                            }
369                    }
370    
371                    return (nextFlag) ? data : null ;
372            }
373    
374            /**
375             * プロセスの処ç�?µ�果のレポã?ト表現を返しますã?
376             * 処ç�??ログラãƒ?��、å?力件数、å?力件数などのæƒ??ですã?
377             * こã?æ–?­—å?をそのまま、標準å?力に出すことで、結果レポã?トと出来るよã�?�ª
378             * 形式で出してくださいã€?
379             *
380             * @return   処ç�?µ�果のレポã?ãƒ?
381             */
382            public String report() {
383                    String report = "[" + getClass().getName() + "]" + CR
384                                    + TAB + "Search File Count : " + inCount    + CR
385                                    + TAB + "Key Find    Count : " + findCount  + CR
386                                    + TAB + "Key Change  Count : " + cngCount ;
387    
388                    return report ;
389            }
390    
391            /**
392             * こã?クラスの使用方法を返しますã?
393             *
394             * @return      こã?クラスの使用方æ³?
395             */
396            public String usage() {
397                    StringBuilder buf = new StringBuilder();
398    
399                    buf.append( "Process_GrepChange は、上流から受け取っã�?FileLineModelから、語句ã‚?                      ).append( CR );
400                    buf.append( "置換するã?ChainProcess インターフェースの実è£?‚¯ラスですã?"                                              ).append( CR );
401                    buf.append( "Process_Grep との違いは、チェãƒ?‚¯するファイルのコピã?ã‚?キーワードが存在"           ).append( CR );
402                    buf.append( "しなくとã‚?作æ?することと、検索キーに正規表現が使えなã�??è¤?•°行置き換えが"            ).append( CR );
403                    buf.append( "出来なã�?�“とですã?"                                                                                                                  ).append( CR );
404                    buf.append( CR );
405                    buf.append( "keywordFile より、置換する語句を含ã‚?‚­ーと値のペアー(タブ区åˆ?‚Š)を読取りã€?  ).append( CR );
406                    buf.append( "対象とする語句を置換しますã?"                                                                                                  ).append( CR );
407                    buf.append( "keywordFile に、タブが含まれなã�?¡Œや、å?頭にタブが存在してã�?‚‹場合ã?ã€?               ).append( CR );
408                    buf.append( "そã?行を読み飛ã?しますã?またã?区åˆ?‚Šタブã?何å?存在しても構いませんã€?                    ).append( CR );
409                    buf.append( "ただしã?タブで区åˆ?�£た前(キー)と後ろ(値)は、trim() されますã?で、スペã?ス"            ).append( CR );
410                    buf.append( "が前後に存在してã�?‚‹場合ã?、ご注意くã�?�•ã�??"                                                                        ).append( CR );
411                    buf.append( "置換文å­?値)は、\t と \n の特殊文字が使用できますã?"                                                      ).append( CR );
412                    buf.append( "こã? GrepChange では、語句に、正規表現は使用できません。正規表現のキーワーãƒ?   ).append( CR );
413                    buf.append( "ã‚?–‡字å?をè¤?•°行ã?æ–?­—å?と置き換える場合ã?、Process_Grep を使用して下さã�??"   ).append( CR );
414                    buf.append( "こã?プログラãƒ?�§は、上流から受け取っã�?FileLineModel のファイルに対してã€?           ).append( CR );
415                    buf.append( "置き換えた結果もã?同じファイルにセーブしますã?"                                                            ).append( CR );
416                    buf.append( "å…??ファイルを保存したい場合ã?、予めバックアãƒ??を取得しておいてくださいã€?      ).append( CR );
417                    buf.append( "-inEncode は、å?力ファイルのエンコード指定になりますã?"                                          ).append( CR );
418                    buf.append( "-outEncode は、å?力ファイルのエンコードや、キーワードファイルのエンコーãƒ?       ).append( CR );
419                    buf.append( "æŒ?®šになりますã?(keywordFile は、å¿?�š 出力ファイルと同じエンコードですã?)"         ).append( CR );
420                    buf.append( "これらã?エンコードが無æŒ?®šã?場合ã?、System.getProperty(\"file.encoding\") "      ).append( CR );
421                    buf.append( "で求まるå?を使用しますã?"                                                                                                              ).append( CR );
422                    buf.append( CR );
423                    buf.append( "上流ã?ロセスでは、Name 属æ?として、ã?File』を持ち、å?は、Fileオブジェクãƒ?            ).append( CR );
424                    buf.append( "である、Process_FileSearch を使用するのがã?便利ですã?それ以外ã?クラスã‚?           ).append( CR );
425                    buf.append( "使用する場合でもã?Name属æ?と、File オブジェクトを持つ LineModel を受け渡ã�?  ).append( CR );
426                    buf.append( "できれば、使用可能ですã?"                                                                                                            ).append( CR );
427                    buf.append( CR );
428                    buf.append( "引数æ–?­—å?中に空白を含ã‚??合ã?、ダブルコーãƒ??ション(\"\") で括って下さã�??" ).append( CR );
429                    buf.append( "引数æ–?­—å?の ã€?』ã?前後には、空白は挟めません。å¿?�šã€?key=value の様に"             ).append( CR );
430                    buf.append( "繋げてくださいã€?                                                                                                                              ).append( CR );
431                    buf.append( CR ).append( CR );
432    
433                    buf.append( getArgument().usage() ).append( CR );
434    
435                    return buf.toString();
436            }
437    
438            /**
439             * こã?クラスは、main メソãƒ?ƒ‰から実行できませんã€?
440             *
441             * @param       args    コマンド引数配å?
442             */
443            public static void main( final String[] args ) {
444                    LogWriter.log( new Process_GrepChange().usage() );
445            }
446    }