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  
  * $Id: ScriptDefinitionParser.java 19191 2010-08-25 21:05:23Z tcarlson $
 3  
  * --------------------------------------------------------------------------------------
 4  
  * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
 5  
  *
 6  
  * The software in this package is published under the terms of the CPAL v1.0
 7  
  * license, a copy of which has been included with this distribution in the
 8  
  * LICENSE.txt file.
 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  0
         super("script", Scriptable.class);
 28  0
         addIgnored("name");
 29  0
         addAlias("engine", "scriptEngineName");
 30  0
         addAlias("file", "scriptFile");        
 31  
 
 32  
         // The "engine" attribute is required unless "file" is specified, in which case the 
 33  
         // file extension will be used to determine the appropriate script engine.
 34  0
         String[][] requiredAttributeSets = new String[2][];
 35  0
         requiredAttributeSets[0] = new String[]{"engine"};
 36  0
         requiredAttributeSets[1] = new String[]{"file"};
 37  0
         registerPreProcessor(new CheckRequiredAttributes(requiredAttributeSets));
 38  0
     }
 39  
 
 40  
     protected void postProcess(ParserContext context, BeanAssembler assembler, Element element)
 41  
     {
 42  0
         Node node = element.getFirstChild();
 43  0
         if (node != null)
 44  
         {
 45  0
             String value = node.getNodeValue();
 46  
             //Support CDATA for script text
 47  0
             if(node.getNextSibling()!=null && node.getNextSibling().getNodeType()== Node.CDATA_SECTION_NODE)
 48  
             {
 49  0
                 value = node.getNextSibling().getNodeValue();
 50  
             }
 51  
 
 52  0
             if (!StringUtils.isBlank(value))
 53  
             {
 54  0
                 assembler.getBean().addPropertyValue("scriptText", value);
 55  
             }
 56  
         }
 57  0
         super.postProcess(context, assembler, element);
 58  0
     }
 59  
 }
 60  
 
 61