Changeset 17553

Show
Ignore:
Timestamp:
17.10.2008 14:24:07 (11 years ago)
Author:
oranfry
Message:

changes to make rsr properly handle UTF-8

Location:
other-projects/trunk/anttasks
Files:
2 added
2 modified

Legend:

Unmodified
Added
Removed
  • other-projects/trunk/anttasks/build.xml

    r17350 r17553  
    4949    <target name="test-rsr" depends="test-setup"> 
    5050 
    51         <echo file="test/rsr1.txt">This is a test of the rsr task 
    52 To see if it can replace things with other things 
    53 Or if those things 
    54 Stay the same things 
    55  
    56 Or not 
    57  
    58 Replace with a path 
    59 @path@ 
    60  
    61 Replace with a path, with winPath on 
    62 @path-with-winpath@ 
    63  
    64  
    65 </echo> 
    66         <copy file="test/rsr1.txt" tofile="test/rsr2.txt"/> 
    67         <copy file="test/rsr1.txt" tofile="test/rsr3.txt"/> 
    68         <copy file="test/rsr1.txt" tofile="test/rsr4.txt"/> 
     51        <copy file="src/test/rsr.txt" tofile="test/rsr1.txt"/> 
     52        <copy file="src/test/rsr.txt" tofile="test/rsr2.txt"/> 
     53        <copy file="src/test/rsr.txt" tofile="test/rsr3.txt"/> 
     54        <copy file="src/test/rsr.txt" tofile="test/rsr4.txt"/> 
    6955 
    7056        <rsr file="test/rsr1.txt" pattern="things" replacement="strings"/> 
  • other-projects/trunk/anttasks/src/org/greenstone/anttasks/RegexSearchReplace.java

    r17349 r17553  
    5353        } 
    5454 
     55        if ( !file.exists() ) { 
     56            throw new BuildException( "Error - File not found !!" ); 
     57        } 
     58 
    5559        if ( jobs == null && pattern == null ) { 
    5660            throw new BuildException( "Error - No pattern attribute and no nested jobs !!" ); 
     
    98102 
    99103            //writer to temp file 
    100             out = new BufferedWriter(new FileWriter(temp)); 
     104            out = new BufferedWriter( new OutputStreamWriter(new FileOutputStream(temp), "UTF8") ); 
    101105 
    102106        } catch (IOException e) { 
     
    108112        BufferedReader in = null; 
    109113        try { 
    110             in = new BufferedReader( new FileReader( file ) ); 
     114            in = new BufferedReader( new InputStreamReader(new FileInputStream(file), "UTF8") ); 
    111115        } catch ( Exception e ) { 
    112116            throw new BuildException( "Error - Couldn't open the specified file" ); 
     
    114118 
    115119        //pass the file through, searching and replacing 
    116         String line; 
     120        String line = null; 
    117121        boolean hasMoreLines = true; 
    118122        while ( hasMoreLines ) { 
     
    121125                line = in.readLine(); 
    122126            } catch ( Exception e ) { 
     127                System.err.println( e.getMessage() ); 
    123128                throw new BuildException( "Error - Couldn't read from the specified file" ); 
    124129            } 
     
    150155 
    151156                try { 
    152                     out.write(line); 
     157                    out.write( line ); 
    153158                    out.newLine(); 
    154159                } catch ( Exception e ) { 
     
    157162            } 
    158163        } 
    159              
    160  
     164         
    161165        try { 
    162166            //close them both up