本文整理汇总了Java中com.sun.org.apache.xml.internal.dtm.DTM.ELEMENT_NODE属性的典型用法代码示例。如果您正苦于以下问题:Java DTM.ELEMENT_NODE属性的具体用法?Java DTM.ELEMENT_NODE怎么用?Java DTM.ELEMENT_NODE使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类com.sun.org.apache.xml.internal.dtm.DTM
的用法示例。
在下文中一共展示了DTM.ELEMENT_NODE属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: next
/**
* Get the next node in the iteration.
*
* @return The next node handle in the iteration, or END.
*/
public int next() {
if (_currentNode == DTM.NULL) {
return DTM.NULL;
}
int node = _currentNode;
final int nodeType = _nodeType;
if (nodeType != DTM.ELEMENT_NODE) {
while ((node = _nextsib2(node)) != DTM.NULL && _exptype2(node) != nodeType) {}
} else {
while ((node = _nextsib2(node)) != DTM.NULL && _exptype2(node) < DTM.NTYPES) {}
}
_currentNode = node;
return (node == DTM.NULL)
? DTM.NULL
: returnNode(makeNodeHandle(node));
}
示例2: getLanguage
/**
* Returns a node' defined language for a node (if any)
*/
public String getLanguage(int node)
{
int parent = node;
while (DTM.NULL != parent) {
if (DTM.ELEMENT_NODE == getNodeType(parent)) {
int langAttr = getAttributeNode(parent, "http://www.w3.org/XML/1998/namespace", "lang");
if (DTM.NULL != langAttr) {
return getNodeValue(langAttr);
}
}
parent = getParent(parent);
}
return(null);
}
示例3: getElementsByTagName
/**
*
* @param tagname
*
*
* @see org.w3c.dom.Document
*/
@Override
public final NodeList getElementsByTagName(String tagname)
{
Vector listVector = new Vector();
Node retNode = dtm.getNode(node);
if (retNode != null)
{
boolean isTagNameWildCard = "*".equals(tagname);
if (DTM.ELEMENT_NODE == retNode.getNodeType())
{
NodeList nodeList = retNode.getChildNodes();
for (int i = 0; i < nodeList.getLength(); i++)
{
traverseChildren(listVector, nodeList.item(i), tagname,
isTagNameWildCard);
}
} else if (DTM.DOCUMENT_NODE == retNode.getNodeType()) {
traverseChildren(listVector, dtm.getNode(node), tagname,
isTagNameWildCard);
}
}
int size = listVector.size();
NodeSet nodeSet = new NodeSet(size);
for (int i = 0; i < size; i++)
{
nodeSet.addNode((Node) listVector.elementAt(i));
}
return (NodeList) nodeSet;
}
示例4: if
/**
*
* @param listVector
* @param tempNode
* @param tagname
* @param isTagNameWildCard
*
*
* Private method to be used for recursive iterations to obtain elements by tag name.
*/
private final void traverseChildren
(
Vector listVector,
Node tempNode,
String tagname,
boolean isTagNameWildCard) {
if (tempNode == null)
{
return;
}
else
{
if (tempNode.getNodeType() == DTM.ELEMENT_NODE
&& (isTagNameWildCard || tempNode.getNodeName().equals(tagname)))
{
listVector.add(tempNode);
}
if(tempNode.hasChildNodes())
{
NodeList nodeList = tempNode.getChildNodes();
for (int i = 0; i < nodeList.getLength(); i++)
{
traverseChildren(listVector, nodeList.item(i), tagname,
isTagNameWildCard);
}
}
}
}
示例5: getFirstAttributeIdentity
/**
* The optimized version of DTMDefaultBase.getFirstAttributeIdentity(int).
* <p>
* Given a node identity, get the index of the node's first attribute.
*
* @param identity int identity of the node.
* @return Identity of first attribute, or DTM.NULL to indicate none exists.
*/
protected int getFirstAttributeIdentity(int identity) {
if (identity == NULL) {
return NULL;
}
int type = _type2(identity);
if (DTM.ELEMENT_NODE == type)
{
// Assume that attributes and namespaces immediately follow the element.
while (true)
{
identity++;
// Assume this can not be null.
type = _type2(identity);
if (type == DTM.ATTRIBUTE_NODE)
{
return identity;
}
else if (DTM.NAMESPACE_NODE != type)
{
break;
}
}
}
return DTM.NULL;
}
示例6: execute
/**
* Execute the function. The function must return
* a valid object.
* @param xctxt The current execution context.
* @return A valid XObject.
*
* @throws javax.xml.transform.TransformerException
*/
public XObject execute(XPathContext xctxt) throws javax.xml.transform.TransformerException
{
int context = getArg0AsNode(xctxt);
String s;
if(context != DTM.NULL)
{
DTM dtm = xctxt.getDTM(context);
int t = dtm.getNodeType(context);
if(t == DTM.ELEMENT_NODE)
{
s = dtm.getNamespaceURI(context);
}
else if(t == DTM.ATTRIBUTE_NODE)
{
// This function always returns an empty string for namespace nodes.
// We check for those here. Fix inspired by Davanum Srinivas.
s = dtm.getNodeName(context);
if(s.startsWith("xmlns:") || s.equals("xmlns"))
return XString.EMPTYSTRING;
s = dtm.getNamespaceURI(context);
}
else
return XString.EMPTYSTRING;
}
else
return XString.EMPTYSTRING;
return ((null == s) ? XString.EMPTYSTRING : new XString(s));
}
示例7: getElementsByTagNameNS
/**
*
* @param namespaceURI
* @param localName
*
*
* @see org.w3c.dom.Document as of DOM Level 2
*/
@Override
public final NodeList getElementsByTagNameNS(String namespaceURI,
String localName)
{
Vector listVector = new Vector();
Node retNode = dtm.getNode(node);
if (retNode != null)
{
boolean isNamespaceURIWildCard = "*".equals(namespaceURI);
boolean isLocalNameWildCard = "*".equals(localName);
if (DTM.ELEMENT_NODE == retNode.getNodeType())
{
NodeList nodeList = retNode.getChildNodes();
for(int i = 0; i < nodeList.getLength(); i++)
{
traverseChildren(listVector, nodeList.item(i), namespaceURI, localName, isNamespaceURIWildCard, isLocalNameWildCard);
}
}
else if(DTM.DOCUMENT_NODE == retNode.getNodeType())
{
traverseChildren(listVector, dtm.getNode(node), namespaceURI, localName, isNamespaceURIWildCard, isLocalNameWildCard);
}
}
int size = listVector.size();
NodeSet nodeSet = new NodeSet(size);
for (int i = 0; i < size; i++)
{
nodeSet.addNode((Node)listVector.elementAt(i));
}
return (NodeList) nodeSet;
}
示例8: getNodeByPosition
/**
* Return the node at the given position.
*/
public int getNodeByPosition(int position) {
if (position <= 0)
return DTM.NULL;
int node = _currentNode;
int pos = 0;
final int nodeType = _nodeType;
if (nodeType != DTM.ELEMENT_NODE) {
while (node != DTM.NULL) {
if (_exptype2(node) == nodeType) {
pos++;
if (pos == position)
return makeNodeHandle(node);
}
node = _nextsib2(node);
}
return NULL;
} else {
while (node != DTM.NULL) {
if (_exptype2(node) >= DTM.NTYPES) {
pos++;
if (pos == position)
return makeNodeHandle(node);
}
node = _nextsib2(node);
}
return NULL;
}
}
示例9: getFirstAttribute
/**
* The optimized version of DTMDefaultBase.getFirstAttribute().
* <p>
* Given a node handle, get the index of the node's first attribute.
*
* @param nodeHandle int Handle of the node.
* @return Handle of first attribute, or DTM.NULL to indicate none exists.
*/
public final int getFirstAttribute(int nodeHandle)
{
int nodeID = makeNodeIdentity(nodeHandle);
if (nodeID == DTM.NULL)
return DTM.NULL;
int type = _type2(nodeID);
if (DTM.ELEMENT_NODE == type)
{
// Assume that attributes and namespaces immediately follow the element.
while (true)
{
nodeID++;
// Assume this can not be null.
type = _type2(nodeID);
if (type == DTM.ATTRIBUTE_NODE)
{
return makeNodeHandle(nodeID);
}
else if (DTM.NAMESPACE_NODE != type)
{
break;
}
}
}
return DTM.NULL;
}
示例10: execute
/**
* Execute the function. The function must return
* a valid object.
* @param xctxt The current execution context.
* @return A valid XObject.
*
* @throws javax.xml.transform.TransformerException
*/
public XObject execute(XPathContext xctxt) throws javax.xml.transform.TransformerException
{
String lang = m_arg0.execute(xctxt).str();
int parent = xctxt.getCurrentNode();
boolean isLang = false;
DTM dtm = xctxt.getDTM(parent);
while (DTM.NULL != parent)
{
if (DTM.ELEMENT_NODE == dtm.getNodeType(parent))
{
int langAttr = dtm.getAttributeNode(parent, "http://www.w3.org/XML/1998/namespace", "lang");
if (DTM.NULL != langAttr)
{
String langVal = dtm.getNodeValue(langAttr);
// %OPT%
if (langVal.toLowerCase().startsWith(lang.toLowerCase()))
{
int valLen = lang.length();
if ((langVal.length() == valLen)
|| (langVal.charAt(valLen) == '-'))
{
isLang = true;
}
}
break;
}
}
parent = dtm.getParent(parent);
}
return isLang ? XBoolean.S_TRUE : XBoolean.S_FALSE;
}
示例11: copy
private final void copy(final int node, SerializationHandler handler, boolean isChild)
throws TransletException
{
int nodeID = makeNodeIdentity(node);
int eType = _exptype2(nodeID);
int type = _exptype2Type(eType);
try {
switch(type)
{
case DTM.ROOT_NODE:
case DTM.DOCUMENT_NODE:
for(int c = _firstch2(nodeID); c != DTM.NULL; c = _nextsib2(c)) {
copy(makeNodeHandle(c), handler, true);
}
break;
case DTM.PROCESSING_INSTRUCTION_NODE:
copyPI(node, handler);
break;
case DTM.COMMENT_NODE:
handler.comment(getStringValueX(node));
break;
case DTM.TEXT_NODE:
boolean oldEscapeSetting = false;
boolean escapeBit = false;
if (_dontEscape != null) {
escapeBit = _dontEscape.getBit(getNodeIdent(node));
if (escapeBit) {
oldEscapeSetting = handler.setEscaping(false);
}
}
copyTextNode(nodeID, handler);
if (escapeBit) {
handler.setEscaping(oldEscapeSetting);
}
break;
case DTM.ATTRIBUTE_NODE:
copyAttribute(nodeID, eType, handler);
break;
case DTM.NAMESPACE_NODE:
handler.namespaceAfterStartElement(getNodeNameX(node), getNodeValue(node));
break;
default:
if (type == DTM.ELEMENT_NODE)
{
// Start element definition
final String name = copyElement(nodeID, eType, handler);
//if(isChild) => not to copy any namespaces from parents
// else copy all namespaces in scope
copyNS(nodeID, handler,!isChild);
copyAttributes(nodeID, handler);
// Copy element children
for (int c = _firstch2(nodeID); c != DTM.NULL; c = _nextsib2(c)) {
copy(makeNodeHandle(c), handler, true);
}
// Close element definition
handler.endElement(name);
}
// Shallow copy of attribute to output handler
else {
final String uri = getNamespaceName(node);
if (uri.length() != 0) {
final String prefix = getPrefix(node);
handler.namespaceAfterStartElement(prefix, uri);
}
handler.addAttribute(getNodeName(node), getNodeValue(node));
}
break;
}
}
catch (Exception e) {
throw new TransletException(e);
}
}
示例12: endNode
/**
* End processing of given node
*
*
* @param node Node we just finished processing
*
* @throws org.xml.sax.SAXException
*/
protected void endNode(int node) throws org.xml.sax.SAXException
{
switch (m_dtm.getNodeType(node))
{
case DTM.DOCUMENT_NODE :
this.m_contentHandler.endDocument();
break;
case DTM.ELEMENT_NODE :
String ns = m_dtm.getNamespaceURI(node);
if(null == ns)
ns = "";
this.m_contentHandler.endElement(ns,
m_dtm.getLocalName(node),
m_dtm.getNodeName(node));
for (int nsn = m_dtm.getFirstNamespaceNode(node, true); DTM.NULL != nsn;
nsn = m_dtm.getNextNamespaceNode(node, nsn, true))
{
// String prefix = m_dtm.getPrefix(nsn);
String prefix = m_dtm.getNodeNameX(nsn);
this.m_contentHandler.endPrefixMapping(prefix);
}
break;
case DTM.CDATA_SECTION_NODE :
break;
case DTM.ENTITY_REFERENCE_NODE :
{
if (m_contentHandler instanceof LexicalHandler)
{
LexicalHandler lh = ((LexicalHandler) this.m_contentHandler);
lh.endEntity(m_dtm.getNodeName(node));
}
}
break;
default :
}
}
示例13: getAttributeNode
/**
* Retrieves an attribute node by by qualified name and namespace URI.
*
* @param nodeHandle int Handle of the node upon which to look up this attribute..
* @param namespaceURI The namespace URI of the attribute to
* retrieve, or null.
* @param name The local name of the attribute to
* retrieve.
* @return The attribute node handle with the specified name (
* <code>nodeName</code>) or <code>DTM.NULL</code> if there is no such
* attribute.
*/
public int getAttributeNode(int nodeHandle, String namespaceURI,
String name)
{
// %OPT% This is probably slower than it needs to be.
if (null == namespaceURI)
namespaceURI = "";
int type = getNodeType(nodeHandle);
if (DTM.ELEMENT_NODE == type)
{
// Assume that attributes immediately follow the element.
int identity = makeNodeIdentity(nodeHandle);
while (DTM.NULL != (identity = getNextNodeIdentity(identity)))
{
// Assume this can not be null.
type = _type(identity);
// %REVIEW%
// Should namespace nodes be retrievable DOM-style as attrs?
// If not we need a separate function... which may be desirable
// architecturally, but which is ugly from a code point of view.
// (If we REALLY insist on it, this code should become a subroutine
// of both -- retrieve the node, then test if the type matches
// what you're looking for.)
if (type == DTM.ATTRIBUTE_NODE || type==DTM.NAMESPACE_NODE)
{
Node node = lookupNode(identity);
String nodeuri = node.getNamespaceURI();
if (null == nodeuri)
nodeuri = "";
String nodelocalname = node.getLocalName();
if (nodeuri.equals(namespaceURI) && name.equals(nodelocalname))
return makeNodeHandle(identity);
}
else // if (DTM.NAMESPACE_NODE != type)
{
break;
}
}
}
return DTM.NULL;
}
示例14: isElement
/**
* Returns 'true' if a specific node is an element (of any type)
*/
public boolean isElement(final int node) {
return getNodeType(node) == DTM.ELEMENT_NODE;
}
示例15: shallowCopy
/**
* Performs a shallow copy (ref. XSLs copy())
*/
public String shallowCopy(final int node, SerializationHandler handler)
throws TransletException
{
int nodeID = makeNodeIdentity(node);
int exptype = _exptype2(nodeID);
int type = _exptype2Type(exptype);
try {
switch(type)
{
case DTM.ELEMENT_NODE:
final String name = copyElement(nodeID, exptype, handler);
copyNS(nodeID, handler, true);
return name;
case DTM.ROOT_NODE:
case DTM.DOCUMENT_NODE:
return EMPTYSTRING;
case DTM.TEXT_NODE:
copyTextNode(nodeID, handler);
return null;
case DTM.PROCESSING_INSTRUCTION_NODE:
copyPI(node, handler);
return null;
case DTM.COMMENT_NODE:
handler.comment(getStringValueX(node));
return null;
case DTM.NAMESPACE_NODE:
handler.namespaceAfterStartElement(getNodeNameX(node), getNodeValue(node));
return null;
case DTM.ATTRIBUTE_NODE:
copyAttribute(nodeID, exptype, handler);
return null;
default:
final String uri1 = getNamespaceName(node);
if (uri1.length() != 0) {
final String prefix = getPrefix(node);
handler.namespaceAfterStartElement(prefix, uri1);
}
handler.addAttribute(getNodeName(node), getNodeValue(node));
return null;
}
} catch (Exception e) {
throw new TransletException(e);
}
}