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 | package Torello.HTML; /** * Used when an invalid, non-HTML, tag or token has been passed to a method. * * <BR /><BR />For instance, if a programmer accidentally passes the characters {@code 'DVI'}, * instead of {@code 'DIV'}, to a method that accepts HTML tokens / tags, then this exception * would throw. */ public class HTMLTokException extends IllegalArgumentException { /** <EMBED CLASS='external-html' DATA-FILE-ID=SVUIDEX> */ public static final long serialVersionUID = 1; /** Constructs an {@code HTMLTokException} with no detail message. */ public HTMLTokException() { super(); } /** * Constructs an {@code HTMLTokException} with the specified detail message. * @param message the detail message. */ public HTMLTokException(String message) { super(message); } /** * Constructs a new exception with the specified detail message and cause. * * <BR /><BR /><B CLASS=JDDescLabel>NOTE:</B> * * <BR /><BR />The detail message associated with cause is not automatically incorporated into * this exception's detail message. * * @param message The detail message (which is saved for later retrieval by the * {@code Throwable.getMessage()} method). * * @param cause the cause (which is saved for later retrieval by the * {@code Throwable.getCause()} method). (A null value is permitted, and indicates that the * cause is non-existent or unknown.) */ public HTMLTokException(String message, Throwable cause) { super(message, cause); } /** * Constructs a new exception with the specified cause and a detail message of * {@code (cause==null ? null : cause.toString())} (which typically contains the class and * detail message of cause). This constructor is useful for exceptions that are little more * than wrappers for other throwables. * * @param cause The cause (which is saved for later retrieval by the * {@code Throwable.getCause()} method). (A null value is permitted, and indicates that the * cause is nonexistent or unknown.) */ public HTMLTokException(Throwable cause) { super(cause); } /** * This just checks if the passed HTML tok(s) is a valid HTML-element, for instance: * {@code img, div, p, a, b, h1, h2, h3} etc... * * <BR /><BR />It throws an HTMLTokException if an "invalid-{@code String}" is passed. * * @param htmlTags This may be any Java String (or strings), but only Java-String's that are * found to be valid HTML 4 or 5 tags will be accepted. * * <BR /><BR /><B>NOTE:</B> Obviously, the '...' notation means multiple tags may be tested. * If one is found invalid, an exception is immediately thrown. * * @throws HTMLTokException if the value passed in the tok parameter is not found in the * {@code HTMLTags.isTag(tok);} hashtable. */ public static void check(String... htmlTags) { if (htmlTags.length == 0) throw new HTMLTokException ("You have passed zero arguments to the variable-length parameter 'htmlTags'"); else if (htmlTags.length == 1) { if (htmlTags[0] == null) throw new NullPointerException( "You have passed null for the value of HTML Tag/Token here, " + "but this is not allowed." ); if (! HTMLTags.isTag(htmlTags[0])) throw new HTMLTokException ("The HTML-Element provided isn't valid! tok = [" + htmlTags[0] + "]"); } else { String tok; for (int i=0; i < htmlTags.length; i++) if ((tok = htmlTags[i]) == null) throw new NullPointerException( "You have passed multiple HTML Tokens, but one of them was null " + "(param #" + i + "). This is not allowed" ); else if (! HTMLTags.isTag(tok)) throw new HTMLTokException( "You have passed multiple HTML Tokens, but one of them isn't valid! " + "(param #" + i + "), tok = [" + tok + "]" ); } } } |