aboutsummaryrefslogtreecommitdiffstats
path: root/java/src/com/android/inputmethod/latin/BaseKeyboardParser.java
blob: 496f65174101e61f87541b37e7597ef80d29bca0 (about) (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
/*
 * Copyright (C) 2010 Google Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
 * use this file except in compliance with the License. You may obtain a copy of
 * the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License.
 */

package com.android.inputmethod.latin;

import com.android.inputmethod.latin.BaseKeyboard.Key;
import com.android.inputmethod.latin.BaseKeyboard.Row;
import com.android.inputmethod.latin.KeyboardSwitcher.KeyboardId;

import org.xmlpull.v1.XmlPullParserException;

import android.content.res.Resources;
import android.content.res.TypedArray;
import android.content.res.XmlResourceParser;
import android.util.Log;
import android.util.TypedValue;
import android.util.Xml;
import android.view.InflateException;

import java.io.IOException;
import java.util.List;

/**
 * Parser for BaseKeyboard.
 *
 * This class parses Keyboard XML file and fill out keys in BaseKeyboard.
 * The Keyboard XML file looks like:
 * <pre>
 *   &gt;!-- xml/keyboard.xml --&lt;
 *   &gt;Keyboard keyboard_attributes*&lt;
 *     &gt;!-- Keyboard Content --&lt;
 *     &gt;Row row_attributes*&lt;
 *       &gt;!-- Row Content --&lt;
 *       &gt;Key key_attributes* /&lt;
 *       &gt;Spacer horizontalGap="0.2in" /&lt;
 *       &gt;include keyboardLayout="@xml/other_keys"&lt;
 *       ...
 *     &gt;/Row&lt;
 *     &gt;include keyboardLayout="@xml/other_rows"&lt;
 *     ...
 *   &gt;/Keyboard&lt;
 * </pre>
 * The XML file which is included in other file must have &gt;merge&lt; as root element, such as:
 * <pre>
 *   &gt;!-- xml/other_keys.xml --&lt;
 *   &gt;merge&lt;
 *     &gt;Key key_attributes* /&lt;
 *     ...
 *   &gt;/merge&lt;
 * </pre>
 * and
 * <pre>
 *   &gt;!-- xml/other_rows.xml --&lt;
 *   &gt;merge&lt;
 *     &gt;Row row_attributes*&lt;
 *       &gt;Key key_attributes* /&lt;
 *     &gt;/Row&lt;
 *     ...
 *   &gt;/merge&lt;
 * </pre>
 * You can also use switch-case-default tags to select Rows and Keys.
 * <pre>
 *   &gt;switch&lt;
 *     &gt;case case_attribute*&lt;
 *       &gt;!-- Any valid tags at switch position --&lt;
 *     &gt;/case&lt;
 *     ...
 *     &gt;default&lt;
 *       &gt;!-- Any valid tags at switch position --&lt;
 *     &gt;/default&lt;
 *   &gt;/switch&lt;
 * </pre>
 *
 * TODO: These are some random ideas to improve this parser.
 * - can specify keyWidth attribute by multiplication of default keyWidth
 *   for example: keyWidth="200%b" ("b" stands for "base")
 * - can declare style and specify styles within tags.
 *   for example:
 *     &gt;switch&lt;
 *       &gt;case colorScheme="white"&lt;
 *         &gt;declare-style name="shift-key" parentStyle="modifier-key"&lt;
 *           &gt;item name="keyIcon"&lt;@drawable/sym_keyboard_shift"&gt;/item&lt;
 *         &gt;/declare-style&lt;
 *       &gt;/case&lt;
 *       &gt;case colorScheme="black"&lt;
 *         &gt;declare-style name="shift-key" parentStyle="modifier-key"&lt;
 *           &gt;item name="keyIcon"&lt;@drawable/sym_bkeyboard_shift"&gt;/item&lt;
 *         &gt;/declare-style&lt;
 *       &gt;/case&lt;
 *     &gt;/switch&lt;
 *     ...
 *     &gt;Key include-style="shift-key" ... /&lt;
 */
public class BaseKeyboardParser {
    private static final String TAG = "BaseKeyboardParser";
    private static final boolean DEBUG_TAG = false;
    private static final boolean DEBUG_PARSER = false;

    // Keyboard XML Tags
    private static final String TAG_KEYBOARD = "Keyboard";
    private static final String TAG_ROW = "Row";
    private static final String TAG_KEY = "Key";
    private static final String TAG_SPACER = "Spacer";
    private static final String TAG_INCLUDE = "include";
    private static final String TAG_MERGE = "merge";
    private static final String TAG_SWITCH = "switch";
    private static final String TAG_CASE = "case";
    private static final String TAG_DEFAULT = "default";

    // String representation of KeyboardSwitcher.MODE_xxx.
    private static final String MODE_TEXT = "text";
    private static final String MODE_URL = "url";
    private static final String MODE_EMAIL = "email";
    private static final String MODE_IM = "im";
    private static final String MODE_WEB = "web";
    private static final String MODE_PHONE = "phone";

    private final BaseKeyboard mKeyboard;
    private final Resources mResources;

    private int mCurrentX = 0;
    private int mCurrentY = 0;
    private int mMaxRowWidth = 0;
    private int mTotalHeight = 0;
    private Row mCurrentRow = null;

    public BaseKeyboardParser(BaseKeyboard keyboard, Resources res) {
        mKeyboard = keyboard;
        mResources = res;
    }

    public int getMaxRowWidth() {
        return mMaxRowWidth;
    }

    public int getTotalHeight() {
        return mTotalHeight;
    }

    public void parseKeyboard(XmlResourceParser parser)
            throws XmlPullParserException, IOException {
        if (DEBUG_PARSER) debugEnterMethod("parseKeyboard", false);
        int event;
        while ((event = parser.next()) != XmlResourceParser.END_DOCUMENT) {
            if (event == XmlResourceParser.START_TAG) {
                final String tag = parser.getName();
                if (DEBUG_TAG) debugStartTag("parseKeyboard", tag, false);
                if (TAG_KEYBOARD.equals(tag)) {
                    parseKeyboardAttributes(parser);
                    parseKeyboardContent(parser, mKeyboard.getKeys());
                    break;
                } else {
                    throw new IllegalStartTag(parser, TAG_KEYBOARD);
                }
            }
        }
        if (DEBUG_PARSER) debugLeaveMethod("parseKeyboard", false);
    }

    private void parseKeyboardAttributes(XmlResourceParser parser) {
        final BaseKeyboard keyboard = mKeyboard;
        final TypedArray a = mResources.obtainAttributes(Xml.asAttributeSet(parser),
                R.styleable.BaseKeyboard);
        final int width = keyboard.getKeyboardWidth();
        final int height = keyboard.getKeyboardHeight();
        keyboard.setKeyWidth(getDimensionOrFraction(a,
                R.styleable.BaseKeyboard_keyWidth, width, width / 10));
        keyboard.setKeyHeight(getDimensionOrFraction(a,
                R.styleable.BaseKeyboard_keyHeight, height, 50));
        keyboard.setHorizontalGap(getDimensionOrFraction(a,
                R.styleable.BaseKeyboard_horizontalGap, width, 0));
        keyboard.setVerticalGap(getDimensionOrFraction(a,
                R.styleable.BaseKeyboard_verticalGap, height, 0));
        a.recycle();
    }

    private void parseKeyboardContent(XmlResourceParser parser, List<Key> keys)
            throws XmlPullParserException, IOException {
        if (DEBUG_PARSER) debugEnterMethod("parseKeyboardContent", keys == null);
        int event;
        while ((event = parser.next()) != XmlResourceParser.END_DOCUMENT) {
            if (event == XmlResourceParser.START_TAG) {
                final String tag = parser.getName();
                if (DEBUG_TAG) debugStartTag("parseKeyboardContent", tag, keys == null);
                if (TAG_ROW.equals(tag)) {
                    Row row = mKeyboard.createRowFromXml(mResources, parser);
                    if (keys != null)
                        startRow(row);
                    parseRowContent(parser, row, keys);
                } else if (TAG_INCLUDE.equals(tag)) {
                    parseIncludeKeyboardContent(parser, keys);
                } else if (TAG_SWITCH.equals(tag)) {
                    parseSwitchKeyboardContent(parser, keys);
                } else {
                    throw new IllegalStartTag(parser, TAG_ROW);
                }
            } else if (event == XmlResourceParser.END_TAG) {
                final String tag = parser.getName();
                if (DEBUG_TAG) debugEndTag("parseKeyboardContent", tag, keys == null);
                if (TAG_KEYBOARD.equals(tag)) {
                    endKeyboard(mKeyboard.getVerticalGap());
                    break;
                } else if (TAG_CASE.equals(tag) || TAG_DEFAULT.equals(tag)) {
                    break;
                } else if (TAG_MERGE.equals(tag)) {
                    break;
                } else {
                    throw new IllegalEndTag(parser, TAG_ROW);
                }
            }
        }
        if (DEBUG_PARSER) debugLeaveMethod("parseKeyboardContent", keys == null);
    }

    private void parseRowContent(XmlResourceParser parser, Row row, List<Key> keys)
            throws XmlPullParserException, IOException {
        if (DEBUG_PARSER) debugEnterMethod("parseRowContent", keys == null);
        int event;
        while ((event = parser.next()) != XmlResourceParser.END_DOCUMENT) {
            if (event == XmlResourceParser.START_TAG) {
                final String tag = parser.getName();
                if (DEBUG_TAG) debugStartTag("parseRowContent", tag, keys == null);
                if (TAG_KEY.equals(tag)) {
                    parseKey(parser, row, keys);
                } else if (TAG_SPACER.equals(tag)) {
                    parseSpacer(parser, keys);
                } else if (TAG_INCLUDE.equals(tag)) {
                    parseIncludeRowContent(parser, row, keys);
                } else if (TAG_SWITCH.equals(tag)) {
                    parseSwitchRowContent(parser, row, keys);
                } else {
                    throw new IllegalStartTag(parser, TAG_KEY);
                }
            } else if (event == XmlResourceParser.END_TAG) {
                final String tag = parser.getName();
                if (DEBUG_TAG) debugEndTag("parseRowContent", tag, keys == null);
                if (TAG_ROW.equals(tag)) {
                    if (keys != null)
                        endRow();
                    break;
                } else if (TAG_CASE.equals(tag) || TAG_DEFAULT.equals(tag)) {
                    break;
                } else if (TAG_MERGE.equals(tag)) {
                    break;
                } else {
                    throw new IllegalEndTag(parser, TAG_KEY);
                }
            }
        }
        if (DEBUG_PARSER) debugLeaveMethod("parseRowContent", keys == null);
    }

    private void parseKey(XmlResourceParser parser, Row row, List<Key> keys)
            throws XmlPullParserException, IOException {
        if (DEBUG_PARSER) debugEnterMethod("parseKey", keys == null);
        if (keys == null) {
            checkEndTag(TAG_KEY, parser);
        } else {
            Key key = mKeyboard.createKeyFromXml(mResources, row, mCurrentX, mCurrentY, parser);
            checkEndTag(TAG_KEY, parser);
            keys.add(key);
            if (key.codes[0] == BaseKeyboard.KEYCODE_SHIFT)
                mKeyboard.getShiftKeys().add(key);
            endKey(key);
        }
    }

    private void parseSpacer(XmlResourceParser parser, List<Key> keys)
            throws XmlPullParserException, IOException {
        if (DEBUG_PARSER) debugEnterMethod("parseSpacer", keys == null);
        if (keys == null) {
            checkEndTag(TAG_SPACER, parser);
        } else {
            final TypedArray a = mResources.obtainAttributes(Xml.asAttributeSet(parser),
                    R.styleable.BaseKeyboard);
            final int gap = getDimensionOrFraction(a, R.styleable.BaseKeyboard_horizontalGap,
                    mKeyboard.getKeyboardWidth(), 0);
            a.recycle();
            checkEndTag(TAG_SPACER, parser);
            setSpacer(gap);
        }
    }

    private void parseIncludeKeyboardContent(XmlResourceParser parser, List<Key> keys)
            throws XmlPullParserException, IOException {
        if (DEBUG_PARSER) debugEnterMethod("parseIncludeKeyboardContent", keys == null);
        parseIncludeInternal(parser, null, keys);
        if (DEBUG_PARSER) debugLeaveMethod("parseIncludeKeyboardContent", keys == null);
    }

    private void parseIncludeRowContent(XmlResourceParser parser, Row row, List<Key> keys)
            throws XmlPullParserException, IOException {
        if (DEBUG_PARSER) debugEnterMethod("parseIncludeRowContent", keys == null);
        parseIncludeInternal(parser, row, keys);
        if (DEBUG_PARSER) debugLeaveMethod("parseIncludeRowContent", keys == null);
    }

    private void parseIncludeInternal(XmlResourceParser parser, Row row, List<Key> keys)
            throws XmlPullParserException, IOException {
        if (keys == null) {
            checkEndTag(TAG_INCLUDE, parser);
        } else {
            final TypedArray a = mResources.obtainAttributes(Xml.asAttributeSet(parser),
                    R.styleable.BaseKeyboard_Include);
            final int keyboardLayout = a.getResourceId(
                    R.styleable.BaseKeyboard_Include_keyboardLayout, 0);
            a.recycle();

            checkEndTag(TAG_INCLUDE, parser);
            if (keyboardLayout == 0)
                throw new ParseException("No keyboardLayout attribute in <include/>", parser);
            parseMerge(mResources.getLayout(keyboardLayout), row, keys);
        }
    }

    private void parseMerge(XmlResourceParser parser, Row row, List<Key> keys)
            throws XmlPullParserException, IOException {
        if (DEBUG_PARSER) debugEnterMethod("parseMerge", keys == null);
        int event;
        while ((event = parser.next()) != XmlResourceParser.END_DOCUMENT) {
            if (event == XmlResourceParser.START_TAG) {
                final String tag = parser.getName();
                if (DEBUG_TAG) debugStartTag("parseMerge", tag, keys == null);
                if (TAG_MERGE.equals(tag)) {
                    if (row == null) {
                        parseKeyboardContent(parser, keys);
                    } else {
                        parseRowContent(parser, row, keys);
                    }
                    break;
                } else {
                    throw new ParseException(
                            "Included keyboard layout must have <merge> root element", parser);
                }
            }
        }
        if (DEBUG_PARSER) debugLeaveMethod("parseMerge", keys == null);
    }

    private void parseSwitchKeyboardContent(XmlResourceParser parser, List<Key> keys)
            throws XmlPullParserException, IOException {
        if (DEBUG_PARSER) debugEnterMethod("parseSwitchKeyboardContent", keys == null);
        parseSwitchInternal(parser, null, keys);
        if (DEBUG_PARSER) debugLeaveMethod("parseSwitchKeyboardContent", keys == null);
    }

    private void parseSwitchRowContent(XmlResourceParser parser, Row row, List<Key> keys)
            throws XmlPullParserException, IOException {
        if (DEBUG_PARSER) debugEnterMethod("parseSwitchRowContent", keys == null);
        parseSwitchInternal(parser, row, keys);
        if (DEBUG_PARSER) debugLeaveMethod("parseSwitchRowContent", keys == null);
    }

    private void parseSwitchInternal(XmlResourceParser parser, Row row, List<Key> keys)
            throws XmlPullParserException, IOException {
        boolean selected = false;
        int event;
        if (DEBUG_TAG) Log.d(TAG, "parseSwitchInternal: id=" + mKeyboard.mId);
        while ((event = parser.next()) != XmlResourceParser.END_DOCUMENT) {
            if (event == XmlResourceParser.START_TAG) {
                final String tag = parser.getName();
                if (DEBUG_TAG) debugStartTag("parseSwitchInternal", tag, keys == null);
                if (TAG_CASE.equals(tag)) {
                    selected |= parseCase(parser, row, selected ? null : keys);
                } else if (TAG_DEFAULT.equals(tag)) {
                    selected |= parseDefault(parser, row, selected ? null : keys);
                } else {
                    throw new IllegalStartTag(parser, TAG_KEY);
                }
            } else if (event == XmlResourceParser.END_TAG) {
                final String tag = parser.getName();
                if (DEBUG_TAG) debugEndTag("parseRowContent", tag, keys == null);
                if (TAG_SWITCH.equals(tag)) {
                    break;
                } else {
                    throw new IllegalEndTag(parser, TAG_KEY);
                }
            }
        }
    }

    private boolean parseCase(XmlResourceParser parser, Row row, List<Key> keys)
            throws XmlPullParserException, IOException {
        if (DEBUG_PARSER) debugEnterMethod("parseCase", keys == null);
        final boolean selected = parseCaseCondition(parser);
        if (row == null) {
            // Processing Rows.
            parseKeyboardContent(parser, selected ? keys : null);
        } else {
            // Processing Keys.
            parseRowContent(parser, row, selected ? keys : null);
        }
        if (DEBUG_PARSER) debugLeaveMethod("parseCase", keys == null || !selected);
        return selected;
    }

    private boolean parseCaseCondition(XmlResourceParser parser) {
        final BaseKeyboard keyboard = mKeyboard;
        final TypedArray a = mResources.obtainAttributes(Xml.asAttributeSet(parser),
                R.styleable.BaseKeyboard_Case);
        final String mode = a.getString(R.styleable.BaseKeyboard_Case_mode);
        final String settingsKey = a.getString(R.styleable.BaseKeyboard_Case_settingsKey);
        final String voiceKey = a.getString(R.styleable.BaseKeyboard_Case_voiceKey);
        a.recycle();

        final KeyboardId id = keyboard.mId;
        if (id == null)
            return true;
        final boolean modeMatched = (mode == null
                || id.mMode == parseModeString(mode));
        final boolean settingsKeyMatched = (settingsKey == null
                || id.mHasSettingsKey == Boolean.parseBoolean(settingsKey));
        final boolean voiceKeyMatched = (voiceKey == null
                || id.mHasVoiceKey == Boolean.parseBoolean(voiceKey));
        final boolean selected = modeMatched && settingsKeyMatched && voiceKeyMatched;
        if (DEBUG_TAG) {
            Log.d(TAG, "parseCaseCondition: " + Boolean.toString(selected).toUpperCase()
                    + (mode != null ? " mode=" + mode : "")
                    + (settingsKey != null ? " settingsKey="+settingsKey : "")
                    + (voiceKey != null ? " voiceKey=" + voiceKey : ""));
        }
        return selected;
    }

    private static int parseModeString(String mode) {
        if (mode.equals(MODE_TEXT)) return KeyboardSwitcher.MODE_TEXT;
        if (mode.equals(MODE_URL)) return KeyboardSwitcher.MODE_URL;
        if (mode.equals(MODE_EMAIL)) return KeyboardSwitcher.MODE_EMAIL;
        if (mode.equals(MODE_IM)) return KeyboardSwitcher.MODE_IM;
        if (mode.equals(MODE_WEB)) return KeyboardSwitcher.MODE_WEB;
        if (mode.equals(MODE_PHONE)) return KeyboardSwitcher.MODE_PHONE;
        throw new RuntimeException("uknown mode attribute in Keyboard XML: " + mode);
    }

    private boolean parseDefault(XmlResourceParser parser, Row row, List<Key> keys)
            throws XmlPullParserException, IOException {
        if (DEBUG_PARSER) debugEnterMethod("parseDefault", keys == null);
        if (row == null) {
            parseKeyboardContent(parser, keys);
        } else {
            parseRowContent(parser, row, keys);
        }
        if (DEBUG_PARSER) debugLeaveMethod("parseDefault", keys == null);
        return true;
    }

    private static void checkEndTag(String tag, XmlResourceParser parser)
            throws XmlPullParserException, IOException {
        if (parser.next() == XmlResourceParser.END_TAG && tag.equals(parser.getName()))
            return;
        throw new NonEmptyTag(tag, parser);
    }

    private void startRow(Row row) {
        mCurrentX = 0;
        mCurrentRow = row;
    }

    private void endRow() {
        if (mCurrentRow == null)
            throw new InflateException("orphant end row tag");
        mCurrentY += mCurrentRow.verticalGap + mCurrentRow.defaultHeight;
        mCurrentRow = null;
    }

    private void endKey(Key key) {
        mCurrentX += key.gap + key.width;
        if (mCurrentX > mMaxRowWidth)
            mMaxRowWidth = mCurrentX;
    }

    private void endKeyboard(int defaultVerticalGap) {
        mTotalHeight = mCurrentY - defaultVerticalGap;
    }

    private void setSpacer(int gap) {
        mCurrentX += gap;
    }

    public static int getDimensionOrFraction(TypedArray a, int index, int base, int defValue) {
        final TypedValue value = a.peekValue(index);
        if (value == null)
            return defValue;
        if (value.type == TypedValue.TYPE_DIMENSION) {
            return a.getDimensionPixelOffset(index, defValue);
        } else if (value.type == TypedValue.TYPE_FRACTION) {
            // Round it to avoid values like 47.9999 from getting truncated
            return Math.round(a.getFraction(index, base, base, defValue));
        }
        return defValue;
    }

    @SuppressWarnings("serial")
    private static class ParseException extends InflateException {
        public ParseException(String msg, XmlResourceParser parser) {
            super(msg + " at line " + parser.getLineNumber());
        }
    }

    @SuppressWarnings("serial")
    private static class IllegalStartTag extends ParseException {
        public IllegalStartTag(XmlResourceParser parser, String parent) {
            super("Illegal start tag " + parser.getName() + " in " + parent, parser);
        }
    }

    @SuppressWarnings("serial")
    private static class IllegalEndTag extends ParseException {
        public IllegalEndTag(XmlResourceParser parser, String parent) {
            super("Illegal end tag " + parser.getName() + " in " + parent, parser);
        }
    }

    @SuppressWarnings("serial")
    private static class NonEmptyTag extends ParseException {
        public NonEmptyTag(String tag, XmlResourceParser parser) {
            super(tag + " must be empty tag", parser);
        }
    }

    private static void debugEnterMethod(String title, boolean skip) {
        Log.d(TAG, title + ": enter" + (skip ? " skip" : ""));
    }

    private static void debugLeaveMethod(String title, boolean skip) {
        Log.d(TAG, title + ": leave" + (skip ? " skip" : ""));
    }

    private static void debugStartTag(String title, String tag, boolean skip) {
        Log.d(TAG, title + ": <" + tag + ">" + (skip ? " skip" : ""));
    }

    private static void debugEndTag(String title, String tag, boolean skip) {
        Log.d(TAG, title + ": </" + tag + ">" + (skip ? " skip" : ""));
    }
 }