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 36 public class ConcatenateData implements Transformer { 37 private String filePath = ""; 38 private List retValue = new Vector (); 39 private String prefix = ""; 40 private String postfix = ""; 41 private String insertBlank = ""; 42 private Properties properties = new Properties (); 43 49 public void configure(String filePath) throws Exception { 50 try { 51 52 this.filePath = filePath; 53 File propertyFile = new File (this.filePath); 54 this.properties.load(new FileInputStream (propertyFile)); 55 this.prefix = this.properties.getProperty("prefix"); 56 this.postfix = this.properties.getProperty("postfix"); 57 this.insertBlank = this.properties.getProperty("insertBlank"); 58 59 } catch (FileNotFoundException e) { 60 throw new Exception ("File not found!"); 61 } catch (IOException e) { 62 throw new Exception ("Error while reading property file!"); 63 } 64 } 65 66 69 public void release() throws Exception { 70 71 } 72 73 78 public List transformValue(List valueToTransform) throws Exception { 79 retValue.clear(); 80 String oldValue = valueToTransform.get(0).toString(); 81 String newValue = ""; 82 String finalValue = ""; 83 String key = ""; 84 boolean isSet = false; 85 try { 86 boolean containsKey = this.properties.containsKey(oldValue); 87 newValue = this.properties.getProperty(oldValue); 88 89 if (this.prefix.equalsIgnoreCase("true") && this.postfix.equalsIgnoreCase("true")) { 90 if (containsKey == true) { 91 isSet = true; 92 if (this.insertBlank.equalsIgnoreCase("true")){ 93 finalValue = newValue +" "+ oldValue +" "+ newValue; 94 }else{ 95 finalValue = newValue + oldValue + newValue; 96 } 97 } 98 } else if (this.prefix.equalsIgnoreCase("true")) { 99 if (containsKey == true) { 100 isSet = true; 101 if (this.insertBlank.equalsIgnoreCase("true")){ 102 finalValue = newValue + " " + oldValue; 103 }else{ 104 finalValue = newValue + oldValue; 105 } 106 } 107 } else if (this.postfix.equalsIgnoreCase("true")) { 108 if (containsKey == true) { 109 isSet = true; 110 if (this.insertBlank.equalsIgnoreCase("true")){ 111 finalValue = oldValue + " " + newValue; 112 }else{ 113 finalValue = oldValue + newValue; 114 } 115 } 116 } 117 if (isSet) { 118 retValue.add(finalValue); 119 } else { 120 retValue.add(oldValue); 121 } 122 } catch (Exception e) { 123 throw new Exception ("Error while concatenate data using class ConcatenateData!",e); 124 } 125 return retValue; 126 } 127 } | Popular Tags |