001package votorola.a.response; // Copyright 2007, 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. 002 003import java.util.*; 004import votorola.a.*; 005import votorola.g.option.*; 006 007 008/** Responder for the command 'help' - to request general information on the voter 009 * service, and instructions on using it. 010 * 011 * @see <a href='../../../../../s/manual.xht#Mail-Response-help' 012 * >../../s/manual.xht#Mail-Response-help</a> 013 */ 014public final class CR_Help extends CommandResponder.Base 015{ 016 017 /** Constructs a CR_Help. 018 */ 019 public CR_Help( VoterService voterService ) { super( voterService, "a.response.CR_Help." ); } 020 021 022 // - C o m m a n d - R e s p o n d e r ------------------------------------------------ 023 024 025 /** Returns true. 026 */ 027 public @Override boolean acceptsAnonymousIssue() { return true; } 028 029 030 031 /** Handles the routine argument processing, and defers the rest 032 * to the {@linkplain VoterService#help(String[],CommandResponder.Session) voter service}. 033 */ 034 public @Override Exception respond( final String[] argv, 035 final CommandResponder.Session session ) 036 { 037 final String commandName = argv[0]; // before rearranged by option parser 038 039 final ReplyBuilder replyB = session.replyBuilder(); 040 final Map<String,Option> optionMap = compileBaseOptions( session ); 041 { 042 final int aFirstNonOption = parse( argv, optionMap, session ); // rearranges argv 043 if( aFirstNonOption == -1 ) return null; // parse error, message already appended 044 045 if( optionMap.get("a.voter.CommandResponder.option.help").hasOccured() ) 046 { 047 help( session ); 048 return null; 049 } 050 051 if( aFirstNonOption < argv.length ) 052 { 053 // replyB.lappend( "a.voter.CommandResponder.unrecognizedArgument(1,2)", 054 replyB.lappend( "a.voter.CommandResponder.unrecognizedArgument.ignored(1,2)", 055 commandName, argv[aFirstNonOption] ).append( '\n' ); 056 replyB.lappendlnn( "a.voter.CommandResponder.helpPrompt(1)", commandName ); 057 // return null; 058 } 059 } 060 061 return voterService.help( argv, session ); 062 } 063 064 065 066}