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 concatenate
30 * data from table with values placed into property file
31 * Date: 23.07.2004.
32 * @version 1.0
33 * @author Zeljko Kovacevic
34 *
35 */
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 /***
44 * This method reads path to property file which is used for replacing data
45 * Keys from property file are values from table, and values from property
46 * file are values which will be concatenated as prefix or postfix on original value
47 * @param filePath Path to property file
48 */
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 /***
67 * This method release resources
68 */
69 public void release() throws Exception {
70
71 }
72
73 /*** This method will concatenate values from property file to values from table
74 * as prefix or postfix
75 * @param valueToTransform List for transformation
76 * @return List with transformed values
77 */
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 }
This page was automatically generated by Maven