private SectionInfo writeSection()

in src/main/java/org/apache/maven/doxia/book/services/renderer/LatexBookRenderer.java [193:245]


    private SectionInfo writeSection( Section section, BookContext context )
        throws IOException, BookDoxiaException
    {
        File file = new File( context.getOutputDirectory(), ( section.getId() + ".tex" ) );

        Writer writer = WriterFactory.newWriter( file, context.getOutputEncoding() );

        LatexBookSink sink = new LatexBookSink( writer );

        BookContext.BookFile bookFile = (BookContext.BookFile) context.getFiles().get( section.getId() );

        if ( bookFile == null )
        {
            throw new BookDoxiaException( "No document that matches section with id="
                        + section.getId() + "." );
        }

        Reader reader = null;
        try
        {
            reader = ReaderFactory.newReader( bookFile.getFile(), context.getInputEncoding() );
            doxia.parse( reader, bookFile.getParserId(), sink );
        }
        catch ( ParserNotFoundException e )
        {
            throw new BookDoxiaException( "Parser not found: "
                        + bookFile.getParserId() + ".", e );
        }
        catch ( ParseException e )
        {
            throw new BookDoxiaException( "Error while parsing document: "
                        + bookFile.getFile().getAbsolutePath() + ".", e );
        }
        catch ( FileNotFoundException e )
        {
            throw new BookDoxiaException( "Could not find document: "
                        + bookFile.getFile().getAbsolutePath() + ".", e );
        }
        finally
        {
            sink.flush();
            sink.close();

            IOUtil.close( reader );
            IOUtil.close( writer );
        }

        SectionInfo info = new SectionInfo();
        info.id = section.getId();
        info.title = sink.getTitle();

        return info;
    }