View Javadoc
1 /* 2 Copyright (C) 2003 Together 3 4 This library is free software; you can redistribute it and/or 5 modify it under the terms of the GNU Lesser General Public 6 License as published by the Free Software Foundation; either 7 version 2.1 of the License, or (at your option) any later version. 8 9 This library is distributed in the hope that it will be useful, 10 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 Lesser General Public License for more details. 13 14 You should have received a copy of the GNU Lesser General Public 15 License along with this library; if not, write to the Free Software 16 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 17 */ 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 /*** 29 * This class implements Transformer interface. It can be used to replace 30 * data from database table with values placed in property file 31 * format to another 32 * Date: 23.07.2004. 33 * @version 1.0 34 * @author Zeljko Kovacevic 35 * 36 */ 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 /*** 47 * This method reads path to property file which is used for replacing data 48 * Keys from property file are values from table, and values from property 49 * file are new values which will be placed instead of old ones. 50 * @param filePath Path to property file 51 */ 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 /*** 69 * This method release resources 70 */ 71 public void release() throws Exception { 72 73 } 74 75 /*** This method will change old values from table with new ones from 76 * property file 77 * @param valueToTransform List for transformation 78 * @return List with transformed values 79 */ 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 }

This page was automatically generated by Maven