if ( existing != null && existing.isSubscribed()){
if ( warn_user ){
UIManager ui_manager = StaticUtilities.getUIManager( 120*1000 );
String details = MessageText.getString(
"subscript.add.dup.desc",
new String[]{ existing.getName()});
ui_manager.showMessageBox(
"subscript.add.dup.title",
"!" + details + "!",
UIManagerEvent.MT_OK );
}
selectSubscription( existing );
return( existing );
}else{
if ( warn_user ){
UIManager ui_manager = StaticUtilities.getUIManager( 120*1000 );
String details = MessageText.getString(
"subscript.add.desc",
new String[]{ name });
long res = ui_manager.showMessageBox(
"subscript.add.title",
"!" + details + "!",
UIManagerEvent.MT_YES | UIManagerEvent.MT_NO );
if ( res != UIManagerEvent.MT_YES ){
log_errors = false;
throw( new SubscriptionException( "User declined addition" ));
}
}
if ( existing == null ){
SubscriptionImpl new_subs = (SubscriptionImpl)createSingletonRSSSupport( name, url, is_public, check_interval_mins, SubscriptionImpl.ADD_TYPE_IMPORT, true );
log( "Imported new singleton subscription: " + new_subs.getString());
return( new_subs );
}else{
existing.setSubscribed( true );
selectSubscription( existing );
return( existing );
}
}
}else{
SubscriptionBodyImpl body = new SubscriptionBodyImpl( this, map );
SubscriptionImpl existing = getSubscriptionFromSID( body.getShortID());
if ( existing != null && existing.isSubscribed()){
if ( existing.getVersion() >= body.getVersion()){
log( "Not upgrading subscription: " + existing.getString() + " as supplied (" + body.getVersion() + ") is not more recent than existing (" + existing.getVersion() + ")");
if ( warn_user ){
UIManager ui_manager = StaticUtilities.getUIManager( 120*1000 );
String details = MessageText.getString(
"subscript.add.dup.desc",
new String[]{ existing.getName()});
ui_manager.showMessageBox(
"subscript.add.dup.title",
"!" + details + "!",
UIManagerEvent.MT_OK );
}
// we have a newer one, ignore
selectSubscription( existing );
return( existing );
}else{
if ( warn_user ){
UIManager ui_manager = StaticUtilities.getUIManager( 120*1000 );
String details = MessageText.getString(
"subscript.add.upgrade.desc",
new String[]{ existing.getName()});
long res = ui_manager.showMessageBox(
"subscript.add.upgrade.title",
"!" + details + "!",
UIManagerEvent.MT_YES | UIManagerEvent.MT_NO );
if ( res != UIManagerEvent.MT_YES ){
throw( new SubscriptionException( "User declined upgrade" ));
}
}
log( "Upgrading subscription: " + existing.getString());
existing.upgrade( body );
saveConfig();
subscriptionUpdated();
return( existing );
}
}else{
SubscriptionImpl new_subs = new SubscriptionImpl( this, body, SubscriptionImpl.ADD_TYPE_IMPORT, true );
if ( warn_user ){
UIManager ui_manager = StaticUtilities.getUIManager( 120*1000 );
String details = MessageText.getString(
"subscript.add.desc",
new String[]{ new_subs.getName()});
long res = ui_manager.showMessageBox(
"subscript.add.title",
"!" + details + "!",
UIManagerEvent.MT_YES | UIManagerEvent.MT_NO );
if ( res != UIManagerEvent.MT_YES ){
throw( new SubscriptionException( "User declined addition" ));
}
}
log( "Imported new subscription: " + new_subs.getString());
if ( existing != null ){
existing.remove();
}
new_subs = addSubscription( new_subs );
return( new_subs );
}
}
}catch( Throwable e ){
throw( new SubscriptionException( "Subscription import failed", e ));
}
}catch( SubscriptionException e ){
if ( warn_user && log_errors ){
UIManager ui_manager = StaticUtilities.getUIManager( 120*1000 );
String details = MessageText.getString(
"subscript.import.fail.desc",
new String[]{ Debug.getNestedExceptionMessage(e)});
ui_manager.showMessageBox(
"subscript.import.fail.title",
"!" + details + "!",
UIManagerEvent.MT_OK );
}