1
/****************************************************************
2
* Licensed to the Apache Software Foundation (ASF) under one *
3
* or more contributor license agreements. See the NOTICE file *
4
* distributed with this work for additional information *
5
* regarding copyright ownership. The ASF licenses this file *
6
* to you under the Apache License, Version 2.0 (the *
7
* "License"); you may not use this file except in compliance *
8
* with the License. You may obtain a copy of the License at *
10
* http://www.apache.org/licenses/LICENSE-2.0 *
12
* Unless required by applicable law or agreed to in writing, *
13
* software distributed under the License is distributed on an *
14
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY *
15
* KIND, either express or implied. See the License for the *
16
* specific language governing permissions and limitations *
17
* under the License. *
18
****************************************************************/
22
* RFC2045 Content-Type parser.
25
* by Joe Cheng <code@joecheng.com>
32
OUTPUT_DIRECTORY = "../../../../../../../../../target/generated-sources/javacc";
34
//DEBUG_TOKEN_MANAGER=true;
37
PARSER_BEGIN(ContentTypeParser)
38
/****************************************************************
39
* Licensed to the Apache Software Foundation (ASF) under one *
40
* or more contributor license agreements. See the NOTICE file *
41
* distributed with this work for additional information *
42
* regarding copyright ownership. The ASF licenses this file *
43
* to you under the Apache License, Version 2.0 (the *
44
* "License"); you may not use this file except in compliance *
45
* with the License. You may obtain a copy of the License at *
47
* http://www.apache.org/licenses/LICENSE-2.0 *
49
* Unless required by applicable law or agreed to in writing, *
50
* software distributed under the License is distributed on an *
51
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY *
52
* KIND, either express or implied. See the License for the *
53
* specific language governing permissions and limitations *
54
* under the License. *
55
****************************************************************/
56
package org.apache.james.mime4j.field.contenttype.parser;
58
import java.util.List;
59
import java.util.ArrayList;
61
public class ContentTypeParser {
64
private String subtype;
65
private List<String> paramNames = new ArrayList<String>();
66
private List<String> paramValues = new ArrayList<String>();
68
public String getType() { return type; }
69
public String getSubType() { return subtype; }
70
public List<String> getParamNames() { return paramNames; }
71
public List<String> getParamValues() { return paramValues; }
73
public static void main(String args[]) throws ParseException {
76
ContentTypeParser parser = new ContentTypeParser(System.in);
78
} catch (Exception x) {
86
PARSER_END(ContentTypeParser)
106
type=<ATOKEN> "/" subtype=<ATOKEN>
108
this.type = type.image;
109
this.subtype = subtype.image;
120
attrib=<ATOKEN> "=" val=value()
122
paramNames.add(attrib.image);
123
paramValues.add(val);
141
< WS: ( [" ", "\t"] )+ >
146
// Keeps track of how many levels of comment nesting
147
// we've encountered. This is only used when the 2nd
148
// level is reached, for example ((this)), not (this).
149
// This is because the outermost level must be treated
150
// specially anyway, because the outermost ")" has a
151
// different token type than inner ")" instances.
152
static int commentNest;
165
< COMMENT: ")" > : DEFAULT
166
// if this is ever changed to not be a SKIP, need
167
// to make sure matchedToken.token = token.toString()
174
< <QUOTEDPAIR>> { image.deleteCharAt(image.length() - 2); }
175
| "(" { commentNest = 1; } : NESTED_COMMENT
182
< <QUOTEDPAIR>> { image.deleteCharAt(image.length() - 2); }
183
| "(" { ++commentNest; }
184
| ")" { --commentNest; if (commentNest == 0) SwitchTo(INCOMMENT); }
194
"\"" { image.deleteCharAt(image.length() - 1); } : INQUOTEDSTRING
200
< <QUOTEDPAIR>> { image.deleteCharAt(image.length() - 2); }
201
| < (~["\"", "\\"])+ >
207
< QUOTEDSTRING: "\"" > { matchedToken.image = image.substring(0, image.length() - 1); } : DEFAULT
213
< DIGITS: ( ["0"-"9"] )+ >
218
< ATOKEN: ( ~[" ", "\t", "(", ")", "<", ">", "@", ",", ";", ":", "\\", "\"", "/", "[", "]", "?", "="] )+ >
227
< #QUOTEDPAIR: "\\" <ANY> >