1 18 package org.webdocwf.util.loader.transformation; 19 20 import java.io.File ; 21 import java.io.FileInputStream ; 22 import java.io.FileNotFoundException ; 23 import java.io.IOException ; 24 import java.util.List ; 25 import java.util.Properties ; 26 import java.util.Vector ; 27 28 37 public class ReplaceData implements Transformer { 38 39 private String filePath = ""; 40 private List retValue = new Vector (); 41 private String valueToReplace = ""; 42 private String valueReplaceWith = ""; 43 private String replaceAll = ""; 44 private String newPropValue = ""; 45 private Properties properties = new Properties (); 46 52 public void configure(String filePath) throws Exception { 53 try { 54 55 this.filePath = filePath; 56 File propertyFile = new File (this.filePath); 57 this.properties.load(new FileInputStream (propertyFile)); 58 this.replaceAll = this.properties.getProperty("replaceAll"); 59 this.newPropValue = this.properties.getProperty("newPropValue"); 60 61 } catch (FileNotFoundException e) { 62 throw new Exception ("File not found!"); 63 } catch (IOException e) { 64 throw new Exception ("Error while reading property file!"); 65 } 66 } 67 68 71 public void release() throws Exception { 72 73 } 74 75 80 public List transformValue(List valueToTransform) throws Exception { 81 retValue.clear(); 82 String oldValue = valueToTransform.get(0).toString(); 83 String key = ""; 84 try { 85 if (this.replaceAll.equalsIgnoreCase("true")){ 86 retValue.add(this.newPropValue); 87 }else{ 88 boolean containsKey = this.properties.containsKey(oldValue); 89 if (containsKey == true) { 90 String newValue = this.properties.getProperty(oldValue); 91 retValue.add(newValue); 92 } else { 93 retValue.add(oldValue); 94 } 95 } 96 } catch (Exception e) { 97 throw new Exception ("Error while replacing data using class ReplaceData!",e); 98 } 99 100 return retValue; 101 } 102 } | Popular Tags |