~ubuntu-branches/ubuntu/vivid/doxia/vivid-proposed

« back to all changes in this revision

Viewing changes to doxia-book/src/main/java/org/apache/maven/doxia/book/services/renderer/XHtmlBookRenderer.java

  • Committer: Bazaar Package Importer
  • Author(s): Matthias Klose
  • Date: 2009-10-08 14:20:22 UTC
  • mfrom: (2.3.1 squeeze)
  • Revision ID: james.westby@ubuntu.com-20091008142022-f6ccxganfr2tbaig
Tags: 1.1-3build1
Upload to karmic, avoiding new version from unstable. LP: #443292.

Show diffs side-by-side

added added

removed removed

Lines of Context:
26
26
import org.apache.maven.doxia.book.model.Chapter;
27
27
import org.apache.maven.doxia.book.model.Section;
28
28
import org.apache.maven.doxia.book.services.renderer.xhtml.XhtmlBookSink;
29
 
import org.apache.maven.doxia.module.xhtml.decoration.render.RenderingContext;
 
29
import org.apache.maven.doxia.sink.render.RenderingContext;
30
30
import org.apache.maven.doxia.parser.manager.ParserNotFoundException;
31
31
import org.apache.maven.doxia.parser.ParseException;
32
32
import org.codehaus.plexus.logging.AbstractLogEnabled;
 
33
import org.codehaus.plexus.util.IOUtil;
 
34
import org.codehaus.plexus.util.ReaderFactory;
33
35
 
34
36
import java.io.File;
35
37
import java.io.FileNotFoundException;
36
 
import java.io.FileReader;
37
38
import java.io.FileWriter;
38
39
import java.io.IOException;
 
40
import java.io.Reader;
39
41
import java.io.Writer;
40
42
import java.util.Iterator;
41
43
 
42
44
/**
 
45
 * <p>XHtmlBookRenderer class.</p>
 
46
 *
43
47
 * @plexus.component role-hint="xhtml"
44
 
 *
45
48
 * @author <a href="mailto:trygvis@inamo.no">Trygve Laugst&oslash;l</a>
46
 
 * @version $Id: XHtmlBookRenderer.java 573052 2007-09-05 20:53:09Z ltheussl $
 
49
 * @version $Id: XHtmlBookRenderer.java 746976 2009-02-23 12:15:38Z vsiveton $
47
50
 */
48
51
public class XHtmlBookRenderer
49
52
    extends AbstractLogEnabled
89
92
        XhtmlBookSink sink = new XhtmlBookSink( fileWriter,
90
93
              new RenderingContext( context.getOutputDirectory(), bookFile.getAbsolutePath() ) );
91
94
 
92
 
        sink.bookHead();
93
 
        // TODO: book author, title?
94
 
        sink.bookHead_();
95
 
        sink.bookBody();
96
 
 
97
 
        int chapterNumber = 1;
98
 
 
99
 
        for ( Iterator it = book.getChapters().iterator(); it.hasNext(); )
100
 
        {
101
 
            Chapter chapter = (Chapter) it.next();
102
 
 
103
 
            sink.sectionTitle();
104
 
            sink.text( Integer.toString( chapterNumber ) + ". " + chapter.getTitle() );
105
 
            sink.sectionTitle_();
106
 
 
107
 
            renderChapter( sink, chapter, context );
108
 
 
109
 
            chapterNumber++;
110
 
        }
111
 
 
112
 
        sink.bookBody_();
113
 
 
114
95
        try
115
96
        {
116
 
            fileWriter.close();
 
97
            sink.bookHead();
 
98
            // TODO: book author, title?
 
99
            sink.bookHead_();
 
100
            sink.bookBody();
 
101
 
 
102
            int chapterNumber = 1;
 
103
 
 
104
            for ( Iterator it = book.getChapters().iterator(); it.hasNext(); )
 
105
            {
 
106
                Chapter chapter = (Chapter) it.next();
 
107
 
 
108
                sink.sectionTitle();
 
109
                sink.text( Integer.toString( chapterNumber ) + ". " + chapter.getTitle() );
 
110
                sink.sectionTitle_();
 
111
 
 
112
                renderChapter( sink, chapter, context );
 
113
 
 
114
                chapterNumber++;
 
115
            }
 
116
 
 
117
            sink.bookBody_();
117
118
        }
118
 
        catch ( IOException e )
 
119
        finally
119
120
        {
120
 
            throw new BookDoxiaException( "Error while closing file.", e );
 
121
            sink.flush();
 
122
 
 
123
            sink.close();
 
124
 
 
125
            IOUtil.close( fileWriter );
121
126
        }
122
127
    }
123
128
 
164
169
            throw new BookDoxiaException( "No document that matches section with id=" + section.getId() + "." );
165
170
        }
166
171
 
 
172
        Reader reader = null;
167
173
        try
168
174
        {
169
 
            doxia.parse( new FileReader( bookFile.getFile() ), bookFile.getParserId(), sink );
 
175
            reader = ReaderFactory.newReader( bookFile.getFile(), context.getInputEncoding() );
 
176
            doxia.parse( reader, bookFile.getParserId(), sink );
170
177
        }
171
178
        catch ( ParserNotFoundException e )
172
179
        {
183
190
            throw new BookDoxiaException( "Could not find document: "
184
191
                      + bookFile.getFile().getAbsolutePath() + ".", e );
185
192
        }
 
193
        catch ( IOException e )
 
194
        {
 
195
            throw new BookDoxiaException( "Error while rendering book: "
 
196
                      + bookFile.getFile().getAbsolutePath() + ".", e );
 
197
        }
 
198
        finally
 
199
        {
 
200
            IOUtil.close( reader );
 
201
        }
186
202
 
187
203
        sink.section2_();
188
204
    }