Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
DocBookBookSink |
|
| 1.0869565217391304;1,087 |
1 | package org.apache.maven.doxia.book.services.renderer.docbook; | |
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 | ||
24 | import javax.swing.text.MutableAttributeSet; | |
25 | import javax.swing.text.html.HTML.Tag; | |
26 | ||
27 | import org.apache.maven.doxia.module.docbook.DocBookSink; | |
28 | ||
29 | /** | |
30 | * An Docbook Sink that doesn't write out head or body elements for every section of a book, and has some convenience | |
31 | * methods relating to the construction of a Doxia Book. | |
32 | * | |
33 | * @author Dave Syer | |
34 | * @version $Id: DocBookBookSink.java 808201 2009-08-26 22:04:43Z vsiveton $ | |
35 | * @since 1.1 | |
36 | */ | |
37 | public class DocBookBookSink | |
38 | extends DocBookSink | |
39 | { | |
40 | /** Indicates if we're inside a head. */ | |
41 | 40 | private boolean hasHead = false; |
42 | ||
43 | /** | |
44 | * Construct a new DocBookSink. | |
45 | * | |
46 | * @param out the writer for the sink. | |
47 | */ | |
48 | public DocBookBookSink( Writer out ) | |
49 | { | |
50 | 40 | super( out ); |
51 | ||
52 | 40 | setSystemId( "http://www.oasis-open.org/docbook/xml/4.4/docbookx.dtd" ); |
53 | 40 | setPublicId( "-//OASIS//DTD DocBook V4.4//EN" ); |
54 | 40 | } |
55 | ||
56 | // ---------------------------------------------------------------------- | |
57 | // | |
58 | // ---------------------------------------------------------------------- | |
59 | ||
60 | /** | |
61 | * {@inheritDoc} | |
62 | * | |
63 | * Does nothing because we don't want the header from each document to crop up in the middle of a book. | |
64 | */ | |
65 | public void head() | |
66 | { | |
67 | // noop | |
68 | 6 | } |
69 | ||
70 | /** | |
71 | * {@inheritDoc} | |
72 | * | |
73 | * Does nothing because we don't want the header from each document to crop up in the middle of a book. | |
74 | */ | |
75 | public void head_() | |
76 | { | |
77 | // noop | |
78 | 6 | } |
79 | ||
80 | /** | |
81 | * {@inheritDoc} | |
82 | * | |
83 | * Marks the skip flag to true so that this element's text is not emitted by the base class. | |
84 | */ | |
85 | public void title() | |
86 | { | |
87 | 6 | setSkip( true ); |
88 | 6 | } |
89 | ||
90 | /** | |
91 | * {@inheritDoc} | |
92 | * | |
93 | * Marks the skip flag to false so that rendering can resume. | |
94 | */ | |
95 | public void title_() | |
96 | { | |
97 | 6 | setSkip( false ); |
98 | 6 | } |
99 | ||
100 | /** | |
101 | * {@inheritDoc} | |
102 | * | |
103 | * Marks the skip flag to true so that this element's text is not emitted by the base class. | |
104 | */ | |
105 | public void author() | |
106 | { | |
107 | 6 | setSkip( true ); |
108 | 6 | } |
109 | ||
110 | /** | |
111 | * {@inheritDoc} | |
112 | * | |
113 | * Marks the skip flag to false so that rendering can resume. | |
114 | */ | |
115 | public void author_() | |
116 | { | |
117 | 6 | setSkip( false ); |
118 | 6 | } |
119 | ||
120 | /** | |
121 | * {@inheritDoc} | |
122 | * | |
123 | * Does nothing because we don't want the header from each document to crop up in the middle of a book. | |
124 | */ | |
125 | public void body() | |
126 | { | |
127 | // noop | |
128 | 6 | } |
129 | ||
130 | /** | |
131 | * {@inheritDoc} | |
132 | * | |
133 | * Does nothing because we don't want the header from each document to crop up in the middle of a book. | |
134 | */ | |
135 | public void body_() | |
136 | { | |
137 | // noop | |
138 | 6 | } |
139 | ||
140 | /** | |
141 | * Emit the start tag for the book. | |
142 | * | |
143 | * @see org.apache.maven.doxia.module.docbook.DocbookMarkup#BOOK_TAG | |
144 | */ | |
145 | public void book() | |
146 | { | |
147 | 2 | init(); |
148 | ||
149 | 2 | MutableAttributeSet att = writeXmlHeader( "book" ); |
150 | ||
151 | 2 | writeStartTag( BOOK_TAG, att ); |
152 | ||
153 | 2 | } |
154 | ||
155 | /** | |
156 | * Emit the end tag for the book. | |
157 | * | |
158 | * @see org.apache.maven.doxia.module.docbook.DocbookMarkup#BOOK_TAG | |
159 | */ | |
160 | public void book_() | |
161 | { | |
162 | 2 | writeEndTag( BOOK_TAG ); |
163 | 2 | flush(); |
164 | 2 | } |
165 | ||
166 | /** If no header matter has yet been encountered emit the book info start tag. */ | |
167 | private void bookHead() | |
168 | { | |
169 | 4 | if ( !hasHead ) |
170 | { | |
171 | 4 | writeStartTag( BOOKINFO_TAG ); |
172 | 4 | hasHead = true; |
173 | } | |
174 | 4 | } |
175 | ||
176 | /** | |
177 | * If some header matter has been encountered emit the book info end tag. | |
178 | */ | |
179 | public void bookHead_() | |
180 | { | |
181 | 2 | if ( hasHead ) |
182 | { | |
183 | 1 | writeEndTag( BOOKINFO_TAG ); |
184 | 1 | hasHead = false; |
185 | } | |
186 | 2 | } |
187 | ||
188 | /** | |
189 | * Emit the title start tag for the whole book. | |
190 | */ | |
191 | public void bookTitle() | |
192 | { | |
193 | 2 | bookHead(); |
194 | 2 | writeStartTag( Tag.TITLE ); |
195 | 2 | } |
196 | ||
197 | /** | |
198 | * Emit the title end tag for the whole book. | |
199 | */ | |
200 | public void bookTitle_() | |
201 | { | |
202 | 2 | super.title_(); |
203 | 2 | } |
204 | ||
205 | /** | |
206 | * Emit the author start tag for the whole book. | |
207 | */ | |
208 | public void bookAuthor() | |
209 | { | |
210 | 1 | bookHead(); |
211 | 1 | super.author(); |
212 | 1 | } |
213 | ||
214 | /** | |
215 | * Emit the author end tag for the whole book. | |
216 | */ | |
217 | public void bookAuthor_() | |
218 | { | |
219 | 1 | super.author_(); |
220 | 1 | } |
221 | ||
222 | /** | |
223 | * Emit the date start tag for the whole book. | |
224 | */ | |
225 | public void bookDate() | |
226 | { | |
227 | 1 | bookHead(); |
228 | 1 | super.date(); |
229 | 1 | } |
230 | ||
231 | /** | |
232 | * Emit the date end tag for the whole book. | |
233 | */ | |
234 | public void bookDate_() | |
235 | { | |
236 | 1 | super.date_(); |
237 | 1 | } |
238 | ||
239 | /** | |
240 | * Emit the chapter start tag. | |
241 | */ | |
242 | public void chapter() | |
243 | { | |
244 | 3 | writeStartTag( CHAPTER_TAG ); |
245 | 3 | } |
246 | ||
247 | /** | |
248 | * Emit the chapter end tag. | |
249 | */ | |
250 | public void chapter_() | |
251 | { | |
252 | 3 | writeEndTag( CHAPTER_TAG ); |
253 | 3 | } |
254 | ||
255 | /** | |
256 | * Emit the chapter title start tag. | |
257 | */ | |
258 | public void chapterTitle() | |
259 | { | |
260 | 3 | writeStartTag( Tag.TITLE ); |
261 | 3 | } |
262 | ||
263 | /** | |
264 | * Emit the chapter title end tag. | |
265 | */ | |
266 | public void chapterTitle_() | |
267 | { | |
268 | 3 | writeEndTag( Tag.TITLE ); |
269 | 3 | } |
270 | } |