Package org.codehaus.mojo.xml.format
Class IndentCheckSaxHandler
java.lang.Object
org.xml.sax.helpers.DefaultHandler
org.codehaus.mojo.xml.format.IndentCheckSaxHandler
- All Implemented Interfaces:
ContentHandler
,DTDHandler
,EntityResolver
,ErrorHandler
A
DefaultHandler
implementation that detects formatting violations and reports them to the supplied
XmlFormatViolationHandler
.-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static class
An entry that can be stored on a stackprivate static class
An indent occurrence within a file characterized byIndentCheckSaxHandler.Indent.lineNumber
andIndentCheckSaxHandler.Indent.size
. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final StringBuilder
private int
private final File
The file being checkedprivate final int
The number of spaces for indentationprivate IndentCheckSaxHandler.Indent
private Locator
The locator set bySAXParser
private Deque
<IndentCheckSaxHandler.ElementEntry> The element stackprivate final XmlFormatViolationHandler
TheXmlFormatViolationHandler
for reporting found violations -
Constructor Summary
ConstructorsConstructorDescriptionIndentCheckSaxHandler
(File file, int indentSize, XmlFormatViolationHandler violationHandler) -
Method Summary
Modifier and TypeMethodDescriptionvoid
characters
(char[] ch, int start, int length) Stores the passed characters into a character buffer.void
endElement
(String uri, String localName, String qName) Checks indentation for an end element.private void
void
ignorableWhitespace
(char[] chars, int start, int length) Just delegates tocharacters(char[], int, int)
, since this method is not called in all situations where it could be naively expected.resolveEntity
(String publicId, String systemId) Always returns an emptyInputSource
to avoid loading of any DTDs.void
setDocumentLocator
(Locator locator) void
startElement
(String uri, String localName, String qName, Attributes attributes) Checks indentation for a start element.Methods inherited from class org.xml.sax.helpers.DefaultHandler
endDocument, endPrefixMapping, error, fatalError, notationDecl, processingInstruction, skippedEntity, startDocument, startPrefixMapping, unparsedEntityDecl, warning
-
Field Details
-
charBuffer
-
charLineNumber
private int charLineNumber -
file
The file being checked -
indentSize
private final int indentSizeThe number of spaces for indentation -
lastIndent
-
locator
The locator set bySAXParser
-
stack
The element stack -
violationHandler
TheXmlFormatViolationHandler
for reporting found violations
-
-
Constructor Details
-
IndentCheckSaxHandler
-
-
Method Details
-
characters
Stores the passed characters into a character buffer.- Specified by:
characters
in interfaceContentHandler
- Overrides:
characters
in classDefaultHandler
- Throws:
SAXException
- See Also:
-
endElement
Checks indentation for an end element.- Specified by:
endElement
in interfaceContentHandler
- Overrides:
endElement
in classDefaultHandler
- Throws:
SAXException
- See Also:
-
flushCharacters
private void flushCharacters() -
ignorableWhitespace
Just delegates tocharacters(char[], int, int)
, since this method is not called in all situations where it could be naively expected.- Specified by:
ignorableWhitespace
in interfaceContentHandler
- Overrides:
ignorableWhitespace
in classDefaultHandler
- Throws:
SAXException
- See Also:
-
resolveEntity
Always returns an emptyInputSource
to avoid loading of any DTDs.- Specified by:
resolveEntity
in interfaceEntityResolver
- Overrides:
resolveEntity
in classDefaultHandler
- Throws:
SAXException
IOException
- See Also:
-
setDocumentLocator
- Specified by:
setDocumentLocator
in interfaceContentHandler
- Overrides:
setDocumentLocator
in classDefaultHandler
- See Also:
-
startElement
public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException Checks indentation for a start element.- Specified by:
startElement
in interfaceContentHandler
- Overrides:
startElement
in classDefaultHandler
- Throws:
SAXException
- See Also:
-