Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
SectionXdocBookSink |
|
| 1.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 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 | 8 | super( out, i18n, locale ); |
51 | ||
52 | 8 | this.indexEntry = indexEntry; |
53 | 8 | } |
54 | ||
55 | /** {@inheritDoc} */ | |
56 | protected void navigationPanel() | |
57 | { | |
58 | 16 | write( "<!--Navigation Panel-->" ); |
59 | ||
60 | 16 | write( "<table width=\"100%\" align=\"center\" border=\"0\">" ); |
61 | 16 | write( "<tr>" ); |
62 | ||
63 | 16 | IndexEntry parent = indexEntry.getParent(); |
64 | ||
65 | // ----------------------------------------------------------------------- | |
66 | // Prev | |
67 | // ----------------------------------------------------------------------- | |
68 | ||
69 | 16 | IndexEntry prevEntry = indexEntry.getPrevEntry(); |
70 | ||
71 | 16 | write( "<td align=\"left\">" ); |
72 | ||
73 | 16 | previous( parent, prevEntry ); |
74 | ||
75 | 16 | write( "</td>" ); |
76 | ||
77 | // ----------------------------------------------------------------------- | |
78 | // Parent | |
79 | // ----------------------------------------------------------------------- | |
80 | ||
81 | 16 | write( "<td align=\"center\">" ); |
82 | 16 | up( parent ); |
83 | 16 | write( "</td>" ); |
84 | ||
85 | // ----------------------------------------------------------------------- | |
86 | // Next | |
87 | // ----------------------------------------------------------------------- | |
88 | ||
89 | 16 | IndexEntry nextEntry = indexEntry.getNextEntry(); |
90 | ||
91 | 16 | write( "<td align=\"right\">" ); |
92 | ||
93 | 16 | next( parent, nextEntry ); |
94 | ||
95 | 16 | write( "</td>" ); |
96 | ||
97 | 16 | write( "</tr>" ); |
98 | 16 | write( "</table>" ); |
99 | ||
100 | 16 | write( "<!--End of Navigation Panel-->" ); |
101 | 16 | } |
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 | 16 | if ( prevEntry != null ) |
112 | { | |
113 | 8 | write( getString( "previous" ) + ": <a href=\"" + prevEntry.getId() + ".html\">" ); |
114 | 8 | content( prevEntry.getTitle() ); |
115 | 8 | write( "</a>" ); |
116 | } | |
117 | else | |
118 | { | |
119 | 8 | write( getString( "previous" ) + ": <a href=\"" + parent.getId() + ".html\">" ); |
120 | 8 | content( parent.getTitle() ); |
121 | 8 | write( "</a>" ); |
122 | } | |
123 | 16 | } |
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 | 16 | write( getString( "up" ) + ": <a href=\"" + parent.getId() + ".html\">" + parent.getTitle() + "</a>" ); |
134 | 16 | } |
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 | 16 | if ( nextEntry != null ) |
145 | { | |
146 | 8 | write( getString( "next" ) + ": <a href=\"" + nextEntry.getId() + ".html\">" ); |
147 | 8 | content( nextEntry.getTitle() ); |
148 | 8 | write( "</a>" ); |
149 | } | |
150 | else | |
151 | { | |
152 | 8 | IndexEntry nextChapter = parent.getNextEntry(); |
153 | ||
154 | 8 | if ( nextChapter == null ) |
155 | { | |
156 | 4 | write( "<i>End of book</i>" ); |
157 | } | |
158 | else | |
159 | { | |
160 | 4 | write( getString( "next" ) + ": <a href=\"" + nextChapter.getId() + ".html\">" ); |
161 | 4 | content( nextChapter.getTitle() ); |
162 | 4 | write( "</a>" ); |
163 | } | |
164 | } | |
165 | 16 | } |
166 | } |