001package Torello.HTML;
002
003/**
004 * <CODE>InnerTagValueException - Documentation.</CODE><BR /><BR />
005 * 
006 * This class is not used internally.  Initially the intent was to check for "new-lines" in HTML
007 * attribute-<B STYLE="color: red;">values</B>.  However after looking at some complex java-script
008 * listeners, I saw that is actually allowed pretty readily.  Therefore attribute
009 * <B STYLE="color: red;">values</B> may contain just about anything.  This package was written for
010 * foreign-language news translations and higher-level {@code UTF-8} characters occur inside HTML
011 * element inner-tag <B STYLE="color: red;">values</B> all the time.  I have not deleted this yet,
012 * perhaps it could be used by a another programmer trying to set his own rules.
013 */
014public class InnerTagValueException extends IllegalArgumentException
015{
016    /** <EMBED CLASS="external-html" DATA-FILE-ID="SVUIDEX"> */
017    public static final long serialVersionUID = 1;
018
019    /** Constructs an {@code InnerTagValueException} with no detail message. */
020    public InnerTagValueException()
021    { super(); }
022
023    /**
024     * Constructs an {@code InnerTagValueException} with the specified detail message.
025     * @param message the detail message.
026     */
027    public InnerTagValueException(String message)
028    { super(message); }
029
030    /**
031     * Constructs a new exception with the specified detail message and cause.
032     * <BR /><BR /><B>NOTE:</B> The detail message associated with cause is not automatically
033     * incorporated in this exception's detail message.
034     * @param message The detail message (which is saved for later retrieval by the
035     * {@code Throwable.getMessage()} method).
036     * @param cause the cause (which is saved for later retrieval by the {@code Throwable.getCause()}
037     * method).  (A null value is permitted, and indicates that the cause is nonexistent or unknown.)
038     */
039    public InnerTagValueException(String message, Throwable cause)
040    { super(message, cause); }
041
042    /**
043     * Constructs a new exception with the specified cause and a detail message of
044     * {@code (cause==null ? null : cause.toString())} (which typically contains the class and detail
045     * message of cause).
046     * This constructor is useful for exceptions that are little more than wrappers for other
047     * throwables.
048     * @param cause The cause (which is saved for later retrieval by the {@code Throwable.getCause()}
049     * method).  (A null value is permitted, and indicates that the cause is nonexistent or unknown.)
050     */
051    public InnerTagValueException(Throwable cause)
052    { super(cause); }
053
054    /**
055     * This merely performs a "new-line {@code ('\n')}" test.  If a new-line character is found, an
056     * exception is thrown.
057     * @param value Any Java-{@code String}, but this <B STYLE="color: red;">value</B> is intended to
058     * be used in an HTML-Element Attribute-<B STYLE="color: red;">Value</B> Pair as the
059     * attribute-<B STYLE="color: red;">value</B> (not the attribute-<B STYLE="color: red;">key</B>).
060     * @throws InnerTagValueException If this new-line test fails, this exception is thrown.
061     */
062    public static void check(String value)
063    {
064        if (value.indexOf("\n") != -1) throw new InnerTagValueException(
065            "The following inner-tag attribute-value contains the newline-character:\n" +
066            value.replace("\n", "[\\n]") + "\n"
067        );
068    }
069
070    /**
071     * This performs the identical test as the other method by this same name, but allows for the
072     * attribute-<B STYLE="color: red;">key</B> to be included in the Exception's "Error Message"
073     * (for reporting purposes only)
074     * @param value Any Java-{@code String}, but this <B STYLE="color: red;">value</B> is intended to\
075     * be used in an HTML-Element Attribute-<B STYLE="color: red;">Value</B> Pair as the
076     * attribute-<B STYLE="color: red;">value</B> (not the attribute-<B STYLE="color: red;">key</B>).
077     * @param key This is the key associated with this value.  It is included for "error-reporting'
078     * (the exception's Message {@code String}) only!
079     * @see #check(String)
080     * @throws InnerTagValueException If this new-line test fails, this exception is thrown.
081     */
082    public static void check(String value, String key)
083    {
084        if (value.indexOf("\n") != -1) throw new InnerTagValueException(
085            "The following inner-tag attribute-value contains the newline-character:\n" +
086            "key:\t" + key + "\n" +
087            "value:\t" + value.replace("\n", "[\\n]") + "\n"
088        );
089    }
090}