Coverage Report - org.mule.config.spring.parsers.specific.RegExFilterDefinitionParser
 
Classes in this File Line Coverage Branch Coverage Complexity
RegExFilterDefinitionParser
0%
0/3
N/A
0
RegExFilterDefinitionParser$FlagsMapping
0%
0/17
0%
0/4
0
 
 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.config.spring.parsers.specific;
 8  
 
 9  
 import org.mule.config.spring.parsers.assembly.configuration.ValueMap;
 10  
 import org.mule.routing.filters.RegExFilter;
 11  
 import org.mule.util.StringUtils;
 12  
 
 13  
 import java.util.HashMap;
 14  
 import java.util.Map;
 15  
 import java.util.regex.Pattern;
 16  
 
 17  
 public class RegExFilterDefinitionParser extends FilterDefinitionParser
 18  
 {
 19  
     public RegExFilterDefinitionParser()
 20  
     {
 21  0
         super(RegExFilter.class);
 22  0
         addMapping("flags", new FlagsMapping());
 23  0
     }
 24  
 
 25  
     /**
 26  
      * Map a comma-separated string to an Integer object that can be used to set the flags
 27  
      * on a {@link RegExFilter}.
 28  
      */
 29  0
     public static class FlagsMapping implements ValueMap
 30  
     {
 31  
         private static final Map<String, Integer> FlagsMapping;
 32  
 
 33  
         static
 34  
         {
 35  0
             FlagsMapping = new HashMap<String, Integer>();
 36  0
             FlagsMapping.put("CANON_EQ", Integer.valueOf(Pattern.CANON_EQ));
 37  0
             FlagsMapping.put("CASE_INSENSITIVE", Integer.valueOf(Pattern.CASE_INSENSITIVE));
 38  0
             FlagsMapping.put("DOTALL", Integer.valueOf(Pattern.DOTALL));
 39  0
             FlagsMapping.put("MULTILINE", Integer.valueOf(Pattern.MULTILINE));
 40  0
             FlagsMapping.put("UNICODE_CASE", Integer.valueOf(Pattern.UNICODE_CASE));
 41  0
         }
 42  
 
 43  
         public Object rewrite(String value)
 44  
         {
 45  0
             int combinedFlags = 0;
 46  
 
 47  0
             String[] flagStrings = StringUtils.split(value, ',');
 48  0
             for (String flagString : flagStrings)
 49  
             {
 50  0
                 Integer flag = FlagsMapping.get(flagString);
 51  0
                 if (flag == null)
 52  
                 {
 53  0
                     String message = String.format("Invalid flag '%1s'. Must be one of %2s", flagString,
 54  
                         FlagsMapping.keySet().toString());
 55  0
                     throw new IllegalArgumentException(message);
 56  
                 }
 57  
 
 58  0
                 combinedFlags = combinedFlags | flag.intValue();
 59  
             }
 60  
 
 61  0
             return Integer.valueOf(combinedFlags);
 62  
         }
 63  
     }
 64  
 }