Package Torello.HTML
Class QuotesException
- java.lang.Object
-
- java.lang.Throwable
-
- java.lang.Exception
-
- java.lang.RuntimeException
-
- java.lang.IllegalArgumentException
-
- Torello.HTML.QuotesException
-
- All Implemented Interfaces:
java.io.Serializable
public class QuotesException extends java.lang.IllegalArgumentException
ThisExceptionis generated, usually, when a quote-within-quote problem has occurred inside HTML Attributes.
Attribute-values cannot contain quotes, unless the inner-quotes do not match the outer-quotes. Generally, there are not many HTML Inner-Tags that use quotes, other than the occasionalALT="..."text (in an image element), or possibly a Java-Script listener attribute.
However, this package performs quite a bit ofString-operations, soString'sare checked when any method or constructor which builds instances of classTagNodecontaining any Inner-Tag Key-Value Pairs.
In addition to checking for double-within-double-quotation mark problems (or single-quote inside of a singly-quoted string), thisExceptionis also thrown if a user attempts to assign an attribute value that uses the 'no-quotation-marks' version of attribute-value pairs when the value he is passing has any white-space, inside the value-Stringat all.- See Also:
- Serialized Form
Hi-Lited Source-Code:- View Here: Torello/HTML/QuotesException.java
- Open New Browser-Tab: Torello/HTML/QuotesException.java
File Size: 6,119 Bytes Line Count: 135 '\n' Characters Found
-
-
Field Summary
Serializable ID Modifier and Type Field static longserialVersionUIDRegEx Used to Check for Quotes-within-Quotes Errors Modifier and Type Field protected static PatternQUOTES_CHECKER
-
Constructor Summary
Constructors Constructor QuotesException()QuotesException(String message)QuotesException(String message, Throwable cause)QuotesException(Throwable cause)
-
Method Summary
'static'Exception Check MethodsModifier and Type Method static voidcheck(String s, SD quotes, String message)
-
-
-
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 theSerializableImplementation 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.Exceptionandjava.lang.Errorclasses 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;
-
QUOTES_CHECKER
protected static final java.util.regex.Pattern QUOTES_CHECKER
This Regular-ExpressionPatternis used internally for one particular scenario involving a null quotes specifier. It states that aStringmust conform to either single-quotes, double-quotes or no-quotes.
Java Line of Code:
// Throws Exception - No surrounding-quotes, has spaces check("This is an Attribute Value", null, "No Message"); // Passes Inspection - No surrounding-quotes, but has no spaces. check("This-is-an-Attribute-Value", null, "No Message"); // Throws Exception - Has surrounding-quotes, but has quote-within-quote check("This is an\"Attribute\" Value", null, "No Message"); // Passes Inspection - Has surrounding-quotes, no quote-within-quote check("'This is an attribute value'", null, "No Message");
- Code:
- Exact Field Declaration Expression:
protected static final Pattern QUOTES_CHECKER = Pattern.compile("^(\"[^\"]*\"|'[^']*'|[^'\"\\s]*)$");
-
-
Constructor Detail
-
QuotesException
public QuotesException()
Constructs aQuotesExceptionwith no detail message.
-
QuotesException
public QuotesException(java.lang.String message)
Constructs aQuotesExceptionwith the specified detail message.- Parameters:
message- the detail message.
-
QuotesException
public QuotesException(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.)
-
QuotesException
public QuotesException(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 s, SD quotes, java.lang.String message)
The primary purpose of thisstaticfunction is to generate a uniformly formatted error message when a "Quote within Quote" problem is identified. If parameter'quotes'is set toSD.SingleQuotes, then finding a single-quote within the inputStringwill cause thisExceptionthrow. If quotes is set toSD.DoubleQuotes, then finding a double-quote in the inputStringwill cause thisExceptionthrow. If parameter'quotes'is null, then finding either will generate aQuotesException.- Parameters:
s- TheString-token to checkquotes- The surrounding quotes used, or null if no quotes are being used. If this value is null, then finding either quote in the's'parameter will cause thisQuotesExceptionthrow.message- A brief error message to report to the programmer. If this is null, then it is not included.- Throws:
QuotesException- If there is a "Quote within Quote" problem identified, as explained above.- Code:
- Exact Method Body:
if (quotes == null) { if (! QUOTES_CHECKER.matcher(s).find()) throw new QuotesException( ((message == null) ? "" : (message.endsWith("\n") ? message : (message + "\n"))) + "\nString: [" + s + "]\nis not being properly quoted." ); } else if (s.indexOf(quotes.quote) != -1) throw new QuotesException( ((message == null) ? "" : (message.endsWith("\n") ? message : (message + "\n"))) + "\nString: [" + s + "]\n" + "contains a quote that matches the surrounding quotes: " + quotes.quote );
-
-