org.exolab.adaptx.xslt

Class XSLObject

public class XSLObject extends Object

This class represents an XSLObject in the style tree. It is the most basic of all XSLObjects and contains common functionality across different XSLObjects. I originally had this implemented as an extended W3C DOM XML Element, but due to problems with extending different implementations, and to make it more cross-DOM accessible I've chosen an this approach. Since this once was a DOM Element, you will notice many of the methods are very DOM-like.

Version: $Revision: 3934 $ $Date: 2003-10-02 05:58:30 -0400 (Thu, 02 Oct 2003) $

Author: Keith Visco

Field Summary
static shortAPPLY_IMPORTS
static shortAPPLY_TEMPLATES
static shortARG
static shortATTRIBUTE
static shortATTRIBUTE_SET
static shortCALL_TEMPLATE
static shortCDATA
static shortCHOOSE
static shortCOMMENT
static shortCONTENTS
static shortCOPY
static shortCOPY_OF
static shortELEMENT
static shortENTITY_REF
static shortFOR_EACH
static shortFUNCTIONS
static shortID
static shortIF
static shortIMPORT
static shortINCLUDE
static shortKEY
static shortLITERAL
static shortLOCALE
static shortMESSAGE
static shortNUMBER
static shortOTHERWISE
static shortOUTPUT
static shortPARAM
static shortPI
static shortPRESERVE_SPACE
static shortSCRIPT
static shortSORT
static shortSTRIP_SPACE
static shortSTYLESHEET
static shortTEMPLATE
static shortTEXT
static shortVALUE_OF
static shortVARIABLE
static shortWHEN
static shortWITH_PARAM
Constructor Summary
XSLObject(short type)
Creates an XSLObject using the specified type
Method Summary
voidaddNamespaceDecl(String prefix, String namespace)
Adds the Given namespace declaration to this XSLObject's set of namespace declarations
booleanappendAction(XSLObject xslObject)
Appends the given XSLObject to this XSLObject's list of actions.
voidappendText(String text)
Appends the text to this XSLObject.
voidappendText(char[] chars, int start, int length)
Appends the text to this XSLObject.
ActionTemplategetActions()
Returns the list of actions for this XSLObject
StringgetAttribute(String name)
Returns the value of the attribute whose name is equal to the given name.
AttributeListgetAttributes()
Returns the value of the specified attribute as an AttributeValueTemplate
StringgetNamespace()
Returns this XSLObject's namespace URI.
XSLObjectgetNearestAncestor(short type)
Returns the nearest ancestor of this XSLObject that is of the given type.
static StringgetNodeValue(Node node)
Returns the String value of a DOM Node.
XSLTStylesheetgetStylesheet()
Returns the XSLStylesheet which contains this XSLObject
static StringgetText(Element element)
Retrieves the text of an Element
shortgetType()
Returns the type of XSLObject this Object represents
static shortgetTypeFromName(String name)
Returns the type of XSL Object that has the given name
StringgetTypeName()
Returns the name of this XSLObject
StringresolveNamespace(String prefix)
voidsetAllowActions(boolean allow)
voidsetAttribute(String name, String value)
Sets the attribute with the given name to the given value.
voidsetNamespace(String uri)
Sets this XSLObject's namespace URI
voidsetTypeName(String name)

Field Detail

APPLY_IMPORTS

public static final short APPLY_IMPORTS

APPLY_TEMPLATES

public static final short APPLY_TEMPLATES

ARG

public static final short ARG

ATTRIBUTE

public static final short ATTRIBUTE

ATTRIBUTE_SET

public static final short ATTRIBUTE_SET

CALL_TEMPLATE

public static final short CALL_TEMPLATE

CDATA

public static final short CDATA

CHOOSE

public static final short CHOOSE

COMMENT

public static final short COMMENT

CONTENTS

public static final short CONTENTS

COPY

public static final short COPY

COPY_OF

public static final short COPY_OF

ELEMENT

public static final short ELEMENT

ENTITY_REF

public static final short ENTITY_REF

FOR_EACH

public static final short FOR_EACH

FUNCTIONS

public static final short FUNCTIONS

ID

public static final short ID

IF

public static final short IF

IMPORT

public static final short IMPORT

INCLUDE

public static final short INCLUDE

KEY

public static final short KEY

LITERAL

public static final short LITERAL

LOCALE

public static final short LOCALE

MESSAGE

public static final short MESSAGE

NUMBER

public static final short NUMBER

OTHERWISE

public static final short OTHERWISE

OUTPUT

public static final short OUTPUT

PARAM

public static final short PARAM

PI

public static final short PI

PRESERVE_SPACE

public static final short PRESERVE_SPACE

SCRIPT

public static final short SCRIPT

SORT

public static final short SORT

STRIP_SPACE

public static final short STRIP_SPACE

