View Javadoc

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          super( out );
48          this.renderingContext = context;
49      }
50  
51      // ----------------------------------------------------------------------
52      //
53      // ----------------------------------------------------------------------
54  
55      /**
56       * {@inheritDoc}
57       *
58       * Does nothing.
59       */
60      public void head()
61      {
62          init();
63  
64          setHeadFlag( true );
65      }
66  
67      /**
68       * {@inheritDoc}
69       *
70       * Does nothing.
71       */
72      public void head_()
73      {
74          setHeadFlag( false );
75      }
76  
77      /**
78       * {@inheritDoc}
79       *
80       * Does nothing.
81       */
82      public void title()
83      {
84          // noop
85      }
86  
87      /**
88       * {@inheritDoc}
89       *
90       * Does nothing.
91       */
92      public void title_()
93      {
94          resetTextBuffer();
95      }
96  
97      /**
98       * {@inheritDoc}
99       *
100      * Does nothing.
101      */
102     public void author_()
103     {
104         resetTextBuffer();
105     }
106 
107     /**
108      * {@inheritDoc}
109      *
110      * Does nothing.
111      */
112     public void date_()
113     {
114         resetTextBuffer();
115     }
116 
117     /**
118      * {@inheritDoc}
119      *
120      * Does nothing.
121      */
122     public void body()
123     {
124         // noop
125     }
126 
127     /**
128      * {@inheritDoc}
129      *
130      * Does nothing.
131      */
132     public void body_()
133     {
134         // noop
135     }
136 
137     /**
138      * Calls super.head().
139      */
140     public void bookHead()
141     {
142         super.head();
143     }
144 
145     /**
146      * Calls super.head_().
147      */
148     public void bookHead_()
149     {
150         super.head_();
151     }
152 
153     /**
154      * Calls super.title().
155      */
156     public void bookTitle()
157     {
158         super.title();
159     }
160 
161     /**
162      * Calls super.title_().
163      */
164     public void bookTitle_()
165     {
166         super.title_();
167     }
168 
169     /**
170      * Calls super.author().
171      */
172     public void bookAuthor()
173     {
174         super.author();
175     }
176 
177     /**
178      * Calls super.author_().
179      */
180     public void bookAuthor_()
181     {
182         super.author_();
183     }
184 
185     /**
186      * Calls super.date().
187      */
188     public void bookDate()
189     {
190         super.date();
191     }
192 
193     /**
194      * Calls super.date_().
195      */
196     public void bookDate_()
197     {
198         super.date_();
199     }
200 
201     /**
202      * Calls super.body().
203      */
204     public void bookBody()
205     {
206         super.body();
207     }
208 
209     /**
210      * Calls super.body_().
211      */
212     public void bookBody_()
213     {
214         super.body_();
215     }
216 
217     /** {@inheritDoc} */
218     public void sectionTitle()
219     {
220         writeStartTag( H1 );
221     }
222 
223     /** {@inheritDoc} */
224     public void sectionTitle_()
225     {
226         writeEndTag( H1 );
227     }
228 
229     /** {@inheritDoc} */
230     protected void write( String text )
231     {
232         if ( renderingContext != null )
233         {
234             String relativePathToBasedir = renderingContext.getRelativePath();
235 
236             if ( relativePathToBasedir == null )
237             {
238                 text = StringUtils.replace( text, "$relativePath", "." );
239             }
240             else
241             {
242                 text = StringUtils.replace( text, "$relativePath", relativePathToBasedir );
243             }
244         }
245 
246         super.write( text );
247     }
248 }