📄 concatenatedata.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 concatenate
* data from table with values placed into property file
* Date: 23.07.2004.
* @version 1.0
* @author Zeljko Kovacevic
*
*/
public class ConcatenateData implements Transformer {
private String filePath = "";
private List retValue = new Vector();
private String prefix = "";
private String postfix = "";
private String insertBlank = "";
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 values which will be concatenated as prefix or postfix on original value
* @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.prefix = this.properties.getProperty("prefix");
this.postfix = this.properties.getProperty("postfix");
this.insertBlank = this.properties.getProperty("insertBlank");
} 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 concatenate values from property file to values from table
* as prefix or postfix
* @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 newValue = "";
String finalValue = "";
String key = "";
boolean isSet = false;
try {
boolean containsKey = this.properties.containsKey(oldValue);
newValue = this.properties.getProperty(oldValue);
if (this.prefix.equalsIgnoreCase("true") && this.postfix.equalsIgnoreCase("true")) {
if (containsKey == true) {
isSet = true;
if (this.insertBlank.equalsIgnoreCase("true")){
finalValue = newValue +" "+ oldValue +" "+ newValue;
}else{
finalValue = newValue + oldValue + newValue;
}
}
} else if (this.prefix.equalsIgnoreCase("true")) {
if (containsKey == true) {
isSet = true;
if (this.insertBlank.equalsIgnoreCase("true")){
finalValue = newValue + " " + oldValue;
}else{
finalValue = newValue + oldValue;
}
}
} else if (this.postfix.equalsIgnoreCase("true")) {
if (containsKey == true) {
isSet = true;
if (this.insertBlank.equalsIgnoreCase("true")){
finalValue = oldValue + " " + newValue;
}else{
finalValue = oldValue + newValue;
}
}
}
if (isSet) {
retValue.add(finalValue);
} else {
retValue.add(oldValue);
}
} catch (Exception e) {
throw new Exception("Error while concatenate data using class ConcatenateData!",e);
}
return retValue;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -