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 | 0 | { |
28 | 0 | this.target = target; |
29 | 0 | this.separator = separator; |
30 | 0 | this.sources = sources; |
31 | 0 | } |
32 | |
|
33 | |
public void preProcess(PropertyConfiguration config, Element element) |
34 | |
{ |
35 | 0 | StringBuffer concat = new StringBuffer(); |
36 | 0 | boolean first = true; |
37 | 0 | for (int i = 0; i < sources.length; ++i) |
38 | |
{ |
39 | 0 | String value = config.translateValue(sources[i], element.getAttribute(sources[i])).toString(); |
40 | 0 | if (StringUtils.isNotEmpty(value)) |
41 | |
{ |
42 | 0 | if (first) |
43 | |
{ |
44 | 0 | first = false; |
45 | |
} |
46 | |
else |
47 | |
{ |
48 | 0 | concat.append(separator); |
49 | |
} |
50 | 0 | concat.append(value); |
51 | |
} |
52 | |
} |
53 | 0 | element.setAttribute(target, concat.toString()); |
54 | 0 | } |
55 | |
|
56 | |
} |