本文整理汇总了Java中org.apache.xml.dtm.DTM类的典型用法代码示例。如果您正苦于以下问题:Java DTM类的具体用法?Java DTM怎么用?Java DTM使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
DTM类属于org.apache.xml.dtm包,在下文中一共展示了DTM类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getPath
import org.apache.xml.dtm.DTM; //导入依赖的package包/类
public static String getPath(DTM dtm, int node) {
String pre;
switch (dtm.getNodeType(node)) {
case Node.DOCUMENT_NODE:
return "/";
case Node.ELEMENT_NODE:
pre = getPath(dtm, dtm.getParent(node));
return (pre.equals("/") ? "" : pre) +
"/" + dtm.getNodeName(node) + "[" + getNumberSimple(dtm, node) + "]";
case Node.ATTRIBUTE_NODE:
return getPath(dtm, dtm.getParent(node)) + "/@" + dtm.getNodeNameX(node);
case Node.TEXT_NODE:
pre = getPath(dtm, dtm.getParent(node));
return (pre.equals("/") ? "" : pre) +
"/text()[" + getNumberSimple(dtm, node) + "]";
case Node.COMMENT_NODE:
pre = getPath(dtm, dtm.getParent(node));
return (pre.equals("/") ? "" : pre) +
"/comment()[" + getNumberSimple(dtm, node) + "]";
case Node.PROCESSING_INSTRUCTION_NODE:
pre = getPath(dtm, dtm.getParent(node));
return (pre.equals("/") ? "" : pre) +
"/processing-instruction()[" + getNumberSimple(dtm, node) + "]";
}
return "?";
}
示例2: executeCharsToContentHandler
import org.apache.xml.dtm.DTM; //导入依赖的package包/类
/**
* Execute an expression in the XPath runtime context, and return the
* result of the expression.
*
*
* @param xctxt The XPath runtime context.
* @param handler The target content handler.
*
* @return The result of the expression in the form of a <code>XObject</code>.
*
* @throws javax.xml.transform.TransformerException if a runtime exception
* occurs.
* @throws org.xml.sax.SAXException
*/
public void executeCharsToContentHandler(
XPathContext xctxt, org.xml.sax.ContentHandler handler)
throws javax.xml.transform.TransformerException,
org.xml.sax.SAXException
{
LocPathIterator clone = (LocPathIterator)m_clones.getInstance();
int current = xctxt.getCurrentNode();
clone.setRoot(current, xctxt);
int node = clone.nextNode();
DTM dtm = clone.getDTM(node);
clone.detach();
if(node != DTM.NULL)
{
dtm.dispatchCharactersEvents(node, handler, false);
}
}
示例3: isDefinedNSDecl
import org.apache.xml.dtm.DTM; //导入依赖的package包/类
/**
* Returns whether a namespace is defined
*
*
* @param attr Namespace attribute node
* @param dtm The DTM that owns attr.
*
* @return True if the namespace is already defined in
* list of namespaces
*/
public static boolean isDefinedNSDecl(
SerializationHandler serializer,
int attr,
DTM dtm)
{
if (DTM.NAMESPACE_NODE == dtm.getNodeType(attr))
{
// String prefix = dtm.getPrefix(attr);
String prefix = dtm.getNodeNameX(attr);
String uri = serializer.getNamespaceURIFromPrefix(prefix);
// String uri = getURI(prefix);
if ((null != uri) && uri.equals(dtm.getStringValue(attr)))
return true;
}
return false;
}
示例4: ensureNamespaceDeclDeclared
import org.apache.xml.dtm.DTM; //导入依赖的package包/类
/**
* This function checks to make sure a given prefix is really
* declared. It might not be, because it may be an excluded prefix.
* If it's not, it still needs to be declared at this point.
* TODO: This needs to be done at an earlier stage in the game... -sb
*
* NEEDSDOC @param dtm
* NEEDSDOC @param namespace
*
* @throws org.xml.sax.SAXException
*/
public static void ensureNamespaceDeclDeclared(
SerializationHandler handler,
DTM dtm,
int namespace)
throws org.xml.sax.SAXException
{
String uri = dtm.getNodeValue(namespace);
String prefix = dtm.getNodeNameX(namespace);
if ((uri != null && uri.length() > 0) && (null != prefix))
{
String foundURI;
NamespaceMappings ns = handler.getNamespaceMappings();
if (ns != null)
{
foundURI = ns.lookupNamespace(prefix);
if ((null == foundURI) || !foundURI.equals(uri))
{
handler.startPrefixMapping(prefix, uri, false);
}
}
}
}
示例5: getCurrentNode
import org.apache.xml.dtm.DTM; //导入依赖的package包/类
/**
* Return the last fetched node. Needed to support the UnionPathIterator.
*
* @return the last fetched node.
* @throws RuntimeException thrown if this NodeSetDTM is not of
* a cached type, and thus doesn't permit indexed access.
*/
public int getCurrentNode()
{
if (!m_cacheNodes)
throw new RuntimeException(
"This NodeSetDTM can not do indexing or counting functions!");
int saved = m_next;
// because nextNode always increments
// But watch out for copy29, where the root iterator didn't
// have nextNode called on it.
int current = (m_next > 0) ? m_next-1 : m_next;
int n = (current < m_firstFree) ? elementAt(current) : DTM.NULL;
m_next = saved; // HACK: I think this is a bit of a hack. -sb
return n;
}
示例6: shouldStripWhiteSpace
import org.apache.xml.dtm.DTM; //导入依赖的package包/类
/**
* Get information about whether or not an element should strip whitespace.
* @see <a href="http://www.w3.org/TR/xslt#strip">strip in XSLT Specification</a>
*
* @param support The XPath runtime state.
* @param targetElement Element to check
*
* @return true if the whitespace should be stripped.
*
* @throws TransformerException
*/
public boolean shouldStripWhiteSpace(
XPathContext support, int targetElement) throws TransformerException
{
if (null != m_whiteSpaceInfoList)
{
while(DTM.NULL != targetElement)
{
DTM dtm = support.getDTM(targetElement);
WhiteSpaceInfo info = (WhiteSpaceInfo) m_whiteSpaceInfoList.getTemplate(support,
targetElement, null, false, dtm);
if(null != info)
return info.getShouldStripSpace();
int parent = dtm.getParent(targetElement);
if(DTM.NULL != parent && DTM.ELEMENT_NODE == dtm.getNodeType(parent))
targetElement = parent;
else
targetElement = DTM.NULL;
}
}
return false;
}
示例7: getArg0AsNumber
import org.apache.xml.dtm.DTM; //导入依赖的package包/类
/**
* Execute the first argument expression that is expected to return a
* number. If the argument is null, then get the number value from the
* current context node.
*
* @param xctxt Runtime XPath context.
*
* @return The number value of the first argument, or the number value of the
* current context node if the first argument is null.
*
* @throws javax.xml.transform.TransformerException if an error occurs while
* executing the argument expression.
*/
protected double getArg0AsNumber(XPathContext xctxt)
throws javax.xml.transform.TransformerException
{
if(null == m_arg0)
{
int currentNode = xctxt.getCurrentNode();
if(DTM.NULL == currentNode)
return 0;
else
{
DTM dtm = xctxt.getDTM(currentNode);
XMLString str = dtm.getStringValue(currentNode);
return str.toDouble();
}
}
else
return m_arg0.execute(xctxt).num();
}
示例8: execute
import org.apache.xml.dtm.DTM; //导入依赖的package包/类
/**
* 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 which = getArg0AsNode(xctxt);
if (DTM.NULL != which)
{
// Note that this is a different value than in previous releases
// of Xalan. It's sensitive to the exact encoding of the node
// handle anyway, so fighting to maintain backward compatability
// really didn't make sense; it may change again as we continue
// to experiment with balancing document and node numbers within
// that value.
return new XString("N" + Integer.toHexString(which).toUpperCase());
}
else
return XString.EMPTYSTRING;
}
示例9: execute
import org.apache.xml.dtm.DTM; //导入依赖的package包/类
/**
* 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
{
SubContextList subContextList = xctxt.getCurrentNodeList();
int currentNode = DTM.NULL;
if (null != subContextList) {
if (subContextList instanceof PredicatedNodeTest) {
LocPathIterator iter = ((PredicatedNodeTest)subContextList)
.getLocPathIterator();
currentNode = iter.getCurrentContextNode();
} else if(subContextList instanceof StepPattern) {
throw new RuntimeException(XSLMessages.createMessage(
XSLTErrorResources.ER_PROCESSOR_ERROR,null));
}
} else {
// not predicate => ContextNode == CurrentNode
currentNode = xctxt.getContextNode();
}
return new XNodeSet(currentNode, xctxt.getDTMManager());
}
示例10: getNextNode
import org.apache.xml.dtm.DTM; //导入依赖的package包/类
/**
* Get the next node via getNextXXX. Bottlenecked for derived class override.
* @return The next node on the axis, or DTM.NULL.
*/
protected int getNextNode()
{
if(true /* 0 == m_extendedTypeID */)
{
m_lastFetched = (DTM.NULL == m_lastFetched)
? m_traverser.first(m_context)
: m_traverser.next(m_context, m_lastFetched);
}
// else
// {
// m_lastFetched = (DTM.NULL == m_lastFetched)
// ? m_traverser.first(m_context, m_extendedTypeID)
// : m_traverser.next(m_context, m_lastFetched,
// m_extendedTypeID);
// }
return m_lastFetched;
}
示例11: getSourceTree
import org.apache.xml.dtm.DTM; //导入依赖的package包/类
/**
* Get the source tree from the input source.
*
* @param source The Source object that should identify the desired node.
* @param locator The location of the caller, for diagnostic purposes.
*
* @return non-null reference to a node.
*
* @throws TransformerException if the Source argument can't be resolved to
* a node.
*/
public int getSourceTree(Source source, SourceLocator locator, XPathContext xctxt)
throws TransformerException
{
int n = getNode(source);
if (DTM.NULL != n)
return n;
n = parseToNode(source, locator, xctxt);
if (DTM.NULL != n)
putDocumentInCache(n, source);
return n;
}
示例12: TransformerHandlerImpl
import org.apache.xml.dtm.DTM; //导入依赖的package包/类
/**
* Construct a TransformerHandlerImpl.
*
* @param transformer Non-null reference to the Xalan transformer impl.
* @param doFragment True if the result should be a document fragement.
* @param baseSystemID The system ID to use as the base for relative URLs.
*/
public TransformerHandlerImpl(TransformerImpl transformer,
boolean doFragment, String baseSystemID)
{
super();
m_transformer = transformer;
m_baseSystemID = baseSystemID;
XPathContext xctxt = transformer.getXPathContext();
DTM dtm = xctxt.getDTM(null, true, transformer, true, true);
m_dtm = dtm;
dtm.setDocumentBaseURI(baseSystemID);
m_contentHandler = dtm.getContentHandler();
m_dtdHandler = dtm.getDTDHandler();
m_entityResolver = dtm.getEntityResolver();
m_errorHandler = dtm.getErrorHandler();
m_lexicalHandler = dtm.getLexicalHandler();
m_incremental = transformer.getIncremental();
m_optimizer = transformer.getOptimize();
m_source_location = transformer.getSource_location();
}
示例13: removeElement
import org.apache.xml.dtm.DTM; //导入依赖的package包/类
/**
* Removes the first occurrence of the argument from this vector.
* If the object is found in this vector, each component in the vector
* with an index greater or equal to the object's index is shifted
* downward to have an index one smaller than the value it had
* previously.
*
* @param s Node to remove from the list
*
* @return True if the node was successfully removed
*/
public boolean removeElement(int s)
{
if (null == m_map)
return false;
for (int i = 0; i < m_firstFree; i++)
{
int node = m_map[i];
if (node == s)
{
if (i > m_firstFree)
System.arraycopy(m_map, i + 1, m_map, i - 1, m_firstFree - i);
else
m_map[i] = DTM.NULL;
m_firstFree--;
return true;
}
}
return false;
}
示例14: getNamedItemNS
import org.apache.xml.dtm.DTM; //导入依赖的package包/类
/**
* Retrieves a node specified by local name and namespace URI. HTML-only
* DOM implementations do not need to implement this method.
* @param namespaceURI The namespace URI of the node to retrieve.
* @param localName The local name of the node to retrieve.
*
* @return A <code>Node</code> (of any type) with the specified local
* name and namespace URI, or <code>null</code> if they do not
* identify any node in this map.
* @since DOM Level 2
*/
public Node getNamedItemNS(String namespaceURI, String localName)
{
Node retNode = null;
for (int n = dtm.getFirstAttribute(element); n != DTM.NULL;
n = dtm.getNextAttribute(n))
{
if (localName.equals(dtm.getLocalName(n)))
{
String nsURI = dtm.getNamespaceURI(n);
if ((namespaceURI == null && nsURI == null)
|| (namespaceURI != null && namespaceURI.equals(nsURI)))
{
retNode = dtm.getNode(n);
break;
}
}
}
return retNode;
}
示例15: getHandleFromNode
import org.apache.xml.dtm.DTM; //导入依赖的package包/类
/**
* Get the handle from a Node.
* <p>%OPT% This will be pretty slow.</p>
*
* <p>%OPT% An XPath-like search (walk up DOM to root, tracking path;
* walk down DTM reconstructing path) might be considerably faster
* on later nodes in large documents. That might also imply improving
* this call to handle nodes which would be in this DTM but
* have not yet been built, which might or might not be a Good Thing.</p>
*
* %REVIEW% This relies on being able to test node-identity via
* object-identity. DTM2DOM proxying is a great example of a case where
* that doesn't work. DOM Level 3 will provide the isSameNode() method
* to fix that, but until then this is going to be flaky.
*
* @param node A node, which may be null.
*
* @return The node handle or <code>DTM.NULL</code>.
*/
private int getHandleFromNode(Node node)
{
if (null != node)
{
int len = m_nodes.size();
boolean isMore;
int i = 0;
do
{
for (; i < len; i++)
{
if (m_nodes.elementAt(i) == node)
return makeNodeHandle(i);
}
isMore = nextNode();
len = m_nodes.size();
}
while(isMore || i < len);
}
return DTM.NULL;
}