1 17 18 package org.apache.james.imapserver.commands; 19 20 import org.apache.james.util.Assert; 21 22 import java.util.StringTokenizer ; 23 24 class AstringArgument implements ImapArgument 25 { 26 private String name; 27 private boolean isFinal; 28 29 public AstringArgument( String name ) 30 { 31 this.name = name; 32 } 33 34 public Object parse( StringTokenizer tokens ) 35 throws Exception 36 { 37 39 if ( ! tokens.hasMoreTokens() ) { 40 throw new Exception ( "Missing argument <" + this.name + ">"); 41 } 42 String token = tokens.nextToken(); 43 Assert.isTrue( token.length() > 0 ); 44 45 StringBuffer astring = new StringBuffer ( token ); 46 47 if ( astring.charAt(0) == '\"' ) { 48 while ( astring.length() == 1 || 49 astring.charAt( astring.length() - 1 ) != '\"' ) { 50 if ( tokens.hasMoreTokens() ) { 51 astring.append( " " ); 52 astring.append( tokens.nextToken() ); 53 } 54 else { 55 throw new Exception ( "Missing closing quote for <" + this.name + ">" ); 56 } 57 } 58 astring.deleteCharAt( 0 ); 59 astring.deleteCharAt( astring.length() - 1 ); 60 } 61 62 return astring.toString(); 63 } 64 65 public String format() 66 { 67 return "<" + this.name + ">"; 68 } 69 70 } 71 | Popular Tags |