STYLESHEET

public static final short STYLESHEET

TEMPLATE

public static final short TEMPLATE

TEXT

public static final short TEXT

VALUE_OF

public static final short VALUE_OF

VARIABLE

public static final short VARIABLE

WHEN

public static final short WHEN

WITH_PARAM

public static final short WITH_PARAM

Constructor Detail

XSLObject

public XSLObject(short type)
Creates an XSLObject using the specified type

Parameters: parentStylesheet the owner XSLStylesheet of the new Element type the type of XSLObject that the new instance represents

Method Detail

addNamespaceDecl

public void addNamespaceDecl(String prefix, String namespace)
Adds the Given namespace declaration to this XSLObject's set of namespace declarations

appendAction

public boolean appendAction(XSLObject xslObject)
Appends the given XSLObject to this XSLObject's list of actions.

Parameters: xslObject the XSLObject to add to this XSLObject's list of actions

Returns: true if the given XSLObject has been added to this XSLObject otherwise false

appendText

public void appendText(String text)
Appends the text to this XSLObject. This is slightly more efficient than using appendAction(new XSLText(text)) if the last child is already an XSLText object. Otherwise there is no difference.

Parameters: text the text to append

appendText

public void appendText(char[] chars, int start, int length)
Appends the text to this XSLObject. This is slightly more efficient than using appendAction(new XSLText(text)) if the last child is already an XSLText object. Otherwise there is no difference.

Parameters: text the text to append

getActions

public ActionTemplate getActions()
Returns the list of actions for this XSLObject

Returns: the list of actions for this XSLObject

getAttribute

public String getAttribute(String name)
Returns the value of the attribute whose name is equal to the given name.

Returns: the value of the attribute whose name is equal to the given name or null if no attribute exist's with such a name.

getAttributes

public AttributeList getAttributes()
Returns the value of the specified attribute as an AttributeValueTemplate

Returns: the value of the specified attribute as an AttributeValueTemplate an Enumeration of the names of the attributes of this XSLObject

Throws: XSLException when the Attribute is not a valid AttrubueValueTemplate public AttributeValueTemplate getAttributeAsAVT(String name) throws XSLException { if (name == null) return null; String attValue = getAttribute(name); AttributeValueTemplate avt = null; if ((attValue != null) && (attValue.length() > 0)) { // look in cache first avt = (AttributeValueTemplate) avtCache.get(attValue); if (avt == null) { try { avt = new AttributeValueTemplate(attValue); // add to cache for performace // Do we need to clean cache? Yes if we are reusing // XSLObjects. No if not. I am currently not // reusing XSLObjects so I am not doing any house // cleaning. This could lead to memory problems if // XSLObjects are reused heavily. avtCache.put(attValue, avt); } catch(InvalidExprException iee) { throw new XSLException (XSLException.INVALID_ATTRIBUTE_VALUE_TEMPLATE, iee.getMessage()); } } } return avt; } //-- getAttributeAsAVT /** Returns the AttributeList for this XSLObject

getNamespace

public String getNamespace()
Returns this XSLObject's namespace URI.

Returns: the namespace URI or null if none exists.

getNearestAncestor

public XSLObject getNearestAncestor(short type)
Returns the nearest ancestor of this XSLObject that is of the given type.

Parameters: type the type of ancestor to search for

Returns: the nearest ancestor of this XSLObject that is of the given type.

getNodeValue

public static String getNodeValue(Node node)
Returns the String value of a DOM Node.

Returns: the String value of a DOM Node.

See Also: org.w3c.dom.Node

getStylesheet

public XSLTStylesheet getStylesheet()
Returns the XSLStylesheet which contains this XSLObject

Returns: the XSLStylesheet which contains this XSLObject

getText

public static String getText(Element element)
Retrieves the text of an Element

Returns: the text of the given Element

See Also: org.w3c.dom.Element

getType

public final short getType()
Returns the type of XSLObject this Object represents

Returns: the type of XSLObject that this Object represents

getTypeFromName

public static short getTypeFromName(String name)
Returns the type of XSL Object that has the given name

Parameters: name the name the XSLObject

Returns: the type of XSL Object that has the given name

getTypeName

public String getTypeName()
Returns the name of this XSLObject

Returns: the name of this XSLObject

resolveNamespace

public String resolveNamespace(String prefix)

setAllowActions

public void setAllowActions(boolean allow)

setAttribute

public void setAttribute(String name, String value)
Sets the attribute with the given name to the given value.

Parameters: name the name of the attribute to set value the value to set the attribute to

Throws: XSLException if this XSLObject does not allow attributes with the given name, or if the attribute is read only

setNamespace

public void setNamespace(String uri)
Sets this XSLObject's namespace URI

Parameters: uri the namespace URI

setTypeName

public void setTypeName(String name)