Coverage Report - org.simpleframework.xml.filter.SystemFilter
 
Classes in this File Line Coverage Branch Coverage Complexity
SystemFilter
72%
8/11
25%
1/4
2.333
 
 1  
 /*
 2  
  * SystemFilter.java May 2006
 3  
  *
 4  
  * Copyright (C) 2006, Niall Gallagher <niallg@users.sf.net>
 5  
  *
 6  
  * Licensed under the Apache License, Version 2.0 (the "License");
 7  
  * you may not use this file except in compliance with the License.
 8  
  * You may obtain a copy of the License at
 9  
  *
 10  
  *     http://www.apache.org/licenses/LICENSE-2.0
 11  
  *
 12  
  * Unless required by applicable law or agreed to in writing, software
 13  
  * distributed under the License is distributed on an "AS IS" BASIS,
 14  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 
 15  
  * implied. See the License for the specific language governing 
 16  
  * permissions and limitations under the License.
 17  
  */
 18  
 
 19  
 package org.simpleframework.xml.filter;
 20  
 
 21  
 /**
 22  
  * The <code>SystemFilter</code> object is used to provide a filter
 23  
  * that will replace the specified values with system properties.
 24  
  * This can be given a delegate filter which can be used to resolve
 25  
  * replacements should the value requested not match a property. 
 26  
  * 
 27  
  * @author Niall Gallagher
 28  
  */
 29  
 public class SystemFilter implements Filter {
 30  
    
 31  
    /**
 32  
     * Filter delegated to if no system property can be resolved.
 33  
     */
 34  
    private Filter filter;        
 35  
         
 36  
    /**
 37  
     * Constructor for the <code>SystemFilter</code> object. This 
 38  
     * creates a filter that will resolve replacements using system
 39  
     * properties. Should the system properties not contain the
 40  
     * requested mapping this will return a null value.
 41  
     */
 42  
    public SystemFilter() {
 43  946
       this(null);           
 44  946
    }
 45  
         
 46  
    /**
 47  
     * Constructor for the <code>SystemFilter</code> object. This 
 48  
     * creates a filter that will resolve replacements using system
 49  
     * properties. Should the system properties not contain the
 50  
     * requested mapping this delegates to the specified filter.
 51  
     * 
 52  
     * @param filter the filter delegated to if resolution fails
 53  
     */   
 54  946
    public SystemFilter(Filter filter) {
 55  946
       this.filter = filter;           
 56  946
    }
 57  
    
 58  
    /**
 59  
     * Replaces the text provided with the value resolved from the
 60  
     * system properties. If the system properties fails this will
 61  
     * delegate to the specified <code>Filter</code> if it is not
 62  
     * a null object. If no match is found a null is returned.
 63  
     * 
 64  
     * @param text this is the text value to be replaced
 65  
     * 
 66  
     * @return this will return the replacement text resolved
 67  
     */
 68  
    public String replace(String text) {
 69  100041
       String value = System.getProperty(text);           
 70  
 
 71  100041
       if(value != null) {
 72  100041
          return value;                       
 73  
       }
 74  0
       if(filter != null) {
 75  0
          return filter.replace(text);              
 76  
       }      
 77  0
       return null;
 78  
    }   
 79  
 }