com.ibm.designer.domino.xsp.api.util
Class XPagesDOMUtil

java.lang.Object
  extended by com.ibm.designer.domino.xsp.api.util.XPagesDOMUtil

public class XPagesDOMUtil
extends java.lang.Object

A utility class that allows users to perform certain operations on the DOM Model of an XPage. It is recommended to use this class when performing certain operations on an XPage like getting the value of an attribute, setting an attribute value etc.


Field Summary
protected static java.util.regex.Pattern _formattingPattern
           
protected static java.util.regex.Pattern _lineTermPattern
           
protected static java.lang.String _platformNewLine
           
protected static java.util.regex.Pattern _whitespacePattern
           
protected static java.lang.String FORMATTING_REGEX
           
protected static java.lang.String LINE_TERMINATORS_REGEX
           
static int MODE_ATTRIBUTE
           
static int MODE_COMPLEXCDATA
           
static int MODE_COMPLEXTEXT
           
static int MODE_INVALID_CDATA
           
protected static java.lang.String WHITE_SPACE_REGEX
           
static java.lang.String XML_NAMESPACE
           
static java.lang.String XML_NAMESPACE_PREFIX_SEP
           
protected static java.lang.String XML_PI_DATA
           
protected static java.lang.String XML_PI_TAG
           
static java.lang.String XSDXP_PROTOCOL
           
static java.lang.String XSI
           
 
Constructor Summary
XPagesDOMUtil()
           
 
Method Summary
static org.w3c.dom.Element addComplexProperty(org.w3c.dom.Element elt, java.lang.String propertyName, java.lang.String value)
          Adds a complex property to the given element.
static java.lang.String addSchemaLocation(org.w3c.dom.Document doc, java.lang.String prefix, java.lang.String namespaceUri)
          Adds a schemaLocation attribute to the view tag of the provided document.
protected static boolean checkParent(FacesDefinition definition, java.lang.String namespaceUri, java.lang.String id)
           
static void clearElement(org.w3c.dom.Element element)
          Remove all of the given element's children.
static void clearIds(org.w3c.dom.Element element)
          Set all the IDs in the given element and all it's children to null.
static org.w3c.dom.Element createChildElement(org.w3c.dom.Element parent, FacesRegistry registry, java.lang.String tag)
          Create a child control inside another element.
static org.w3c.dom.Element createElement(org.w3c.dom.Document ownerDocument, FacesRegistry registry, java.lang.String uri, java.lang.String tagName)
          Helper method to create an element.
static java.lang.String createNamespacePrefix(java.lang.String prefix)
          Creates a namespace prefix, given the control prefix.
static java.lang.String createQualifiedTagName(java.lang.String prefix, java.lang.String localName)
          Combine a prefix and local name into a qualified name.
static java.lang.String createSchemaLocationPrefix(java.lang.String prefix)
          Creates a namespace prefix, given the control prefix.
static org.w3c.dom.Element createXPagesElement(org.w3c.dom.Document doc, java.lang.String localName)
          Creates an XPages core control element.
protected static boolean elementNeedsId(FacesRegistry registry, org.w3c.dom.Element element, org.w3c.dom.Document doc)
          Determines if the given element requires an ID in accordance with the tag's definition in the FacesRegistry.
protected static boolean elementNeedsVar(FacesRegistry registry, org.w3c.dom.Element element, org.w3c.dom.Document doc)
          Determines if the given element requires a var attribute in accordance with the tag's definition in the FacesRegistry.
static java.lang.String ensureNamespaceDeclaration(org.w3c.dom.Document doc, java.lang.String namespaceUri, java.lang.String prefix)
          Ensure a namspaceUri exists in a document.
static boolean ensureRequiredNodesExist(org.w3c.dom.Document root)
          Ensure the required document nodes exist to make this model a legal XPages form.
static java.lang.String ensureSchemaLocationDeclaration(org.w3c.dom.Document doc, java.lang.String namespaceUri, boolean formatView)
          Ensure a schema location (xsi:schemaLocation) attribute is defined for the specified namespace uri.
static void ensureUniqueIds(org.w3c.dom.Document doc, org.w3c.dom.Node root, FacesRegistry registry)
          Ensures the ids applied to the supplied node are unique in the context of the document they are being inserted into.
static void ensureUniqueIds(org.w3c.dom.Document doc, org.w3c.dom.Node root, FacesRegistry registry, boolean generateIdIfNotSet)
          Ensures the ids applied to the supplied node are unique in the context of the document they are being inserted into.
static void ensureUniqueIdsGenerateIfRequested(org.w3c.dom.Document doc, org.w3c.dom.Node root, FacesRegistry registry, boolean generateId)
          Using the given document as a reference for existing ids, ensures every element in the root has a unique id.
