Coverage Report - org.mule.module.scripting.config.ScriptDefinitionParser
 
Classes in this File Line Coverage Branch Coverage Complexity
ScriptDefinitionParser
0%
0/18
0%
0/8
2.5
 
 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.module.scripting.config;
 8  
 
 9  
 import org.mule.config.spring.parsers.assembly.BeanAssembler;
 10  
 import org.mule.config.spring.parsers.generic.OptionalChildDefinitionParser;
 11  
 import org.mule.config.spring.parsers.processors.CheckRequiredAttributes;
 12  
 import org.mule.module.scripting.component.Scriptable;
 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  
 public class ScriptDefinitionParser extends OptionalChildDefinitionParser
 20  
 {
 21  
     public ScriptDefinitionParser()
 22  
     {
 23  0
         super("script", Scriptable.class);
 24  0
         addIgnored("name");
 25  0
         addAlias("engine", "scriptEngineName");
 26  0
         addAlias("file", "scriptFile");        
 27  
 
 28  
         // The "engine" attribute is required unless "file" is specified, in which case the 
 29  
         // file extension will be used to determine the appropriate script engine.
 30  0
         String[][] requiredAttributeSets = new String[2][];
 31  0
         requiredAttributeSets[0] = new String[]{"engine"};
 32  0
         requiredAttributeSets[1] = new String[]{"file"};
 33  0
         registerPreProcessor(new CheckRequiredAttributes(requiredAttributeSets));
 34  0
     }
 35  
 
 36  
     protected void postProcess(ParserContext context, BeanAssembler assembler, Element element)
 37  
     {
 38  0
         Node node = element.getFirstChild();
 39  0
         if (node != null)
 40  
         {
 41  0
             String value = node.getNodeValue();
 42  
             //Support CDATA for script text
 43  0
             if(node.getNextSibling()!=null && node.getNextSibling().getNodeType()== Node.CDATA_SECTION_NODE)
 44  
             {
 45  0
                 value = node.getNextSibling().getNodeValue();
 46  
             }
 47  
 
 48  0
             if (!StringUtils.isBlank(value))
 49  
             {
 50  0
                 assembler.getBean().addPropertyValue("scriptText", value);
 51  
             }
 52  
         }
 53  0
         super.postProcess(context, assembler, element);
 54  0
     }
 55  
 }
 56  
 
 57