Package org.apache.maven.doxia.tools

## Class DefaultSiteTool

- java.lang.Object
- - org.codehaus.plexus.logging.AbstractLogEnabled
  - - org.apache.maven.doxia.tools.DefaultSiteTool

All Implemented Interfaces:
  `SiteTool`, `org.codehaus.plexus.logging.LogEnabled`

    @Component(role=SiteTool.class)
    public class DefaultSiteTool
    extends org.codehaus.plexus.logging.AbstractLogEnabled
    implements SiteTool

Default implementation of the site tool.

Version:
  $Id: DefaultSiteTool.java 1763022 2016-10-01 16:31:29Z hboutemy $
Author:
  Vincent Siveton

### Field Summary

Fields
`protected DecorationModelInheritanceAssembler` `assembler` The component for assembling inheritance.
`protected org.codehaus.plexus.i18n.I18N` `i18n` Internationalization.
`protected org.apache.maven.project.MavenProjectBuilder` `mavenProjectBuilder` Project builder (deprecated in Maven 3: should use ProjectBuilder, which will avoid issues like DOXIASITETOOLS-166)

### Fields inherited from interface org.apache.maven.doxia.tools.SiteTool

`DEFAULT_LOCALE, ROLE`

### Constructor Summary

Constructors
`DefaultSiteTool()`

### Method Summary

All Methods Static Methods Instance Methods Concrete Methods

`DecorationModel`

`getDecorationModel​(java.io.File siteDirectory, java.util.Locale locale, org.apache.maven.project.MavenProject project, java.util.List<org.apache.maven.project.MavenProject> reactorProjects, org.apache.maven.artifact.repository.ArtifactRepository localRepository, java.util.List<org.apache.maven.artifact.repository.ArtifactRepository> repositories)`

Get a decoration model for a project.

`org.apache.maven.artifact.Artifact` `getDefaultSkinArtifact​(org.apache.maven.artifact.repository.ArtifactRepository localRepository, java.util.List<org.apache.maven.artifact.repository.ArtifactRepository> remoteArtifactRepositories)` Get the default skin artifact for a project from one of the repositories.
`java.lang.String` `getInterpolatedSiteDescriptorContent​(java.util.Map<java.lang.String,​java.lang.String> props, org.apache.maven.project.MavenProject aProject, java.lang.String siteDescriptorContent)` Interpolating several expressions in the site descriptor content.
`protected static java.lang.String` `getNormalizedPath​(java.lang.String path)`
`org.apache.maven.project.MavenProject` `getParentProject​(org.apache.maven.project.MavenProject aProject, java.util.List<org.apache.maven.project.MavenProject> reactorProjects, org.apache.maven.artifact.repository.ArtifactRepository localRepository)` Returns the parent POM with interpolated URLs.
`java.lang.String` `getRelativePath​(java.lang.String to, java.lang.String from)` Calculate the relative path between two URLs or between two files.
`java.io.File` `getSiteDescriptor​(java.io.File siteDirectory, java.util.Locale locale)` Get a site descriptor from the project's site directory.
`java.util.List<java.util.Locale>` `getSiteLocales​(java.lang.String locales)` Extracts from a comma-separated list the locales that are available in `site-tool` resource bundle.
`org.apache.maven.artifact.Artifact` `getSkinArtifactFromRepository​(org.apache.maven.artifact.repository.ArtifactRepository localRepository, java.util.List<org.apache.maven.artifact.repository.ArtifactRepository> remoteArtifactRepositories, DecorationModel decoration)` Get a skin artifact from one of the repositories.
`void` `populateReportsMenu​(DecorationModel decorationModel, java.util.Locale locale, java.util.Map<java.lang.String,​java.util.List<org.apache.maven.reporting.MavenReport>> categories)` Populate the pre-defined `reports` menu of the decoration model, if used through `<menu ref="reports"/>`.

### Methods inherited from class org.codehaus.plexus.logging.AbstractLogEnabled

`enableLogging, getLogger, setupLogger, setupLogger, setupLogger`

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

### Field Detail

#### i18n

    @Requirement
    protected org.codehaus.plexus.i18n.I18N i18n

Internationalization.

#### assembler

    @Requirement
    protected DecorationModelInheritanceAssembler assembler

