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  2
         super( out, i18n, locale );
 51  
 
 52  2
         this.chapterIndex = chapterIndex;
 53  2
     }
 54  
 
 55  
     /** {@inheritDoc} */
 56  
     protected void navigationPanel()
 57  
     {
 58  4
         write( "<!--Navigation Panel-->" );
 59  
 
 60  4
         write( "<table width=\"100%\" align=\"center\">" );
 61  4
         write( "<tr>" );
 62  
 
 63  
         // -----------------------------------------------------------------------
 64  
         // Prev
 65  
         // -----------------------------------------------------------------------
 66  
 
 67  4
         IndexEntry prevChapter = chapterIndex.getPrevEntry();
 68  
 
 69  4
         write( "<td><div align=\"left\">" );
 70  
 
 71  4
         previous( prevChapter );
 72  
 
 73  4
         write( "</div></td>" );
 74  
 
 75  
         // -----------------------------------------------------------------------
 76  
         // Parent
 77  
         // -----------------------------------------------------------------------
 78  
 
 79  4
         write( "<td><div align=\"center\">" );
 80  4
         up();
 81  4
         write( "</div></td>" );
 82  
 
 83  
         // -----------------------------------------------------------------------
 84  
         // Next
 85  
         // -----------------------------------------------------------------------
 86  
 
 87  4
         write( "<td><div align=\"right\">" );
 88  
 
 89  4
         next();
 90  
 
 91  4
         write( "</div></td>" );
 92  
 
 93  4
         write( "</tr>" );
 94  4
         write( "</table>" );
 95  
 
 96  4
         write( "<!--End of Navigation Panel-->" );
 97  4
     }
 98  
 
 99  
     /**
 100  
      * Add previous link.
 101  
      *
 102  
      * @param prevChapter the previous IndexEntry.
 103  
      */
 104  
     protected void previous( IndexEntry prevChapter )
 105  
     {
 106  4
         if ( prevChapter != null )
 107  
         {
 108  2
             IndexEntry lastEntry = prevChapter.getLastEntry();
 109  2
             if ( lastEntry == null )
 110  
             {
 111  0
                 write( "<i>Start of book</i>" );
 112  
             }
 113  
             else
 114  
             {
 115  2
                 write( getString( "previous" ) + ": <a href=\"" + lastEntry.getId() + ".html\">" );
 116  2
                 content( lastEntry.getTitle() );
 117  2
                 write( "</a>" );
 118  
             }
 119  2
         }
 120  
         else
 121  
         {
 122  2
             write( getString( "previous" ) + ":<a href=\"index.html\">" + getString( "toc" ) + "</a>" );
 123  
         }
 124  4
     }
 125  
 
 126  
     /**
 127  
      * Add parent/up link.
 128  
      */
 129  
     protected void up()
 130  
     {
 131  4
         write( getString( "up" ) + ": <a href=\"index.html\">" + getString( "toc" ) + "</a>" );
 132  4
     }
 133  
 
 134  
     /**
 135  
      * Add next link
 136  
      */
 137  
     protected void next()
 138  
     {
 139  4
         IndexEntry firstEntry = chapterIndex.getFirstEntry();
 140  4
         if ( firstEntry == null )
 141  
         {
 142  0
             write( "<i>End of book</i>" );
 143  
         }
 144  
         else
 145  
         {
 146  4
             write( getString( "next" ) + ": <a href=\"" + firstEntry.getId() + ".html\">" );
 147  4
             content( firstEntry.getTitle() );
 148  4
             write( "</a>" );
 149  
         }
 150  4
     }
 151  
 }