Coverage Report - org.apache.maven.doxia.book.services.renderer.xdoc.ChapterXdocBookSink
 
Classes in this File Line Coverage Branch Coverage Complexity
ChapterXdocBookSink
94%
37/39
66%
4/6
1,6
 
 1  
 package org.apache.maven.doxia.book.services.renderer.xdoc;
 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.Writer;
 23  
 import java.util.Locale;
 24  
 
 25  
 import org.apache.maven.doxia.index.IndexEntry;
 26  
 import org.codehaus.plexus.i18n.I18N;
 27  
 
 28  
 /**
 29  
  * A <code>XdocSink</code> implementation for chapter in a book.
 30  
  *
 31  
  * @author <a href="mailto:vincent.siveton@gmail.com">Vincent Siveton</a>
 32  
  * @version $Id: ChapterXdocBookSink.java 782330 2009-06-07 05:55:26Z ltheussl $
 33  
  */
 34  
 public class ChapterXdocBookSink
 35  
     extends AbstractXdocBookSink
 36  
 {
 37  
    /** the chapter IndexEntry. */
 38  
     private final IndexEntry chapterIndex;
 39  
 
 40  
     /**
 41  
      * Default constructor.
 42  
      *
 43  
      * @param out the Writer.
 44  
      * @param chapterIndex the chapter IndexEntry.
 45  
      * @param i18n I18N.
 46  
      * @param locale wanted locale.
 47  
      */
 48  
     public ChapterXdocBookSink( Writer out, IndexEntry chapterIndex, I18N i18n, Locale locale )
 49  
     {
 50  4
         super( out, i18n, locale );
 51  
 
 52  4
         this.chapterIndex = chapterIndex;
 53  4
     }
 54  
 
 55  
     /** {@inheritDoc} */
 56  
     protected void navigationPanel()
 57  
     {
 58  8
         write( "<!--Navigation Panel-->" );
 59  
 
 60  8
         write( "<table width=\"100%\" align=\"center\">" );
 61  8
         write( "<tr>" );
 62  
 
 63  
         // -----------------------------------------------------------------------
 64  
         // Prev
 65  
         // -----------------------------------------------------------------------
 66  
 
 67  8
         IndexEntry prevChapter = chapterIndex.getPrevEntry();
 68  
 
 69  8
         write( "<td><div align=\"left\">" );
 70  
 
 71  8
         previous( prevChapter );
 72  
 
 73  8
         write( "</div></td>" );
 74  
 
 75  
         // -----------------------------------------------------------------------
 76  
         // Parent
 77  
         // -----------------------------------------------------------------------
 78  
 
 79  8
         write( "<td><div align=\"center\">" );
 80  8
         up();
 81  8
         write( "</div></td>" );
 82  
 
 83  
         // -----------------------------------------------------------------------
 84  
         // Next
 85  
         // -----------------------------------------------------------------------
 86  
 
 87  8
         write( "<td><div align=\"right\">" );
 88  
 
 89  8
         next();
 90  
 
 91  8
         write( "</div></td>" );
 92  
 
 93  8
         write( "</tr>" );
 94  8
         write( "</table>" );
 95  
 
 96  8
         write( "<!--End of Navigation Panel-->" );
 97  8
     }
 98  
 
 99  
     /**
 100  
      * Add previous link.
 101  
      *
 102  
      * @param prevChapter the previous IndexEntry.
 103  
      */
 104  
     protected void previous( IndexEntry prevChapter )
 105  
     {
 106  8
         if ( prevChapter != null )
 107  
         {
 108  4
             IndexEntry lastEntry = prevChapter.getLastEntry();
 109  4
             if ( lastEntry == null )
 110  
             {
 111  0
                 write( "<i>Start of book</i>" );
 112  
             }
 113  
             else
 114  
             {
 115  4
                 write( getString( "previous" ) + ": <a href=\"" + lastEntry.getId() + ".html\">" );
 116  4
                 content( lastEntry.getTitle() );
 117  4
                 write( "</a>" );
 118  
             }
 119  4
         }
 120  
         else
 121  
         {
 122  4
             write( getString( "previous" ) + ":<a href=\"index.html\">" + getString( "toc" ) + "</a>" );
 123  
         }
 124  8
     }
 125  
 
 126  
     /**
 127  
      * Add parent/up link.
 128  
      */
 129  
     protected void up()
 130  
     {
 131  8
         write( getString( "up" ) + ": <a href=\"index.html\">" + getString( "toc" ) + "</a>" );
 132  8
     }
 133  
 
 134  
     /**
 135  
      * Add next link
 136  
      */
 137  
     protected void next()
 138  
     {
 139  8
         IndexEntry firstEntry = chapterIndex.getFirstEntry();
 140  8
         if ( firstEntry == null )
 141  
         {
 142  0
             write( "<i>End of book</i>" );
 143  
         }
 144  
         else
 145  
         {
 146  8
             write( getString( "next" ) + ": <a href=\"" + firstEntry.getId() + ".html\">" );
 147  8
             content( firstEntry.getTitle() );
 148  8
             write( "</a>" );
 149  
         }
 150  8
     }
 151  
 }