The component for assembling inheritance.

#### mavenProjectBuilder

    @Requirement
    protected org.apache.maven.project.MavenProjectBuilder mavenProjectBuilder

Project builder (deprecated in Maven 3: should use ProjectBuilder, which will avoid issues like DOXIASITETOOLS-166)

### Constructor Detail

#### DefaultSiteTool

    public DefaultSiteTool()

### Method Detail

#### getSkinArtifactFromRepository

    public org.apache.maven.artifact.Artifact getSkinArtifactFromRepository​(org.apache.maven.artifact.repository.ArtifactRepository localRepository,
                                                                            java.util.List<org.apache.maven.artifact.repository.ArtifactRepository> remoteArtifactRepositories,
                                                                            DecorationModel decoration)
                                                                     throws SiteToolException

Get a skin artifact from one of the repositories.

Specified by:
  `getSkinArtifactFromRepository` in interface `SiteTool`
Parameters:
  `localRepository` - the Maven local repository, not null.
  `remoteArtifactRepositories` - the Maven remote repositories, not null.
  `decoration` - the Doxia site descriptor model, not null.
Returns:
  the `Skin` artifact defined in a `DecorationModel` from a given project and a local repository
Throws:
  `SiteToolException` - if any

#### getDefaultSkinArtifact

    public org.apache.maven.artifact.Artifact getDefaultSkinArtifact​(org.apache.maven.artifact.repository.ArtifactRepository localRepository,
                                                                     java.util.List<org.apache.maven.artifact.repository.ArtifactRepository> remoteArtifactRepositories)
                                                              throws SiteToolException

Get the default skin artifact for a project from one of the repositories.

Specified by:
  `getDefaultSkinArtifact` in interface `SiteTool`
Parameters:
  `localRepository` - the Maven local repository, not null.
  `remoteArtifactRepositories` - the Maven remote repositories, not null.
Returns:
  the default `Skin` artifact from a given project and a local repository
Throws:
  `SiteToolException` - if any
See Also:
  `Skin.getDefaultSkin()`, `SiteTool.getSkinArtifactFromRepository(ArtifactRepository, List, DecorationModel)`

#### getRelativePath

    public java.lang.String getRelativePath​(java.lang.String to,
                                            java.lang.String from)

Calculate the relative path between two URLs or between two files. For example:

to = "http://maven.apache.org" and from = "http://maven.apache.org"
  return ""
to = "http://maven.apache.org" and from = "http://maven.apache.org/plugins/maven-site-plugin/"
  return "../.."
to = "http://maven.apache.org/plugins/maven-site-plugin/" and from = "http://maven.apache.org"
  return "plugins/maven-site-plugin"
to = "/myproject/myproject-module1" and from = "/myproject/myproject"
  return "../myproject-module1"

Note: The file separator depends on the system. Maven-specific urls are supported, like `dav:https://dav.codehaus.org/` or `scm:svn:https://svn.apache.org/repos/asf`.

Specified by:
  `getRelativePath` in interface `SiteTool`
Parameters:
  `to` - the `to` url of file as string
  `from` - the `from` url of file as string
Returns:
  a relative path from `from` to `to`.

#### getSiteDescriptor

    public java.io.File getSiteDescriptor​(java.io.File siteDirectory,
                                          java.util.Locale locale)

Get a site descriptor from the project's site directory.

Specified by:
  `getSiteDescriptor` in interface `SiteTool`
Parameters:
  `siteDirectory` - the site directory, not null
  `locale` - the locale wanted for the site descriptor. If not null, searching for `site_localeLanguage.xml`, otherwise searching for `site.xml`.
Returns:
  the site descriptor file

#### getDecorationModel

    public DecorationModel getDecorationModel​(java.io.File siteDirectory,
                                              java.util.Locale locale,
                                              org.apache.maven.project.MavenProject project,
                                              java.util.List<org.apache.maven.project.MavenProject> reactorProjects,
                                              org.apache.maven.artifact.repository.ArtifactRepository localRepository,
                                              java.util.List<org.apache.maven.artifact.repository.ArtifactRepository> repositories)
                                       throws SiteToolException

Get a decoration model for a project.

Specified by:
  `getDecorationModel` in interface `SiteTool`
