diff --git a/java/src/com/android/inputmethod/keyboard/KeyboardLayoutSet.java b/java/src/com/android/inputmethod/keyboard/KeyboardLayoutSet.java index fd9edec70..9997ff44f 100644 --- a/java/src/com/android/inputmethod/keyboard/KeyboardLayoutSet.java +++ b/java/src/com/android/inputmethod/keyboard/KeyboardLayoutSet.java @@ -301,8 +301,8 @@ public final class KeyboardLayoutSet { final int xmlId = mResources.getIdentifier(keyboardLayoutSetName, "xml", packageName); try { parseKeyboardLayoutSet(mResources, xmlId); - } catch (Exception e) { - throw new RuntimeException(e.getMessage() + " in " + keyboardLayoutSetName); + } catch (final Exception e) { + throw new RuntimeException(e.getMessage() + " in " + keyboardLayoutSetName, e); } return new KeyboardLayoutSet(mContext, mParams); } @@ -318,7 +318,7 @@ public final class KeyboardLayoutSet { if (TAG_KEYBOARD_SET.equals(tag)) { parseKeyboardLayoutSetContent(parser); } else { - throw new XmlParseUtils.IllegalStartTag(parser, TAG_KEYBOARD_SET); + throw new XmlParseUtils.IllegalStartTag(parser, tag, TAG_KEYBOARD_SET); } } } @@ -336,14 +336,14 @@ public final class KeyboardLayoutSet { if (TAG_ELEMENT.equals(tag)) { parseKeyboardLayoutSetElement(parser); } else { - throw new XmlParseUtils.IllegalStartTag(parser, TAG_KEYBOARD_SET); + throw new XmlParseUtils.IllegalStartTag(parser, tag, TAG_KEYBOARD_SET); } } else if (event == XmlPullParser.END_TAG) { final String tag = parser.getName(); if (TAG_KEYBOARD_SET.equals(tag)) { break; } else { - throw new XmlParseUtils.IllegalEndTag(parser, TAG_KEYBOARD_SET); + throw new XmlParseUtils.IllegalEndTag(parser, tag, TAG_KEYBOARD_SET); } } } diff --git a/java/src/com/android/inputmethod/keyboard/internal/KeyboardBuilder.java b/java/src/com/android/inputmethod/keyboard/internal/KeyboardBuilder.java index 8ae1b8881..34f26bc11 100644 --- a/java/src/com/android/inputmethod/keyboard/internal/KeyboardBuilder.java +++ b/java/src/com/android/inputmethod/keyboard/internal/KeyboardBuilder.java @@ -220,7 +220,7 @@ public class KeyboardBuilder { parseKeyboardContent(parser, false); break; } else { - throw new XmlParseUtils.IllegalStartTag(parser, TAG_KEYBOARD); + throw new XmlParseUtils.IllegalStartTag(parser, tag, TAG_KEYBOARD); } } } @@ -321,7 +321,7 @@ public class KeyboardBuilder { } else if (TAG_KEY_STYLE.equals(tag)) { parseKeyStyle(parser, skip); } else { - throw new XmlParseUtils.IllegalStartTag(parser, TAG_ROW); + throw new XmlParseUtils.IllegalStartTag(parser, tag, TAG_ROW); } } else if (event == XmlPullParser.END_TAG) { final String tag = parser.getName(); @@ -333,7 +333,7 @@ public class KeyboardBuilder { || TAG_MERGE.equals(tag)) { break; } else { - throw new XmlParseUtils.IllegalEndTag(parser, TAG_ROW); + throw new XmlParseUtils.IllegalEndTag(parser, tag, TAG_ROW); } } } @@ -345,10 +345,10 @@ public class KeyboardBuilder { R.styleable.Keyboard); try { if (a.hasValue(R.styleable.Keyboard_horizontalGap)) { - throw new XmlParseUtils.IllegalAttribute(parser, "horizontalGap"); + throw new XmlParseUtils.IllegalAttribute(parser, TAG_ROW, "horizontalGap"); } if (a.hasValue(R.styleable.Keyboard_verticalGap)) { - throw new XmlParseUtils.IllegalAttribute(parser, "verticalGap"); + throw new XmlParseUtils.IllegalAttribute(parser, TAG_ROW, "verticalGap"); } return new KeyboardRow(mResources, mParams, parser, mCurrentY); } finally { @@ -373,7 +373,7 @@ public class KeyboardBuilder { } else if (TAG_KEY_STYLE.equals(tag)) { parseKeyStyle(parser, skip); } else { - throw new XmlParseUtils.IllegalStartTag(parser, TAG_KEY); + throw new XmlParseUtils.IllegalStartTag(parser, tag, TAG_ROW); } } else if (event == XmlPullParser.END_TAG) { final String tag = parser.getName(); @@ -387,7 +387,7 @@ public class KeyboardBuilder { || TAG_MERGE.equals(tag)) { break; } else { - throw new XmlParseUtils.IllegalEndTag(parser, TAG_KEY); + throw new XmlParseUtils.IllegalEndTag(parser, tag, TAG_ROW); } } } @@ -548,7 +548,7 @@ public class KeyboardBuilder { } else if (TAG_DEFAULT.equals(tag)) { selected |= parseDefault(parser, row, selected ? true : skip); } else { - throw new XmlParseUtils.IllegalStartTag(parser, TAG_KEY); + throw new XmlParseUtils.IllegalStartTag(parser, tag, TAG_SWITCH); } } else if (event == XmlPullParser.END_TAG) { final String tag = parser.getName(); @@ -556,7 +556,7 @@ public class KeyboardBuilder { if (DEBUG) endTag("", TAG_SWITCH); break; } else { - throw new XmlParseUtils.IllegalEndTag(parser, TAG_KEY); + throw new XmlParseUtils.IllegalEndTag(parser, tag, TAG_SWITCH); } } } diff --git a/java/src/com/android/inputmethod/latin/XmlParseUtils.java b/java/src/com/android/inputmethod/latin/XmlParseUtils.java index f01d4c5e6..48e5ed30a 100644 --- a/java/src/com/android/inputmethod/latin/XmlParseUtils.java +++ b/java/src/com/android/inputmethod/latin/XmlParseUtils.java @@ -30,50 +30,53 @@ public final class XmlParseUtils { @SuppressWarnings("serial") public static class ParseException extends XmlPullParserException { - public ParseException(String msg, XmlPullParser parser) { + public ParseException(final String msg, final XmlPullParser parser) { super(msg + " at " + parser.getPositionDescription()); } } @SuppressWarnings("serial") public static final class IllegalStartTag extends ParseException { - public IllegalStartTag(XmlPullParser parser, String parent) { - super("Illegal start tag " + parser.getName() + " in " + parent, parser); + public IllegalStartTag(final XmlPullParser parser, final String tag, final String parent) { + super("Illegal start tag " + tag + " in " + parent, parser); } } @SuppressWarnings("serial") public static final class IllegalEndTag extends ParseException { - public IllegalEndTag(XmlPullParser parser, String parent) { - super("Illegal end tag " + parser.getName() + " in " + parent, parser); + public IllegalEndTag(final XmlPullParser parser, final String tag, final String parent) { + super("Illegal end tag " + tag + " in " + parent, parser); } } @SuppressWarnings("serial") public static final class IllegalAttribute extends ParseException { - public IllegalAttribute(XmlPullParser parser, String attribute) { - super("Tag " + parser.getName() + " has illegal attribute " + attribute, parser); + public IllegalAttribute(final XmlPullParser parser, final String tag, + final String attribute) { + super("Tag " + tag + " has illegal attribute " + attribute, parser); } } @SuppressWarnings("serial") public static final class NonEmptyTag extends ParseException{ - public NonEmptyTag(String tag, XmlPullParser parser) { + public NonEmptyTag(final XmlPullParser parser, final String tag) { super(tag + " must be empty tag", parser); } } - public static void checkEndTag(String tag, XmlPullParser parser) + public static void checkEndTag(final String tag, final XmlPullParser parser) throws XmlPullParserException, IOException { if (parser.next() == XmlPullParser.END_TAG && tag.equals(parser.getName())) return; - throw new NonEmptyTag(tag, parser); + throw new NonEmptyTag(parser, tag); } - public static void checkAttributeExists(TypedArray attr, int attrId, String attrName, - String tag, XmlPullParser parser) throws XmlPullParserException { - if (attr.hasValue(attrId)) + public static void checkAttributeExists(final TypedArray attr, final int attrId, + final String attrName, final String tag, final XmlPullParser parser) + throws XmlPullParserException { + if (attr.hasValue(attrId)) { return; + } throw new ParseException( "No " + attrName + " attribute found in <" + tag + "/>", parser); }