Package Torello.HTML
Class InnerTagKeyException
- java.lang.Object
-
- java.lang.Throwable
-
- java.lang.Exception
-
- java.lang.RuntimeException
-
- java.lang.IllegalArgumentException
-
- Torello.HTML.InnerTagKeyException
-
- All Implemented Interfaces:
java.io.Serializable
public class InnerTagKeyException extends java.lang.IllegalArgumentException
This occurs whenever a parameter specifies an Inner-Tag "Key-Value Pair" (which, in this package, are also known as Attribute-Value Pairs) that contain inappropriate characters inside thekey-String
.
Reg-Ex Rules:
All matching HTML Element Attributes must have attribute-names (inner-tags) whose nomenclature conforms to this regular-expression:[A-Za-z][\w-]+
.
All this says is that attribute-names must begin with an alphabetic character, and then the characters that follow must be "regular-expression"word-characters '\w'
.
In a regular-expression, the characters that match a\w
include the lettersA-Z
, the (lower-case) lettersa-z
, the digits0-9
, and the underscore'_'
. The minus-sign'-'
may also be used in an attribute-name (it just may not be the first character used in an attribute-name).
Example:
<IMG SRC="http://example.com/pic.jpg"> <DIV data-id="this is example data">
For the above two examples, both the'SRC'
attribute-name (key-name) and the'data-id'
key-name are legitimately named. No exceptions would be thrown if a programmer initiated a search using a string to look for an inner-tag that was named'src'
nor would there be problems using a string named'data-id'
to look for the value ofdata-id
above.
Example:
Properties p = new java.util.Properties(); p.put("My Attribute Value", "data 1"); p.put("123Attribute", "data 2"); p.put("SpecialChars!@#$%", "data 3"); TagNode tn = new TagNode("DIV", p, SD.DoubleQuotes, false);
AnInnerTagKeyException
would be generated for all three cases! Each of the above inner-tag key-value pairs have key-names with illegal characters.
Specifically:- Attribute-Value Pair 1: The key-name contains a space.
- Attribute-Value Pair 2: The key-name begins with a number.
- Attribute-Value Pair 3: The key-name has invalid, non-alpha-numeric characters!
If a search were made using an inner-tag (attribute-name)using aString
that did not meet these criteria, anInnerTagKeyException
would be thrown.- See Also:
- Serialized Form
Hi-Lited Source-Code:- View Here: Torello/HTML/InnerTagKeyException.java
- Open New Browser-Tab: Torello/HTML/InnerTagKeyException.java
File Size: 7,473 Bytes Line Count: 172 '\n' Characters Found
-
-
Field Summary
Serializable ID Modifier and Type Field static long
serialVersionUID
-
Constructor Summary
Constructors Constructor Description InnerTagKeyException()
Constructs anInnerTagKeyException
with no detail message.InnerTagKeyException(String message)
Constructs anInnerTagKeyException
with the specified detail message.InnerTagKeyException(String message, Throwable cause)
Constructs a new exception with the specified detail message and cause.InnerTagKeyException(Throwable cause)
Constructs a new exception with the specified cause and a detail message of(cause==null ? null : cause.toString())
(which typically contains the class and detail message of cause).
-
Method Summary
'static'
Exception Check MethodsModifier and Type Method static void
check(String... keys)
static void
check(String key, String value)
-
-
-
Field Detail
-
serialVersionUID
public static final long serialVersionUID
This fulfils the SerialVersion UID requirement for all classes that implement Java'sinterface java.io.Serializable
. Using theSerializable
Implementation offered by java is very easy, and can make saving program state when debugging a lot easier. It can also be used in place of more complicated systems like "hibernate" to store data as well.
Note that Java'sjava.lang.Exception
andjava.lang.Error
classes implement theSerializable interface
, and a warning-free build expects this field be defined here.- See Also:
- Constant Field Values
- Code:
- Exact Field Declaration Expression:
public static final long serialVersionUID = 1;
-
-
Constructor Detail
-
InnerTagKeyException
public InnerTagKeyException()
Constructs anInnerTagKeyException
with no detail message.
-
InnerTagKeyException
public InnerTagKeyException(java.lang.String message)
Constructs anInnerTagKeyException
with the specified detail message.- Parameters:
message
- the detail message.
-
InnerTagKeyException
public InnerTagKeyException(java.lang.String message, java.lang.Throwable cause)
Constructs a new exception with the specified detail message and cause.
NOTE:
The detail message associated with cause is not automatically incorporated into this exception's detail message.- Parameters:
message
- The detail message (which is saved for later retrieval by theThrowable.getMessage()
method).cause
- the cause (which is saved for later retrieval by theThrowable.getCause()
method). (A null value is permitted, and indicates that the cause is nonexistent or unknown).
-
InnerTagKeyException
public InnerTagKeyException(java.lang.Throwable cause)
Constructs a new exception with the specified cause and a detail message of(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.- Parameters:
cause
- The cause (which is saved for later retrieval by theThrowable.getCause()
method). (A null value is permitted, and indicates that the cause is nonexistent or unknown.)
-
-
Method Detail
-
check
public static void check(java.lang.String... keys)
This verifies that any Java-String
that is intended to be use as an inner-tag conforms to the right rules. If a problem is found, then anInnerTagKeyException
orNullPointerException
is thrown.- Parameters:
keys
- One or many HTML-Inner-Tag to be checked for use as an HTML-Attribute name- Throws:
InnerTagKeyException
- If anyString
does not match theCHECK_KEY
Regular-ExpressionPattern
.java.lang.NullPointerException
- If any of the attributes / inner-tag keys passed are null.- Code:
- Exact Method Body:
for (String key : keys) if (key == null) throw new NullPointerException( "You have passed a null as an Attribute-Name (also known as an " + "'InnerTag-Key Name'), but this is not allowed." ); else if (! AttrRegEx.ATTRIBUTE_KEY_REGEX.matcher(key).find()) throw new InnerTagKeyException ("Inner-tag key has invalid characters: [" + key + ']');
-
check
public static void check(java.lang.String key, java.lang.String value)
This method is identical to thepublic static void check(key);
, except it allows the programmer to add the key-value pair to the Exception's error message. No change to the code is present, except the exception's error message.- Parameters:
key
- Any HTML-Inner-Tag nameto be checked for use as an HTML-Attributevalue
- This is the value taken by this key, it is included for error-logging only, but it is not checked.- Throws:
InnerTagKeyException
- If this class does not match theCHECK_KEY
Regular-ExpressionPattern
, than it throws.- Code:
- Exact Method Body:
if (key == null) throw new NullPointerException( "You have passed a null as an Attribute-Name (also known as an 'InnerTag-Key Name'), " + "but this is not allowed." ); if (! AttrRegEx.ATTRIBUTE_KEY_REGEX.matcher(key).find()) throw new InnerTagKeyException( "The specified inner-tag key has invalid characters: [" + key + "]\n" + "For Key-Value Pair: [" + key + ", " + value + "]" );
-
-