package votorola.a.count; // Copyright 2010, 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.io.*; import java.util.*; import votorola.a.*; import votorola.a.response.*; import votorola.g.option.*; /** Responder for the command 'reconstruct' - to reconstruct a poll from scratch. All * configuration items that were cached in previous constructions are ignored. * * @see ../../s/manual.xht#Poll-Response-reconstruct */ public final class CR_Reconstruct extends CommandResponder.Base { /** Constructs a CR_Reconstruct. */ public CR_Reconstruct( VoterService voterService ) { super( voterService, "a.count.CR_Reconstruct." ); } // - C o m m a n d - R e s p o n d e r ------------------------------------------------ /** Returns true. */ public @Override boolean acceptsAnonymousIssue() { return true; } public @Override Exception respond( final String[] argv, final CommandResponder.Session session ) { 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; } } final StringWriter logStringWriter = new StringWriter(); final PrintWriter logWriter = new PrintWriter( logStringWriter ); try { voterService.vsRun().scopePoll().constructCachedPoll( voterService.name(), logWriter ); } catch( IOException x ) { return x; } catch( javax.script.ScriptException x ) { return x; } catch( java.sql.SQLException x ) { return x; } logWriter.close(); replyB.append( logStringWriter.toString() ); return null; } }