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