source: contrib/MailArchiver/sources/vendor/mime4j/custom/dom/src/main/javacc/org/apache/james/mime4j/field/contentdisposition/ContentDispositionParser.jj @ 6785

Revision 6785, 5.6 KB checked in by rafaelraymundo, 12 years ago (diff)

Ticket #2946 - Liberado codigo do MailArchiver?. Documentação na subpasta DOCS.

Line 
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   *
9 *                                                              *
10 *   http://www.apache.org/licenses/LICENSE-2.0                 *
11 *                                                              *
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 ****************************************************************/
19
20
21/**
22 * RFC2183 Content-Disposition parser.
23 */
24
25options {
26        STATIC=false;
27        LOOKAHEAD=1;
28        JDK_VERSION = "1.5";
29        OUTPUT_DIRECTORY = "../../../../../../../../../target/generated-sources/javacc";
30        //DEBUG_PARSER=true;
31        //DEBUG_TOKEN_MANAGER=true;
32}
33
34PARSER_BEGIN(ContentDispositionParser)
35/****************************************************************
36 * Licensed to the Apache Software Foundation (ASF) under one   *
37 * or more contributor license agreements.  See the NOTICE file *
38 * distributed with this work for additional information        *
39 * regarding copyright ownership.  The ASF licenses this file   *
40 * to you under the Apache License, Version 2.0 (the            *
41 * "License"); you may not use this file except in compliance   *
42 * with the License.  You may obtain a copy of the License at   *
43 *                                                              *
44 *   http://www.apache.org/licenses/LICENSE-2.0                 *
45 *                                                              *
46 * Unless required by applicable law or agreed to in writing,   *
47 * software distributed under the License is distributed on an  *
48 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
49 * KIND, either express or implied.  See the License for the    *
50 * specific language governing permissions and limitations      *
51 * under the License.                                           *
52 ****************************************************************/
53package org.apache.james.mime4j.field.contentdisposition.parser;
54
55import java.util.List;
56import java.util.ArrayList;
57
58public class ContentDispositionParser {
59
60    private String dispositionType;
61    private List<String> paramNames = new ArrayList<String>();
62    private List<String> paramValues = new ArrayList<String>();
63
64    public String getDispositionType() {
65        return dispositionType;
66    }
67
68    public List<String> getParamNames() {
69        return paramNames;
70    }
71
72    public List<String> getParamValues() {
73        return paramValues;
74    }
75
76    public static void main(String args[]) throws ParseException {
77        while (true) {
78            try {
79                ContentDispositionParser parser = new ContentDispositionParser(
80                        System.in);
81                parser.parseLine();
82            } catch (Exception x) {
83                x.printStackTrace();
84                return;
85            }
86        }
87    }
88}
89
90PARSER_END(ContentDispositionParser)
91
92void parseLine() :
93{}
94{
95        parse() ["\r"] "\n"
96}
97
98void parseAll() :
99{}
100{
101        parse() <EOF>
102}
103
104void parse() :
105{
106        Token dispositionType;
107}
108{
109        dispositionType=<ATOKEN>
110        {
111                this.dispositionType = dispositionType.image;
112        }
113        ( ";" parameter() )*
114}
115
116void parameter() :
117{
118        Token attrib;
119        String val;
120}
121{
122        attrib=<ATOKEN> "=" val=value()
123        {
124                paramNames.add(attrib.image);
125                paramValues.add(val);
126        }
127}
128
129String value() :
130{Token t;}
131{
132(       t=<ATOKEN>
133|   t=<DIGITS>
134|       t=<QUOTEDSTRING>
135)
136        { return t.image; }
137}
138
139
140
141SPECIAL_TOKEN :
142{
143        < WS: ( [" ", "\t"] )+ >
144}
145
146TOKEN_MGR_DECLS :
147{
148        // Keeps track of how many levels of comment nesting
149        // we've encountered.  This is only used when the 2nd
150        // level is reached, for example ((this)), not (this).
151        // This is because the outermost level must be treated
152        // specially anyway, because the outermost ")" has a
153        // different token type than inner ")" instances.
154        static int commentNest;
155}
156
157MORE :
158{
159        // starts a comment
160        "(" : INCOMMENT
161}
162
163<INCOMMENT>
164SKIP :
165{
166        // ends a comment
167        < COMMENT: ")" > : DEFAULT
168        // if this is ever changed to not be a SKIP, need
169        // to make sure matchedToken.token = token.toString()
170        // is called.
171}
172
173<INCOMMENT>
174MORE :
175{
176        < <QUOTEDPAIR>> { image.deleteCharAt(image.length() - 2); }
177|       "(" { commentNest = 1; } : NESTED_COMMENT
178|       < <ANY>>
179}
180
181<NESTED_COMMENT>
182MORE :
183{
184        < <QUOTEDPAIR>> { image.deleteCharAt(image.length() - 2); }
185|       "(" { ++commentNest; }
186|       ")" { --commentNest; if (commentNest == 0) SwitchTo(INCOMMENT); }
187|       < <ANY>>
188}
189
190
191
192// QUOTED STRINGS
193
194MORE :
195{
196        "\"" { image.deleteCharAt(image.length() - 1); } : INQUOTEDSTRING
197}
198
199<INQUOTEDSTRING>
200MORE :
201{
202        < <QUOTEDPAIR>> { image.deleteCharAt(image.length() - 2); }
203|       < (~["\"", "\\"])+ >
204}
205
206<INQUOTEDSTRING>
207TOKEN :
208{
209        < QUOTEDSTRING: "\"" > { matchedToken.image = image.substring(0, image.length() - 1); } : DEFAULT
210}
211
212
213TOKEN :
214{
215        < DIGITS: ( ["0"-"9"] )+ >
216}
217
218TOKEN :
219{
220        < ATOKEN: ( ~[" ", "\t", "(", ")", "<", ">", "@", ",", ";", ":", "\\", "\"", "/", "[", "]", "?", "="] )+ >
221}
222
223
224// GLOBALS
225
226<*>
227TOKEN :
228{
229        < #QUOTEDPAIR: "\\" <ANY> >
230|       < #ANY: ~[] >
231}
Note: See TracBrowser for help on using the repository browser.