1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
package org.mule.config.spring.parsers.generic; |
11 | |
|
12 | |
import org.mule.config.spring.parsers.assembly.BeanAssembler; |
13 | |
import org.mule.util.StringUtils; |
14 | |
|
15 | |
import org.springframework.beans.factory.xml.ParserContext; |
16 | |
import org.w3c.dom.Element; |
17 | |
import org.w3c.dom.Node; |
18 | |
|
19 | |
|
20 | |
|
21 | |
|
22 | |
|
23 | |
|
24 | |
|
25 | |
|
26 | |
|
27 | |
|
28 | |
|
29 | |
|
30 | |
|
31 | |
public class TextDefinitionParser extends ChildDefinitionParser |
32 | |
{ |
33 | 0 | private boolean requireCdata = false; |
34 | |
|
35 | |
public TextDefinitionParser(String setterMethod) |
36 | |
{ |
37 | 0 | super(setterMethod, String.class); |
38 | 0 | } |
39 | |
|
40 | |
public TextDefinitionParser(String setterMethod, boolean requireCdata) |
41 | |
{ |
42 | 0 | super(setterMethod, String.class); |
43 | 0 | this.requireCdata = requireCdata; |
44 | 0 | } |
45 | |
|
46 | |
@Override |
47 | |
protected void postProcess(ParserContext context, BeanAssembler assembler, Element element) |
48 | |
{ |
49 | 0 | Node node = element.getFirstChild(); |
50 | |
|
51 | 0 | if(requireCdata && node.getNodeType() != Node.CDATA_SECTION_NODE) |
52 | |
{ |
53 | 0 | node = node.getNextSibling(); |
54 | 0 | if(node == null) |
55 | |
{ |
56 | 0 | throw new IllegalArgumentException("No CDATA node found in " + element.getNodeName()); |
57 | |
} |
58 | 0 | else if(node.getNodeType() != Node.CDATA_SECTION_NODE) |
59 | |
{ |
60 | 0 | throw new IllegalArgumentException("Sibling node is not a CDATA section, but one should be defined. Elements is " + element.getNodeName()); |
61 | |
} |
62 | |
} |
63 | 0 | if (node != null) |
64 | |
{ |
65 | 0 | String value = node.getNodeValue(); |
66 | 0 | if (!StringUtils.isBlank(value)) |
67 | |
{ |
68 | 0 | assembler.getTarget().getPropertyValues().addPropertyValue(setterMethod, value); |
69 | |
} |
70 | |
} |
71 | 0 | } |
72 | |
} |