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ø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 super( out ); 56 57 this.i18n = i18n; 58 this.locale = locale; 59 } 60 61 /** {@inheritDoc} */ 62 public void date_() 63 { 64 // nop 65 } 66 67 /** {@inheritDoc} */ 68 public void body() 69 { 70 writeStartTag( BODY ); 71 72 write( "<section name=\"\">" ); 73 74 navigationPanel(); 75 horizontalRule(); 76 77 write( "</section>" ); 78 } 79 80 /** {@inheritDoc} */ 81 public void body_() 82 { 83 write( "<section name=\"\">" ); 84 85 horizontalRule(); 86 87 navigationPanel(); 88 89 write( "</section>" ); 90 91 writeEndTag( BODY ); 92 93 writeEndTag( DOCUMENT_TAG ); 94 95 flush(); 96 97 close(); 98 99 init(); 100 } 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 if ( StringUtils.isEmpty( key ) ) 115 { 116 throw new IllegalArgumentException( "The key cannot be empty" ); 117 } 118 119 return i18n.getString( "book-renderer", locale, key ).trim(); 120 } 121 122 /** 123 * Add a navigation panel. 124 */ 125 protected abstract void navigationPanel(); 126 }