Search in sources :

Example 1 with DOM2DTMExt

use of org.apache.xml.dtm.ref.dom2dtm.DOM2DTMExt in project nokogiri by sparklemotion.

the class XalanDTMManagerPatch method getDTMExt.

private DOM2DTMExt getDTMExt(DOMSource source, boolean unique, DTMWSFilter whiteSpaceFilter) /*, boolean incremental, boolean doIndexing*/
{
    int dtmPos = getFirstFreeDTMID();
    int documentID = dtmPos << IDENT_DTM_NODE_BITS;
    //DOM2DTM dtm = new DOM2DTM(this, source, documentID, whiteSpaceFilter, m_xsf, true);
    DOM2DTMExt dtm = new DOM2DTMExt(this, source, documentID, whiteSpaceFilter, m_xsf, true);
    addDTM(dtm, dtmPos, 0);
    return dtm;
}
Also used : DOM2DTMExt(org.apache.xml.dtm.ref.dom2dtm.DOM2DTMExt)

Example 2 with DOM2DTMExt

use of org.apache.xml.dtm.ref.dom2dtm.DOM2DTMExt in project nokogiri by sparklemotion.

the class XalanDTMManagerPatch method getDTMHandleFromNode.

/**
     * Given a W3C DOM node, try and return a DTM handle.
     * Note: calling this may be non-optimal, and there is no guarantee that
     * the node will be found in any particular DTM.
     *
     * @param node Non-null reference to a DOM node.
     *
     * @return a valid DTM handle.
     */
@Override
public /* synchronized */
int getDTMHandleFromNode(org.w3c.dom.Node node) {
    //    throw new IllegalArgumentException(XMLMessages.createXMLMessage(XMLErrorResources.ER_NODE_NON_NULL, null));
    assert node != null;
    if (node instanceof org.apache.xml.dtm.ref.DTMNodeProxy) {
        return ((org.apache.xml.dtm.ref.DTMNodeProxy) node).getDTMNodeNumber();
    }
    //   Have each DTM cache last DOM node search?
    for (int i = 0; i < m_dtms.length; i++) {
        DTM thisDTM = m_dtms[i];
        if (thisDTM instanceof org.apache.xml.dtm.ref.dom2dtm.DOM2DTM) {
            int handle = ((org.apache.xml.dtm.ref.dom2dtm.DOM2DTM) thisDTM).getHandleOfNode(node);
            if (handle != DTM.NULL) {
                return handle;
            }
        }
    }
    // Not found; generate a new DTM.
    //
    // %REVIEW% Is this really desirable, or should we return null
    // and make folks explicitly instantiate from a DOMSource? The
    // latter is more work but gives the caller the opportunity to
    // explicitly add the DTM to a DTMManager... and thus to know when
    // it can be discarded again, which is something we need to pay much
    // more attention to. (Especially since only DTMs which are assigned
    // to a manager can use the overflow addressing scheme.)
    //
    // %BUG% If the source node was a DOM2DTM$defaultNamespaceDeclarationNode
    // and the DTM wasn't registered with this DTMManager, we will create
    // a new DTM and _still_ not be able to find the node (since it will
    // be resynthesized). Another reason to push hard on making all DTMs
    // be managed DTMs.
    // Since the real root of our tree may be a DocumentFragment, we need to
    // use getParent to find the root, instead of getOwnerDocument.  Otherwise
    // DOM2DTM#getHandleOfNode will be very unhappy.
    Node root = node;
    int rootType = root.getNodeType();
    Node p = (rootType == Node.ATTRIBUTE_NODE) ? ((org.w3c.dom.Attr) root).getOwnerElement() : root.getParentNode();
    for (; p != null; p = p.getParentNode()) root = p;
    // DOM2DTM dtm = (DOM2DTM) getDTM(new DOMSource(root), false, null);
    DOM2DTMExt dtm = getDTMExt(new DOMSource(root), false, null);
    int handle;
    if (node instanceof org.apache.xml.dtm.ref.dom2dtm.DOM2DTMdefaultNamespaceDeclarationNode) {
        // Can't return the same node since it's unique to a specific DTM,
        // but can return the equivalent node -- find the corresponding
        // Document Element, then ask it for the xml: namespace decl.
        handle = dtm.getHandleOfNode(((org.w3c.dom.Attr) node).getOwnerElement());
        handle = dtm.getAttributeNode(handle, node.getNamespaceURI(), node.getLocalName());
    } else {
        handle = dtm.getHandleOfNode(node);
        rootType = root.getNodeType();
        // we decided to allow wrapping a DTM around a subtree.
        if ((root == node) || (rootType == Node.DOCUMENT_NODE && root == node.getOwnerDocument()) || (rootType != Node.DOCUMENT_NODE && root.getOwnerDocument() == node.getOwnerDocument())) {
            // available!
            for (Node cursor = node; cursor != null; cursor = (cursor.getNodeType() != Node.ATTRIBUTE_NODE) ? cursor.getParentNode() : ((org.w3c.dom.Attr) cursor).getOwnerElement()) {
                if (cursor == root) {
                    // We know this node; find its handle.
                    return (dtm).getHandleFromNode(node);
                }
            }
        // for ancestors of node
        }
    // if node and m_root in same Document
    }
    if (DTM.NULL == handle)
        //"Could not resolve the node to a handle!");
        throw new RuntimeException(XMLMessages.createXMLMessage(XMLErrorResources.ER_COULD_NOT_RESOLVE_NODE, null));
    return handle;
}
Also used : DOMSource(javax.xml.transform.dom.DOMSource) Node(org.w3c.dom.Node) DOM2DTMExt(org.apache.xml.dtm.ref.dom2dtm.DOM2DTMExt) DTM(org.apache.xml.dtm.DTM)

Aggregations

DOM2DTMExt (org.apache.xml.dtm.ref.dom2dtm.DOM2DTMExt)2 DOMSource (javax.xml.transform.dom.DOMSource)1 DTM (org.apache.xml.dtm.DTM)1 Node (org.w3c.dom.Node)1