static void ensureUniqueVars(org.w3c.dom.Document doc, org.w3c.dom.Node root, FacesRegistry registry)
          Using the given document as a reference for existing vars, ensures every element in the given node has a unique var.
static boolean findGlobalDefAndAddDependency(java.lang.String uri, java.lang.String tagName, DesignerProject project)
          Finds a FacesDefinition for the given tag.
static void formatNode(org.w3c.dom.Node node, org.w3c.dom.ranges.Range range)
          Formats a single node
static void formatNodes(org.w3c.dom.Node[] nodes, org.w3c.dom.ranges.Range range)
          Format an array of nodes.
static java.lang.String generateSchemaNameFromURI(java.lang.String namespaceUri)
          Generates a schema file name (and location) for the given namespace uri.
static java.lang.String generateUniqueId(java.util.List<java.lang.String> idList, org.w3c.dom.Element element)
          Returns a unique id candidate for the given element.
static java.lang.String generateUniqueId(java.util.List<java.lang.String> idList, org.w3c.dom.Element element, java.lang.String hint)
          Returns a unique id candidate for the given element.
static java.lang.String generateUniqueVar(java.util.List<java.lang.String> varList, org.w3c.dom.Element element)
          Returns a unique var candidate for the given element.
static java.lang.String generateUniqueVar(java.util.List<java.lang.String> varList, org.w3c.dom.Element element, java.lang.String hint)
          Returns a unique var candidate for the given element.
static java.lang.String getAttribute(org.w3c.dom.Element element, java.lang.String attribute)
          Helper method to get an attribute value.
static java.util.Map<java.lang.String,java.lang.String> getAttributeChildren(org.w3c.dom.Element element)
          Get all the "this." attribute children of a node.
static org.w3c.dom.Element getAttributeElement(org.w3c.dom.Element element, java.lang.String attribute)
          Return the element for the given attribute if it exists.
static java.util.Map<java.lang.String,java.lang.String> getAttributes(org.w3c.dom.Element element)
          Get all the attributes for an element.
static org.w3c.dom.Node getContainer(org.w3c.dom.Node node, java.lang.String targetUri, java.lang.String targetName)
          Search for the given container node, stating with the node's parent.
static java.lang.String getDefaultPrefix()
          Returns the default namespace prefix for an XPage Core tag.
static FacesDefinition getFacesDefinition(org.w3c.dom.Element element, FacesRegistry registry)
          Return a FacesDefintion for the given element.
static java.lang.String[] getIds(org.w3c.dom.Node root, org.w3c.dom.Node nodeToExclude)
          Returns the IDs of all of the node that are a child of the given node.
static java.lang.String[] getIds(org.w3c.dom.Node startNode, org.w3c.dom.Node nodeToExclude, FacesRegistry registry, java.lang.String namespaceUri, java.lang.String id, boolean checkParent)
          Returns an array of ids that are already defined on the XPage.
static java.lang.String[] getIdsExcludeList(org.w3c.dom.Node root, java.util.List<org.w3c.dom.Node> nodesToExclude)
           
static java.lang.String[] getIdsExcludeList(org.w3c.dom.Node startNode, java.util.List<org.w3c.dom.Node> nodesToExclude, FacesRegistry registry, java.lang.String namespaceUri, java.lang.String id, boolean checkParent)
           
static int getModeForValue(java.lang.String attributeValue)
          Returns the 'mode' for a given attribute value.
static java.lang.String getNamespacePrefix(org.w3c.dom.Document doc, java.lang.String namespaceUri)
          Get the namespace prefix in use in a document of a namespaceUri.
static java.lang.String getNamespaceUri()
          Get the default namespace URI for core XPage controls
static java.lang.String getNamespaceUri(org.w3c.dom.Document doc, org.w3c.dom.Node node)
          Return the namespace uri for the given element, searching the document if necessary.
static java.lang.String getNamespaceUriForPrefix(org.w3c.dom.Document doc, java.lang.String prefix)
          Return the namespace uri associated with the given prefix, or null if there is none.
static org.w3c.dom.Node getNextChild(org.w3c.dom.Node node, int offset)
          Get the next child of a node, skipping any text nodes that are whitespace.
static org.w3c.dom.Node getNextSibling(org.w3c.dom.Node node)
          Same as Node.getPreviousSibling except that is skips text nodes that are whitespace.
static java.lang.String getPrefix(org.w3c.dom.Document doc, java.lang.String namespaceUri, FacesRegistry registry, java.lang.String tagName)
          Return the prefix for the given namespace URI and tag name.
static org.w3c.dom.Node getPreviousChild(org.w3c.dom.Node node, int offset)
          Get the previous child of a node, skipping any text nodes that are whitespace.
