if ( parentProject == null )
{
throw new IllegalArgumentException( "The parameter 'parentProject' can not be null" );
}
Menu menu = decorationModel.getMenuRef( "parent" );
if ( menu == null )
{
return;
}
if ( keepInheritedRefs && menu.isInheritAsRef() )
{
return;
}
final Locale llocale = ( locale == null ) ? Locale.getDefault() : locale;
String parentUrl = getDistMgmntSiteUrl( parentProject );
if ( parentUrl != null )
{
if ( parentUrl.endsWith( "/" ) )
{
parentUrl += "index.html";
}
else
{
parentUrl += "/index.html";
}
parentUrl = getRelativePath( parentUrl, getDistMgmntSiteUrl( project ) );
}
else
{
// parent has no url, assume relative path is given by site structure
File parentBasedir = parentProject.getBasedir();
// First make sure that the parent is available on the file system
if ( parentBasedir != null )
{
// Try to find the relative path to the parent via the file system
String parentPath = parentBasedir.getAbsolutePath();
String projectPath = project.getBasedir().getAbsolutePath();
parentUrl = getRelativePath( parentPath, projectPath ) + "/index.html";
}
}
// Only add the parent menu if we were able to find a URL for it
if ( parentUrl == null )
{
getLogger().warn( "Unable to find a URL to the parent project. The parent menu will NOT be added." );
}
else
{
if ( menu.getName() == null )
{
menu.setName( i18n.getString( "site-tool", llocale, "decorationModel.menu.parentproject" ) );
}
MenuItem item = new MenuItem();
item.setName( parentProject.getName() );
item.setHref( parentUrl );
menu.addItem( item );
}
}