1 /**
2 * $Id: SimpleTransformComponent.java 78 2006-12-15 21:37:36Z maldito_orco $
3 * $Revision: 78 $
4 * $Date: 2006-12-15 18:37:36 -0300 (Fri, 15 Dec 2006) $
5 *
6 * =========================================================================
7 *
8 * Copyright 2005 Tubo
9 *
10 * Licensed under the Apache License, Version 2.0 (the "License");
11 * you may not use this file except in compliance with the License.
12 * You may obtain a copy of the License at
13 *
14 * http://www.apache.org/licenses/LICENSE-2.0
15 *
16 * Unless required by applicable law or agreed to in writing, software
17 * distributed under the License is distributed on an "AS IS" BASIS,
18 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19 * See the License for the specific language governing permissions and
20 * limitations under the License.
21 */
22 package org.tubo.resource.component.transform;
23
24
25 import org.apache.commons.logging.Log;
26 import org.apache.commons.logging.LogFactory;
27
28 import org.tubo.resource.component.BaseComponentImpl;
29 import org.tubo.resource.flow.FlowContext;
30 import org.tubo.exception.TuboException;
31 import org.tubo.item.Item;
32
33 /**
34 * Simple Transformation Component
35 *
36 * <p>This component rename (or move) item properties to another names, one by
37 * one, in the same order as they are defined in component node in flow
38 * configuration. For example:
39 * </p>
40 *
41 * <pre>
42 * <component-node refId="simple-transform">
43 * <property>
44 * <prop-name>t0</prop-name>
45 * <prop-value>SSLINEREADER_SAY_HELO->ECHO_SAY_HELO</prop-value>
46 * </property>
47 * <property>
48 * <prop-name>t1</prop-name>
49 * <prop-value>SSLINEREADER_INPUT->ECHO_INPUT</prop-value>
50 * </property>
51 * </component-node>
52 * </pre>
53 *
54 * <p/>
55 * Created: Nov 8, 2006, 12:30:24 AM <br>
56 * Last Modification Date: $Date: 2006-12-15 18:37:36 -0300 (Fri, 15 Dec 2006) $
57 * </p>
58 *
59 * @author maldito_orco (maldito_orco@users.sourceforge.net)
60 * @version $Revision: 78 $
61 */
62 public class SimpleTransformComponent extends BaseComponentImpl {
63 public static final String RCS_ID = "$Id: SimpleTransformComponent.java 78 2006-12-15 21:37:36Z maldito_orco $";
64 private static Log log = LogFactory.getLog(SimpleTransformComponent.class);
65
66
67 public void execute(FlowContext flowContext) throws TuboException {
68
69
70 Item item = flowContext.getItem();
71
72
73 int i=0;
74 String transform = null;
75 do {
76
77
78 String ti = "t"+i;
79 transform = (String)item.getProperty(ti);
80
81
82 if (transform!=null) {
83
84
85 int inx = transform.indexOf("->");
86 String from = transform.substring(0,inx).trim();
87 String to = transform.substring(inx+"->".length(),transform.length()).trim();
88
89
90 Object value = item.getProperties().remove(from);
91 item.setProperty(to,value);
92
93
94 i++;
95 }
96
97
98 } while (transform!=null);
99 }
100
101
102 }