1 18 19 package org.apache.tools.ant.types.mappers; 20 21 import java.io.StringReader ; 22 import java.io.Reader ; 23 24 import java.util.Vector ; 25 26 import org.apache.tools.ant.BuildException; 27 import org.apache.tools.ant.UnsupportedAttributeException; 28 import org.apache.tools.ant.filters.util.ChainReaderHelper; 29 import org.apache.tools.ant.types.FilterChain; 30 import org.apache.tools.ant.util.FileNameMapper; 31 import org.apache.tools.ant.util.FileUtils; 32 33 36 public class FilterMapper extends FilterChain implements FileNameMapper { 37 42 public void setFrom(String from) { 43 throw new UnsupportedAttributeException( 44 "filtermapper doesn't support the \"from\" attribute.", "from"); 45 } 46 47 52 public void setTo(String to) { 53 throw new UnsupportedAttributeException( 54 "filtermapper doesn't support the \"to\" attribute.", "to"); 55 } 56 57 63 public String [] mapFileName(String sourceFileName) { 64 try { 65 Reader stringReader = new StringReader (sourceFileName); 66 ChainReaderHelper helper = new ChainReaderHelper(); 67 helper.setBufferSize(8192); 68 helper.setPrimaryReader(stringReader); 69 helper.setProject(getProject()); 70 Vector filterChains = new Vector (); 71 filterChains.add(this); 72 helper.setFilterChains(filterChains); 73 String result = FileUtils.readFully(helper.getAssembledReader()); 74 if (result.length() == 0) { 75 return null; 76 } else { 77 return new String [] {result}; 78 } 79 } catch (BuildException ex) { 80 throw ex; 81 } catch (Exception ex) { 82 throw new BuildException(ex); 83 } 84 } 85 } 86 | Popular Tags |