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;

/**
 * This class is not used internally, but is intended to be used to check for invalid 
 * attribute-<B STYLE="color: red;">values</B> inside HTML Tags.  
 * 
 * <BR /><BR />One variant of such a check is look for the presence of new-line ({@code '\n'})
 * characters in those <B STYLE='color:red'>values</B>.  (The HTML 5.0 Specification certainly does
 * not disallow new-lines, though).  Since attribute <B STYLE="color: red;">values</B> may contain
 * just about anything.
 * 
 * <BR /><BR />Since this package was initially written for foreign-language news translations, 
 * higher-level {@code UTF-8} characters occur inside HTML element inner-tag
 * <B STYLE="color: red;">values</B> all the time.  
 */
public class InnerTagValueException extends IllegalArgumentException
{
    /** <EMBED CLASS='external-html' DATA-FILE-ID=SVUIDEX> */
    public static final long serialVersionUID = 1;

    /** Constructs an {@code InnerTagValueException} with no detail message. */
    public InnerTagValueException()
    { super(); }

    /**
     * Constructs an {@code InnerTagValueException} with the specified detail message.
     * @param message the detail message.
     */
    public InnerTagValueException(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 nonexistent or unknown).
     */
    public InnerTagValueException(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 InnerTagValueException(Throwable cause)
    { super(cause); }

    /**
     * This merely performs a "new-line {@code ('\n')}" test.  If a new-line character is found, an
     * exception is thrown.
     * 
     * @param value Any Java-{@code String}, but this <B STYLE="color: red;">value</B> is intended
     * to be used in an HTML-Element Attribute-<B STYLE="color: red;">Value</B> Pair as the
     * attribute-<B STYLE="color: red;">value</B> (not the
     * attribute-<B STYLE="color: red;">key</B>).
     * 
     * @throws InnerTagValueException If this new-line test fails, this exception is thrown.
     */
    public static void check(String value)
    {
        if (value.indexOf("\n") != -1) throw new InnerTagValueException(
            "The following inner-tag attribute-value contains the newline-character:\n" +
            value.replace("\n", "[\\n]") + "\n"
        );
    }

    /**
     * This performs the identical test as the other method by this same name, but allows for the
     * attribute-<B STYLE="color: red;">key</B> to be included in the Exception's "Error Message"
     * (for reporting purposes only)
     * 
     * @param value Any Java-{@code String}, but this <B STYLE="color: red;">value</B> is intended
     * to be used in an HTML-Element Attribute-<B STYLE="color: red;">Value</B> Pair as the
     * attribute-<B STYLE="color: red;">value</B> (not the
     * attribute-<B STYLE="color: red;">key</B>).
     * 
     * @param key This is the key associated with this value.  It is included for "error-reporting'
     * (the exception's Message {@code String}) only!
     * 
     * @see #check(String)
     * @throws InnerTagValueException If this new-line test fails, this exception is thrown.
     */
    public static void check(String value, String key)
    {
        if (value.indexOf("\n") != -1) throw new InnerTagValueException(
            "The following inner-tag attribute-value contains the newline-character:\n" +
            "key:\t" + key + "\n" +
            "value:\t" + value.replace("\n", "[\\n]") + "\n"
        );
    }
}