Coverage Report - org.apache.maven.doxia.book.services.renderer.xdoc.AbstractXdocBookSink
 
Classes in this File Line Coverage Branch Coverage Complexity
AbstractXdocBookSink
91%
22/24
50%
1/2
1,333
 
 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.module.xdoc.XdocSink;
 26  
 
 27  
 import org.codehaus.plexus.i18n.I18N;
 28  
 import org.codehaus.plexus.util.StringUtils;
 29  
 
 30  
 /**
 31  
  * Abstract <code>XdocSink</code> implementation for book.
 32  
  *
 33  
  * @author <a href="mailto:trygvis@inamo.no">Trygve Laugst&oslash;l</a>
 34  
  * @author <a href="mailto:vincent.siveton@gmail.com">Vincent Siveton</a>
 35  
  * @version $Id: AbstractXdocBookSink.java 808201 2009-08-26 22:04:43Z vsiveton $
 36  
  */
 37  
 public abstract class AbstractXdocBookSink
 38  
     extends XdocSink
 39  
 {
 40  
     /** I18N for localized messages. */
 41  
     private final I18N i18n;
 42  
 
 43  
     /** The wanted locale */
 44  
     private final Locale locale;
 45  
 
 46  
     /**
 47  
      * Default constructor.
 48  
      *
 49  
      * @param out a Writer.
 50  
      * @param i18n I18N.
 51  
      * @param locale the wanted locale.
 52  
      */
 53  
     public AbstractXdocBookSink( Writer out, I18N i18n, Locale locale )
 54  
     {
 55  14
         super( out );
 56  
 
 57  14
         this.i18n = i18n;
 58  14
         this.locale = locale;
 59  14
     }
 60  
 
 61  
     /** {@inheritDoc} */
 62  
     public void date_()
 63  
     {
 64  
         // nop
 65  0
     }
 66  
 
 67  
     /** {@inheritDoc} */
 68  
     public void body()
 69  
     {
 70  14
         writeStartTag( BODY );
 71  
 
 72  14
         write( "<section name=\"\">" );
 73  
 
 74  14
         navigationPanel();
 75  14
         horizontalRule();
 76  
 
 77  14
         write( "</section>" );
 78  14
     }
 79  
 
 80  
     /** {@inheritDoc} */
 81  
     public void body_()
 82  
     {
 83  14
         write( "<section name=\"\">" );
 84  
 
 85  14
         horizontalRule();
 86  
 
 87  14
         navigationPanel();
 88  
 
 89  14
         write( "</section>" );
 90  
 
 91  14
         writeEndTag( BODY );
 92  
 
 93  14
         writeEndTag( DOCUMENT_TAG );
 94  
 
 95  14
         flush();
 96  
 
 97  14
         close();
 98  
 
 99  14
         init();
 100  14
     }
 101  
 
 102  
     // -----------------------------------------------------------------------
 103  
     // Protected
 104  
     // -----------------------------------------------------------------------
 105  
 
 106  
     /**
 107  
      * Gets a trimmed String for the given key from the resource bundle defined by Plexus.
 108  
      *
 109  
      * @param key the key for the desired string
 110  
      * @return the string for the given key
 111  
      */
 112  
     protected String getString( String key )
 113  
     {
 114  84
         if ( StringUtils.isEmpty( key ) )
 115  
         {
 116  0
             throw new IllegalArgumentException( "The key cannot be empty" );
 117  
         }
 118  
 
 119  84
         return i18n.getString( "book-renderer", locale, key ).trim();
 120  
     }
 121  
 
 122  
     /**
 123  
      * Add a navigation panel.
 124  
      */
 125  
     protected abstract void navigationPanel();
 126  
 }