public void renderBook()

in src/main/java/org/apache/maven/doxia/book/services/renderer/AbstractITextBookRenderer.java [67:168]


    public void renderBook( BookContext context )
        throws BookDoxiaException
    {
        BookModel book = context.getBook();

        if ( !context.getOutputDirectory().exists() )
        {
            if ( !context.getOutputDirectory().mkdirs() )
            {
                throw new BookDoxiaException( "Could not make directory: "
                    + context.getOutputDirectory().getAbsolutePath() + "." );
            }
        }

        File bookFile = new File( context.getOutputDirectory(), book.getId() + ".xml" );

        Writer fileWriter;
        try
        {
            fileWriter = WriterFactory.newXmlWriter( bookFile );
        }
        catch ( IOException e )
        {
            throw new BookDoxiaException( "Error while opening file.", e );
        }

        // ----------------------------------------------------------------------
        // Create the XML File
        // ----------------------------------------------------------------------

        PrettyPrintXMLWriter writer = new PrettyPrintXMLWriter( fileWriter, "UTF-8", null );
        writer.startElement( "itext" );
        writer.addAttribute( "creationdate", DateFormat.getDateTimeInstance().format( new Date() ) );
        writer.addAttribute( "producer", "Doxia iText" );

        //        writer.startElement( "paragraph" );
        //        writer.addAttribute( "leading", "18.0" );
        //        writer.addAttribute( "font", "unknown" );
        //        writer.addAttribute( "align", "Default" );
        //        writer.writeText( "Please visit my" + System.getProperty( "line.separator" ) );
        //
        //        writer.startElement( "anchor" );
        //        writer.addAttribute( "leading", "18.0" );
        //        writer.addAttribute( "font", "Helvetica" );
        //        writer.addAttribute( "size", "12.0" );
        //        writer.addAttribute( "fontstyle", "normal, underline" );
        //        writer.addAttribute( "red", "0" );
        //        writer.addAttribute( "green", "0" );
        //        writer.addAttribute( "blue", "255" );
        //        writer.addAttribute( "name", "top" );
        //        writer.addAttribute( "reference", "http://www.lowagie.com/iText/" );
        //
        //        writer.startElement( "chunk" );
        //        writer.addAttribute( "font", "Helvetica" );
        //        writer.addAttribute( "size", "12.0" );
        //        writer.addAttribute( "fontstyle", "normal, underline" );
        //        writer.addAttribute( "red", "0" );
        //        writer.addAttribute( "green", "0" );
        //        writer.addAttribute( "blue", "255" );
        //        writer.writeText( "website (external reference)" );
        //        writer.endElement();
        //
        //        writer.endElement(); // anchor
        //
        //        writer.endElement(); // paragraph

        // TODO: Write out TOC

        System.setProperty( "itext.basedir", bookFile.getParentFile().getAbsolutePath() );
        Sink sink = new ITextSinkFactory().createSink( writer );

        try
        {
            for ( Chapter chapter : book.getChapters() )
            {
                renderChapter( sink, writer, chapter, context );
            }

            writer.endElement(); // itext
        }
        finally
        {
            sink.flush();
            sink.close();

            IOUtil.close( fileWriter );
            System.getProperties().remove( "itext.basedir" );
        }

        // ----------------------------------------------------------------------
        // Render the XML to PDF
        // ----------------------------------------------------------------------
        File outputFile = new File( context.getOutputDirectory(), book.getId() + "." + getOutputExtension() );
        try
        {
            renderXML( bookFile, outputFile );
        }
        catch ( IOException e )
        {
            throw new BookDoxiaException( "Error while rendering file", e );
        }
    }