if ( params == null )
{
return;
}
final FileItem startItem = getParameter( params, FIELD_START );
final FileItem startLevelItem = getParameter( params, FIELD_STARTLEVEL );
final FileItem[] bundleItems = getFileItems( params, FIELD_BUNDLEFILE );
final FileItem refreshPackagesItem = getParameter( params, FIELD_REFRESH_PACKAGES );
// don't care any more if no bundle item
if ( bundleItems.length == 0 )
{
return;
}
// default values
// it exists
int startLevel = -1;
String bundleLocation = "inputstream:";
// convert the start level value
if ( startLevelItem != null )
{
try
{
startLevel = Integer.parseInt( startLevelItem.getString() );
}
catch ( NumberFormatException nfe )
{
log( LogService.LOG_INFO, "Cannot parse start level parameter " + startLevelItem
+ " to a number, not setting start level" );
}
}
for ( int i = 0; i < bundleItems.length; i++ )
{
final FileItem bundleItem = bundleItems[i];
// write the bundle data to a temporary file to ease processing
File tmpFile = null;
try
{
// copy the data to a file for better processing
tmpFile = File.createTempFile( "install", ".tmp" );
bundleItem.write( tmpFile );
}
catch ( Exception e )
{
log( LogService.LOG_ERROR, "Problem accessing uploaded bundle file: " + bundleItem.getName(), e );
// remove the tmporary file
if ( tmpFile != null )
{
tmpFile.delete();
tmpFile = null;
}
}
// install or update the bundle now
if ( tmpFile != null )
{
// start, refreshPackages just needs to exist, don't care for value
final boolean start = startItem != null;
final boolean refreshPackages = refreshPackagesItem != null;
bundleLocation = "inputstream:" + bundleItem.getName();
installBundle( bundleLocation, tmpFile, startLevel, start, refreshPackages );
}
}
}