boolean tryAgain = true;
while( !bot.isLoggedIn() && tryAgain ){
UIRequest requestArray[] = {
new UIRequest_String("username", str("username"),
str("helpUsername"), username),
new UIRequest_String("password", str("password"),
str("helpPassword"),
UIRequest_String.LayoutFlag.hideInput)
};
NamedDataSet reply = uiForRequests.request(requestArray);
if ( reply == null ) { //cancelled
tryAgain = false;
}
else {
try {
username = reply.get("username");
password = reply.get("password");
try {
bot.login(username,password);
} catch (ActionException e) {
/* error message will be printed */
}
/* if login failed: ask about giving up */
if( bot.isLoggedIn() == false ){
UIRequest tryAgainRequestArray[] = { new UIRequest_Boolean("tryAgain", str("loginFailedTryAgain"), str("helpLoginFailedTryAgain")) };
try {
tryAgain = uiForRequests.request(tryAgainRequestArray).<Boolean>get("tryAgain");
} catch ( NamedDataNotAvailableException ndnae ){ tryAgain = false; /* no further attempts to log in */ }
}
} catch (NamedDataNotAvailableException ndnae) {
uiForRequests.request( new UIRequest_Output(str("errorGetAccountInfo")) );
username = null;
password = null;
}
}
}
/* after successful login: write the article to the MediaWiki */
if ( bot.isLoggedIn() ) {
boolean ready = false;
while ( !ready ) {
try {
writeArticle(text);
ready = true;
} catch ( ActionException ae ) {
/* writing failed, ready remains false */
} catch ( ProcessException pe ) {
/* writing failed, ready remains false */
}
if ( !ready ) {
UIRequest tryAgainRequestArray[] = { new UIRequest_Boolean("tryAgain", str("writingFailedTryAgain"), str("helpWritingFailedTryAgain")) };
try {
ready = (false == uiForRequests.request(tryAgainRequestArray).<Boolean>get("tryAgain"));
} catch ( NamedDataNotAvailableException ndnae ) {
System.err.println(str("exceptionUserInput", ndnae.toString()));