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