Search in sources :

Example 1 with DocumentModel

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);
        }
    }
}
Also used : Locale(java.util.Locale) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) DocumentRendererContext(org.apache.maven.doxia.docrenderer.DocumentRendererContext) FileUtils(org.codehaus.plexus.util.FileUtils) DocumentRendererException(org.apache.maven.doxia.docrenderer.DocumentRendererException) DocumentModel(org.apache.maven.doxia.document.DocumentModel) PathTool(org.codehaus.plexus.util.PathTool) StringUtils(org.codehaus.plexus.util.StringUtils) AbstractDocumentRenderer(org.apache.maven.doxia.docrenderer.AbstractDocumentRenderer) File(java.io.File) Map(java.util.Map) HashMap(java.util.HashMap)

Example 2 with DocumentModel

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());
}
Also used : FilteringMavenProjectStub(org.apache.maven.plugins.pdf.stubs.FilteringMavenProjectStub) File(java.io.File) DocumentModel(org.apache.maven.doxia.document.DocumentModel)

Example 3 with DocumentModel

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());
}
Also used : DocumentTOC(org.apache.maven.doxia.document.DocumentTOC) DecorationModel(org.apache.maven.doxia.site.decoration.DecorationModel) ModelBuilderMavenProjectStub(org.apache.maven.plugins.pdf.stubs.ModelBuilderMavenProjectStub) File(java.io.File) DocumentModel(org.apache.maven.doxia.document.DocumentModel)

Example 4 with DocumentModel

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;
}
Also used : DocumentModel(org.apache.maven.doxia.document.DocumentModel)

Example 5 with DocumentModel

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;
}
Also used : Date(java.util.Date) DocumentModel(org.apache.maven.doxia.document.DocumentModel)

Aggregations

DocumentModel (org.apache.maven.doxia.document.DocumentModel)8 File (java.io.File)4 DocumentTOC (org.apache.maven.doxia.document.DocumentTOC)2 ModelBuilderMavenProjectStub (org.apache.maven.plugins.pdf.stubs.ModelBuilderMavenProjectStub)2 Date (java.util.Date)1 HashMap (java.util.HashMap)1 Locale (java.util.Locale)1 Map (java.util.Map)1 AbstractDocumentRenderer (org.apache.maven.doxia.docrenderer.AbstractDocumentRenderer)1 DocumentRendererContext (org.apache.maven.doxia.docrenderer.DocumentRendererContext)1 DocumentRendererException (org.apache.maven.doxia.docrenderer.DocumentRendererException)1 DocumentCover (org.apache.maven.doxia.document.DocumentCover)1 DocumentMeta (org.apache.maven.doxia.document.DocumentMeta)1 DecorationModel (org.apache.maven.doxia.site.decoration.DecorationModel)1 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)1 FilteringMavenProjectStub (org.apache.maven.plugins.pdf.stubs.FilteringMavenProjectStub)1 FileUtils (org.codehaus.plexus.util.FileUtils)1 PathTool (org.codehaus.plexus.util.PathTool)1 StringUtils (org.codehaus.plexus.util.StringUtils)1