Coverage Report - org.simpleframework.xml.core.TemplateFilter
 
Classes in this File Line Coverage Branch Coverage Complexity
TemplateFilter
100%
8/8
100%
2/2
2
 
 1  
 /*
 2  
  * TemplateFilter.java May 2005
 3  
  *
 4  
  * Copyright (C) 2005, 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.core;
 20  
 
 21  
 import org.simpleframework.xml.filter.Filter;
 22  
 
 23  
 /**
 24  
  * The <code>TemplateFilter</code> class is used to provide variables
 25  
  * to the template engine. This template acquires variables from two
 26  
  * different sources. Firstly this will consult the user contextual
 27  
  * <code>Context</code> object, which can contain variables that have
 28  
  * been added during the deserialization process. If a variable is
 29  
  * not present from this context it asks the <code>Filter</code> that
 30  
  * has been specified by the user.
 31  
  * 
 32  
  * @author Niall Gallagher
 33  
  */ 
 34  
 class TemplateFilter implements Filter {
 35  
 
 36  
    /**
 37  
     * This is the template context object used by the persister.
 38  
     */ 
 39  
    private Context context;
 40  
 
 41  
    /**
 42  
     * This is the filter object provided to the persister.
 43  
     */ 
 44  
    private Filter filter;
 45  
         
 46  
    /**
 47  
     * Constructor for the <code>TemplateFilter</code> object. This
 48  
     * creates a filter object that acquires template values from
 49  
     * two different contexts. Firstly the <code>Context</code> is
 50  
     * queried for a variables followed by the <code>Filter</code>.
 51  
     *
 52  
     * @param context this is the context object for the persister
 53  
     * @param filter the filter that has been given to the persister
 54  
     */ 
 55  98473
    public TemplateFilter(Context context, Filter filter) {
 56  98473
       this.context = context;     
 57  98473
       this.filter = filter;      
 58  98473
    }        
 59  
 
 60  
    /**
 61  
     * This will acquire the named variable value if it exists. If
 62  
     * the named variable cannot be found in either the context or
 63  
     * the user specified filter then this returns null.
 64  
     * 
 65  
     * @param name this is the name of the variable to acquire
 66  
     *
 67  
     * @return this returns the value mapped to the variable name
 68  
     */ 
 69  
    public String replace(String name) {
 70  200081
       Object value = context.getAttribute(name);
 71  
 
 72  200081
       if(value != null) {
 73  3
          return value.toString();              
 74  
       }      
 75  200078
       return filter.replace(name);
 76  
    }
 77  
 }