static org.w3c.dom.Node getPreviousSibling(org.w3c.dom.Node node)
          Same as Node.getPreviousSibling except that is skips text nodes that are whitespace.
static java.lang.String getRootTagName()
          Get the tagname that is the root of the xsp file (view).
static java.lang.String getSchemaLocationDeclaration(org.w3c.dom.Document doc, java.lang.String namespaceUri)
          Get the schemaLocation in use in a document for a namespaceUri.
static java.lang.String[] getValuesOfAttr(org.w3c.dom.Node root, org.w3c.dom.Node nodeToExclude, FacesRegistry registry, java.lang.String namespaceUri, java.lang.String id, boolean checkParent, java.lang.String attrName)
          Returns the values for all occurrances of a given attribute on a given document
static java.lang.String[] getValuesOfAttrExcludeList(org.w3c.dom.Node root, java.util.List<org.w3c.dom.Node> nodesToExclude, FacesRegistry registry, java.lang.String namespaceUri, java.lang.String id, boolean checkParent, java.lang.String attrName)
          Returns the values for all occurrances of a given attribute on a given document
static java.lang.String[] getVars(org.w3c.dom.Node startNode, org.w3c.dom.Node nodeToExclude)
          Returns all of the values of the 'var' attributes on the document
static java.lang.String[] getVars(org.w3c.dom.Node startNode, org.w3c.dom.Node nodeToExclude, FacesRegistry registry, java.lang.String namespaceUri, java.lang.String id, boolean checkParent)
          Returns the values of all of the var attributes on the given document.
static org.w3c.dom.Element getViewNode(org.w3c.dom.Document doc)
          Get the view node of a given document.
static void initializeDefaultValues(org.w3c.dom.Element element, FacesRegistry registry)
          Helper method to call after an element has been created.
static boolean isComponent(FacesDefinition def, java.lang.String namespaceUri, java.lang.String id)
          Return true if the given def matches the given uri and id.
static boolean isWhitespace(org.w3c.dom.Node node)
          test if a node is a text node that contains just whitespace.
static boolean isWhitespace(java.lang.String text)
          test if a string to see if it contains just whitespace.
static org.w3c.dom.Node replaceNode(org.w3c.dom.Node node, java.lang.String newTagName)
          Replace the given node with an identical node, except with a new tag name.
static boolean setAttribute(org.w3c.dom.Element elt, java.lang.String attributeName, java.lang.String value)
          Helper method to set an attribute.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

MODE_ATTRIBUTE

public static final int MODE_ATTRIBUTE
See Also:
Constant Field Values

MODE_COMPLEXTEXT

public static final int MODE_COMPLEXTEXT
See Also:
Constant Field Values

MODE_COMPLEXCDATA

public static final int MODE_COMPLEXCDATA
See Also:
Constant Field Values

MODE_INVALID_CDATA

public static final int MODE_INVALID_CDATA
See Also:
Constant Field Values

XML_PI_TAG

protected static final java.lang.String XML_PI_TAG
See Also:
Constant Field Values

XML_PI_DATA

protected static final java.lang.String XML_PI_DATA
See Also:
Constant Field Values

XML_NAMESPACE

public static final java.lang.String XML_NAMESPACE
See Also:
Constant Field Values

XML_NAMESPACE_PREFIX_SEP

public static final java.lang.String XML_NAMESPACE_PREFIX_SEP
See Also:
Constant Field Values

XSI

public static final java.lang.String XSI
See Also:
Constant Field Values

XSDXP_PROTOCOL

public static final java.lang.String XSDXP_PROTOCOL
See Also:
Constant Field Values

LINE_TERMINATORS_REGEX

protected static final java.lang.String LINE_TERMINATORS_REGEX
See Also:
Constant Field Values

WHITE_SPACE_REGEX

protected static final java.lang.String WHITE_SPACE_REGEX
See Also:
Constant Field Values

FORMATTING_REGEX

protected static final java.lang.String FORMATTING_REGEX
See Also:
Constant Field Values

_platformNewLine

protected static java.lang.String _platformNewLine

_lineTermPattern

protected static java.util.regex.Pattern _lineTermPattern

_whitespacePattern

protected static java.util.regex.Pattern _whitespacePattern

_formattingPattern

protected static java.util.regex.Pattern _formattingPattern
Constructor Detail

XPagesDOMUtil

public XPagesDOMUtil()
Method Detail

addComplexProperty

public static org.w3c.dom.Element addComplexProperty(org.w3c.dom.Element elt,
                                                     java.lang.String propertyName,
                                                     java.lang.String value)
