Package Torello.HTML

Class QuotesException

  • All Implemented Interfaces:
    java.io.Serializable

    public class QuotesException
    extends java.lang.IllegalArgumentException
    This Exception is 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 occasional ALT="..." text (in an image element), or possibly a Java-Script listener attribute.

    However, this package performs quite a bit of String-operations, so String's are checked when any method or constructor which builds instances of class TagNode containing 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), this Exception is 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-string, at all.
    See Also:
    Serialized Form


    • Field Summary

       
      Serializable ID
      Modifier and Type Field
      static long serialVersionUID
       
      RegEx Used to Check for Quotes-within-Quotes Errors
      Modifier and Type Field
      protected static Pattern QUOTES_CHECKER
    • Method Summary

       
      'static' Exception Check Methods
      Modifier and Type Method
      static void check​(String s, SD quotes, String message)
      • Methods inherited from class java.lang.Throwable

        addSuppressed, fillInStackTrace, getCause, getLocalizedMessage, getMessage, getStackTrace, getSuppressed, initCause, printStackTrace, printStackTrace, printStackTrace, setStackTrace, toString
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Field Detail

      • serialVersionUID

        🡇    
        public static final long serialVersionUID
        This fulfils the SerialVersion UID requirement for all classes that implement Java's interface java.io.Serializable. Using the Serializable 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's java.lang.Exception and java.lang.Error classes implement the Serializable 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-Expression Pattern is used internally for one particular scenario involving a null quotes specifier. It states that a String must 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​(java.lang.String message)
        Constructs a QuotesException with 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 in this exception's detail message.
        Parameters:
        message - The detail message (which is saved for later retrieval by the Throwable.getMessage() method).
        cause - the cause (which is saved for later retrieval by the Throwable.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 the Throwable.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 this static function is to generate a uniformly formatted error message when a "Quote within Quote" problem is identified. If parameter 'quotes' is set to SD.SingleQuotes, then finding a single-quote within the input String will cause this Exception throw. If quotes is set to SD.DoubleQuotes, then finding a double-quote in the input String will cause this Exception throw. If parameter 'quotes' is null, then finding either will generate a QuotesException.
        Parameters:
        s - The String-token to check
        quotes - 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 this QuotesException throw.
        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
         );