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