KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > derbyTesting > functionTests > harness > Sed


1 /*
2
3    Derby - Class org.apache.derbyTesting.functionTests.harness.Sed
4
5    Licensed to the Apache Software Foundation (ASF) under one or more
6    contributor license agreements. See the NOTICE file distributed with
7    this work for additional information regarding copyright ownership.
8    The ASF licenses this file to You under the Apache License, Version 2.0
9    (the "License"); you may not use this file except in compliance with
10    the License. You may obtain a copy of the License at
11
12       http://www.apache.org/licenses/LICENSE-2.0
13
14    Unless required by applicable law or agreed to in writing, software
15    distributed under the License is distributed on an "AS IS" BASIS,
16    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17    See the License for the specific language governing permissions and
18    limitations under the License.
19
20  */

21
22 package org.apache.derbyTesting.functionTests.harness;
23
24 /***
25  * Sed.java
26  *
27  * This is a version of "sed" in Java for the Derby Function Tests,
28  * written using the OROMatcher Perl5 regular expression classes.
29  * The substitutions/deletions are based on the original kornshell tests.
30  *
31  ***/

32
33 import java.io.*;
34 import java.util.Vector JavaDoc;
35 import org.apache.oro.text.regex.*;
36 import java.util.Enumeration JavaDoc;
37 import java.util.Properties JavaDoc;
38 import java.util.StringTokenizer JavaDoc;
39 import org.apache.derbyTesting.functionTests.util.TestUtil;
40
41 public class Sed
42 {
43     private static final String JavaDoc SQL_EXCEPTION_FILTERED_SUBSTITUTION =
44         "java.sql.SQLException:";
45
46     public Sed()
47     {
48     }
49
50     public static void main(String JavaDoc[] args) throws Exception JavaDoc {
51         if (args == null || args.length != 2) {
52             System.err.println("Usage: Sed sourcefile targetfile");
53             System.exit(1);
54         }
55         File src = new File(args[0]);
56         File tgt = new File(args[1]);
57         new Sed().exec(src,tgt,null, false, false,false);
58     }
59
60     // The arguments should be the names of the input and output files
61
public void exec
62         (File srcFile, File dstFile, InputStream isSed, boolean isJCC, boolean isI18N, boolean isJDBC4)
63         throws IOException
64     {
65         String JavaDoc hostName = TestUtil.getHostName();
66         
67         // Vector for storing lines to be deleted
68
Vector JavaDoc deleteLines = new Vector JavaDoc();
69         deleteLines.addElement("^ij version.*$");
70         deleteLines.addElement("^\\*\\*\\*\\* Test Run Started .* \\*\\*\\*\\*$");
71         deleteLines.addElement("^\\*\\*\\*\\* Test Run Completed .* \\*\\*\\*\\*$");
72         deleteLines.addElement("^ELAPSED TIME = [0-9]* milliseconds$");
73         deleteLines.addElement("^\\^\\?$");
74         //deleteLines.addElement("^\\.$"); // originally to remove lines with a dot
75
deleteLines.addElement("^S.*ij> $");
76         deleteLines.addElement("^ *$");
77         deleteLines.addElement("^Server StackTrace:$");
78         deleteLines.addElement("^\\[ *$");
79         deleteLines.addElement("^\\] *$");
80         deleteLines.addElement("^\\[$");
81         deleteLines.addElement("^\\]$");
82         deleteLines.addElement("^<not available>\\]$");
83         deleteLines.addElement("^(.*at .*)\\(.*:[0-9].*\\)$");
84         deleteLines.addElement("^(.*at .*)\\(*.java\\)$");
85         deleteLines.addElement("^(.*at .*)\\(Compiled Code\\)$");
86         deleteLines.addElement("^(.*at .*)\\(Interpreted Code\\)$");
87         deleteLines.addElement("^(.*at .*)\\(Unknown Source\\)$");
88         deleteLines.addElement("^(.*at .*)\\(Native Method\\)$");
89         deleteLines.addElement("^\\tat $"); // rare case of incomplete stack trace line
90
deleteLines.addElement("optimizer estimated cost");
91         deleteLines.addElement("optimizer estimated row count");
92         deleteLines.addElement("Using executables built for native_threads");
93         deleteLines.addElement("Estimate of memory used");
94         deleteLines.addElement("Size of merge runs");
95         deleteLines.addElement("Number of merge runs");
96         deleteLines.addElement("Sort type");
97         deleteLines.addElement("Optimization started at .*$");
98         deleteLines.addElement("WARNING 02000: No row was found for FETCH, UPDATE or DELETE");
99         // deleteLines for stack traces from j9 jvm to match those above for other jvms
100
deleteLines.addElement("Stack trace:");
101         deleteLines.addElement("^.*java/.*\\<init\\>\\(.*\\)V");
102         deleteLines.addElement("^.*org/apache/derby/.*\\(.*\\).*$");
103         // next for j9 stack trace with jarfiles test run.
104
deleteLines.addElement("^.*java/.*\\(.*\\).*$");
105         deleteLines.addElement("^\\[.*db2jcc.jar\\] [0-9].[1-9] - .*$");
106         deleteLines.addElement("^\\[.*db2jcc_license_c.jar\\] [1-9].[0-9] - .*$");
107         deleteLines.addElement("^XSDB.*$");
108
109         // JUnit noise
110
deleteLines.addElement("^\\.*$");
111         deleteLines.addElement("^Time: [0-9].*$");
112         deleteLines.addElement("^OK \\(.*$");
113
114         // Vectors for substitutions
115
Vector JavaDoc searchStrings = new Vector JavaDoc();
116         searchStrings.addElement("^Transaction:\\(.*\\) *\\|");
117         searchStrings.addElement("^Read [0-9]* of [0-9]* bytes$");
118         searchStrings.addElement("Directory .*connect.wombat.seg0");
119         // Filter for constraint names - bug 5622 - our internal constraint names are too long. To be db2 compatible, we have reworked them.
120
StringBuffer JavaDoc constraintNameFilter = new StringBuffer JavaDoc();
121         constraintNameFilter.append("SQL[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]");
122         searchStrings.addElement(constraintNameFilter.toString());
123         // Filter for uuids
124
StringBuffer JavaDoc uuidFilter = new StringBuffer JavaDoc();
125         uuidFilter.append("[0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f]-");
126         uuidFilter.append("[0-9a-f][0-9a-f][0-9a-f][0-9a-f]-");
127         uuidFilter.append("[0-9a-f][0-9a-f][0-9a-f][0-9a-f]-");
128         uuidFilter.append("[0-9a-f][0-9a-f][0-9a-f][0-9a-f]-");
129         uuidFilter.append("[0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f]");
130         searchStrings.addElement(uuidFilter.toString());
131         // Filter for timestamps
132
StringBuffer JavaDoc timestampFilter = new StringBuffer JavaDoc();
133         timestampFilter.append( "[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9] " );
134         timestampFilter.append( "[0-9][0-9]:[0-9][0-9]:[0-9][0-9].[0-9]* *" );
135         searchStrings.addElement( timestampFilter.toString() );
136         // 3 digit year
137
timestampFilter = new StringBuffer JavaDoc();
138         timestampFilter.append( "[0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9] " );
139         timestampFilter.append( "[0-9][0-9]:[0-9][0-9]:[0-9][0-9].[0-9]* *" );
140         searchStrings.addElement( timestampFilter.toString() );
141         // ibm13 year
142
timestampFilter = new StringBuffer JavaDoc();
143         timestampFilter.append( "[0-9]-[0-9][0-9]-[0-9][0-9] " );
144         timestampFilter.append( "[0-9][0-9]:[0-9][0-9]:[0-9][0-9].[0-9]* *" );
145         searchStrings.addElement( timestampFilter.toString() );
146         // Filter remove transaction id's from deadlock messages
147
searchStrings.addElement("^ Waiting XID : {.*}");
148         searchStrings.addElement("^ Granted XID : .*$");
149         searchStrings.addElement("^The selected victim is XID : .*");
150         // Filters for build numbers
151
searchStrings.addElement("(beta - )\\(([0-9]*)\\)");
152         searchStrings.addElement("Level2CostEstimateImpl: .*");
153         // Filter for xa tests for the numbers representing the db name (it can change)
154
searchStrings.addElement("^Transaction ([0-9])* : \\(([0-9]*)\\,([0-9a-f]*)\\,([0-9a-f]*)\\)");
155         // Filter for optimizer number for zindexesLevel1 test (due to a change in display width for the test)
156
searchStrings.addElement("^Modifying access paths using optimizer .[0-9]*");
157         searchStrings.addElement("CDWS[0-9]*");
158         searchStrings.addElement("IXWS[0-9]*");
159         // for j9, to eliminate intermittent failures due to this problem in j9:
160
searchStrings.addElement("FAILED STACK MAP");
161         if (isJCC)
162         {
163             searchStrings.addElement("[ ]*\\|");
164             searchStrings.addElement("^--*");
165         }
166
167         //Filter to suppress absould paths in error message for roll forward recovery tests
168
searchStrings.addElement("Directory.*.wombat.already.exists");
169         searchStrings.addElement("Directory.*.extinout/crwombatlog/log.*.exists");
170
171         // Filter for "DB2ConnectionCorrelator" text that can be printed as
172
// part of some JCC error messages.
173
searchStrings.addElement(" DB2ConnectionCorrelator: [0-9A-Z.]*");
174         // Filter for SAX exception name diffs between jvms.
175
searchStrings.addElement("org.xml.sax.SAX.*$");
176         // Filter out localhost, or hostName
177
searchStrings.addElement(hostName);
178
179         if ( isJDBC4 )
180         {
181             // Filters for the sql exception class names which appear in
182
// exception messages. These are different in JDBC3 and JDBC4.
183
searchStrings.addElement("java.sql.SQLDataException:");
184             searchStrings.addElement("java.sql.SQLDataSetSyncException:");
185             searchStrings.addElement("java.sql.SQLException:");
186             searchStrings.addElement("java.sql.SQLFeatureNotSupportedException:");
187             searchStrings.addElement("java.sql.SQLIntegrityConstraintViolationException:");
188             searchStrings.addElement("java.sql.SQLInvalidAuthorizationSpecException:");
189             searchStrings.addElement("java.sql.SQLNonTransientConnectionException:");
190             searchStrings.addElement("java.sql.SQLNonTransientException:");
191             searchStrings.addElement("java.sql.SQLRuntimeException:");
192             searchStrings.addElement("java.sql.SQLSyntaxErrorException:");
193             searchStrings.addElement("java.sql.SQLTimeoutException:");
194             searchStrings.addElement("java.sql.SQLTransactionRollbackException:");
195             searchStrings.addElement("java.sql.SQLTransientConnectionException:");
196             searchStrings.addElement("java.sql.SQLTransientException:");
197
198             // The JDBC4 error from the driver is a little chattier
199
searchStrings.addElement("No suitable driver found for [0-9A-Za-z:]*");
200             searchStrings.addElement("No suitable driver;[0-9A-Za-z:=]*");
201             searchStrings.addElement("SQL Exception: No suitable driver");
202
203             // Timestamp diagnostic looks a little different under jdk16
204
searchStrings.addElement("\\[\\.fffffffff\\]");
205         }
206         
207         Vector JavaDoc subStrings = new Vector JavaDoc();
208         subStrings.addElement("Transaction:(XXX)|");
209         subStrings.addElement("Read ... bytes");
210         subStrings.addElement("Directory DBLOCATION/seg0");
211         subStrings.addElement("xxxxGENERATED-IDxxxx");
212         subStrings.addElement("xxxxFILTERED-UUIDxxxx");
213         subStrings.addElement("xxxxxxFILTERED-TIMESTAMPxxxxx");
214         subStrings.addElement("xxxxxxFILTERED-TIMESTAMPxxxxx");
215         subStrings.addElement("xxxxxxFILTERED-TIMESTAMPxxxxx");
216         // remove transaction id's from deadlock messages
217
subStrings.addElement(" Waiting XID : {WWW,QQQ}");
218         subStrings.addElement(" Granted XID : {GGG.QQQ}...");
219         subStrings.addElement("The selected victim is XID : VVV");
220         // sub build numbers
221
subStrings.addElement("$1(xxXXxxFILTERED-BUILD-NUMBERxxXXxx)");
222         subStrings.addElement("Level2CostEstimateImpl: xxXXxxFILTERED-INFORMATIONxxXXxx");
223         // sub for db name in xa tests (it can change)
224
subStrings.addElement("Transaction $1 : ($2,FILTERED,FILTERED)");
225         // sub for optimizer number for zindexesLevel1 test
226
subStrings.addElement("Modifying access paths using optimizer FILTERED_NUMBER");
227         subStrings.addElement("CDWSno");
228         subStrings.addElement("IXWSno");
229         // for j9, to eliminate intermittent failures due to this problem in j9:
230
subStrings.addElement("");
231         // for JCC replace multiple blanks with one blank to handle differences
232
// in display width
233
if (isJCC)
234         {
235             subStrings.addElement(" |");
236             subStrings.addElement("-----");
237         }
238         subStrings.addElement("Directory DBLOCATION/wombat already exists");
239         subStrings.addElement("Directory 'extinout<sp>crwombatlog<sp>log' exists");
240         // ignore the 'DB2ConnectionCorrelator' thing altogether.
241
subStrings.addElement("");
242         // Filter for SAX exception name diffs between jvms.
243
subStrings.addElement("xxxFILTERED-SAX-EXCEPTIONxxx'.");
244         // Filter out localhost, or hostName
245
subStrings.addElement("xxxFILTERED_HOSTNAMExxx");
246
247         if ( isJDBC4 )
248         {
249             subStrings.addElement(SQL_EXCEPTION_FILTERED_SUBSTITUTION);
250             subStrings.addElement(SQL_EXCEPTION_FILTERED_SUBSTITUTION);
251             subStrings.addElement(SQL_EXCEPTION_FILTERED_SUBSTITUTION);
252             subStrings.addElement(SQL_EXCEPTION_FILTERED_SUBSTITUTION);
253             subStrings.addElement(SQL_EXCEPTION_FILTERED_SUBSTITUTION);
254             subStrings.addElement(SQL_EXCEPTION_FILTERED_SUBSTITUTION);
255             subStrings.addElement(SQL_EXCEPTION_FILTERED_SUBSTITUTION);
256             subStrings.addElement(SQL_EXCEPTION_FILTERED_SUBSTITUTION);
257             subStrings.addElement(SQL_EXCEPTION_FILTERED_SUBSTITUTION);
258             subStrings.addElement(SQL_EXCEPTION_FILTERED_SUBSTITUTION);
259             subStrings.addElement(SQL_EXCEPTION_FILTERED_SUBSTITUTION);
260             subStrings.addElement(SQL_EXCEPTION_FILTERED_SUBSTITUTION);
261             subStrings.addElement(SQL_EXCEPTION_FILTERED_SUBSTITUTION);
262             subStrings.addElement(SQL_EXCEPTION_FILTERED_SUBSTITUTION);
263
264             subStrings.addElement("No suitable driver");
265             subStrings.addElement("No suitable driver");
266             subStrings.addElement("java.sql.SQLException: No suitable driver");
267
268             subStrings.addElement(".fffffffff");
269         }
270
271         doWork(srcFile, dstFile, null, deleteLines, searchStrings, subStrings, isSed, isI18N);
272         
273     } // end exec
274

275     // This just does JCC changes on the output master file
276
public void execJCC(InputStream is, File dstFile)
277         throws IOException
278     {
279         // Vector for storing lines to be deleted
280
Vector JavaDoc deleteLines = new Vector JavaDoc();
281
282         // Vectors for substitutions
283
Vector JavaDoc searchStrings = new Vector JavaDoc();
284         searchStrings.addElement("[ ]*\\|");
285         searchStrings.addElement("^--*");
286
287         Vector JavaDoc subStrings = new Vector JavaDoc();
288         // true and false show up as 1 and 0 in JCC.
289
//because they have no boolean support
290
subStrings.addElement(" |");
291         subStrings.addElement("-----");
292
293         doWork(null, dstFile, is, deleteLines, searchStrings, subStrings, null);
294
295     }
296
297     private void doWork(File srcFile, File dstFile, InputStream is, Vector JavaDoc deleteLines,
298         Vector JavaDoc searchStrings, Vector JavaDoc subStrings, InputStream isSed)
299         throws IOException
300     {
301         doWork(srcFile, dstFile, is, deleteLines, searchStrings, subStrings, isSed, false);
302     }
303         
304
305     private void doWork(File srcFile, File dstFile, InputStream is, Vector JavaDoc deleteLines,
306         Vector JavaDoc searchStrings, Vector JavaDoc subStrings, InputStream isSed, boolean isI18N)
307         throws IOException
308     {
309         
310         boolean lineDeleted = false;
311         PatternMatcher matcher;
312         Perl5Compiler pcompiler;
313         PatternMatcherInput input;
314         BufferedReader inFile;
315         PrintWriter outFile;
316         String JavaDoc result = "";
317         String JavaDoc regex;
318         Vector JavaDoc delPatternVector = new Vector JavaDoc();
319         Vector JavaDoc subPatternVector = new Vector JavaDoc();
320
321         // ---------------------------------
322
// Try loading the sed properties if they exist (see jdbc_sed.properties as an example)
323
if ( isSed != null )
324         {
325             Properties JavaDoc sedp = new Properties JavaDoc();
326
327             sedp.load(isSed);
328             for (Enumeration JavaDoc e = sedp.propertyNames(); e.hasMoreElements(); )
329             {
330                 String JavaDoc key = (String JavaDoc)e.nextElement();
331                 if (key.equals("substitute"))
332                 {
333                     String JavaDoc value = sedp.getProperty(key);
334                     // value string contains a comma separated list of patterns
335
StringTokenizer JavaDoc st = new StringTokenizer JavaDoc(value,",");
336                     String JavaDoc patternName = "";
337                     String JavaDoc patName = "";
338                     String JavaDoc subName = "";
339                     while (st.hasMoreTokens())
340                     {
341                         patternName = st.nextToken();
342                         // pattern;substitute
343
StringTokenizer JavaDoc st2 = new StringTokenizer JavaDoc(patternName,";");
344                         patName = st2.nextToken();
345                         subName = st2.nextToken();
346                         if (!patName.equals("") && !subName.equals(""))
347                         {
348                             searchStrings.addElement(patName);
349                             subStrings.addElement(subName);
350                         }
351                     //System.out.println("pattern = " + patName + " substitute " + subName);
352
}
353                 }
354                 else if (key.equals("delete"))
355                 {
356                     String JavaDoc value = sedp.getProperty(key);
357                     // value string contains a comma separated list of patterns
358
StringTokenizer JavaDoc st = new StringTokenizer JavaDoc(value,",");
359                     String JavaDoc patternName = "";
360                     while (st.hasMoreTokens())
361                     {
362                         patternName = st.nextToken();
363                         deleteLines.addElement(patternName);
364                     }
365                 }
366             }
367         }
368         // ---------------------------------
369

370         //Create Perl5Compiler and Perl5Matcher
371
pcompiler = new Perl5Compiler();
372         matcher = new Perl5Matcher();
373
374         // Define the input and output files based on args
375
if (is == null && isI18N) {
376             // read UTF-8 encoded file
377
InputStream fs = new FileInputStream(srcFile);
378             inFile = new BufferedReader(new InputStreamReader(fs, "UTF-8"));
379         } else if (is == null) {
380             // read the file using the default encoding
381
inFile = new BufferedReader(new FileReader(srcFile));
382         } else {
383             inFile = new BufferedReader(new InputStreamReader(is, "UTF-8"));
384         }
385         outFile = new PrintWriter
386         ( new BufferedWriter(new FileWriter(dstFile), 10000), true );
387
388         // Attempt to compile the patterns for deletes
389
for (int i = 0; i < deleteLines.size(); i++)
390         {
391             try
392             {
393                 regex = (String JavaDoc)deleteLines.elementAt(i);
394                 //System.out.println("The pattern: " + regex);
395
Pattern pattern = pcompiler.compile(regex);
396                 if (pattern == null)
397                     System.out.println("pattern is null");
398                 delPatternVector.addElement(pattern);
399             }
400             catch(MalformedPatternException e)
401             {
402                 System.out.println("Bad pattern.");
403                 System.out.println(e.getMessage());
404             }
405         }
406
407         // Attempt to compile the patterns for substitutes
408
for (int i = 0; i < searchStrings.size(); i++)
409         {
410             try
411             {
412                 regex = (String JavaDoc)searchStrings.elementAt(i);
413                 //System.out.println("The pattern: " + regex);
414
Pattern pattern = pcompiler.compile(regex);
415                 if (pattern == null)
416                     System.out.println("pattern is null");
417                 subPatternVector.addElement(pattern);
418             }
419             catch(MalformedPatternException e)
420             {
421                 System.out.println("Bad pattern.");
422                 System.out.println(e.getMessage());
423             }
424         }
425
426         String JavaDoc str;
427         int j;
428         int lineCount = 0;
429         // Read the input file
430
while ( (str = inFile.readLine()) != null )
431         {
432             lineCount++;
433         
434             //System.out.println("***Line no: " + lineCount);
435
//System.out.println("***Line is: " + str);
436
lineDeleted = false;
437
438             // First delete any nulls (Cafe 1.8 leaves nulls)
439
if (str.length() == 1)
440             {
441                 if (str.charAt(0) == (char) 0)
442                 {
443                     // Skip this line, don't write it
444
//System.out.println("Skip this line...");
445
lineDeleted = true;
446                 }
447             }
448
449             // Now determine if & if so, replace, any non-ascii characters
450
// We do this because non-ascii characters in .sql files will
451
// result in different characters depending on encoding, and
452
// encoding may be different on different os's
453
if (isI18N)
454             {
455                 boolean hasNonAscii = false;
456                 // check for any characters in the control range
457
for (int si = 0; si < str.length(); si++)
458                 {
459                     char c = str.charAt(si);
460                     if (c < (char) 0x20 || c >= (char) 0x7f)
461                     {
462                         hasNonAscii = true;
463                         break;
464                     }
465                 }
466
467                 if (hasNonAscii)
468                 {
469                     StringBuffer JavaDoc sb = new StringBuffer JavaDoc();
470                     for (int si = 0; si < str.length(); si++)
471                     {
472                         char c = str.charAt(si);
473                         if (c < (char) 0x20 || c >= (char) 0x7f)
474                         {
475                             sb.append(' ');
476                             // Encoded Character:> ... <
477
sb.append("EnC:>");
478                             sb.append((int) str.charAt(si));
479                             sb.append("< ");
480                         }
481                         else
482                             sb.append(c);
483                     }
484                     str = sb.toString();
485                 }
486             }
487
488             // Determine if this line should be deleted for delete pattern match
489
if ( lineDeleted == false )
490             {
491                 for (j = 0; j < delPatternVector.size(); j++)
492                 {
493                     if ( matcher.contains( str, (Pattern)delPatternVector.elementAt(j) ) )
494                     {
495                         //System.out.println("***Match found to delete line***");
496
String JavaDoc tmpp = ((Pattern)delPatternVector.elementAt(j)).getPattern();
497                         //System.out.println("***Pattern is: " + tmpp);
498

499                         // In this case we are removing the line, so don't write it out
500
lineDeleted = true;
501                         break;
502                     }
503                 }
504             }
505
506             // Determine if any substitutions are needed
507
if (lineDeleted == false)
508             {
509                 Substitution substitution;
510                 StringSubstitution strsub = new StringSubstitution("");
511                 Perl5Substitution perlsub = new Perl5Substitution("");
512                 boolean subDone = false;
513                 for (j = 0; j < subPatternVector.size(); j++)
514                 {
515                     input = new PatternMatcherInput(str);
516                     Pattern patt = (Pattern)subPatternVector.elementAt(j);
517                     String JavaDoc pstr = patt.getPattern();
518                     //System.out.println("Pattern string is " + pstr);
519
String JavaDoc sub = (String JavaDoc)subStrings.elementAt(j);
520                     if (sub.indexOf("$") > 0)
521                     {
522                         perlsub.setSubstitution(sub);
523                         substitution = (Substitution)perlsub;
524                     } else {
525                         strsub.setSubstitution(sub);
526                         substitution = (Substitution)strsub;
527                     }
528                     //System.out.println("Substitute str = " + sub);
529
if ( matcher.contains( input, patt ) )
530                     {
531                         MatchResult mr = matcher.getMatch();
532                         //System.out.println("***Match found for substitute***");
533
// In this case we do a substitute
534
result = Util.substitute(matcher, patt, substitution, str,
535                         Util.SUBSTITUTE_ALL);
536                         //System.out.println("New string: " + result);
537
//outFile.println(result);
538
str = result;
539                         subDone = true;
540                     }
541                 }
542                 if (subDone)
543                 {
544                     //System.out.println("write the subbed line");
545
outFile.println(result);
546                 }
547                 else
548                 {
549                     //System.out.println("Write the str: " + str);
550
outFile.println(str);
551                     outFile.flush();
552                 }
553             }// end if
554
} // end while
555
inFile.close();
556         outFile.flush();
557         outFile.close();
558     }// end doWork
559
}
560
Popular Tags