use of org.apache.maven.doxia.document.DocumentModel in project maven-plugins by apache.
the class PdfMojo method generatePdf.
/**
* Generate the PDF.
*
* @throws MojoExecutionException if any
* @throws IOException if any
* @since 1.1
*/
private void generatePdf() throws MojoExecutionException, IOException {
Locale.setDefault(getDefaultLocale());
for (final Locale locale : getAvailableLocales()) {
final File workingDir = getLocaleDirectory(workingDirectory, locale);
File siteDirectoryFile = getLocaleDirectory(getSiteDirectoryTmp(), locale);
copyResources(locale);
generateMavenReports(locale);
DocumentRendererContext context = new DocumentRendererContext();
context.put("project", project);
context.put("settings", settings);
context.put("PathTool", new PathTool());
context.put("FileUtils", new FileUtils());
context.put("StringUtils", new StringUtils());
context.put("i18n", i18n);
context.put("generateTOC", generateTOC);
context.put("validate", validate);
// Put any of the properties in directly into the Velocity context
for (Map.Entry<Object, Object> entry : project.getProperties().entrySet()) {
context.put((String) entry.getKey(), entry.getValue());
}
final DocumentModel model = aggregate ? getDocumentModel(locale) : null;
try {
// TODO use interface see DOXIASITETOOLS-30
((AbstractDocumentRenderer) docRenderer).render(siteDirectoryFile, workingDir, model, context);
} catch (DocumentRendererException e) {
throw new MojoExecutionException("Error during document generation: " + e.getMessage(), e);
}
}
}
use of org.apache.maven.doxia.document.DocumentModel in project maven-plugins by apache.
the class DocumentDescriptorReaderTest method testFiltering.
/**
* Test of readAndFilterDocumentDescriptor method, of class DocumentDescriptorReader.
* @throws Exception if something happens.
*/
public void testFiltering() throws Exception {
DocumentDescriptorReader reader = new DocumentDescriptorReader(new FilteringMavenProjectStub());
File descriptorFile = new File(testBaseDir() + "src/site/", "pdf_filtering.xml");
DocumentModel model = reader.readAndFilterDocumentDescriptor(descriptorFile);
assertNotNull(model);
assertNull(model.getCover());
assertNotNull(model.getToc());
assertEquals("Table of Contents", model.getToc().getName());
assertEquals(5, model.getToc().getItems().size());
assertNotNull(model.getMeta());
assertTrue(model.getMeta().getTitle().indexOf("User guide in en of Test filtering version 1.0-SNAPSHOT") == 0);
assertEquals("vsiveton@apache.org ltheussl@apache.org", model.getMeta().getAuthor());
}
use of org.apache.maven.doxia.document.DocumentModel in project maven-plugins by apache.
the class DocumentModelBuilderTest method testGetDocumentModelWithSiteDescriptor.
/**
* Test of getDocumentModel method, of class DocumentModelBuilder.
* @throws Exception if something happens.
*/
public void testGetDocumentModelWithSiteDescriptor() throws Exception {
File descriptorFile = new File(testBaseDir() + "src/site/", "model_builder_site.xml");
DecorationModel dModel = getDecorationModelFromFile(descriptorFile);
DocumentModel model = new DocumentModelBuilder(new ModelBuilderMavenProjectStub(), dModel).getDocumentModel();
DocumentTOC toc = model.getToc();
assertEquals(1, toc.getItems().size());
assertEquals("Intro", toc.getItems().get(0).getName());
assertEquals("index.html", toc.getItems().get(0).getRef());
}
use of org.apache.maven.doxia.document.DocumentModel in project maven-plugins by apache.
the class PdfMojo method getDocumentModel.
/**
* Constructs a DocumentModel for the current project. The model is either read from
* a descriptor file, if it exists, or constructed from information in the pom and site.xml.
*
* @param locale not null
* @return DocumentModel.
* @throws MojoExecutionException if any
* @see #appendGeneratedReports(DocumentModel, Locale)
*/
private DocumentModel getDocumentModel(Locale locale) throws MojoExecutionException {
if (docDescriptor.exists()) {
DocumentModel doc = getDocumentModelFromDescriptor(locale);
// TODO: descriptor model should get merged into default model, see MODELLO-63
appendGeneratedReports(doc, locale);
return doc;
}
DocumentModel model = new DocumentModelBuilder(project, getDefaultDecorationModel()).getDocumentModel();
model.getMeta().setGenerator(getDefaultGenerator());
model.getMeta().setLanguage(locale.getLanguage());
model.getCover().setCoverType(i18n.getString("pdf-plugin", getDefaultLocale(), "toc.type"));
model.getToc().setName(i18n.getString("pdf-plugin", getDefaultLocale(), "toc.title"));
appendGeneratedReports(model, locale);
debugLogGeneratedModel(model);
return model;
}
use of org.apache.maven.doxia.document.DocumentModel in project maven-plugins by apache.
the class DocumentModelBuilder method getDocumentModel.
// ----------------------------------------------------------------------
// Private methods
// ----------------------------------------------------------------------
/**
* Extract a DocumentModel from a MavenProject.
*
* @param project a MavenProject. May be null.
* @param decorationModel a DecorationModel. May be null.
* @param date the date of the TOC. May be null in which case the build date will be used.
*
* @return a DocumentModel. Always non-null.
*/
private static DocumentModel getDocumentModel(MavenProject project, DecorationModel decorationModel, Date date) {
final Date now = (date == null ? new Date() : date);
final DocumentModel docModel = new DocumentModel();
docModel.setModelEncoding(getProjectModelEncoding(project));
docModel.setOutputName(project == null || project.getArtifactId() == null ? "unnamed" : project.getArtifactId());
docModel.setMeta(getDocumentMeta(project, now));
docModel.setCover(getDocumentCover(project, now));
docModel.setToc(getDocumentTOC(decorationModel));
return docModel;
}
Aggregations