Coverage Report - org.apache.maven.doxia.book.services.renderer.xhtml.XhtmlBookSink
 
Classes in this File Line Coverage Branch Coverage Complexity
XhtmlBookSink
93%
45/48
50%
2/4
1,091
 
 1  
 package org.apache.maven.doxia.book.services.renderer.xhtml;
 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 org.apache.maven.doxia.module.xhtml.XhtmlSink;
 23  
 import org.apache.maven.doxia.sink.render.RenderingContext;
 24  
 import org.codehaus.plexus.util.StringUtils;
 25  
 
 26  
 import java.io.Writer;
 27  
 
 28  
 /**
 29  
  * An Xhtml Sink that doesn't write out head or body elements.
 30  
  *
 31  
  * @author ltheussl
 32  
  * @version $Id: XhtmlBookSink.java 808201 2009-08-26 22:04:43Z vsiveton $
 33  
  */
 34  
 public class XhtmlBookSink
 35  
     extends XhtmlSink
 36  
 {
 37  
     private RenderingContext renderingContext;
 38  
 
 39  
     /**
 40  
      * Construct a new XhtmlBookSink.
 41  
      *
 42  
      * @param out the writer for the sink.
 43  
      * @param context the RenderingContext.
 44  
      */
 45  
     public XhtmlBookSink( Writer out, RenderingContext context )
 46  
     {
 47  1
         super( out );
 48  1
         this.renderingContext = context;
 49  1
     }
 50  
 
 51  
     // ----------------------------------------------------------------------
 52  
     //
 53  
     // ----------------------------------------------------------------------
 54  
 
 55  
     /**
 56  
      * {@inheritDoc}
 57  
      *
 58  
      * Does nothing.
 59  
      */
 60  
     public void head()
 61  
     {
 62  4
         init();
 63  
 
 64  4
         setHeadFlag( true );
 65  4
     }
 66  
 
 67  
     /**
 68  
      * {@inheritDoc}
 69  
      *
 70  
      * Does nothing.
 71  
      */
 72  
     public void head_()
 73  
     {
 74  4
         setHeadFlag( false );
 75  4
     }
 76  
 
 77  
     /**
 78  
      * {@inheritDoc}
 79  
      *
 80  
      * Does nothing.
 81  
      */
 82  
     public void title()
 83  
     {
 84  
         // noop
 85  4
     }
 86  
 
 87  
     /**
 88  
      * {@inheritDoc}
 89  
      *
 90  
      * Does nothing.
 91  
      */
 92  
     public void title_()
 93  
     {
 94  4
         resetTextBuffer();
 95  4
     }
 96  
 
 97  
     /**
 98  
      * {@inheritDoc}
 99  
      *
 100  
      * Does nothing.
 101  
      */
 102  
     public void author_()
 103  
     {
 104  4
         resetTextBuffer();
 105  4
     }
 106  
 
 107  
     /**
 108  
      * {@inheritDoc}
 109  
      *
 110  
      * Does nothing.
 111  
      */
 112  
     public void date_()
 113  
     {
 114  0
         resetTextBuffer();
 115  0
     }
 116  
 
 117  
     /**
 118  
      * {@inheritDoc}
 119  
      *
 120  
      * Does nothing.
 121  
      */
 122  
     public void body()
 123  
     {
 124  
         // noop
 125  4
     }
 126  
 
 127  
     /**
 128  
      * {@inheritDoc}
 129  
      *
 130  
      * Does nothing.
 131  
      */
 132  
     public void body_()
 133  
     {
 134  
         // noop
 135  4
     }
 136  
 
 137  
     /**
 138  
      * Calls super.head().
 139  
      */
 140  
     public void bookHead()
 141  
     {
 142  1
         super.head();
 143  1
     }
 144  
 
 145  
     /**
 146  
      * Calls super.head_().
 147  
      */
 148  
     public void bookHead_()
 149  
     {
 150  1
         super.head_();
 151  1
     }
 152  
 
 153  
     /**
 154  
      * Calls super.title().
 155  
      */
 156  
     public void bookTitle()
 157  
     {
 158  1
         super.title();
 159  1
     }
 160  
 
 161  
     /**
 162  
      * Calls super.title_().
 163  
      */
 164  
     public void bookTitle_()
 165  
     {
 166  1
         super.title_();
 167  1
     }
 168  
 
 169  
     /**
 170  
      * Calls super.author().
 171  
      */
 172  
     public void bookAuthor()
 173  
     {
 174  1
         super.author();
 175  1
     }
 176  
 
 177  
     /**
 178  
      * Calls super.author_().
 179  
      */
 180  
     public void bookAuthor_()
 181  
     {
 182  1
         super.author_();
 183  1
     }
 184  
 
 185  
     /**
 186  
      * Calls super.date().
 187  
      */
 188  
     public void bookDate()
 189  
     {
 190  1
         super.date();
 191  1
     }
 192  
 
 193  
     /**
 194  
      * Calls super.date_().
 195  
      */
 196  
     public void bookDate_()
 197  
     {
 198  1
         super.date_();
 199  1
     }
 200  
 
 201  
     /**
 202  
      * Calls super.body().
 203  
      */
 204  
     public void bookBody()
 205  
     {
 206  1
         super.body();
 207  1
     }
 208  
 
 209  
     /**
 210  
      * Calls super.body_().
 211  
      */
 212  
     public void bookBody_()
 213  
     {
 214  1
         super.body_();
 215  1
     }
 216  
 
 217  
     /** {@inheritDoc} */
 218  
     public void sectionTitle()
 219  
     {
 220  2
         writeStartTag( H1 );
 221  2
     }
 222  
 
 223  
     /** {@inheritDoc} */
 224  
     public void sectionTitle_()
 225  
     {
 226  2
         writeEndTag( H1 );
 227  2
     }
 228  
 
 229  
     /** {@inheritDoc} */
 230  
     protected void write( String text )
 231  
     {
 232  98
         if ( renderingContext != null )
 233  
         {
 234  98
             String relativePathToBasedir = renderingContext.getRelativePath();
 235  
 
 236  98
             if ( relativePathToBasedir == null )
 237  
             {
 238  0
                 text = StringUtils.replace( text, "$relativePath", "." );
 239  
             }
 240  
             else
 241  
             {
 242  98
                 text = StringUtils.replace( text, "$relativePath", relativePathToBasedir );
 243  
             }
 244  
         }
 245  
 
 246  98
         super.write( text );
 247  98
     }
 248  
 }