Search in sources :

Example 1 with DocumentTOCItem

use of org.apache.maven.doxia.document.DocumentTOCItem in project maven-plugins by apache.

the class DocumentModelBuilder method getDocumentTOC.

/**
     * Extract a DocumentTOC from a DecorationModel.
     *
     * @param decorationModel a DecorationModel. May be null.
     * @return a DocumentTOC, always non-null.
     */
private static DocumentTOC getDocumentTOC(DecorationModel decorationModel) {
    final DocumentTOC toc = new DocumentTOC();
    if (decorationModel != null && decorationModel.getMenus() != null) {
        for (final Menu menu : decorationModel.getMenus()) {
            for (final MenuItem item : menu.getItems()) {
                final DocumentTOCItem documentTOCItem = new DocumentTOCItem();
                documentTOCItem.setName(item.getName());
                documentTOCItem.setRef(item.getHref());
                toc.addItem(documentTOCItem);
            }
        }
    }
    return toc;
}
Also used : DocumentTOC(org.apache.maven.doxia.document.DocumentTOC) DocumentTOCItem(org.apache.maven.doxia.document.DocumentTOCItem) MenuItem(org.apache.maven.doxia.site.decoration.MenuItem) Menu(org.apache.maven.doxia.site.decoration.Menu)

Example 2 with DocumentTOCItem

use of org.apache.maven.doxia.document.DocumentTOCItem in project maven-plugins by apache.

the class PdfMojo method appendGeneratedReports.

/**
     * Append generated reports to the toc only if <code>generateReports</code> is enabled, for instance:
     * <pre>
     * &lt;item name="Project Reports" ref="/project-info"&gt;
     * &nbsp;&nbsp;&lt;item name="Project License" ref="/license" /&gt;
     * &nbsp;&nbsp;&lt;item name="Project Team" ref="/team-list" /&gt;
     * &nbsp;&nbsp;&lt;item name="Continuous Integration" ref="/integration" /&gt;
     * &nbsp;&nbsp;...
     * &lt;/item&gt;
     * </pre>
     *
     * @param model not null
     * @param locale not null
     * @see #generateMavenReports(Locale)
     * @since 1.1
     */
private void appendGeneratedReports(DocumentModel model, Locale locale) {
    if (!includeReports) {
        return;
    }
    if (getGeneratedMavenReports(locale).isEmpty()) {
        return;
    }
    final DocumentTOCItem documentTOCItem = new DocumentTOCItem();
    documentTOCItem.setName(i18n.getString("pdf-plugin", locale, "toc.project-info.item"));
    // see #generateMavenReports(Locale)
    documentTOCItem.setRef("/project-info");
    List<String> addedRef = new ArrayList<String>(4);
    List<DocumentTOCItem> items = new ArrayList<DocumentTOCItem>(4);
    // append generated report defined as MavenReport
    for (final MavenReport report : getGeneratedMavenReports(locale)) {
        final DocumentTOCItem reportItem = new DocumentTOCItem();
        reportItem.setName(report.getName(locale));
        reportItem.setRef("/" + report.getOutputName());
        items.add(reportItem);
        addedRef.add(report.getOutputName());
    }
    // append all generated reports from generated-site
    try {
        if (generatedSiteDirectory.exists()) {
            String excludes = getDefaultExcludesWithLocales(getAvailableLocales(), getDefaultLocale());
            List<String> generatedDirs = FileUtils.getDirectoryNames(generatedSiteDirectory, "*", excludes, true);
            if (!locale.getLanguage().equals(getDefaultLocale().getLanguage())) {
                generatedDirs = FileUtils.getFileNames(new File(generatedSiteDirectory, locale.getLanguage()), "*", excludes, true);
            }
            for (final String generatedDir : generatedDirs) {
                List<String> generatedFiles = FileUtils.getFileNames(new File(generatedDir), "**.*", excludes, false);
                for (final String generatedFile : generatedFiles) {
                    final String ref = generatedFile.substring(0, generatedFile.lastIndexOf('.'));
                    if (!addedRef.contains(ref)) {
                        final String title = getGeneratedDocumentTitle(new File(generatedDir, generatedFile));
                        if (title != null) {
                            final DocumentTOCItem reportItem = new DocumentTOCItem();
                            reportItem.setName(title);
                            reportItem.setRef("/" + ref);
                            items.add(reportItem);
                        }
                    }
                }
            }
        }
    } catch (IOException e) {
        getLog().error("IOException: " + e.getMessage());
        getLog().debug(e);
    }
    // append to Toc
    documentTOCItem.setItems(items);
    model.getToc().addItem(documentTOCItem);
}
Also used : MavenReport(org.apache.maven.reporting.MavenReport) DocumentTOCItem(org.apache.maven.doxia.document.DocumentTOCItem) ArrayList(java.util.ArrayList) IOException(java.io.IOException) File(java.io.File)

Aggregations

DocumentTOCItem (org.apache.maven.doxia.document.DocumentTOCItem)2 File (java.io.File)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 DocumentTOC (org.apache.maven.doxia.document.DocumentTOC)1 Menu (org.apache.maven.doxia.site.decoration.Menu)1 MenuItem (org.apache.maven.doxia.site.decoration.MenuItem)1 MavenReport (org.apache.maven.reporting.MavenReport)1