FileDocCategorySizeDatePackage
HTMLElementImpl.javaAPI DocJava SE 5 API10657Fri Aug 26 14:55:26 BST 2005com.sun.org.apache.html.internal.dom

HTMLElementImpl

public class HTMLElementImpl extends ElementImpl implements HTMLElement
Implements an HTML-specific element, an {@link org.w3c.dom.Element} that will only appear inside HTML documents. This element extends {@link com.sun.org.apache.xerces.internal.dom.ElementImpl} by adding methods for directly manipulating HTML-specific attributes. All HTML elements gain access to the id, title, lang, dir and class attributes. Other elements add their own specific attributes.
version
$Revision: 1.6 $ $Date: 2003/05/08 20:13:09 $
author
Assaf Arkin
see
org.w3c.dom.html.HTMLElement

Fields Summary
Constructors Summary
HTMLElementImpl(HTMLDocumentImpl owner, String tagName)
Constructor required owner document and element tag name. Will be called by the constructor of specific element types but with a known tag name. Assures that the owner document is an HTML element.

param
owner The owner HTML document
param
tagName The element's tag name

        super( owner, tagName.toUpperCase(Locale.ENGLISH) );
    
Methods Summary
java.lang.Stringcapitalize(java.lang.String value)
Convenience method used to capitalize a one-off attribute value before it is returned. For example, the align values "LEFT" and "left" will both return as "Left".

param
value The value of the attribute
return
The capitalized value

        char[]    chars;
        int        i;
        
        // Convert string to charactares. Convert the first one to upper case,
        // the other characters to lower case, and return the converted string.
        chars = value.toCharArray();
        if ( chars.length > 0 )
        {
            chars[ 0 ] = Character.toUpperCase( chars[ 0 ] );
            for ( i = 1 ; i < chars.length ; ++i )
                chars[ i ] = Character.toLowerCase( chars[ i ] );
            return String.valueOf( chars );
        }
        return value;
    
public java.lang.StringgetAttribute(java.lang.String attrName)

	return super.getAttribute( attrName.toLowerCase(Locale.ENGLISH) );
    
public java.lang.StringgetAttributeNS(java.lang.String namespaceURI, java.lang.String localName)

	if ( namespaceURI != null && namespaceURI.length() > 0 )
	    return super.getAttributeNS( namespaceURI, localName );
	else
	    return super.getAttribute( localName.toLowerCase(Locale.ENGLISH) );
    
public org.w3c.dom.AttrgetAttributeNode(java.lang.String attrName)

	return super.getAttributeNode( attrName.toLowerCase(Locale.ENGLISH) );
    
public org.w3c.dom.AttrgetAttributeNodeNS(java.lang.String namespaceURI, java.lang.String localName)

	if ( namespaceURI != null && namespaceURI.length() > 0 )
	    return super.getAttributeNodeNS( namespaceURI, localName );
	else
	    return super.getAttributeNode( localName.toLowerCase(Locale.ENGLISH) );
    
booleangetBinary(java.lang.String name)
Convenience method used to translate an attribute value into a boolean value. If the attribute has an associated value (even an empty string), it is set and true is returned. If the attribute does not exist, false is returend.

param
value The value of the attribute
return
True or false depending on whether the attribute has been set

        return ( getAttributeNode( name ) != null );
    
java.lang.StringgetCapitalized(java.lang.String name)
Convenience method used to capitalize a one-off attribute value before it is returned. For example, the align values "LEFT" and "left" will both return as "Left".

param
name The name of the attribute
return
The capitalized value

        String    value;
        char[]    chars;
        int        i;
        
        value = getAttribute( name );
        if ( value != null )
        {
            // Convert string to charactares. Convert the first one to upper case,
            // the other characters to lower case, and return the converted string.
            chars = value.toCharArray();
            if ( chars.length > 0 )
            {
                chars[ 0 ] = Character.toUpperCase( chars[ 0 ] );
                for ( i = 1 ; i < chars.length ; ++i )
                    chars[ i ] = Character.toLowerCase( chars[ i ] );
                return String.valueOf( chars );
            }
        }
        return value;
    
public java.lang.StringgetClassName()

        return getAttribute( "class" );
    
public java.lang.StringgetDir()

        return getAttribute( "dir" );
    
public final org.w3c.dom.NodeListgetElementsByTagName(java.lang.String tagName)

	return super.getElementsByTagName( tagName.toUpperCase(Locale.ENGLISH) );
    
public final org.w3c.dom.NodeListgetElementsByTagNameNS(java.lang.String namespaceURI, java.lang.String localName)

	if ( namespaceURI != null && namespaceURI.length() > 0 )
	    return super.getElementsByTagNameNS( namespaceURI, localName.toUpperCase(Locale.ENGLISH) );
	else
	    return super.getElementsByTagName( localName.toUpperCase(Locale.ENGLISH) );
    
public org.w3c.dom.html.HTMLFormElementgetForm()
Convenience method returns the form in which this form element is contained. This method is exposed for form elements through the DOM API, but other elements have no access to it through the API.

        Node    parent;
        
        parent = getParentNode(); 
        while ( parent != null )
        {
            if ( parent instanceof HTMLFormElement )
                return (HTMLFormElement) parent;
            parent = parent.getParentNode();
        }
        return null;
    
public java.lang.StringgetId()

        return getAttribute( "id" );
    
intgetInteger(java.lang.String value)
Convenience method used to translate an attribute value into an integer value. Returns the integer value or zero if the attribute is not a valid numeric string.

param
value The value of the attribute
return
The integer value, or zero if not a valid numeric string

        try
        {
            return Integer.parseInt( value );
        }
        catch ( NumberFormatException except )
        {
            return 0;
        }
    
public java.lang.StringgetLang()

        return getAttribute( "lang" );
    
public java.lang.StringgetTitle()

        return getAttribute( "title" );
    
voidsetAttribute(java.lang.String name, boolean value)
Convenience method used to set a boolean attribute. If the value is true, the attribute is set to an empty string. If the value is false, the attribute is removed. HTML 4.0 understands empty strings as set attributes.

param
name The name of the attribute
param
value The value of the attribute

        if ( value )
            setAttribute( name, name );
        else
            removeAttribute( name );
    
public voidsetClassName(java.lang.String className)

        setAttribute( "class", className );
    
public voidsetDir(java.lang.String dir)

        setAttribute( "dir", dir );
    
public voidsetId(java.lang.String id)

        setAttribute( "id", id );
    
public voidsetLang(java.lang.String lang)

        setAttribute( "lang", lang );
    
public voidsetTitle(java.lang.String title)

        setAttribute( "title", title );