package org.javarosa.xml.util;

import org.kxml2.io.KXmlParser;

/**
 * Invalid Structure Exceptions are thrown when an invalid
 * definition is found while parsing XML defining CommCare
 * Models.
 *
 * @author ctsims
 */
public class InvalidStructureException extends Exception {

    /**
     * @param message A Message associated with the error.
     * @param parser  The parser in the position at which the error was detected.
     */
    public InvalidStructureException(String message, KXmlParser parser) {
        super("Invalid XML Structure(" + parser.getPositionDescription() + "): " + message);
    }

    /**
     * @param message A Message associated with the error.
     * @param parser  The parser in the position at which the error was detected.
     * @param file    The file being parsed
     */
    public InvalidStructureException(String message, String file, KXmlParser parser) {
        super("Invalid XML Structure in document " + file + "(" + parser.getPositionDescription() + "): " + message);
    }

    public InvalidStructureException(String message) {
        super(message);
    }

    public static InvalidStructureException readableInvalidStructureException(String message, KXmlParser parser) {
        String humanReadableMessage =
                message + InvalidStorageStructureException.buildParserMessage(parser);
        return new InvalidStructureException(humanReadableMessage);
    }
}

@@ -25,16 +25,71 @@
 .util;%0A%0A
+import org.javarosa.core.services.locale.Localization;%0A
 import o
@@ -112,16 +112,16 @@
 Parser;%0A
-
 %0A/**%0A * 
@@ -329,16 +329,97 @@
 eption %7B
+%0A    private String localizationKey;%0A    private String%5B%5D localizationParameters;
 %0A%0A    /*
@@ -1207,24 +1207,24 @@
  message) %7B%0A
-
         supe
@@ -1234,32 +1234,1047 @@
 essage);%0A    %7D%0A%0A
+    private InvalidStructureException(String localizationKey, String%5B%5D localizationParameters, String message) %7B%0A        super(message);%0A        this.localizationKey = localizationKey;%0A        this.localizationParameters = localizationParameters;%0A    %7D%0A%0A    public String getLocalizedMessage() %7B%0A        if (localizationKey != null) %7B%0A            return Localization.get(localizationKey, localizationParameters);%0A        %7D else %7B%0A            return getMessage();%0A        %7D%0A    %7D%0A%0A    public static InvalidStructureException localizableInvalidStructureException(String localizationKey,%0A                                                                                 String%5B%5D localizationParameters,%0A                                                                                 String defaultMessage,%0A                                                                                 KXmlParser parser) %7B%0A        return new InvalidStructureException(localizationKey, localizationParameters, defaultMessage);%0A    %7D%0A%0A
     public stati

Allow for localizable error message to be raised