Coverage Report - org.apache.maven.doxia.sink.render.RenderingContext
 
Classes in this File Line Coverage Branch Coverage Complexity
RenderingContext
55%
15/27
50%
1/2
1,091
 
 1  
 package org.apache.maven.doxia.sink.render;
 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.io.File;
 23  
 import java.util.HashMap;
 24  
 import java.util.Locale;
 25  
 import java.util.Map;
 26  
 
 27  
 import org.codehaus.plexus.util.PathTool;
 28  
 import org.codehaus.plexus.util.StringUtils;
 29  
 
 30  
 /**
 31  
  * The rendering context of a document.
 32  
  *
 33  
  * @author <a href="mailto:jason@maven.org">Jason van Zyl</a>
 34  
  * @version $Id: RenderingContext.java 1090706 2011-04-09 23:15:28Z hboutemy $
 35  
  * @since 1.1
 36  
  */
 37  
 public class RenderingContext
 38  
 {
 39  
     private final File basedir;
 40  
 
 41  
     private final String inputName;
 42  
 
 43  
     private final String outputName;
 44  
 
 45  
     private final String parserId;
 46  
 
 47  
     private final String relativePath;
 48  
 
 49  
     private final String extension;
 50  
 
 51  
     private Map<String, String> attributes;
 52  
 
 53  
     /**
 54  
      * <p>Constructor for RenderingContext.</p>
 55  
      *
 56  
      * @param basedir a {@link java.io.File} object.
 57  
      * @param document a {@link java.lang.String} object.
 58  
      */
 59  
     public RenderingContext( File basedir, String document )
 60  
     {
 61  0
         this( basedir, document, null );
 62  0
     }
 63  
 
 64  
     /**
 65  
      * <p>Constructor for RenderingContext.</p>
 66  
      *
 67  
      * @param basedir a {@link java.io.File} object.
 68  
      * @param document a {@link java.lang.String} object.
 69  
      * @param parserId a {@link java.lang.String} object.
 70  
      */
 71  
     public RenderingContext( File basedir, String document, String parserId )
 72  
     {
 73  0
         this( basedir, document, parserId, null );
 74  
 
 75  0
     }
 76  
 
 77  
     /**
 78  
      * <p>Constructor for RenderingContext.</p>
 79  
      *
 80  
      * @param basedir a {@link java.io.File} object.
 81  
      * @param document a {@link java.lang.String} object.
 82  
      * @param parserId a {@link java.lang.String} object.
 83  
      * @param extension a {@link java.lang.String} object.
 84  
      */
 85  
     public RenderingContext( File basedir, String document, String parserId, String extension )
 86  6
     {
 87  6
         this.basedir = basedir;
 88  6
         this.extension = extension;
 89  6
         if ( StringUtils.isNotEmpty( extension ) )
 90  
         {
 91  
             // here we now the parserId we can play with this
 92  
             // index.xml -> index.html
 93  
             // index.xml.vm -> index.html
 94  
             // download.apt.vm --> download.html
 95  6
             int startIndexOfExtension =
 96  
                 document.toLowerCase( Locale.ENGLISH ).indexOf( "." + extension.toLowerCase( Locale.ENGLISH ) );
 97  6
             String fileNameWithoutExt = document.substring( 0, startIndexOfExtension );
 98  6
             this.outputName = fileNameWithoutExt + ".html";
 99  6
         }
 100  
         else
 101  
         {
 102  0
             this.outputName = document.substring( 0, document.indexOf( '.' ) ).replace( '\\', '/' ) + ".html";
 103  
         }
 104  6
         this.relativePath = PathTool.getRelativePath( basedir.getPath(), new File( basedir, document ).getPath() );
 105  
 
 106  6
         this.inputName = document;
 107  
 
 108  6
         this.parserId = parserId;
 109  
 
 110  6
         this.attributes = new HashMap<String, String>();
 111  6
     }
 112  
 
 113  
     /**
 114  
      * <p>Getter for the field <code>basedir</code>.</p>
 115  
      *
 116  
      * @return a {@link java.io.File} object.
 117  
      */
 118  
     public File getBasedir()
 119  
     {
 120  0
         return basedir;
 121  
     }
 122  
 
 123  
     /**
 124  
      * <p>Getter for the field <code>inputName</code>.</p>
 125  
      *
 126  
      * @return a {@link java.lang.String} object.
 127  
      */
 128  
     public String getInputName()
 129  
     {
 130  0
         return inputName;
 131  
     }
 132  
 
 133  
     /**
 134  
      * <p>Getter for the field <code>outputName</code>.</p>
 135  
      *
 136  
      * @return a {@link java.lang.String} object.
 137  
      */
 138  
     public String getOutputName()
 139  
     {
 140  6
         return outputName;
 141  
     }
 142  
 
 143  
     /**
 144  
      * <p>Getter for the field <code>parserId</code>.</p>
 145  
      *
 146  
      * @return a {@link java.lang.String} object.
 147  
      */
 148  
     public String getParserId()
 149  
     {
 150  0
         return parserId;
 151  
     }
 152  
 
 153  
     /**
 154  
      * <p>Getter for the field <code>relativePath</code>.</p>
 155  
      *
 156  
      * @return a {@link java.lang.String} object.
 157  
      */
 158  
     public String getRelativePath()
 159  
     {
 160  6
         return relativePath;
 161  
     }
 162  
 
 163  
     /**
 164  
      * <p>setAttribute.</p>
 165  
      *
 166  
      * @param key a {@link java.lang.String} object.
 167  
      * @param value a {@link java.lang.String} object.
 168  
      */
 169  
     public void setAttribute( String key, String value )
 170  
     {
 171  0
         attributes.put( key, value );
 172  0
     }
 173  
 
 174  
     /**
 175  
      * <p>getAttribute.</p>
 176  
      *
 177  
      * @param key a {@link java.lang.String} object.
 178  
      * @return a {@link java.lang.String} object.
 179  
      */
 180  
     public String getAttribute( String key )
 181  
     {
 182  0
         return (String) attributes.get( key );
 183  
     }
 184  
 
 185  
     /**
 186  
      * <p>Getter for the field <code>extension</code>.</p>
 187  
      *
 188  
      * @return a {@link java.lang.String} object.
 189  
      */
 190  
     public String getExtension()
 191  
     {
 192  0
         return extension;
 193  
     }
 194  
 }