Home | History | Annotate | Download | only in parser
      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 org.apache.james.mime4j.field.contenttype.parser;
     18 
     19 import java.util.ArrayList;
     20 
     21 public class ContentTypeParser implements ContentTypeParserConstants {
     22 
     23         private String type;
     24         private String subtype;
     25         private ArrayList paramNames = new ArrayList();
     26         private ArrayList paramValues = new ArrayList();
     27 
     28         public String getType() { return type; }
     29         public String getSubType() { return subtype; }
     30         public ArrayList getParamNames() { return paramNames; }
     31         public ArrayList getParamValues() { return paramValues; }
     32 
     33     public static void main(String args[]) throws ParseException {
     34         while (true) {
     35             try {
     36                 ContentTypeParser parser = new ContentTypeParser(System.in);
     37                 parser.parseLine();
     38             } catch (Exception x) {
     39                 x.printStackTrace();
     40                 return;
     41             }
     42         }
     43     }
     44 
     45   final public void parseLine() throws ParseException {
     46     parse();
     47     switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
     48     case 1:
     49       jj_consume_token(1);
     50       break;
     51     default:
     52       jj_la1[0] = jj_gen;
     53       ;
     54     }
     55     jj_consume_token(2);
     56   }
     57 
     58   final public void parseAll() throws ParseException {
     59     parse();
     60     jj_consume_token(0);
     61   }
     62 
     63   final public void parse() throws ParseException {
     64         Token type;
     65         Token subtype;
     66     type = jj_consume_token(ATOKEN);
     67     jj_consume_token(3);
     68     subtype = jj_consume_token(ATOKEN);
     69                 this.type = type.image;
     70                 this.subtype = subtype.image;
     71     label_1:
     72     while (true) {
     73       switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
     74       case 4:
     75         ;
     76         break;
     77       default:
     78         jj_la1[1] = jj_gen;
     79         break label_1;
     80       }
     81       jj_consume_token(4);
     82       parameter();
     83     }
     84   }
     85 
     86   final public void parameter() throws ParseException {
     87         Token attrib;
     88         String val;
     89     attrib = jj_consume_token(ATOKEN);
     90     jj_consume_token(5);
     91     val = value();
     92                 paramNames.add(attrib.image);
     93                 paramValues.add(val);
     94   }
     95 
     96   final public String value() throws ParseException {
     97  Token t;
     98     switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
     99     case ATOKEN:
    100       t = jj_consume_token(ATOKEN);
    101       break;
    102     case QUOTEDSTRING:
    103       t = jj_consume_token(QUOTEDSTRING);
    104       break;
    105     default:
    106       jj_la1[2] = jj_gen;
    107       jj_consume_token(-1);
    108       throw new ParseException();
    109     }
    110           {if (true) return t.image;}
    111     throw new Error("Missing return statement in function");
    112   }
    113 
    114   public ContentTypeParserTokenManager token_source;
    115   SimpleCharStream jj_input_stream;
    116   public Token token, jj_nt;
    117   private int jj_ntk;
    118   private int jj_gen;
    119   final private int[] jj_la1 = new int[3];
    120   static private int[] jj_la1_0;
    121   static {
    122       jj_la1_0();
    123    }
    124    private static void jj_la1_0() {
    125       jj_la1_0 = new int[] {0x2,0x10,0x280000,};
    126    }
    127 
    128   public ContentTypeParser(java.io.InputStream stream) {
    129      this(stream, null);
    130   }
    131   public ContentTypeParser(java.io.InputStream stream, String encoding) {
    132     try { jj_input_stream = new SimpleCharStream(stream, encoding, 1, 1); } catch(java.io.UnsupportedEncodingException e) { throw new RuntimeException(e); }
    133     token_source = new ContentTypeParserTokenManager(jj_input_stream);
    134     token = new Token();
    135     jj_ntk = -1;
    136     jj_gen = 0;
    137     for (int i = 0; i < 3; i++) jj_la1[i] = -1;
    138   }
    139 
    140   public void ReInit(java.io.InputStream stream) {
    141      ReInit(stream, null);
    142   }
    143   public void ReInit(java.io.InputStream stream, String encoding) {
    144     try { jj_input_stream.ReInit(stream, encoding, 1, 1); } catch(java.io.UnsupportedEncodingException e) { throw new RuntimeException(e); }
    145     token_source.ReInit(jj_input_stream);
    146     token = new Token();
    147     jj_ntk = -1;
    148     jj_gen = 0;
    149     for (int i = 0; i < 3; i++) jj_la1[i] = -1;
    150   }
    151 
    152   public ContentTypeParser(java.io.Reader stream) {
    153     jj_input_stream = new SimpleCharStream(stream, 1, 1);
    154     token_source = new ContentTypeParserTokenManager(jj_input_stream);
    155     token = new Token();
    156     jj_ntk = -1;
    157     jj_gen = 0;
    158     for (int i = 0; i < 3; i++) jj_la1[i] = -1;
    159   }
    160 
    161   public void ReInit(java.io.Reader stream) {
    162     jj_input_stream.ReInit(stream, 1, 1);
    163     token_source.ReInit(jj_input_stream);
    164     token = new Token();
    165     jj_ntk = -1;
    166     jj_gen = 0;
    167     for (int i = 0; i < 3; i++) jj_la1[i] = -1;
    168   }
    169 
    170   public ContentTypeParser(ContentTypeParserTokenManager tm) {
    171     token_source = tm;
    172     token = new Token();
    173     jj_ntk = -1;
    174     jj_gen = 0;
    175     for (int i = 0; i < 3; i++) jj_la1[i] = -1;
    176   }
    177 
    178   public void ReInit(ContentTypeParserTokenManager tm) {
    179     token_source = tm;
    180     token = new Token();
    181     jj_ntk = -1;
    182     jj_gen = 0;
    183     for (int i = 0; i < 3; i++) jj_la1[i] = -1;
    184   }
    185 
    186   final private Token jj_consume_token(int kind) throws ParseException {
    187     Token oldToken;
    188     if ((oldToken = token).next != null) token = token.next;
    189     else token = token.next = token_source.getNextToken();
    190     jj_ntk = -1;
    191     if (token.kind == kind) {
    192       jj_gen++;
    193       return token;
    194     }
    195     token = oldToken;
    196     jj_kind = kind;
    197     throw generateParseException();
    198   }
    199 
    200   final public Token getNextToken() {
    201     if (token.next != null) token = token.next;
    202     else token = token.next = token_source.getNextToken();
    203     jj_ntk = -1;
    204     jj_gen++;
    205     return token;
    206   }
    207 
    208   final public Token getToken(int index) {
    209     Token t = token;
    210     for (int i = 0; i < index; i++) {
    211       if (t.next != null) t = t.next;
    212       else t = t.next = token_source.getNextToken();
    213     }
    214     return t;
    215   }
    216 
    217   final private int jj_ntk() {
    218     if ((jj_nt=token.next) == null)
    219       return (jj_ntk = (token.next=token_source.getNextToken()).kind);
    220     else
    221       return (jj_ntk = jj_nt.kind);
    222   }
    223 
    224   private java.util.Vector jj_expentries = new java.util.Vector();
    225   private int[] jj_expentry;
    226   private int jj_kind = -1;
    227 
    228   public ParseException generateParseException() {
    229     jj_expentries.removeAllElements();
    230     boolean[] la1tokens = new boolean[24];
    231     for (int i = 0; i < 24; i++) {
    232       la1tokens[i] = false;
    233     }
    234     if (jj_kind >= 0) {
    235       la1tokens[jj_kind] = true;
    236       jj_kind = -1;
    237     }
    238     for (int i = 0; i < 3; i++) {
    239       if (jj_la1[i] == jj_gen) {
    240         for (int j = 0; j < 32; j++) {
    241           if ((jj_la1_0[i] & (1<<j)) != 0) {
    242             la1tokens[j] = true;
    243           }
    244         }
    245       }
    246     }
    247     for (int i = 0; i < 24; i++) {
    248       if (la1tokens[i]) {
    249         jj_expentry = new int[1];
    250         jj_expentry[0] = i;
    251         jj_expentries.addElement(jj_expentry);
    252       }
    253     }
    254     int[][] exptokseq = new int[jj_expentries.size()][];
    255     for (int i = 0; i < jj_expentries.size(); i++) {
    256       exptokseq[i] = (int[])jj_expentries.elementAt(i);
    257     }
    258     return new ParseException(token, exptokseq, tokenImage);
    259   }
    260 
    261   final public void enable_tracing() {
    262   }
    263 
    264   final public void disable_tracing() {
    265   }
    266 
    267 }
    268