edu.harvard.hul.ois.jhove.module.html
Class HtmlTagDesc

java.lang.Object
  extended by edu.harvard.hul.ois.jhove.module.html.HtmlTagDesc
Direct Known Subclasses:
HtmlTempTagDesc

public class HtmlTagDesc
extends java.lang.Object

This class defines the permitted behavior of a particular HTML tag. The full descriptive power of a DTD description isn't implemented here, but content types and sequences of content are implemented.

Author:
Gary McGath

Field Summary
protected  int[] _sequence
          Array controlling the number of times each element of _contentArray may be used.
static int SEQ0_1
          Value in _sequence indicating an element may be used 0 or 1 times.
static int SEQ0_MANY
          Value in _sequence indicating an element may be used 0 or more times.
static int SEQ1
          Value in _sequence indicating an element must be used exactly once.
static int SEQ1_MANY
          Value in _sequence indicating an element may be used 1 or more times.
 
Constructor Summary
HtmlTagDesc(java.lang.String name, boolean openTagRequired, boolean closeTagRequired, int[] sequence, java.util.List[] contentArray, java.util.List attributes)
          Constructor for sequenced case.
HtmlTagDesc(java.lang.String name, boolean openTagRequired, boolean closeTagRequired, java.util.List content, java.util.List attributes)
          Constructor for simple case.
 
Method Summary
 void addImplicitContainer(HtmlTagDesc container)
          Provides the object with an array of element tags in which this element can be nested.
protected  boolean allowsPCData()
           
protected  boolean allowsTag(java.lang.String tag, HtmlDocDesc doc)
          Reports whether this element allows a given tag name in its content.
protected  boolean allowsTag(java.lang.String tag, int index, HtmlDocDesc doc)
          Reports whether this element allows a given tag name in its content, at the specified index.
protected  boolean canAdvanceFrom(int index, int elemCount)
          Reports whether it's legal to advance to the next content index.
protected  boolean canGetMoreAt(int index, int elemCount)
          Reports whether additional elements can be matched at the specified content index.
 boolean excludesTag(java.lang.String tag)
          Returns true if a given tag is excluded within this element.
protected  java.util.List implicitContainers(java.lang.String tag)
          Reports whether this element can be implicitly nested in an element with a given tag.
protected  boolean isCloseTagRequired()
          Returns true if the closing tag is required
protected  boolean isContentEmpty()
          Returns true if this element has empty content
 boolean isTemp()
          Reports whether this is a temporary tag descriptor.
 boolean matches(java.lang.String name)
           
protected  java.util.List missingRequiredAttributes(java.util.List names)
          Accepts a list of attribute names, and returns a List of required attribute names which are not present in the parameter list.
protected  HtmlAttributeDesc namedAttDesc(java.lang.String name)
          Returns the attribute with a given name, or null if no such attribute is defined for the element
 void setAttributes(java.lang.String[] attributeArray)
          Alternative way of setting the attribute names.
 void setExcludedContent(java.lang.String[] content)
          Specifies tags which may not be included in this element or in any element nested at any depth within it.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_sequence

protected int[] _sequence
Array controlling the number of times each element of _contentArray may be used.


SEQ0_1

public static final int SEQ0_1
Value in _sequence indicating an element may be used 0 or 1 times.

See Also:
Constant Field Values

SEQ1

public static final int SEQ1
Value in _sequence indicating an element must be used exactly once.

See Also:
Constant Field Values

SEQ1_MANY

public static final int SEQ1_MANY
Value in _sequence indicating an element may be used 1 or more times.

See Also:
Constant Field Values

SEQ0_MANY

public static final int SEQ0_MANY
Value in _sequence indicating an element may be used 0 or more times.

See Also:
Constant Field Values
Constructor Detail

HtmlTagDesc

public HtmlTagDesc(java.lang.String name,
                   boolean openTagRequired,
                   boolean closeTagRequired,
                   java.util.List content,
                   java.util.List attributes)
Constructor for simple case.

Parameters:
name - Name of the element
openTagRequired - true if an opening tag is required
closeTagRequired - true if a closing tag is required
content - List of permitted tags. But what do I do when a particular order is required? Null if element is defined at EMPTY.
attributes - List of HtmlAttributeDesc elements enumerating the permitted attributes. May be null, in which case _attributes will be stored as an empty list.

HtmlTagDesc

public HtmlTagDesc(java.lang.String name,
                   boolean openTagRequired,
                   boolean closeTagRequired,
                   int[] sequence,
                   java.util.List[] contentArray,
                   java.util.List attributes)
Constructor for sequenced case.

Parameters:
name - Name of the element
openTagRequired - true if an opening tag is required
closeTagRequired - true if a closing tag is required
sequence - Array indicating the sequencing of elements in content. Must have the same length as sequence.
attributes - List of HtmlAttributeDesc elements enumerating the permitted attributes. May be null, in which case _attributes will be stored as an empty list.
Method Detail

setExcludedContent

public void setExcludedContent(java.lang.String[] content)
Specifies tags which may not be included in this element or in any element nested at any depth within it. Corresponds to the -(content) feature of the DTD.


excludesTag

public boolean excludesTag(java.lang.String tag)
Returns true if a given tag is excluded within this element. It is necessary to call this method for each element on the stack to determine if it is excluded.


setAttributes

public void setAttributes(java.lang.String[] attributeArray)
Alternative way of setting the attribute names. This can be used where all the attributes are unrestricted. This will replace any previously set attributes.


addImplicitContainer

public void addImplicitContainer(HtmlTagDesc container)
Provides the object with an array of element tags in which this element can be nested. Only tags for elements with optional opening tags may be listed here.


matches

public boolean matches(java.lang.String name)

isTemp

public boolean isTemp()
Reports whether this is a temporary tag descriptor. Returns false unless overridden.


allowsTag

protected boolean allowsTag(java.lang.String tag,
                            int index,
                            HtmlDocDesc doc)
Reports whether this element allows a given tag name in its content, at the specified index.


implicitContainers

protected java.util.List implicitContainers(java.lang.String tag)
Reports whether this element can be implicitly nested in an element with a given tag. There may be more than one implicit container for a tag; if the DTD is unambiguous, there should be only one which is permissible in any given context.


canGetMoreAt

protected boolean canGetMoreAt(int index,
                               int elemCount)
Reports whether additional elements can be matched at the specified content index. The index is assumed to be legal.


canAdvanceFrom

protected boolean canAdvanceFrom(int index,
                                 int elemCount)
Reports whether it's legal to advance to the next content index. The index is assumed to be legal, but the one to which it's trying to advance may not be.


allowsTag

protected boolean allowsTag(java.lang.String tag,
                            HtmlDocDesc doc)
Reports whether this element allows a given tag name in its content. This version should be used only with element descriptors that aren't associated with tags, for determining if a hypothetical implied element could contain the given tag.


allowsPCData

protected boolean allowsPCData()

namedAttDesc

protected HtmlAttributeDesc namedAttDesc(java.lang.String name)
Returns the attribute with a given name, or null if no such attribute is defined for the element


missingRequiredAttributes

protected java.util.List missingRequiredAttributes(java.util.List names)
Accepts a list of attribute names, and returns a List of required attribute names which are not present in the parameter list. Returns an empty List if all required attributes are present.


isCloseTagRequired

protected boolean isCloseTagRequired()
Returns true if the closing tag is required


isContentEmpty

protected boolean isContentEmpty()
Returns true if this element has empty content