
org.enhydra.xml.xhtml.dom.xerces.XHTMLElementImpl Maven / Gradle / Ivy
The newest version!
/*
* The Apache Software License, Version 1.1
*
*
* Copyright (c) 1999,2000 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Xerces" and "Apache Software Foundation" must
* not be used to endorse or promote products derived from this
* software without prior written permission. For written
* permission, please contact [email protected].
*
* 5. Products derived from this software may not be called "Apache",
* nor may "Apache" appear in their name, without prior written
* permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation and was
* originally based on software copyright (c) 1999, International
* Business Machines, Inc., http://www.apache.org. For more
* information on the Apache Software Foundation, please see
* .
*/
package org.enhydra.xml.xhtml.dom.xerces;
import java.util.Locale;
import org.enhydra.apache.xerces.dom.ElementNSImpl;
import org.w3c.dom.Attr;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.w3c.dom.html.HTMLElement;
import org.w3c.dom.html.HTMLFormElement;
/*
* Derived from Xerces HTMLDocument implementation.
* Author: Assaf Arkin
*/
/**
* Implements an HTML-specific element, an {@link org.w3c.dom.Element} that
* will only appear inside HTML documents. This element extends {@link
* org.enhydra.apache.xerces.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.
*
* @see org.w3c.dom.html.HTMLElement
*/
public class XHTMLElementImpl
extends ElementNSImpl
implements HTMLElement
{
/**
* 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
*/
XHTMLElementImpl( XHTMLDocumentBase owner, String namespaceURI, String tagName )
{
super( owner, namespaceURI, tagName );
}
public String getId()
{
return getAttribute( "id" );
}
public void setId( String id )
{
setAttribute( "id", id );
}
public String getTitle()
{
return getAttribute( "title" );
}
public void setTitle( String title )
{
setAttribute( "title", title );
}
public String getLang()
{
return getAttribute( "lang" );
}
public void setLang( String lang )
{
setAttribute( "lang", lang );
}
public String getDir()
{
return getAttribute( "dir" );
}
public void setDir( String dir )
{
setAttribute( "dir", dir );
}
public String getClassName()
{
return getAttribute( "class" );
}
public void setClassName( String className )
{
setAttribute( "class", className );
}
/*
* Get the value of a integer attribute
*/
protected final int getIntAttribute(String attr,
int defaultValue) {
String attrVal = getAttribute(attr);
if (attrVal != null) {
return Integer.parseInt(attrVal);
} else {
return defaultValue;
}
}
/*
* Get the value of a integer attribute
*/
protected final int getIntAttribute(String attr) {
return getIntAttribute(attr, 0);
}
/*
* Set the value of a integer attribute.
*/
protected final void setAttribute(String attr,
int value) {
setAttribute(attr, Integer.toString(value));
}
/*
* Get the value of a boolean attribute.
*/
protected final boolean getBooleanAttribute(String name) {
return ( getAttributeNode( name ) != null );
}
/**
* 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
*/
void setAttribute( String name, boolean value )
{
if ( value )
setAttribute( name, name );
else
removeAttribute( name );
}
public Attr getAttributeNode( String attrName )
{
return super.getAttributeNode( attrName.toLowerCase(Locale.ENGLISH) );
}
public Attr getAttributeNodeNS( String namespaceURI,
String localName )
{
if ( namespaceURI != null && namespaceURI.length() > 0 )
return super.getAttributeNodeNS( namespaceURI, localName );
else
return super.getAttributeNode( localName.toLowerCase(Locale.ENGLISH) );
}
public String getAttribute( String attrName )
{
return super.getAttribute( attrName.toLowerCase(Locale.ENGLISH) );
}
public String getAttributeNS( String namespaceURI,
String localName )
{
if ( namespaceURI != null && namespaceURI.length() > 0 )
return super.getAttributeNS( namespaceURI, localName );
else
return super.getAttribute( localName.toLowerCase(Locale.ENGLISH) );
}
public final NodeList getElementsByTagName( String tagName )
{
return super.getElementsByTagName( tagName.toLowerCase(Locale.ENGLISH) );
}
public final NodeList getElementsByTagNameNS( String namespaceURI,
String localName )
{
if ( namespaceURI != null && namespaceURI.length() > 0 )
return super.getElementsByTagNameNS( namespaceURI, localName );
else
return super.getElementsByTagName( localName.toLowerCase(Locale.ENGLISH) );
}
/**
* 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.
*/
public HTMLFormElement getForm()
{
Node parent;
parent = getParentNode();
while ( parent != null )
{
if ( parent instanceof HTMLFormElement )
return (HTMLFormElement) parent;
parent = parent.getParentNode();
}
return null;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy