1
/* Generated By:JavaCC: Do not edit this line. PropertyListParser.java */
2
package org.apache.commons.configuration.plist;
6
import java.util.ArrayList;
8
import org.apache.commons.configuration.HierarchicalConfiguration;
9
import org.apache.commons.configuration.HierarchicalConfiguration.Node;
11
import org.apache.commons.lang.StringUtils;
12
import org.apache.commons.codec.binary.Hex;
15
* JavaCC based parser for the PropertyList format.
17
* @author Emmanuel Bourg
18
* @version $Revision: 590474 $, $Date: 2007-10-30 22:35:11 +0100 (Di, 30. Okt 2007) $
20
class PropertyListParser implements PropertyListParserConstants {
23
* Remove the quotes at the beginning and at the end of the specified String.
25
protected String removeQuotes(String s)
32
if (s.startsWith("\"") && s.endsWith("\"") && s.length() >= 2)
34
s = s.substring(1, s.length() - 1);
40
protected String unescapeQuotes(String s)
42
return StringUtils.replace(s, "\\\"", "\"");
46
* Remove the white spaces and the data delimiters from the specified
47
* string and parse it as a byte array.
49
protected byte[] filterData(String s) throws ParseException
56
// remove the delimiters
57
if (s.startsWith("<") && s.endsWith(">") && s.length() >= 2)
59
s = s.substring(1, s.length() - 1);
62
// remove the white spaces
63
s = StringUtils.replaceChars(s, " \t\n\r", "");
65
// add a leading 0 to ensure well formed bytes
66
if (s.length() % 2 != 0)
71
// parse and return the bytes
74
return Hex.decodeHex(s.toCharArray());
78
throw (ParseException) new ParseException("Unable to parse the byte[] : " + e.getMessage());
83
* Parse a date formatted as <*D2002-03-22 11:30:00 +0100>
85
protected Date parseDate(String s) throws ParseException
87
return PropertyListConfiguration.parseDate(s);
90
final public PropertyListConfiguration parse() throws ParseException {
91
PropertyListConfiguration configuration = null;
92
configuration = Dictionary();
94
{if (true) return configuration;}
95
throw new Error("Missing return statement in function");
98
final public PropertyListConfiguration Dictionary() throws ParseException {
99
PropertyListConfiguration configuration = new PropertyListConfiguration();
100
List children = new ArrayList();
102
jj_consume_token(DICT_BEGIN);
105
switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
115
if (child.getValue() instanceof HierarchicalConfiguration)
117
// prune & graft the nested configuration to the parent configuration
118
HierarchicalConfiguration conf = (HierarchicalConfiguration) child.getValue();
119
Node root = conf.getRoot();
120
root.setName(child.getName());
128
jj_consume_token(DICT_END);
129
for (int i = 0; i < children.size(); i++)
131
child = (Node) children.get(i);
132
configuration.getRoot().addChild(child);
135
{if (true) return configuration;}
136
throw new Error("Missing return statement in function");
139
final public Node Property() throws ParseException {
142
Node node = new Node();
145
jj_consume_token(EQUAL);
147
node.setValue(value);
148
switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
150
jj_consume_token(DICT_SEPARATOR);
156
{if (true) return node;}
157
throw new Error("Missing return statement in function");
160
final public Object Element() throws ParseException {
164
{if (true) return value;}
166
switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
168
value = Dictionary();
169
{if (true) return value;}
174
{if (true) return value;}
178
{if (true) return value;}
182
{if (true) return value;}
186
jj_consume_token(-1);
187
throw new ParseException();
190
throw new Error("Missing return statement in function");
193
final public List Array() throws ParseException {
194
List list = new ArrayList();
195
Object element = null;
196
jj_consume_token(ARRAY_BEGIN);
197
switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
208
switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
209
case ARRAY_SEPARATOR:
216
jj_consume_token(ARRAY_SEPARATOR);
225
jj_consume_token(ARRAY_END);
226
{if (true) return list;}
227
throw new Error("Missing return statement in function");
230
final public String String() throws ParseException {
233
switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
235
token = jj_consume_token(QUOTED_STRING);
236
{if (true) return unescapeQuotes(removeQuotes(token.image));}
239
token = jj_consume_token(STRING);
240
{if (true) return token.image;}
244
jj_consume_token(-1);
245
throw new ParseException();
247
throw new Error("Missing return statement in function");
250
final public byte[] Data() throws ParseException {
252
token = jj_consume_token(DATA);
253
{if (true) return filterData(token.image);}
254
throw new Error("Missing return statement in function");
257
final public Date Date() throws ParseException {
259
token = jj_consume_token(DATE);
260
{if (true) return parseDate(token.image);}
261
throw new Error("Missing return statement in function");
264
final private boolean jj_2_1(int xla) {
265
jj_la = xla; jj_lastpos = jj_scanpos = token;
266
try { return !jj_3_1(); }
267
catch(LookaheadSuccess ls) { return true; }
268
finally { jj_save(0, xla); }
271
final private boolean jj_3R_14() {
272
if (jj_scan_token(QUOTED_STRING)) return true;
276
final private boolean jj_3R_11() {
281
if (jj_3R_15()) return true;
286
final private boolean jj_3R_13() {
287
if (jj_scan_token(DATE)) return true;
291
final private boolean jj_3R_10() {
292
if (jj_scan_token(DICT_BEGIN)) return true;
296
final private boolean jj_3R_9() {
297
if (jj_3R_13()) return true;
301
final private boolean jj_3R_8() {
302
if (jj_3R_12()) return true;
306
final private boolean jj_3R_12() {
307
if (jj_scan_token(DATA)) return true;
311
final private boolean jj_3R_7() {
312
if (jj_3R_11()) return true;
316
final private boolean jj_3R_4() {
317
if (jj_3R_5()) return true;
321
final private boolean jj_3R_6() {
322
if (jj_3R_10()) return true;
326
final private boolean jj_3R_15() {
327
if (jj_scan_token(STRING)) return true;
331
final private boolean jj_3R_3() {
332
if (jj_scan_token(ARRAY_BEGIN)) return true;
335
if (jj_3R_4()) jj_scanpos = xsp;
336
if (jj_scan_token(ARRAY_END)) return true;
340
final private boolean jj_3_1() {
341
if (jj_3R_3()) return true;
345
final private boolean jj_3R_5() {
356
if (jj_3R_9()) return true;
364
public PropertyListParserTokenManager token_source;
365
SimpleCharStream jj_input_stream;
366
public Token token, jj_nt;
368
private Token jj_scanpos, jj_lastpos;
370
public boolean lookingAhead = false;
371
private boolean jj_semLA;
373
final private int[] jj_la1 = new int[6];
374
static private int[] jj_la1_0;
378
private static void jj_la1_0() {
379
jj_la1_0 = new int[] {0x600000,0x400,0x780100,0x80,0x780120,0x600000,};
381
final private JJCalls[] jj_2_rtns = new JJCalls[1];
382
private boolean jj_rescan = false;
383
private int jj_gc = 0;
385
public PropertyListParser(java.io.InputStream stream) {
386
jj_input_stream = new SimpleCharStream(stream, 1, 1);
387
token_source = new PropertyListParserTokenManager(jj_input_stream);
391
for (int i = 0; i < 6; i++) jj_la1[i] = -1;
392
for (int i = 0; i < jj_2_rtns.length; i++) jj_2_rtns[i] = new JJCalls();
395
public void ReInit(java.io.InputStream stream) {
396
jj_input_stream.ReInit(stream, 1, 1);
397
token_source.ReInit(jj_input_stream);
401
for (int i = 0; i < 6; i++) jj_la1[i] = -1;
402
for (int i = 0; i < jj_2_rtns.length; i++) jj_2_rtns[i] = new JJCalls();
405
public PropertyListParser(java.io.Reader stream) {
406
jj_input_stream = new SimpleCharStream(stream, 1, 1);
407
token_source = new PropertyListParserTokenManager(jj_input_stream);
411
for (int i = 0; i < 6; i++) jj_la1[i] = -1;
412
for (int i = 0; i < jj_2_rtns.length; i++) jj_2_rtns[i] = new JJCalls();
415
public void ReInit(java.io.Reader stream) {
416
jj_input_stream.ReInit(stream, 1, 1);
417
token_source.ReInit(jj_input_stream);
421
for (int i = 0; i < 6; i++) jj_la1[i] = -1;
422
for (int i = 0; i < jj_2_rtns.length; i++) jj_2_rtns[i] = new JJCalls();
425
public PropertyListParser(PropertyListParserTokenManager tm) {
430
for (int i = 0; i < 6; i++) jj_la1[i] = -1;
431
for (int i = 0; i < jj_2_rtns.length; i++) jj_2_rtns[i] = new JJCalls();
434
public void ReInit(PropertyListParserTokenManager tm) {
439
for (int i = 0; i < 6; i++) jj_la1[i] = -1;
440
for (int i = 0; i < jj_2_rtns.length; i++) jj_2_rtns[i] = new JJCalls();
443
final private Token jj_consume_token(int kind) throws ParseException {
445
if ((oldToken = token).next != null) token = token.next;
446
else token = token.next = token_source.getNextToken();
448
if (token.kind == kind) {
452
for (int i = 0; i < jj_2_rtns.length; i++) {
453
JJCalls c = jj_2_rtns[i];
455
if (c.gen < jj_gen) c.first = null;
464
throw generateParseException();
467
static private final class LookaheadSuccess extends java.lang.Error { }
468
final private LookaheadSuccess jj_ls = new LookaheadSuccess();
469
final private boolean jj_scan_token(int kind) {
470
if (jj_scanpos == jj_lastpos) {
472
if (jj_scanpos.next == null) {
473
jj_lastpos = jj_scanpos = jj_scanpos.next = token_source.getNextToken();
475
jj_lastpos = jj_scanpos = jj_scanpos.next;
478
jj_scanpos = jj_scanpos.next;
481
int i = 0; Token tok = token;
482
while (tok != null && tok != jj_scanpos) { i++; tok = tok.next; }
483
if (tok != null) jj_add_error_token(kind, i);
485
if (jj_scanpos.kind != kind) return true;
486
if (jj_la == 0 && jj_scanpos == jj_lastpos) throw jj_ls;
490
final public Token getNextToken() {
491
if (token.next != null) token = token.next;
492
else token = token.next = token_source.getNextToken();
498
final public Token getToken(int index) {
499
Token t = lookingAhead ? jj_scanpos : token;
500
for (int i = 0; i < index; i++) {
501
if (t.next != null) t = t.next;
502
else t = t.next = token_source.getNextToken();
507
final private int jj_ntk() {
508
if ((jj_nt=token.next) == null)
509
return (jj_ntk = (token.next=token_source.getNextToken()).kind);
511
return (jj_ntk = jj_nt.kind);
514
private java.util.Vector jj_expentries = new java.util.Vector();
515
private int[] jj_expentry;
516
private int jj_kind = -1;
517
private int[] jj_lasttokens = new int[100];
518
private int jj_endpos;
520
private void jj_add_error_token(int kind, int pos) {
521
if (pos >= 100) return;
522
if (pos == jj_endpos + 1) {
523
jj_lasttokens[jj_endpos++] = kind;
524
} else if (jj_endpos != 0) {
525
jj_expentry = new int[jj_endpos];
526
for (int i = 0; i < jj_endpos; i++) {
527
jj_expentry[i] = jj_lasttokens[i];
529
boolean exists = false;
530
for (java.util.Enumeration e = jj_expentries.elements(); e.hasMoreElements();) {
531
int[] oldentry = (int[])(e.nextElement());
532
if (oldentry.length == jj_expentry.length) {
534
for (int i = 0; i < jj_expentry.length; i++) {
535
if (oldentry[i] != jj_expentry[i]) {
543
if (!exists) jj_expentries.addElement(jj_expentry);
544
if (pos != 0) jj_lasttokens[(jj_endpos = pos) - 1] = kind;
548
public ParseException generateParseException() {
549
jj_expentries.removeAllElements();
550
boolean[] la1tokens = new boolean[24];
551
for (int i = 0; i < 24; i++) {
552
la1tokens[i] = false;
555
la1tokens[jj_kind] = true;
558
for (int i = 0; i < 6; i++) {
559
if (jj_la1[i] == jj_gen) {
560
for (int j = 0; j < 32; j++) {
561
if ((jj_la1_0[i] & (1<<j)) != 0) {
567
for (int i = 0; i < 24; i++) {
569
jj_expentry = new int[1];
571
jj_expentries.addElement(jj_expentry);
576
jj_add_error_token(0, 0);
577
int[][] exptokseq = new int[jj_expentries.size()][];
578
for (int i = 0; i < jj_expentries.size(); i++) {
579
exptokseq[i] = (int[])jj_expentries.elementAt(i);
581
return new ParseException(token, exptokseq, tokenImage);
584
final public void enable_tracing() {
587
final public void disable_tracing() {
590
final private void jj_rescan_token() {
592
for (int i = 0; i < 1; i++) {
593
JJCalls p = jj_2_rtns[i];
595
if (p.gen > jj_gen) {
596
jj_la = p.arg; jj_lastpos = jj_scanpos = p.first;
598
case 0: jj_3_1(); break;
607
final private void jj_save(int index, int xla) {
608
JJCalls p = jj_2_rtns[index];
609
while (p.gen > jj_gen) {
610
if (p.next == null) { p = p.next = new JJCalls(); break; }
613
p.gen = jj_gen + xla - jj_la; p.first = token; p.arg = xla;
616
static final class JJCalls {