fi.iki.hsivonen.xml.checker
Class SignificantInlineChecker

java.lang.Object
  extended by fi.iki.hsivonen.xml.checker.Checker
      extended by fi.iki.hsivonen.xml.checker.SignificantInlineChecker
All Implemented Interfaces:
ContentHandler

public final class SignificantInlineChecker
extends Checker

Checks whether elements that require significant inline content have it.

Version:
$Id: SignificantInlineChecker.java,v 1.6 2006/12/01 12:34:31 hsivonen Exp $
Author:
hsivonen

Nested Class Summary
(package private)  class SignificantInlineChecker.StackNode
          Inner class for wrapping a mutable boolean in an object.
 
Field Summary
private static com.ibm.icu.text.UnicodeSet INSIGNIFICANT_CHARACTERS
          A thread-safe set of insignificant chacarcters.
private  boolean needToCheck
          Indicates whether checking for significant inline content is necessary.
private  char prev
          A holder for the previous UTF-16 code unit for dealing with high surrogates.
private static String[] REQUIRE_SIGNIFICANT_CONTENT
          A lexicographically sorted array of names of XHTML elements that require significant inline content.
private static String[] SIGNIFICANT_ELEMENTS
          A lexicographically sorted array of names of XHTML elements that count as significant inline content.
private  LinkedList<SignificantInlineChecker.StackNode> stack
          The stack for keeping track of which elements have already had significant inline content.
 
Constructor Summary
SignificantInlineChecker()
          Constructor.
 
Method Summary
 void characters(char[] ch, int start, int length)
           
 void endElement(String uri, String localName, String qName)
           
private static boolean isSignificantCharacter(int c)
          Returns true if teh argument is a significant character.
private static boolean isSignificantElement(String localName)
          Returns true if the argument names an XHTML element that counts as significant inline content.
private  void markSignificant()
          Marks the currently open elements as having significant inline content.
private static boolean requiresSignificantContent(String localName)
          Returns true if the argument names an XHTML element that requires significant inline content.
 void reset()
          Does nothing.
 void startElement(String uri, String localName, String qName, Attributes atts)
           
 
Methods inherited from class fi.iki.hsivonen.xml.checker.Checker
endDocument, endPrefixMapping, err, getDocumentLocator, getErrorHandler, ignorableWhitespace, processingInstruction, setDocumentLocator, setErrorHandler, skippedEntity, startDocument, startPrefixMapping, warn
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

INSIGNIFICANT_CHARACTERS

private static final com.ibm.icu.text.UnicodeSet INSIGNIFICANT_CHARACTERS
A thread-safe set of insignificant chacarcters.


SIGNIFICANT_ELEMENTS

private static final String[] SIGNIFICANT_ELEMENTS
A lexicographically sorted array of names of XHTML elements that count as significant inline content.


REQUIRE_SIGNIFICANT_CONTENT

private static final String[] REQUIRE_SIGNIFICANT_CONTENT
A lexicographically sorted array of names of XHTML elements that require significant inline content.


stack

private LinkedList<SignificantInlineChecker.StackNode> stack
The stack for keeping track of which elements have already had significant inline content. Grows from the head of the list!


needToCheck

private boolean needToCheck
Indicates whether checking for significant inline content is necessary.


prev

private char prev
A holder for the previous UTF-16 code unit for dealing with high surrogates.

Constructor Detail

SignificantInlineChecker

public SignificantInlineChecker()
Constructor.

Method Detail

isSignificantElement

private static boolean isSignificantElement(String localName)
Returns true if the argument names an XHTML element that counts as significant inline content.

Parameters:
localName - name of an HTML element
Returns:
true if the argument names an XHTML element that counts as significant inline content

requiresSignificantContent

private static boolean requiresSignificantContent(String localName)
Returns true if the argument names an XHTML element that requires significant inline content.

Parameters:
localName - name of an HTML element
Returns:
true if the argument names an XHTML element that requires significant inline content

isSignificantCharacter

private static boolean isSignificantCharacter(int c)
Returns true if teh argument is a significant character.

Parameters:
c - a Unicode code point
Returns:
true if teh argument is a significant character

characters

public void characters(char[] ch,
                       int start,
                       int length)
                throws SAXException
Specified by:
characters in interface ContentHandler
Overrides:
characters in class Checker
Throws:
SAXException
See Also:
Checker.characters(char[], int, int)

endElement

public void endElement(String uri,
                       String localName,
                       String qName)
                throws SAXException
Specified by:
endElement in interface ContentHandler
Overrides:
endElement in class Checker
Throws:
SAXException
See Also:
Checker.endElement(java.lang.String, java.lang.String, java.lang.String)

startElement

public void startElement(String uri,
                         String localName,
                         String qName,
                         Attributes atts)
                  throws SAXException
Specified by:
startElement in interface ContentHandler
Overrides:
startElement in class Checker
Throws:
SAXException
See Also:
Checker.startElement(java.lang.String, java.lang.String, java.lang.String, org.xml.sax.Attributes)

markSignificant

private void markSignificant()
Marks the currently open elements as having significant inline content.


reset

public void reset()
Description copied from class: Checker
Does nothing. Subclasses are expected to override this method with an implementation that clears the state of the checker and releases objects the checker might hold references to.

Overrides:
reset in class Checker
See Also:
Checker.reset()