gnu.javax.swing.text.html.parser

Class htmlValidator


public abstract class htmlValidator
extends Object

The HTML content validator, is responsible for opening and closing elements with optional start/end tags, detecting the wrongly placed html tags and reporting errors. The working instance is the inner class inside the Parser

This class could potentially provide basis for automated closing and insertion of the html tags, correcting the found html errors.

Nested Class Summary

protected class
htmlValidator.hTag
The tag reference, holding additional information that the tag has been forcibly closed.

Field Summary

protected DTD
dtd
The DTD, providing information about the valid document structure.
protected LinkedList<T>
stack
The stack, holding the current tag context.

Constructor Summary

htmlValidator(DTD a_dtd)
Creates a new tag stack, using the given DTD.

Method Summary

protected void
checkContentModel(TagElement tElement, boolean first)
Check for mandatory elements, subsequent to the last tag:
void
closeAll()
Close all opened tags (called at the end of parsing).
boolean
closeTag(TagElement tElement)
Remove the given tag from the stack or (if found) from the list of the forcibly closed tags.
protected abstract void
handleSupposedEndTag(Element element)
The method is called when the tag must be closed because it does not allow the subsequent elements inside its context or the end of stream has been reached.
protected abstract void
handleSupposedStartTag(Element element)
The method is called when the validator decides to open the tag on its own initiative.
void
openTag(TagElement tElement, htmlAttributeSet parameters)
Add the given HTML tag to the stack of the opened tags.
void
restart()
Clear the stack.
protected abstract void
s_error(String msg)
Handles the error message.
Object
tagIsValidForContext(TagElement tElement)
Check if this tag is valid for the current context.
protected void
validateParameters(TagElement tag, htmlAttributeSet parameters)
Validate the parameters, report the error if the given parameter is not in the parameter set, valid for the given attribute.
void
validateTag(TagElement tElement, htmlAttributeSet parameters)
Validate tag without storing in into the tag stack.

Methods inherited from class java.lang.Object

clone, equals, extends Object> getClass, finalize, hashCode, notify, notifyAll, toString, wait, wait, wait

Field Details

dtd

protected final DTD dtd
The DTD, providing information about the valid document structure.

stack

protected final LinkedList<T> stack
The stack, holding the current tag context.

Constructor Details

htmlValidator

public htmlValidator(DTD a_dtd)
Creates a new tag stack, using the given DTD.
Parameters:
a_dtd - A DTD, providing the information about the valid tag content.

Method Details

checkContentModel

protected void checkContentModel(TagElement tElement,
                                 boolean first)
Check for mandatory elements, subsequent to the last tag:
Parameters:
tElement - The element that will be inserted next.

closeAll

public void closeAll()
Close all opened tags (called at the end of parsing).

closeTag

public boolean closeTag(TagElement tElement)
Remove the given tag from the stack or (if found) from the list of the forcibly closed tags.

handleSupposedEndTag

protected abstract void handleSupposedEndTag(Element element)
The method is called when the tag must be closed because it does not allow the subsequent elements inside its context or the end of stream has been reached. The parser is only informed if the element being closed does not require the end tag (the "omitEnd" flag is set). The closing message must be passed to the parser mechanism before passing message about the opening the next tag.
Parameters:
element - The tag being fictionally (forcibly) closed.

handleSupposedStartTag

protected abstract void handleSupposedStartTag(Element element)
The method is called when the validator decides to open the tag on its own initiative. This may happen if the content model includes the element with the optional (supposed) start tag.
Parameters:
element - The tag being opened.

openTag

public void openTag(TagElement tElement,
                    htmlAttributeSet parameters)
Add the given HTML tag to the stack of the opened tags. Forcibly closes all tags in the stack that does not allow this tag in they content (error is reported).
Parameters:

restart

public void restart()
Clear the stack.

s_error

protected abstract void s_error(String msg)
Handles the error message. This method must be overridden to pass the message where required.
Parameters:
msg - The message text.

tagIsValidForContext

public Object tagIsValidForContext(TagElement tElement)
Check if this tag is valid for the current context. Return Boolean.True if it is OK, Boolean.False if it is surely not OK or the Element that the content model recommends to insert making the situation ok. If Boolean.True is returned, the content model current position is moved forward. Otherwise this position remains the same.
Parameters:
tElement -
Returns:

validateParameters

protected void validateParameters(TagElement tag,
                                  htmlAttributeSet parameters)
Validate the parameters, report the error if the given parameter is not in the parameter set, valid for the given attribute. The information about the valid parameter set is taken from the Element, enclosed inside the tag. The method does not validate the default parameters.
Parameters:
tag - The tag
parameters - The parameters of this tag.

validateTag

public void validateTag(TagElement tElement,
                        htmlAttributeSet parameters)
Validate tag without storing in into the tag stack. This is called for the empty tags and results the subsequent calls to the openTag and closeTag.

tagStack.java -- The HTML tag stack. Copyright (C) 2005 Free Software Foundation, Inc. This file is part of GNU Classpath. GNU Classpath is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. GNU Classpath is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with GNU Classpath; see the file COPYING. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. Linking this library statically or dynamically with other modules is making a combined work based on this library. Thus, the terms and conditions of the GNU General Public License cover the whole combination. As a special exception, the copyright holders of this library give you permission to link this library with independent modules to produce an executable, regardless of the license terms of these independent modules, and to copy and distribute the resulting executable under terms of your choice, provided that you also meet, for each linked independent module, the terms and conditions of the license of that module. An independent module is a module which is not derived from or based on this library. If you modify this library, you may extend this exception to your version of the library, but you are not obligated to do so. If you do not wish to do so, delete this exception statement from your version.