1 package org.apache.maven.doxia.book;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import org.apache.maven.doxia.book.context.BookContext;
23 import org.apache.maven.doxia.book.model.BookModel;
24 import org.apache.maven.doxia.book.services.indexer.BookIndexer;
25 import org.apache.maven.doxia.book.services.io.BookIo;
26 import org.apache.maven.doxia.book.services.renderer.BookRenderer;
27 import org.apache.maven.doxia.book.services.validation.BookValidator;
28 import org.apache.maven.doxia.book.services.validation.ValidationResult;
29 import org.codehaus.plexus.logging.AbstractLogEnabled;
30
31 import java.io.File;
32 import java.util.Collections;
33 import java.util.List;
34 import java.util.Locale;
35 import java.util.Map;
36 import java.util.Set;
37
38
39
40
41
42
43
44
45 public class DefaultBookDoxia
46 extends AbstractLogEnabled
47 implements BookDoxia
48 {
49
50
51
52 private BookIo bookIo;
53
54
55
56
57 private BookValidator bookValidator;
58
59
60
61
62 private BookIndexer bookIndexer;
63
64
65
66
67 private Map<String, BookRenderer> bookRenderers;
68
69
70
71
72
73
74 public BookModel loadBook( File bookDescriptor )
75 throws BookDoxiaException
76 {
77 return bookIo.readBook( bookDescriptor );
78 }
79
80
81 public void renderBook( BookModel book, String bookRendererId, List<File> files, File outputDirectory )
82 throws BookDoxiaException
83 {
84 renderBook( book, bookRendererId, files, outputDirectory, Locale.getDefault(), "UTF-8", "UTF-8" );
85 }
86
87
88 public void renderBook( BookModel book, String bookRendererId, List<File> files, File outputDirectory,
89 Locale locale, String inputEncoding, String outputEncoding )
90 throws BookDoxiaException
91 {
92
93
94
95
96 ValidationResult validationResult = bookValidator.validateBook( book );
97
98 if ( !validationResult.isAllOk() )
99 {
100 throw new InvalidBookDescriptorException( validationResult );
101 }
102
103
104
105
106
107 BookContext context = new BookContext();
108
109 context.setBook( book );
110
111 context.setOutputDirectory( outputDirectory );
112
113 context.setLocale( locale );
114
115 context.setInputEncoding( inputEncoding );
116
117 context.setOutputEncoding( outputEncoding );
118
119
120
121
122
123 bookIo.loadFiles( context, files );
124
125
126
127
128
129 bookIndexer.indexBook( book, context );
130
131
132
133
134
135 BookRenderer bookRenderer = bookRenderers.get( bookRendererId );
136
137 if ( bookRenderer == null )
138 {
139 throw new BookDoxiaException( "No such book renderer '" + bookRendererId + "'." );
140 }
141
142 bookRenderer.renderBook( context );
143 }
144
145
146
147
148
149
150 public Set<String> getAvailableBookRenderers()
151 {
152 return Collections.unmodifiableSet( bookRenderers.keySet() );
153 }
154
155 }