1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
package org.mule.module.scripting.config; |
12 | |
|
13 | |
import org.mule.config.spring.parsers.assembly.BeanAssembler; |
14 | |
import org.mule.config.spring.parsers.generic.OptionalChildDefinitionParser; |
15 | |
import org.mule.config.spring.parsers.processors.CheckRequiredAttributes; |
16 | |
import org.mule.module.scripting.component.Scriptable; |
17 | |
import org.mule.util.StringUtils; |
18 | |
|
19 | |
import org.springframework.beans.factory.xml.ParserContext; |
20 | |
import org.w3c.dom.Element; |
21 | |
import org.w3c.dom.Node; |
22 | |
|
23 | |
public class ScriptDefinitionParser extends OptionalChildDefinitionParser |
24 | |
{ |
25 | |
public ScriptDefinitionParser() |
26 | |
{ |
27 | 36 | super("script", Scriptable.class); |
28 | 36 | addIgnored("name"); |
29 | 36 | addAlias("engine", "scriptEngineName"); |
30 | 36 | addAlias("file", "scriptFile"); |
31 | |
|
32 | |
|
33 | |
|
34 | 36 | String[][] requiredAttributeSets = new String[2][]; |
35 | 36 | requiredAttributeSets[0] = new String[]{"engine"}; |
36 | 36 | requiredAttributeSets[1] = new String[]{"file"}; |
37 | 36 | registerPreProcessor(new CheckRequiredAttributes(requiredAttributeSets)); |
38 | 36 | } |
39 | |
|
40 | |
protected void postProcess(ParserContext context, BeanAssembler assembler, Element element) |
41 | |
{ |
42 | 72 | Node node = element.getFirstChild(); |
43 | 72 | if (node != null) |
44 | |
{ |
45 | 56 | String value = node.getNodeValue(); |
46 | |
|
47 | 56 | if(node.getNextSibling()!=null && node.getNextSibling().getNodeType()== Node.CDATA_SECTION_NODE) |
48 | |
{ |
49 | 0 | value = node.getNextSibling().getNodeValue(); |
50 | |
} |
51 | |
|
52 | 56 | if (!StringUtils.isBlank(value)) |
53 | |
{ |
54 | 40 | assembler.getBean().addPropertyValue("scriptText", value); |
55 | |
} |
56 | |
} |
57 | 72 | super.postProcess(context, assembler, element); |
58 | 72 | } |
59 | |
} |
60 | |
|
61 | |
|