View Javadoc
1   /*
2    * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
3    * The software in this package is published under the terms of the CPAL v1.0
4    * license, a copy of which has been included with this distribution in the
5    * LICENSE.txt file.
6    */
7   package org.mule.config.spring.parsers.processors;
8   
9   import org.mule.config.spring.parsers.PreProcessor;
10  import org.mule.config.spring.parsers.assembly.configuration.PropertyConfiguration;
11  import org.mule.util.StringUtils;
12  
13  import org.w3c.dom.Element;
14  
15  public class AttributeConcatenation implements PreProcessor
16  {
17  
18      private String target;
19      private String separator;
20      private String[] sources;
21  
22      public AttributeConcatenation(String target, String separator, String[] sources)
23      {
24          this.target = target;
25          this.separator = separator;
26          this.sources = sources;
27      }
28  
29      public void preProcess(PropertyConfiguration config, Element element)
30      {
31          StringBuffer concat = new StringBuffer();
32          boolean first = true;
33          for (int i = 0; i < sources.length; ++i)
34          {
35              String value = config.translateValue(sources[i], element.getAttribute(sources[i])).toString();
36              if (StringUtils.isNotEmpty(value))
37              {
38                  if (first)
39                  {
40                      first = false;
41                  }
42                  else
43                  {
44                      concat.append(separator);
45                  }
46                  concat.append(value);
47              }
48          }
49          element.setAttribute(target, concat.toString());
50      }
51  
52  }