~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/LatexBookRenderer.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:
25
25
import org.apache.maven.doxia.book.model.BookModel;
26
26
import org.apache.maven.doxia.book.model.Chapter;
27
27
import org.apache.maven.doxia.book.model.Section;
28
 
import org.apache.maven.doxia.module.latex.LatexSink;
29
28
import org.apache.maven.doxia.parser.manager.ParserNotFoundException;
30
29
import org.apache.maven.doxia.parser.ParseException;
31
30
import org.apache.maven.doxia.Doxia;
 
31
import org.codehaus.plexus.util.ReaderFactory;
32
32
import org.codehaus.plexus.util.StringUtils;
33
33
import org.codehaus.plexus.util.IOUtil;
 
34
import org.codehaus.plexus.util.WriterFactory;
34
35
 
35
36
import java.io.File;
36
37
import java.io.FileWriter;
37
38
import java.io.IOException;
38
39
import java.io.PrintWriter;
39
 
import java.io.FileReader;
40
40
import java.io.FileNotFoundException;
 
41
import java.io.Reader;
 
42
import java.io.Writer;
41
43
import java.util.Iterator;
42
44
import java.util.Map;
43
45
import java.util.HashMap;
44
46
 
45
47
/**
 
48
 * <p>LatexBookRenderer class.</p>
 
49
 *
46
50
 * @plexus.component role-hint="latex"
47
 
 *
48
51
 * @author <a href="mailto:trygvis@inamo.no">Trygve Laugst&oslash;l</a>
49
 
 * @version $Id: LatexBookRenderer.java 572956 2007-09-05 14:22:50Z ltheussl $
 
52
 * @version $Id: LatexBookRenderer.java 746976 2009-02-23 12:15:38Z vsiveton $
50
53
 */
51
54
public class LatexBookRenderer
52
55
    implements BookRenderer
102
105
    // ----------------------------------------------------------------------
103
106
 
104
107
    /** SectionInfo: id and title. */
105
 
    private static class SectionInfo
 
108
    static class SectionInfo
106
109
    {
107
110
        /** id. */
108
 
        private String id;
 
111
        String id;
109
112
 
110
113
        /** title. */
111
 
        private String title;
 
114
        String title;
112
115
    }
113
116
 
114
117
    /**
160
163
            writer.println( "\\author{" + book.getDate() + "}" );
161
164
        }
162
165
 
163
 
        writer.print( IOUtil.toString( LatexSink.getDefaultSinkCommands() ) );
164
 
        writer.print( IOUtil.toString( LatexSink.getDefaultPreamble() ) );
 
166
        LatexBookSink sink = new LatexBookSink( writer );
 
167
        sink.defaultBookPreamble();
 
168
 
165
169
        writer.println( "\\begin{document}" );
166
170
        writer.println( "\\maketitle" );
167
171
        writer.println( "\\tableofcontents" );
200
204
    {
201
205
        File file = new File( context.getOutputDirectory(), ( section.getId() + ".tex" ) );
202
206
 
203
 
        FileWriter writer = new FileWriter( file );
 
207
        Writer writer = WriterFactory.newWriter( file, context.getOutputEncoding() );
204
208
 
205
209
        LatexBookSink sink = new LatexBookSink( writer );
206
210
 
212
216
                        + section.getId() + "." );
213
217
        }
214
218
 
 
219
        Reader reader = null;
215
220
        try
216
221
        {
217
 
            doxia.parse( new FileReader( bookFile.getFile() ), bookFile.getParserId(), sink );
 
222
            reader = ReaderFactory.newReader( bookFile.getFile(), context.getInputEncoding() );
 
223
            doxia.parse( reader, bookFile.getParserId(), sink );
218
224
        }
219
225
        catch ( ParserNotFoundException e )
220
226
        {
231
237
            throw new BookDoxiaException( "Could not find document: "
232
238
                        + bookFile.getFile().getAbsolutePath() + ".", e );
233
239
        }
 
240
        finally
 
241
        {
 
242
            IOUtil.close( reader );
 
243
            IOUtil.close( writer );
 
244
        }
234
245
 
235
246
        SectionInfo info = new SectionInfo();
236
247
        info.id = section.getId();