📄 replacedata.java
字号:
/*
Copyright (C) 2003 Together
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package org.webdocwf.util.loader.transformation;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.List;
import java.util.Properties;
import java.util.Vector;
/**
* This class implements Transformer interface. It can be used to replace
* data from database table with values placed in property file
* format to another
* Date: 23.07.2004.
* @version 1.0
* @author Zeljko Kovacevic
*
*/
public class ReplaceData implements Transformer {
private String filePath = "";
private List retValue = new Vector();
private String valueToReplace = "";
private String valueReplaceWith = "";
private String replaceAll = "";
private String newPropValue = "";
private Properties properties = new Properties();
/**
* This method reads path to property file which is used for replacing data
* Keys from property file are values from table, and values from property
* file are new values which will be placed instead of old ones.
* @param filePath Path to property file
*/
public void configure(String filePath) throws Exception {
try {
this.filePath = filePath;
File propertyFile = new File(this.filePath);
this.properties.load(new FileInputStream(propertyFile));
this.replaceAll = this.properties.getProperty("replaceAll");
this.newPropValue = this.properties.getProperty("newPropValue");
} catch (FileNotFoundException e) {
throw new Exception("File not found!");
} catch (IOException e) {
throw new Exception("Error while reading property file!");
}
}
/**
* This method release resources
*/
public void release() throws Exception {
}
/** This method will change old values from table with new ones from
* property file
* @param valueToTransform List for transformation
* @return List with transformed values
*/
public List transformValue(List valueToTransform) throws Exception {
retValue.clear();
String oldValue = valueToTransform.get(0).toString();
String key = "";
try {
if (this.replaceAll.equalsIgnoreCase("true")){
retValue.add(this.newPropValue);
}else{
boolean containsKey = this.properties.containsKey(oldValue);
if (containsKey == true) {
String newValue = this.properties.getProperty(oldValue);
retValue.add(newValue);
} else {
retValue.add(oldValue);
}
}
} catch (Exception e) {
throw new Exception("Error while replacing data using class ReplaceData!",e);
}
return retValue;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -