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 section in a book
30 *
31 * @author <a href="mailto:vincent.siveton@gmail.com">Vincent Siveton</a>
32 * @version $Id: SectionXdocBookSink.java 782330 2009-06-07 05:55:26Z ltheussl $
33 */
34 public class SectionXdocBookSink
35 extends AbstractXdocBookSink
36 {
37 /** indexEntry. */
38 private final IndexEntry indexEntry;
39
40 /**
41 * Default constructor.
42 *
43 * @param out the Writer to use.
44 * @param indexEntry the IndexEntry.
45 * @param i18n the I18N.
46 * @param locale wanted locale.
47 */
48 public SectionXdocBookSink( Writer out, IndexEntry indexEntry, I18N i18n, Locale locale )
49 {
50 super( out, i18n, locale );
51
52 this.indexEntry = indexEntry;
53 }
54
55 /** {@inheritDoc} */
56 protected void navigationPanel()
57 {
58 write( "<!--Navigation Panel-->" );
59
60 write( "<table width=\"100%\" align=\"center\" border=\"0\">" );
61 write( "<tr>" );
62
63 IndexEntry parent = indexEntry.getParent();
64
65 // -----------------------------------------------------------------------
66 // Prev
67 // -----------------------------------------------------------------------
68
69 IndexEntry prevEntry = indexEntry.getPrevEntry();
70
71 write( "<td align=\"left\">" );
72
73 previous( parent, prevEntry );
74
75 write( "</td>" );
76
77 // -----------------------------------------------------------------------
78 // Parent
79 // -----------------------------------------------------------------------
80
81 write( "<td align=\"center\">" );
82 up( parent );
83 write( "</td>" );
84
85 // -----------------------------------------------------------------------
86 // Next
87 // -----------------------------------------------------------------------
88
89 IndexEntry nextEntry = indexEntry.getNextEntry();
90
91 write( "<td align=\"right\">" );
92
93 next( parent, nextEntry );
94
95 write( "</td>" );
96
97 write( "</tr>" );
98 write( "</table>" );
99
100 write( "<!--End of Navigation Panel-->" );
101 }
102
103 /**
104 * Add previous link.
105 *
106 * @param parent the parent IndexEntry.
107 * @param prevEntry the previous IndexEntry.
108 */
109 protected void previous( IndexEntry parent, IndexEntry prevEntry )
110 {
111 if ( prevEntry != null )
112 {
113 write( getString( "previous" ) + ": <a href=\"" + prevEntry.getId() + ".html\">" );
114 content( prevEntry.getTitle() );
115 write( "</a>" );
116 }
117 else
118 {
119 write( getString( "previous" ) + ": <a href=\"" + parent.getId() + ".html\">" );
120 content( parent.getTitle() );
121 write( "</a>" );
122 }
123 }
124
125 /**
126 * Add parent/up link.
127 *
128 * @param parent the parent IndexEntry.
129 * @see org.apache.maven.doxia.book.services.renderer.xdoc.ChapterXdocBookSink#up()
130 */
131 protected void up( IndexEntry parent )
132 {
133 write( getString( "up" ) + ": <a href=\"" + parent.getId() + ".html\">" + parent.getTitle() + "</a>" );
134 }
135
136 /**
137 * Add next link.
138 *
139 * @param parent the parent IndexEntry.
140 * @param nextEntry the next IndexEntry.
141 */
142 protected void next( IndexEntry parent, IndexEntry nextEntry )
143 {
144 if ( nextEntry != null )
145 {
146 write( getString( "next" ) + ": <a href=\"" + nextEntry.getId() + ".html\">" );
147 content( nextEntry.getTitle() );
148 write( "</a>" );
149 }
150 else
151 {
152 IndexEntry nextChapter = parent.getNextEntry();
153
154 if ( nextChapter == null )
155 {
156 write( "<i>End of book</i>" );
157 }
158 else
159 {
160 write( getString( "next" ) + ": <a href=\"" + nextChapter.getId() + ".html\">" );
161 content( nextChapter.getTitle() );
162 write( "</a>" );
163 }
164 }
165 }
166 }