@Override
public IndexingContext createIndexContext( ManagedRepository repository )
throws RepositoryAdminException
{
IndexingContext context = indexer.getIndexingContexts().get( repository.getId() );
if ( context != null )
{
log.debug( "skip creating repository indexingContent with id {} as already exists", repository.getId() );
return context;
}
// take care first about repository location as can be relative
File repositoryDirectory = new File( repository.getLocation() );
if ( !repositoryDirectory.isAbsolute() )
{
repositoryDirectory =
new File( getRegistry().getString( "appserver.base" ) + File.separatorChar + "repositories",
repository.getLocation() );
}
if ( !repositoryDirectory.exists() )
{
repositoryDirectory.mkdirs();
}
try
{
String indexDir = repository.getIndexDirectory();
//File managedRepository = new File( repository.getLocation() );
File indexDirectory = null;
if ( StringUtils.isNotBlank( indexDir ) )
{
indexDirectory = new File( repository.getIndexDirectory() );
// not absolute so create it in repository directory
if ( !indexDirectory.isAbsolute() )
{
indexDirectory = new File( repositoryDirectory, repository.getIndexDirectory() );
}
repository.setIndexDirectory( indexDirectory.getAbsolutePath() );
}
else
{
indexDirectory = new File( repositoryDirectory, ".indexer" );
if ( !repositoryDirectory.isAbsolute() )
{
indexDirectory = new File( repositoryDirectory, ".indexer" );
}
repository.setIndexDirectory( indexDirectory.getAbsolutePath() );
}
if ( !indexDirectory.exists() )
{
indexDirectory.mkdirs();
}
context = indexer.getIndexingContexts().get( repository.getId() );
if ( context == null )
{
context = indexer.addIndexingContext( repository.getId(), repository.getId(), repositoryDirectory,
indexDirectory,
repositoryDirectory.toURI().toURL().toExternalForm(),
indexDirectory.toURI().toURL().toString(), indexCreators );
context.setSearchable( repository.isScanned() );
}
return context;
}
catch ( MalformedURLException e )
{