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;
}
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>
* <item name="Project Reports" ref="/project-info">
* <item name="Project License" ref="/license" />
* <item name="Project Team" ref="/team-list" />
* <item name="Continuous Integration" ref="/integration" />
* ...
* </item>
* </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);
}
Aggregations