View Javadoc

1   /* Generated By:JavaCC: Do not edit this line. ContentTypeParser.java */
2   /*
3    *  Copyright 2004 the mime4j project
4    *
5    *  Licensed under the Apache License, Version 2.0 (the "License");
6    *  you may not use this file except in compliance with the License.
7    *  You may obtain a copy of the License at
8    *
9    *      http://www.apache.org/licenses/LICENSE-2.0
10   *
11   *  Unless required by applicable law or agreed to in writing, software
12   *  distributed under the License is distributed on an "AS IS" BASIS,
13   *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   *  See the License for the specific language governing permissions and
15   *  limitations under the License.
16   */
17  package net.sf.beep4j.internal.message.contenttype;
18  
19  import java.util.Map;
20  import java.util.HashMap;
21  
22  public class ContentTypeParser implements ContentTypeParserConstants {
23  
24          private String type;
25          private String subtype;
26          private Map parameters = new HashMap();
27  
28          public String getType() { return type; }
29          public String getSubType() { return subtype; }
30          public Map getParameters() { return parameters; }
31  
32    final public void parseLine() throws ParseException {
33      parse();
34      switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
35      case 1:
36        jj_consume_token(1);
37        break;
38      default:
39        jj_la1[0] = jj_gen;
40        ;
41      }
42      jj_consume_token(2);
43    }
44  
45    final public void parseAll() throws ParseException {
46      parse();
47      jj_consume_token(0);
48    }
49  
50    final public void parse() throws ParseException {
51          Token type;
52          Token subtype;
53      type = jj_consume_token(ATOKEN);
54      jj_consume_token(3);
55      subtype = jj_consume_token(ATOKEN);
56                  this.type = type.image;
57                  this.subtype = subtype.image;
58      label_1:
59      while (true) {
60        switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
61        case 4:
62          ;
63          break;
64        default:
65          jj_la1[1] = jj_gen;
66          break label_1;
67        }
68        jj_consume_token(4);
69        parameter();
70      }
71    }
72  
73    final public void parameter() throws ParseException {
74          Token attrib;
75          String val;
76      attrib = jj_consume_token(ATOKEN);
77      jj_consume_token(5);
78      val = value();
79                  parameters.put(attrib.image.toLowerCase(), val);
80    }
81  
82    final public String value() throws ParseException {
83   Token t;
84      switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
85      case ATOKEN:
86        t = jj_consume_token(ATOKEN);
87        break;
88      case QUOTEDSTRING:
89        t = jj_consume_token(QUOTEDSTRING);
90        break;
91      default:
92        jj_la1[2] = jj_gen;
93        jj_consume_token(-1);
94        throw new ParseException();
95      }
96            {if (true) return t.image;}
97      throw new Error("Missing return statement in function");
98    }
99  
100   public ContentTypeParserTokenManager token_source;
101   SimpleCharStream jj_input_stream;
102   public Token token, jj_nt;
103   private int jj_ntk;
104   private int jj_gen;
105   final private int[] jj_la1 = new int[3];
106   static private int[] jj_la1_0;
107   static {
108       jj_la1_0();
109    }
110    private static void jj_la1_0() {
111       jj_la1_0 = new int[] {0x2,0x10,0x280000,};
112    }
113 
114   public ContentTypeParser(java.io.InputStream stream) {
115     jj_input_stream = new SimpleCharStream(stream, 1, 1);
116     token_source = new ContentTypeParserTokenManager(jj_input_stream);
117     token = new Token();
118     jj_ntk = -1;
119     jj_gen = 0;
120     for (int i = 0; i < 3; i++) jj_la1[i] = -1;
121   }
122 
123   public void ReInit(java.io.InputStream stream) {
124     jj_input_stream.ReInit(stream, 1, 1);
125     token_source.ReInit(jj_input_stream);
126     token = new Token();
127     jj_ntk = -1;
128     jj_gen = 0;
129     for (int i = 0; i < 3; i++) jj_la1[i] = -1;
130   }
131 
132   public ContentTypeParser(java.io.Reader stream) {
133     jj_input_stream = new SimpleCharStream(stream, 1, 1);
134     token_source = new ContentTypeParserTokenManager(jj_input_stream);
135     token = new Token();
136     jj_ntk = -1;
137     jj_gen = 0;
138     for (int i = 0; i < 3; i++) jj_la1[i] = -1;
139   }
140 
141   public void ReInit(java.io.Reader stream) {
142     jj_input_stream.ReInit(stream, 1, 1);
143     token_source.ReInit(jj_input_stream);
144     token = new Token();
145     jj_ntk = -1;
146     jj_gen = 0;
147     for (int i = 0; i < 3; i++) jj_la1[i] = -1;
148   }
149 
150   public ContentTypeParser(ContentTypeParserTokenManager tm) {
151     token_source = tm;
152     token = new Token();
153     jj_ntk = -1;
154     jj_gen = 0;
155     for (int i = 0; i < 3; i++) jj_la1[i] = -1;
156   }
157 
158   public void ReInit(ContentTypeParserTokenManager tm) {
159     token_source = tm;
160     token = new Token();
161     jj_ntk = -1;
162     jj_gen = 0;
163     for (int i = 0; i < 3; i++) jj_la1[i] = -1;
164   }
165 
166   final private Token jj_consume_token(int kind) throws ParseException {
167     Token oldToken;
168     if ((oldToken = token).next != null) token = token.next;
169     else token = token.next = token_source.getNextToken();
170     jj_ntk = -1;
171     if (token.kind == kind) {
172       jj_gen++;
173       return token;
174     }
175     token = oldToken;
176     jj_kind = kind;
177     throw generateParseException();
178   }
179 
180   final public Token getNextToken() {
181     if (token.next != null) token = token.next;
182     else token = token.next = token_source.getNextToken();
183     jj_ntk = -1;
184     jj_gen++;
185     return token;
186   }
187 
188   final public Token getToken(int index) {
189     Token t = token;
190     for (int i = 0; i < index; i++) {
191       if (t.next != null) t = t.next;
192       else t = t.next = token_source.getNextToken();
193     }
194     return t;
195   }
196 
197   final private int jj_ntk() {
198     if ((jj_nt=token.next) == null)
199       return (jj_ntk = (token.next=token_source.getNextToken()).kind);
200     else
201       return (jj_ntk = jj_nt.kind);
202   }
203 
204   private java.util.Vector jj_expentries = new java.util.Vector();
205   private int[] jj_expentry;
206   private int jj_kind = -1;
207 
208   public ParseException generateParseException() {
209     jj_expentries.removeAllElements();
210     boolean[] la1tokens = new boolean[24];
211     for (int i = 0; i < 24; i++) {
212       la1tokens[i] = false;
213     }
214     if (jj_kind >= 0) {
215       la1tokens[jj_kind] = true;
216       jj_kind = -1;
217     }
218     for (int i = 0; i < 3; i++) {
219       if (jj_la1[i] == jj_gen) {
220         for (int j = 0; j < 32; j++) {
221           if ((jj_la1_0[i] & (1<<j)) != 0) {
222             la1tokens[j] = true;
223           }
224         }
225       }
226     }
227     for (int i = 0; i < 24; i++) {
228       if (la1tokens[i]) {
229         jj_expentry = new int[1];
230         jj_expentry[0] = i;
231         jj_expentries.addElement(jj_expentry);
232       }
233     }
234     int[][] exptokseq = new int[jj_expentries.size()][];
235     for (int i = 0; i < jj_expentries.size(); i++) {
236       exptokseq[i] = (int[])jj_expentries.elementAt(i);
237     }
238     return new ParseException(token, exptokseq, tokenImage);
239   }
240 
241   final public void enable_tracing() {
242   }
243 
244   final public void disable_tracing() {
245   }
246 
247 }