package votorola.a.count; // Copyright 2007, 2013, Michael Allan. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Votorola Software"), to deal in the Votorola Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicence, and/or sell copies of the Votorola Software, and to permit persons to whom the Votorola Software is furnished to do so, subject to the following conditions: The preceding copyright notice and this permission notice shall be included in all copies or substantial portions of the Votorola Software. THE VOTOROLA SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE VOTOROLA SOFTWARE OR THE USE OR OTHER DEALINGS IN THE VOTOROLA SOFTWARE. import java.util.*; import votorola.a.*; import votorola.a.voter.*; import votorola.a.response.*; import votorola.g.option.*; import static votorola.a.voter.IDPair.NOBODY; /** Responder for the command 'unvote' - to withdraw a vote from a poll. * * @see ../../s/manual.xht#Poll-Response-unvote */ public final class CR_Unvote extends CR_Vote { /** Constructs a CR_Unvote. */ CR_Unvote( PollService _poll ) { super( _poll, "a.count.CR_Unvote." ); } // - C o m m a n d - R e s p o n d e r ------------------------------------------------ public @Override void help( final CommandResponder.Session session ) { final ReplyBuilder replyB = session.replyBuilder(); replyB.lappendlnn( keyPrefix + "help.summary" ); replyB.indent( 4 ).setWrapping( false ); replyB.lappendlnn( keyPrefix + "help.syntax" ); replyB.exdent( 4 ).setWrapping( true ); replyB.lappendlnn( keyPrefix + "help.body(1)", voterService.title() ); } public @Override Exception respond( final String[] argv, final CommandResponder.Session session ) { final String commandName = argv[0]; // before rearranged by option parser final AuthenticatedUser user = session.user(); if( user.email().equals(NOBODY.email()) ) { throw new CommandResponder.AnonymousIssueException( commandName ); } final ReplyBuilder replyB = session.replyBuilder(); final Map optionMap = compileBaseOptions( session ); { final int aFirstNonOption = parse( argv, optionMap, session ); // rearranges argv if( aFirstNonOption == -1 ) return null; // parse error, message already appended if( optionMap.get("a.voter.CommandResponder.option.help").hasOccured() ) { help( session ); return null; } } try { replyB.setWrapping( false ); replyB.lappendlnn( "a.count.CR_Vote.reply.poll(1)", poll().title() ); final Vote vote = new Vote( user.email(), poll().voterInputTable() ); writeVoteAndEcho( /*newCandidateEmail*/null, vote, session ); echoTraces( vote, session ); } catch( VoterInputTable.BadInputException x ) { replyB.appendlnn( x.toString() ); } // though unexpected catch( java.io.IOException|java.sql.SQLException|javax.script.ScriptException|javax.xml.stream.XMLStreamException x ) { return x; } finally{ replyB.resetFormattingToDefaults(); } return null; } }