Parameters:
  `siteDirectory` - the site directory, may be null if project from repository
  `locale` - the locale used for the i18n in DecorationModel. If null, using the default locale in the jvm.
  `project` - the Maven project, not null.
  `reactorProjects` - the Maven reactor projects, not null.
  `localRepository` - the Maven local repository, not null.
  `repositories` - the Maven remote repositories, not null.
Returns:
  the `DecorationModel` object corresponding to the `site.xml` file with some interpolations.
Throws:
  `SiteToolException` - if any

#### getInterpolatedSiteDescriptorContent

    public java.lang.String getInterpolatedSiteDescriptorContent​(java.util.Map<java.lang.String,​java.lang.String> props,
                                                                 org.apache.maven.project.MavenProject aProject,
                                                                 java.lang.String siteDescriptorContent)
                                                          throws SiteToolException

Interpolating several expressions in the site descriptor content. Actually, the expressions can be in the project, the environment variables and the specific properties like `encoding`.

For instance:

${project.name}
  The value from the POM of:

  <project>
  <name>myProjectName</name>
  </project>

${my.value}
  The value from the POM of:

  <properties>
  <my.value>hello</my.value>
  </properties>

${JAVA_HOME}
  The value of JAVA_HOME in the environment variables

Specified by:
  `getInterpolatedSiteDescriptorContent` in interface `SiteTool`
Parameters:
  `props` - a map used for interpolation, not null.
  `aProject` - a Maven project, not null.
  `siteDescriptorContent` - the site descriptor file, not null.
Returns:
  the interpolated site descriptor content.
Throws:
  `SiteToolException` - if errors happened during the interpolation.

#### getParentProject

    public org.apache.maven.project.MavenProject getParentProject​(org.apache.maven.project.MavenProject aProject,
                                                                  java.util.List<org.apache.maven.project.MavenProject> reactorProjects,
                                                                  org.apache.maven.artifact.repository.ArtifactRepository localRepository)

Returns the parent POM with interpolated URLs. If called from Maven 3, just returns `project.getParent()`, which is already interpolated. But when called from Maven 2, attempts to source this value from the `reactorProjects` parameters if available (reactor env model attributes are interpolated), or if the reactor is unavailable (-N) resorts to the `project.getParent().getUrl()` value which will NOT have been interpolated.

Specified by:
  `getParentProject` in interface `SiteTool`
Parameters:
  `aProject` - a Maven project, not null.
  `reactorProjects` - the Maven reactor projects, not null.
  `localRepository` - the Maven local repository, not null.
Returns:
  the parent project with interpolated URLs.

#### populateReportsMenu

    public void populateReportsMenu​(DecorationModel decorationModel,
                                    java.util.Locale locale,
                                    java.util.Map<java.lang.String,​java.util.List<org.apache.maven.reporting.MavenReport>> categories)

Populate the pre-defined `reports` menu of the decoration model, if used through `<menu ref="reports"/>`. Notice this menu reference is translated into 2 separate menus: "Project Information" and "Project Reports".

Specified by:
  `populateReportsMenu` in interface `SiteTool`
Parameters:
  `decorationModel` - the Doxia Sitetools DecorationModel, not null.
  `locale` - the locale used for the i18n in DecorationModel. If null, using the default locale in the jvm.
  `categories` - reports per category to put in "Reports" or "Information" menus, not null.
See Also:
  `MavenReport.CATEGORY_PROJECT_INFORMATION`, `MavenReport.CATEGORY_PROJECT_REPORTS`

#### getSiteLocales

    public java.util.List<java.util.Locale> getSiteLocales​(java.lang.String locales)

Extracts from a comma-separated list the locales that are available in `site-tool` resource bundle. Notice that `default` value will be changed to the default locale of the JVM.

Specified by:
  `getSiteLocales` in interface `SiteTool`
Parameters:
  `locales` - A comma separated list of locales
Returns:
  a list of `Locale`, which at least contains the Maven default locale which is english

#### getNormalizedPath

    protected static java.lang.String getNormalizedPath​(java.lang.String path)

Parameters:
  `path` - could be null.
Returns:
  the path normalized, i.e. by eliminating "/../" and "/./" in the path.
See Also:
  `FilenameUtils.normalize(String)`