]> code.citadel.org Git - citadel.git/blob - shaggy/citReply.java
Began implementing the UIDPLUS extension.
[citadel.git] / shaggy / citReply.java
1 /* citReply.java
2  *
3  * Object to parse the reply from the server, so I don't have to think
4  * about it when I write code.
5  */
6
7 import java.util.*;
8
9 public class citReply {
10     public static final int     LISTING_FOLLOWS=100, OK=200, MORE_DATA=300,
11         SEND_LISTING=400, ERROR=500, BINARY_FOLLOWS=600, SEND_BINARY=700,
12         START_CHAT_MODE=800;
13
14     int         res_code;
15     String      line,data;
16     Vector      args, listing;
17     boolean     expressmsg;
18
19     public citReply( String line ) {
20         this.line = line;
21
22         args = new Vector();
23         listing = null;
24         data = null;
25         res_code = ERROR;
26         expressmsg = false;
27
28         if( line != null )
29             parseLine();
30     }
31
32     public void parseLine() {
33         try {
34             res_code = Integer.parseInt( line.substring( 0, 3 ) );
35         } catch( Exception e ) {};
36
37         StringBuffer    s = new StringBuffer();
38
39         if( (line.length() > 3) && (line.charAt( 3 ) == '*') )
40             expressmsg = true;
41
42         for( int i = 4; i < line.length(); i++ ) {
43             char        c = line.charAt( i );
44             if( c == '|' ) {
45                 args.addElement( s.toString() );
46                 s = new StringBuffer();
47             }
48             else
49                 s.append( c );
50         }
51         if( s.length() != 0 ) args.addElement( s.toString() );
52
53     }
54
55     public boolean expressMessage() {
56         return expressmsg;
57     }
58
59     public boolean listingFollows() {
60         return res_code/100 == LISTING_FOLLOWS/100;
61     }
62
63     public boolean ok() {
64         return res_code/100 == OK/100;
65     }
66
67     public boolean moreData() {
68         return res_code/100 == MORE_DATA/100;
69     }
70
71     public boolean sendListing() {
72         return res_code/100 == SEND_LISTING/100;
73     }
74
75     public boolean error() {
76         return res_code/100 == ERROR/100;
77     }
78
79     public  boolean binaryFollows() {
80         return res_code/100 == BINARY_FOLLOWS/100;
81     }
82
83     public boolean sendBinary() {
84         return res_code/100 == SEND_BINARY/100;
85     }
86
87     public boolean startChatMode() {
88         return res_code/100 == START_CHAT_MODE/100;
89     }
90
91     public boolean addData( String s ) {
92         if( s.equals( "000" ) )
93             return false;
94
95         if( listing == null ) listing = new Vector();
96         listing.addElement( s );
97         return true;
98     }
99
100     public String getLine( int i ) {
101         if( listing == null ) return null;
102
103         if( (i<0) || (i>=listing.size()) ) return null;
104
105         return (String)listing.elementAt( i );
106     }
107
108     public String getData() {
109         if( data != null ) return data;
110
111         StringBuffer    s = new StringBuffer();
112
113         for( Enumeration e=listing.elements(); e.hasMoreElements(); ) {
114             s.append( (String)e.nextElement() );
115             s.append( "\n" );
116         }
117
118         data = s.toString();
119
120         return data;
121     }
122
123     public String getArg( int i ) {
124         if( args == null ) return "";
125
126         if( (i<0) || (i>=args.size()) ) return "";
127
128         return (String)args.elementAt( i );
129     } 
130 }
131