Adds a complex property to the given element. Certain tags support complex properties. This utility method will add complex properties to tags and ensure that the complex property is well formed. e.g.
 <xp:inputText id="inputText1">
  <xp:this.converter>
      <xp:convertDateTime type="date"></xp:convertDateTime>
  </xp:this.converter>
 </xp:inputText>
 

Parameters:
elt - the element to which the complex property is being defined
propertyName - the name of the complex property
value - the value of the complex property
Returns:
the complex property Element

checkParent

protected static boolean checkParent(FacesDefinition definition,
                                     java.lang.String namespaceUri,
                                     java.lang.String id)

clearElement

public static void clearElement(org.w3c.dom.Element element)
Remove all of the given element's children.

Parameters:
element - the element whose children are to be removed

clearIds

public static void clearIds(org.w3c.dom.Element element)
Set all the IDs in the given element and all it's children to null.

Parameters:
element - the element to clear

createChildElement

public static org.w3c.dom.Element createChildElement(org.w3c.dom.Element parent,
                                                     FacesRegistry registry,
                                                     java.lang.String tag)
Create a child control inside another element. Will create the this.facets element if it does not already exist.

Parameters:
parent - the parent of the element to be created
registry - The FacesRegistry for the current application
tag - the tag name of the new element
Returns:
the newly created element

createElement

public static org.w3c.dom.Element createElement(org.w3c.dom.Document ownerDocument,
                                                FacesRegistry registry,
                                                java.lang.String uri,
                                                java.lang.String tagName)
Helper method to create an element. Ensures the element has the correct tag prefix.

Parameters:
owenerDocument - the document where the element is to be created
registry - the FacesRegistry for the current application
uri - the URI for the new element
tagName - the XML tag local name of the new element
Returns:
the newly created Element

createNamespacePrefix

public static java.lang.String createNamespacePrefix(java.lang.String prefix)
Creates a namespace prefix, given the control prefix.

Parameters:
prefix - the proposed prefix, may not be null
Returns:
a string of the form "xmlns:prefix"

createSchemaLocationPrefix

public static java.lang.String createSchemaLocationPrefix(java.lang.String prefix)
Creates a namespace prefix, given the control prefix.

Parameters:
prefix - the proposed prefix, may not be null
Returns:
a string of the form "xmlns:prefix"

createQualifiedTagName

public static java.lang.String createQualifiedTagName(java.lang.String prefix,
                                                      java.lang.String localName)
Combine a prefix and local name into a qualified name.

Parameters:
prefix - the namespace prefix
localName - the XML localname of the tag.
Returns:
a qualified tag name

createXPagesElement

public static org.w3c.dom.Element createXPagesElement(org.w3c.dom.Document doc,
                                                      java.lang.String localName)
Creates an XPages core control element.

Parameters:
doc - document that is to contain the element, cannot be null;
localName - the XML local tag name of the element to be created, must belong to the XPages namespace
Returns:
an element that belongs to the core XPages namespace.

elementNeedsId

protected static boolean elementNeedsId(FacesRegistry registry,
                                        org.w3c.dom.Element element,
                                        org.w3c.dom.Document doc)
Determines if the given element requires an ID in accordance with the tag's definition in the FacesRegistry.

Parameters:
tagName -
Returns:
true if Id attribute is valid for this tag, otherwise false

elementNeedsVar

protected static boolean elementNeedsVar(FacesRegistry registry,
                                         org.w3c.dom.Element element,
                                         org.w3c.dom.Document doc)
Determines if the given element requires a var attribute in accordance with the tag's definition in the FacesRegistry.

Parameters:
tagName -
Returns:
true if var attribute is valid for this tag, otherwise false

ensureNamespaceDeclaration

public static java.lang.String ensureNamespaceDeclaration(org.w3c.dom.Document doc,
                                                          java.lang.String namespaceUri,
                                                          java.lang.String prefix)
Ensure a namspaceUri exists in a document. Add the namespace uri to the document if it does not exist.

Parameters:
doc - the document
namespaceUri - URI being sought
prefix - the prefix to use if one is not already defined
Returns:
the new prefix generated to resolve a conflict in the document. The node being added should be updated to have this prefix. If null, no change to the prefix

ensureSchemaLocationDeclaration

public static java.lang.String ensureSchemaLocationDeclaration(org.w3c.dom.Document doc,
                                                               java.lang.String namespaceUri,
                                                               boolean formatView)
Ensure a schema location (xsi:schemaLocation) attribute is defined for the specified namespace uri. Typically called as a control (XPages control) is being added to an XPage.

Parameters:
doc - the document
namespaceUri - URI whose schema location is to be defined
formatView - true if the XPages view node is to be formatted
Returns:
the location of the schema corresponding to the provided namespace uri.
Always returns null if the "Generate schema location" preference is set to false.

getSchemaLocationDeclaration

