View Javadoc

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  //log
25  import org.apache.commons.logging.Log;
26  import org.apache.commons.logging.LogFactory;
27  //tubo
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   *      &lt;component-node refId="simple-transform"&gt;
43   *         &lt;property&gt;
44   *             &lt;prop-name&gt;t0&lt;/prop-name&gt;
45   *             &lt;prop-value&gt;SSLINEREADER_SAY_HELO-&gt;ECHO_SAY_HELO&lt;/prop-value&gt;
46   *         &lt;/property&gt;
47   *         &lt;property&gt;
48   *             &lt;prop-name&gt;t1&lt;/prop-name&gt;
49   *             &lt;prop-value&gt;SSLINEREADER_INPUT-&gt;ECHO_INPUT&lt;/prop-value&gt;
50   *         &lt;/property&gt;
51   *     &lt;/component-node&gt;
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          // get item
70          Item item = flowContext.getItem();
71          //
72          //
73          int i=0;
74          String transform = null;
75          do {
76              //
77              // get i-esima transformation
78              String ti = "t"+i;
79              transform = (String)item.getProperty(ti);
80              //
81              // if i-esima transformation is null then is cut condition
82              if (transform!=null) {
83                  //
84                  // parse transformation
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                  // transform
90                  Object value = item.getProperties().remove(from);
91                  item.setProperty(to,value);
92                  //
93                  // increment i
94                  i++;
95              }
96          //
97          // check cut condition    
98          } while (transform!=null);
99      }
100 
101 
102 }