Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
XhtmlBookSink |
|
| 1.0909090909090908;1,091 |
1 | package org.apache.maven.doxia.book.services.renderer.xhtml; | |
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 org.apache.maven.doxia.module.xhtml.XhtmlSink; | |
23 | import org.apache.maven.doxia.sink.render.RenderingContext; | |
24 | import org.codehaus.plexus.util.StringUtils; | |
25 | ||
26 | import java.io.Writer; | |
27 | ||
28 | /** | |
29 | * An Xhtml Sink that doesn't write out head or body elements. | |
30 | * | |
31 | * @author ltheussl | |
32 | * @version $Id: XhtmlBookSink.java 808201 2009-08-26 22:04:43Z vsiveton $ | |
33 | */ | |
34 | public class XhtmlBookSink | |
35 | extends XhtmlSink | |
36 | { | |
37 | private RenderingContext renderingContext; | |
38 | ||
39 | /** | |
40 | * Construct a new XhtmlBookSink. | |
41 | * | |
42 | * @param out the writer for the sink. | |
43 | * @param context the RenderingContext. | |
44 | */ | |
45 | public XhtmlBookSink( Writer out, RenderingContext context ) | |
46 | { | |
47 | 2 | super( out ); |
48 | 2 | this.renderingContext = context; |
49 | 2 | } |
50 | ||
51 | // ---------------------------------------------------------------------- | |
52 | // | |
53 | // ---------------------------------------------------------------------- | |
54 | ||
55 | /** | |
56 | * {@inheritDoc} | |
57 | * | |
58 | * Does nothing. | |
59 | */ | |
60 | public void head() | |
61 | { | |
62 | 8 | init(); |
63 | ||
64 | 8 | setHeadFlag( true ); |
65 | 8 | } |
66 | ||
67 | /** | |
68 | * {@inheritDoc} | |
69 | * | |
70 | * Does nothing. | |
71 | */ | |
72 | public void head_() | |
73 | { | |
74 | 8 | setHeadFlag( false ); |
75 | 8 | } |
76 | ||
77 | /** | |
78 | * {@inheritDoc} | |
79 | * | |
80 | * Does nothing. | |
81 | */ | |
82 | public void title() | |
83 | { | |
84 | // noop | |
85 | 8 | } |
86 | ||
87 | /** | |
88 | * {@inheritDoc} | |
89 | * | |
90 | * Does nothing. | |
91 | */ | |
92 | public void title_() | |
93 | { | |
94 | 8 | resetTextBuffer(); |
95 | 8 | } |
96 | ||
97 | /** | |
98 | * {@inheritDoc} | |
99 | * | |
100 | * Does nothing. | |
101 | */ | |
102 | public void author_() | |
103 | { | |
104 | 8 | resetTextBuffer(); |
105 | 8 | } |
106 | ||
107 | /** | |
108 | * {@inheritDoc} | |
109 | * | |
110 | * Does nothing. | |
111 | */ | |
112 | public void date_() | |
113 | { | |
114 | 0 | resetTextBuffer(); |
115 | 0 | } |
116 | ||
117 | /** | |
118 | * {@inheritDoc} | |
119 | * | |
120 | * Does nothing. | |
121 | */ | |
122 | public void body() | |
123 | { | |
124 | // noop | |
125 | 8 | } |
126 | ||
127 | /** | |
128 | * {@inheritDoc} | |
129 | * | |
130 | * Does nothing. | |
131 | */ | |
132 | public void body_() | |
133 | { | |
134 | // noop | |
135 | 8 | } |
136 | ||
137 | /** | |
138 | * Calls super.head(). | |
139 | */ | |
140 | public void bookHead() | |
141 | { | |
142 | 2 | super.head(); |
143 | 2 | } |
144 | ||
145 | /** | |
146 | * Calls super.head_(). | |
147 | */ | |
148 | public void bookHead_() | |
149 | { | |
150 | 2 | super.head_(); |
151 | 2 | } |
152 | ||
153 | /** | |
154 | * Calls super.title(). | |
155 | */ | |
156 | public void bookTitle() | |
157 | { | |
158 | 2 | super.title(); |
159 | 2 | } |
160 | ||
161 | /** | |
162 | * Calls super.title_(). | |
163 | */ | |
164 | public void bookTitle_() | |
165 | { | |
166 | 2 | super.title_(); |
167 | 2 | } |
168 | ||
169 | /** | |
170 | * Calls super.author(). | |
171 | */ | |
172 | public void bookAuthor() | |
173 | { | |
174 | 2 | super.author(); |
175 | 2 | } |
176 | ||
177 | /** | |
178 | * Calls super.author_(). | |
179 | */ | |
180 | public void bookAuthor_() | |
181 | { | |
182 | 2 | super.author_(); |
183 | 2 | } |
184 | ||
185 | /** | |
186 | * Calls super.date(). | |
187 | */ | |
188 | public void bookDate() | |
189 | { | |
190 | 2 | super.date(); |
191 | 2 | } |
192 | ||
193 | /** | |
194 | * Calls super.date_(). | |
195 | */ | |
196 | public void bookDate_() | |
197 | { | |
198 | 2 | super.date_(); |
199 | 2 | } |
200 | ||
201 | /** | |
202 | * Calls super.body(). | |
203 | */ | |
204 | public void bookBody() | |
205 | { | |
206 | 2 | super.body(); |
207 | 2 | } |
208 | ||
209 | /** | |
210 | * Calls super.body_(). | |
211 | */ | |
212 | public void bookBody_() | |
213 | { | |
214 | 2 | super.body_(); |
215 | 2 | } |
216 | ||
217 | /** {@inheritDoc} */ | |
218 | public void sectionTitle() | |
219 | { | |
220 | 4 | writeStartTag( H1 ); |
221 | 4 | } |
222 | ||
223 | /** {@inheritDoc} */ | |
224 | public void sectionTitle_() | |
225 | { | |
226 | 4 | writeEndTag( H1 ); |
227 | 4 | } |
228 | ||
229 | /** {@inheritDoc} */ | |
230 | protected void write( String text ) | |
231 | { | |
232 | 196 | if ( renderingContext != null ) |
233 | { | |
234 | 196 | String relativePathToBasedir = renderingContext.getRelativePath(); |
235 | ||
236 | 196 | if ( relativePathToBasedir == null ) |
237 | { | |
238 | 0 | text = StringUtils.replace( text, "$relativePath", "." ); |
239 | } | |
240 | else | |
241 | { | |
242 | 196 | text = StringUtils.replace( text, "$relativePath", relativePathToBasedir ); |
243 | } | |
244 | } | |
245 | ||
246 | 196 | super.write( text ); |
247 | 196 | } |
248 | } |