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 | package Torello.HTML; import java.util.Hashtable; /** * Used to report unbalanced HTML Tags within any Vectorized-HTML page or sub-page. * * <BR /><BR />HTML that is 'balanced' is HTML that (for each and every non-singleton / * non-self-closing tag) has an equal number of opening and closing elements. As an example, if * within an HTML page or snippet, there exists an unclosed {@code <DIV>} element, the * balance-reporter might show four {@code <DIV>'s}, but only three {@code </DIV>'s}. This would * report a {@code 'DIV'} count of {@code '+1'}. * * <BR /><BR />Read more about this variant of validity-checking in class {@link Balance}. * * @see Balance */ public class BalancedHTMLException extends MalformedHTMLException { /** <EMBED CLASS='external-html' DATA-FILE-ID=SVUIDEX> */ public static final long serialVersionUID = 1; /** Creates a new {@code BalancedHTMLException} with no detail message.*/ public BalancedHTMLException() { super(); } /** * Constructs a {@code BalancedHTMLException} with the specified detail message. * * @param unbalancedTags This is a {@code HashMap} that should have been generated by * {@link Balance#check(Vector)} and {@link Balance#checkNonZero(Hashtable)}. This table * is printed into this exception's error detail message. * * <BR /><BR /><B STYLE='color:red;'>IMPORTANT:</B> If this parameter is left null, this * exception's constructor will throw a {@code NullPointerException}! If this table is * empty, the detail message will look bizarre. */ public BalancedHTMLException(Hashtable<String, Integer> unbalancedTags) { super(MESSAGE("", unbalancedTags)); } /** * Constructs a {@code BalancedHTMLException} with the specified detail message. * @param message the detail message. * * @param unbalancedTags This is a {@code HashMap} that should have been generated by * {@link Balance#check(Vector)} and {@link Balance#checkNonZero(Hashtable)}. This table * is printed into this exception's error detail message. * * <BR /><BR /><B STYLE='color:red;'>IMPORTANT:</B> If this parameter is left null, this * exception's constructor will throw a {@code NullPointerException}! If this table is * empty, the detail message will look bizarre. */ public BalancedHTMLException(String message, Hashtable<String, Integer> unbalancedTags) { super(MESSAGE(message, unbalancedTags)); } // This just prints the balance report to the exceptions message. private static String MESSAGE(String message, Hashtable<String, Integer> unbalancedTags) { if (unbalancedTags.size() == 0) return (((message != null) && (message.length() > 0)) ? (message + '\n') : "") + "AN EMPTY HTML-TAG BALANCE-REPORT WAS PROVIDED TO THIS EXCEPTION'S CONSTRUCTOR."; else return (((message != null) && (message.length() > 0)) ? (message + '\n') : "") + Balance.toStringBalance(Balance.checkNonZero(unbalancedTags)); } } |