Coverage Report - org.apache.maven.doxia.docrenderer.DocumentRendererContext
 
Classes in this File Line Coverage Branch Coverage Complexity
DocumentRendererContext
0%
0/20
0%
0/8
2
 
 1  
 package org.apache.maven.doxia.docrenderer;
 2  
 
 3  
 /*
 4  
  * Licensed to the Apache Software Foundation (ASF) under one
 5  
  * or more contributor license agreements.  See the NOTICE file
 6  
  * distributed with this work for additional information
 7  
  * regarding copyright ownership.  The ASF licenses this file
 8  
  * to you under the Apache License, Version 2.0 (the
 9  
  * "License"); you may not use this file except in compliance
 10  
  * with the License.  You may obtain a copy of the License at
 11  
  *
 12  
  *   http://www.apache.org/licenses/LICENSE-2.0
 13  
  *
 14  
  * Unless required by applicable law or agreed to in writing,
 15  
  * software distributed under the License is distributed on an
 16  
  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 17  
  * KIND, either express or implied.  See the License for the
 18  
  * specific language governing permissions and limitations
 19  
  * under the License.
 20  
  */
 21  
 
 22  
 import java.util.HashMap;
 23  
 import java.util.Map;
 24  
 
 25  
 import org.codehaus.plexus.util.ReaderFactory;
 26  
 
 27  
 /**
 28  
  * Context when processing Velocity files using a {@link java.util.HashMap} for data storage.
 29  
  *
 30  
  * @author <a href="mailto:vincent.siveton@gmail.com">Vincent Siveton</a>
 31  
  * @version $Id: DocumentRendererContext.java 1087124 2011-03-30 22:45:41Z hboutemy $
 32  
  * @since 1.1.2
 33  
  */
 34  
 public class DocumentRendererContext
 35  
 {
 36  0
     private String inputEncoding = ReaderFactory.UTF_8;
 37  
 
 38  
     /**
 39  
      *  Storage for key/value pairs.
 40  
      */
 41  
     private final Map<String, Object> context;
 42  
 
 43  
     /**
 44  
      *  Default constructor.
 45  
      */
 46  
     public DocumentRendererContext()
 47  0
     {
 48  0
         context = new HashMap<String, Object>();
 49  0
     }
 50  
 
 51  
     /**
 52  
      * @return The input encoding when processing files.
 53  
      */
 54  
     public String getInputEncoding()
 55  
     {
 56  0
         return inputEncoding;
 57  
     }
 58  
 
 59  
     /**
 60  
      * @param inputEncoding new input encoding value when processing files.
 61  
      */
 62  
     public void setInputEncoding( String inputEncoding )
 63  
     {
 64  0
         this.inputEncoding = inputEncoding;
 65  0
     }
 66  
 
 67  
     /**
 68  
      * Adds a name/value pair to the context.
 69  
      *
 70  
      * @param key The name to key the provided value with.
 71  
      * @param value The corresponding value.
 72  
      * @return Object that was replaced in the the Context if applicable or null if not.
 73  
      */
 74  
     public Object put( String key, Object value )
 75  
     {
 76  0
         if ( key == null )
 77  
         {
 78  0
             return null;
 79  
         }
 80  
 
 81  0
         return context.put( key, value );
 82  
     }
 83  
 
 84  
     /**
 85  
      *  Gets the value corresponding to the provided key from the context.
 86  
      *
 87  
      *  @param key The name of the desired value.
 88  
      *  @return The value corresponding to the provided key or null if the key param is null.
 89  
      */
 90  
     public Object get( String key )
 91  
     {
 92  0
         if ( key == null )
 93  
         {
 94  0
             return null;
 95  
         }
 96  
 
 97  0
         return context.get( key );
 98  
     }
 99  
 
 100  
     /**
 101  
      *  Indicates whether the specified key is in the context.
 102  
      *
 103  
      * @param key The key to look for.
 104  
      * @return true if the key is in the context, false if not.
 105  
      */
 106  
     public boolean containsKey( Object key )
 107  
     {
 108  0
         if ( key == null )
 109  
         {
 110  0
             return false;
 111  
         }
 112  
 
 113  0
         return context.containsKey( key );
 114  
     }
 115  
 
 116  
     /**
 117  
      *  Get all the keys for the values in the context
 118  
      *
 119  
      *  @return Object[] of keys in the Context.
 120  
      */
 121  
     public Object[] getKeys()
 122  
     {
 123  0
         return context.keySet().toArray();
 124  
     }
 125  
 
 126  
     /**
 127  
      * Removes the value associated with the specified key from the context.
 128  
      *
 129  
      * @param key The name of the value to remove.
 130  
      * @return The value that the key was mapped to, or <code>null</code> if unmapped.
 131  
      */
 132  
     public Object remove( Object key )
 133  
     {
 134  0
         if ( key == null )
 135  
         {
 136  0
             return null;
 137  
         }
 138  
 
 139  0
         return context.remove( key );
 140  
     }
 141  
 }