public static java.lang.String getSchemaLocationDeclaration(org.w3c.dom.Document doc,
                                                            java.lang.String namespaceUri)
Get the schemaLocation in use in a document for a namespaceUri.

Parameters:
doc - the document to search for the schema location attribute (xsi:schemaLocation)
namespaceUri - the namespace URI whose schema location is being sought
Returns:
the schema location, or null if the namespace uri's schema is not declared in this document.

addSchemaLocation

public static java.lang.String addSchemaLocation(org.w3c.dom.Document doc,
                                                 java.lang.String prefix,
                                                 java.lang.String namespaceUri)
Adds a schemaLocation attribute to the view tag of the provided document. The schemaLocation is used by the xpages editor when performing content assist. In order for content assist to work dynamically it is necessary for the schema to use the xsdxp:// protocol, which is a proprietary 'protocol' used internally by Domino Designer.

Parameters:
doc - the document representing the current XPage
prefix - the prefix for the schema URI
namespaceUri - the namespace uri
Returns:
the value of the xsi:schemaLocation attribute after the new uri schema location is added

generateSchemaNameFromURI

public static java.lang.String generateSchemaNameFromURI(java.lang.String namespaceUri)
Generates a schema file name (and location) for the given namespace uri. This location will later be used by the XPages content assist protocol when trying to resolve the schema location.

The location of the schema will be in the form:
xsdxp://localhost/schema~name.xsd

Parameters:
namespaceUri - a fully qualified namespace uri
Returns:
a uri location to the schema for the namespace.

ensureRequiredNodesExist

public static boolean ensureRequiredNodesExist(org.w3c.dom.Document root)
Ensure the required document nodes exist to make this model a legal XPages form. If the required nodes exists, the model will not be modified. If the required nodes are missing, then they will be inserted.
The items tested for are: the XML processing instruction, the XPage "view" tag.
This is a helper method that calls ensureProcessingInstructionExists(Document) and ensureViewExists(Document).

Parameters:
root - the root of the dom document
Returns:
true if the required elements existed, false if some had to be added

ensureUniqueIds

public static void ensureUniqueIds(org.w3c.dom.Document doc,
                                   org.w3c.dom.Node root,
                                   FacesRegistry registry)
Ensures the ids applied to the supplied node are unique in the context of the document they are being inserted into.

Parameters:
doc - the Document that the root Node will be inserted into
root - the Node to be inserted into the Document.
registry - the FacesRegistry for the current application

ensureUniqueIds

public static void ensureUniqueIds(org.w3c.dom.Document doc,
                                   org.w3c.dom.Node root,
                                   FacesRegistry registry,
                                   boolean generateIdIfNotSet)
Ensures the ids applied to the supplied node are unique in the context of the document they are being inserted into. However if a tag does not have a preassigned ID and does not have an ID as a required attribute in the FacesRegistry then an ID will not be assigned. If the client always needs an id to be added regardless of it being a required attribute then it is advised to use

Parameters:
doc - the Document that the root Node will be inserted into
root - the Node to be inserted into the Document.
registry - the FacesRegistry for the current application
generateIdIfNotSet - if true, and a Node is found to not have an id an ID will be generated for the node

ensureUniqueIdsGenerateIfRequested

public static void ensureUniqueIdsGenerateIfRequested(org.w3c.dom.Document doc,
                                                      org.w3c.dom.Node root,
                                                      FacesRegistry registry,
                                                      boolean generateId)
Using the given document as a reference for existing ids, ensures every element in the root has a unique id. This method disregards whether or not the element requires an id, if generateId is true then it will always generate an ID for the given node (and its children).

Parameters:
doc - the document that the node is being inserted into
FacesRegistry - the registry for the current application
generateId - if true and an element doesn't have an id, then a new one will be set. If false an id is not generated

ensureUniqueVars

public static void ensureUniqueVars(org.w3c.dom.Document doc,
                                    org.w3c.dom.Node root,
                                    FacesRegistry registry)
Using the given document as a reference for existing vars, ensures every element in the given node has a unique var.

Parameters:
doc - the document that the node is being inserted into
root - the node being inserted - will be examined for the var attribute
registry - the FacesRegistry for the current application

findGlobalDefAndAddDependency

public static boolean findGlobalDefAndAddDependency(java.lang.String uri,
                                                    java.lang.String tagName,
                                                    DesignerProject project)
Finds a FacesDefinition for the given tag. If the FacesDefinition is not available in the current FacesRegistry as defined in the DesignerProject then it is determined that the current application does not have a dependency on the library that contains the particular tag in question.

Parameters:
uri - the namespace URI of the tag being added to the page
tagName - the tag name of the tag being added to the page
project - the current application
Returns:
true if the FacesDefinition was found.

formatNode

