1
2
3
4
5
6
7
8
9
10
11 package org.mule.config.spring.parsers.processors;
12
13 import org.mule.config.spring.parsers.PreProcessor;
14 import org.mule.config.spring.parsers.assembly.configuration.PropertyConfiguration;
15 import org.mule.util.StringUtils;
16
17 import org.w3c.dom.Element;
18
19 public class AttributeConcatenation implements PreProcessor
20 {
21
22 private String target;
23 private String separator;
24 private String[] sources;
25
26 public AttributeConcatenation(String target, String separator, String[] sources)
27 {
28 this.target = target;
29 this.separator = separator;
30 this.sources = sources;
31 }
32
33 public void preProcess(PropertyConfiguration config, Element element)
34 {
35 StringBuffer concat = new StringBuffer();
36 boolean first = true;
37 for (int i = 0; i < sources.length; ++i)
38 {
39 String value = config.translateValue(sources[i], element.getAttribute(sources[i])).toString();
40 if (StringUtils.isNotEmpty(value))
41 {
42 if (first)
43 {
44 first = false;
45 }
46 else
47 {
48 concat.append(separator);
49 }
50 concat.append(value);
51 }
52 }
53 element.setAttribute(target, concat.toString());
54 }
55
56 }