public static void formatNode(org.w3c.dom.Node node,
                              org.w3c.dom.ranges.Range range)
Formats a single node

Parameters:
node -
range -

formatNodes

public static void formatNodes(org.w3c.dom.Node[] nodes,
                               org.w3c.dom.ranges.Range range)
Format an array of nodes.

Parameters:
nodes -
range -

generateUniqueId

public static java.lang.String generateUniqueId(java.util.List<java.lang.String> idList,
                                                org.w3c.dom.Element element)
Returns a unique id candidate for the given element.

Parameters:
idList - a list of existing ids
element - the new element being added to the page
Returns:
a unique id based on the element's local name, plus a unique index

generateUniqueId

public static java.lang.String generateUniqueId(java.util.List<java.lang.String> idList,
                                                org.w3c.dom.Element element,
                                                java.lang.String hint)
Returns a unique id candidate for the given element.

Parameters:
idList - a list of existing ids
element - the new element being added to the page
hint - a hint that will be used in place of the tag name if provided
Returns:
a unique var based on the element's local name (or the hint if provided), plus a unique index

generateUniqueVar

public static java.lang.String generateUniqueVar(java.util.List<java.lang.String> varList,
                                                 org.w3c.dom.Element element)
Returns a unique var candidate for the given element.

Parameters:
varList - a list of existing vars
element - the new element being added to the page
Returns:
a unique var based on the element's local name, plus a unique index

generateUniqueVar

public static java.lang.String generateUniqueVar(java.util.List<java.lang.String> varList,
                                                 org.w3c.dom.Element element,
                                                 java.lang.String hint)
Returns a unique var candidate for the given element.

Parameters:
varList - a list of existing vars
element - the new element being added to the page
hint - a hint that will be used in place of the tag name if provided
Returns:
a unique var based on the element's local name (or the hint if provided), plus a unique index

getAttribute

public static java.lang.String getAttribute(org.w3c.dom.Element element,
                                            java.lang.String attribute)
Helper method to get an attribute value. This is required because in the XSP markup, some attributes can be defined as this.attribute in a child tag. e.g.
 <inputText id="inputText1">
     <xp:this.value><![CDATA[#{javascript:return "test"}]]></xp:this.value>
 </inputText>
 

Parameters:
elt - the element that whose attribute value is being queried
attributeName - the name of the attribute that is sought
Returns:
the value of the attribute, null if the attribute is not set

getAttributeChildren

public static java.util.Map<java.lang.String,java.lang.String> getAttributeChildren(org.w3c.dom.Element element)
Get all the "this." attribute children of a node. The attribute values are returned as a Map.

Parameters:
element - the element to be examined
Returns:
a map where each entry in the map is a attribute, value pair. The attribute is the this.attribute with the "this." stripped off.

getAttributeElement

public static org.w3c.dom.Element getAttributeElement(org.w3c.dom.Element element,
                                                      java.lang.String attribute)
Return the element for the given attribute if it exists. e.g.
     <xp:inputText>
           <xp:this.style>width:300px;</xp:this.style>
     </xp:inputText>
 
getAttributeElement( element, 'style") would return the element for <this.style>

Parameters:
element - the Element whose attribute is being queried
attribute - the name of the attribute we are looking up
Returns:
the element that is used to store the attribtue value, may be null

getAttributes

public static java.util.Map<java.lang.String,java.lang.String> getAttributes(org.w3c.dom.Element element)
Get all the attributes for an element. This includes both the attributes on the element and complex child attributes.

Parameters:
element - node to get attributes for. May not be null.
Returns:
all attributes of an element. The attribute name is the key and the attribute value is the value of each entry.

getDefaultPrefix

public static java.lang.String getDefaultPrefix()
Returns the default namespace prefix for an XPage Core tag.

Returns:
the default XSP core namespace prefix

getFacesDefinition

public static FacesDefinition getFacesDefinition(org.w3c.dom.Element element,
                                                 FacesRegistry registry)
Return a FacesDefintion for the given element.

Parameters:
element - the element whose definition is sought
registry - the FacesRegistry for the current applicatio
Returns:
the definition of the requested element, may be null

getIds

public static java.lang.String[] getIds(org.w3c.dom.Node root,
                                        org.w3c.dom.Node nodeToExclude)
Returns the IDs of all of the node that are a child of the given node. The caller can optionally choose to ignore a certain node in the hierarchy.

Parameters:
root - the node to search through.
Returns:
an array of strings containing the ids of the XPage components on the page

getIds

public static java.lang.String[] getIds(org.w3c.dom.Node startNode,
                                        org.w3c.dom.Node nodeToExclude,
                                        FacesRegistry registry,
                                        java.lang.String namespaceUri,
                                        java.lang.String id,
                                        boolean checkParent)
Returns an array of ids that are already defined on the XPage.

Parameters:
startNode - the node to start searching from
nodeToExclude - a particular node whose id should not be included in the returned array
registry - the FacesRegistry for the current application
namespaceUri - an optional namespace that can be used to filter the elements whose ids are checked
id - an optional control type id of controls to be filtered. e.g. controls of type "javax.faces.Output"
checkParent - a flag indicating whether or not the FacesDefinition hierarchy should be searched
Returns:
an array of IDs corresponding to the search criteria

getIdsExcludeList

public static java.lang.String[] getIdsExcludeList(org.w3c.dom.Node root,
                                                   java.util.List<org.w3c.dom.Node> nodesToExclude)
Parameters:
root -
nodesToExclude -
Returns:

getIdsExcludeList

public static java.lang.String[] getIdsExcludeList(org.w3c.dom.Node startNode,
                                                   java.util.List<org.w3c.dom.Node> nodesToExclude,
                                                   FacesRegistry registry,
                                                   java.lang.String namespaceUri,
                                                   java.lang.String id,
                                                   boolean checkParent)
Parameters:
id - return only ids of elements with the given ID and URI - pass null in to disregard this check.
checkParent - if looking for only the given namespace, tagname, if this element does not match, should we check to see if it inherits from this type of element?

getModeForValue

public static int getModeForValue(java.lang.String attributeValue)
Returns the 'mode' for a given attribute value. The mode will be one of

Parameters:
attributeValue - the value of an attribute
Returns:

getNamespacePrefix

public static java.lang.String getNamespacePrefix(org.w3c.dom.Document doc,
                                                  java.lang.String namespaceUri)
Get the namespace prefix in use in a document of a namespaceUri.

Parameters:
doc - the document to search for the prefix
namespaceUri - the namespace URI being searched for
Returns:
the namespace prefix, or null if the namespace uri is not declared in this document.

getNamespaceUri

public static java.lang.String getNamespaceUri()
Get the default namespace URI for core XPage controls

Returns:
the namespace uri of the XPage controls.

getNamespaceUri

public static java.lang.String getNamespaceUri(org.w3c.dom.Document doc,
                                               org.w3c.dom.Node node)
Return the namespace uri for the given element, searching the document if necessary.

Parameters:
doc - the document to search
node - the node whose URI is sought

getNamespaceUriForPrefix

public static java.lang.String getNamespaceUriForPrefix(org.w3c.dom.Document doc,
                                                        java.lang.String prefix)
Return the namespace uri associated with the given prefix, or null if there is none.

Parameters:
doc - the document to search
prefix - the prefix whose URI is sought

getPreviousChild

public static org.w3c.dom.Node getPreviousChild(org.w3c.dom.Node node,
                                                int offset)
Get the previous child of a node, skipping any text nodes that are whitespace.

Parameters:
node - - parent node, may not be null.
offset - - offset in node, must be greater than zero and less than the number of children in node.
Returns:
previous child, may be null if no previous child.

getNextChild

public static org.w3c.dom.Node getNextChild(org.w3c.dom.Node node,
                                            int offset)
Get the next child of a node, skipping any text nodes that are whitespace.

Parameters:
node - - parent node, may not be null.
offset - - offset in node, must be greater than zero
Returns:
next child, may be null if there is no next child.

getNextSibling

public static org.w3c.dom.Node getNextSibling(org.w3c.dom.Node node)
Same as Node.getPreviousSibling except that is skips text nodes that are whitespace.

Parameters:
node, - may not be null.
Returns:
next sibling, may be null if no next sibling

getPreviousSibling

public static org.w3c.dom.Node getPreviousSibling(org.w3c.dom.Node node)
Same as Node.getPreviousSibling except that is skips text nodes that are whitespace.

Parameters:
node, - may not be null
Returns:

getPrefix

public static java.lang.String getPrefix(org.w3c.dom.Document doc,
                                         java.lang.String namespaceUri,
                                         FacesRegistry registry,
                                         java.lang.String tagName)
Return the prefix for the given namespace URI and tag name.

Parameters:
doc - the document to search
namespaceUri - the namespace URI whose prefix is sought
registry - the FacesRegistry which contains the tag definition
tagName - the tag that requires a prefix
Returns:
a prefix for the given tag

getRootTagName

public static java.lang.String getRootTagName()
Get the tagname that is the root of the xsp file (view).

Returns:
tagname without the prefix.

getValuesOfAttr

public static java.lang.String[] getValuesOfAttr(org.w3c.dom.Node root,
                                                 org.w3c.dom.Node nodeToExclude,
                                                 FacesRegistry registry,
                                                 java.lang.String namespaceUri,
                                                 java.lang.String id,
                                                 boolean checkParent,
                                                 java.lang.String attrName)
Returns the values for all occurrances of a given attribute on a given document

Parameters:
root - the root node to start searching from
nodeToExclude - a node to exclude from the search
registry - the FacesRegistry for the current application
namespaceUri - the URI for nodes to check
id - an optional control type id of controls to be filtered. e.g. controls of type "javax.faces.Output"
checkParent - a flag which determines if only children of the root should be searched
attrName - the name of the attribute whose values are to be returned
Returns:
an array of attribute values

getValuesOfAttrExcludeList

public static java.lang.String[] getValuesOfAttrExcludeList(org.w3c.dom.Node root,
                                                            java.util.List<org.w3c.dom.Node> nodesToExclude,
                                                            FacesRegistry registry,
                                                            java.lang.String namespaceUri,
                                                            java.lang.String id,
                                                            boolean checkParent,
                                                            java.lang.String attrName)
Returns the values for all occurrances of a given attribute on a given document

Parameters:
root - the root node to start searching from
nodesToExclude - a list of nodes to exclude from the search
registry - the FacesRegistry for the current application
namespaceUri - the URI for nodes to check
id - an optional control type id of controls to be filtered. e.g. controls of type "javax.faces.Output"
checkParent - a flag which determines if only children of the root should be searched
attrName - the name of the attribute whose values are to be returned
Returns:
an array of attribute values

getVars

public static java.lang.String[] getVars(org.w3c.dom.Node startNode,
                                         org.w3c.dom.Node nodeToExclude)
Returns all of the values of the 'var' attributes on the document

Parameters:
startNode - the starting point for the search
nodeToExclue - a node to exclude from the search
Returns:
an array containing all of the values of the var attribute on the page

getVars

public static java.lang.String[] getVars(org.w3c.dom.Node startNode,
                                         org.w3c.dom.Node nodeToExclude,
                                         FacesRegistry registry,
                                         java.lang.String namespaceUri,
                                         java.lang.String id,
                                         boolean checkParent)
Returns the values of all of the var attributes on the given document.

Parameters:
startNode - the node to start searching from
nodeToExclude - a node that should not be included in the search
registry - the FacesRegistry for the current application
namespaceUri - the URI of the tags that are to be searched
id - an optional control type id of controls to be filtered. e.g. controls of type "javax.faces.Output"
checkParent - a flag which determines if only children of the root should be searched
Returns:
an array of values of the var attributes encountered in the search

getViewNode

public static org.w3c.dom.Element getViewNode(org.w3c.dom.Document doc)
Get the view node of a given document.

Parameters:
doc - the document to search
Returns:
the 'view' node that is the root of any XPage

initializeDefaultValues

public static void initializeDefaultValues(org.w3c.dom.Element element,
                                           FacesRegistry registry)
Helper method to call after an element has been created. Sets default values in the element.

Parameters:
element - the element whose attributes are to be initialized
registry - the FacesRegistry that contains a definition for the given element

isComponent

public static boolean isComponent(FacesDefinition def,
                                  java.lang.String namespaceUri,
                                  java.lang.String id)
Return true if the given def matches the given uri and id.


isWhitespace

public static boolean isWhitespace(org.w3c.dom.Node node)
test if a node is a text node that contains just whitespace.

Parameters:
node -
Returns:
true if the node contains all whitespace, false otherwise.

isWhitespace

public static boolean isWhitespace(java.lang.String text)
test if a string to see if it contains just whitespace.

Parameters:
String -
Returns:
true if the string contains all whitespace, false otherwise.

setAttribute

public static boolean setAttribute(org.w3c.dom.Element elt,
                                   java.lang.String attributeName,
                                   java.lang.String value)
Helper method to set an attribute. This is required because in the XSP markup, some attributes can be defined as this.attribute in a child tag. e.g.
 <inputText id="inputText1">
     <xp:this.value><![CDATA[#{javascript:return "test"}]]></xp:this.value>
 </inputText>
 

Parameters:
elt - the element that the attribute is to be set on
attributeName - the name of the attribute that is to be set
value - the new value of the attribute

replaceNode

public static org.w3c.dom.Node replaceNode(org.w3c.dom.Node node,
                                           java.lang.String newTagName)
Replace the given node with an identical node, except with a new tag name.

Returns:
the new node.

getContainer

public static org.w3c.dom.Node getContainer(org.w3c.dom.Node node,
                                            java.lang.String targetUri,
                                            java.lang.String targetName)
Search for the given container node, stating with the node's parent.

Parameters:
node - - may not be null.
targetUri - - names space URI of container to find.
targetName - local name of container to find.
Returns:
Node - container node of the given node. Null if a container with the given name and URI cannot be found.