Пример #1
0
XalanNode*
XercesElementWrapper::item(unsigned int		index) const
{
	assert(index < getLength());

	if (m_navigator.getOwnerDocument()->getMappingMode() == true)
	{
		assert(m_xercesNode->getChildNodes()->item(index));

		return m_navigator.mapNode(m_xercesNode->getChildNodes()->item(index));
	}
	else
	{
		XalanNode*	child = getFirstChild();
		assert(child != 0);

		for(unsigned int i = 0; i < index; ++i)
		{
			child = child->getNextSibling();
			assert(child != 0);
		}

		return child;
	}
}
	bool
	operator()(
			const XalanNode&	node1,
			const XalanNode&	node2) const
	{
		assert(node1.getOwnerDocument() == node2.getOwnerDocument());

		return m_documentPredicate(node1, node2) == true ? true : node1.getIndex() > node2.getIndex() ? true : false;
	}
	bool
	operator()(
			const XalanNode&	node1,
			const XalanNode&	node2) const
	{
		// Always order a document node, or a node from another
		// document after another node...
		return node1.getNodeType() == XalanNode::DOCUMENT_NODE &&
			   node2.getNodeType() == XalanNode::DOCUMENT_NODE ? true :
					node1.getOwnerDocument() != node2.getOwnerDocument() ? true : false;
	}
	bool
	operator()(
			const XalanNode&	node1,
			const XalanNode&	node2) const
	{
		if (m_documentPredicate(node1, node2) == true)
		{
			return true;
		}
		else
		{
			assert(node1.getOwnerDocument() == node2.getOwnerDocument());
			assert(node1.getNodeType() != XalanNode::DOCUMENT_NODE &&
				   node2.getNodeType() != XalanNode::DOCUMENT_NODE);

			return  m_executionContext.isNodeAfter(node1, node2);
		}
	}
Пример #5
0
XalanNode * findHereNodeFromXalan(XercesWrapperNavigator * xwn, XalanNode * n, DOMNode *h) {
	
	const DOMNode * m = xwn->mapNode(n);
	const XalanNode * ret;

	if (m == h)
		return n;

	// Not this one - check the children

	XalanNode * c = n->getFirstChild();

	while (c != 0) {
		ret = findHereNodeFromXalan(xwn, c, h);
		if (ret != 0)
			return (XalanNode *) ret;
		c = c->getNextSibling();
	}

	return 0;
}
Пример #6
0
void
DOMServices::getNodeData(
			const XalanNode&	node,
			FormatterListener&	formatterListener,
			MemberFunctionPtr	function)
{
	switch(node.getNodeType())
	{
	case XalanNode::DOCUMENT_FRAGMENT_NODE:
		{
			const XalanDocumentFragment&		theDocumentFragment =
#if defined(XALAN_OLD_STYLE_CASTS)
				(const XalanDocumentFragment&)node;
#else
				static_cast<const XalanDocumentFragment&>(node);
#endif
			getNodeData(theDocumentFragment, formatterListener, function);
		}
		break;

	case XalanNode::DOCUMENT_NODE:
		{
			const XalanDocument&	theDocument =
#if defined(XALAN_OLD_STYLE_CASTS)
				(const XalanDocument&)node;
#else
				static_cast<const XalanDocument&>(node);
#endif
			getNodeData(theDocument, formatterListener, function);
		}
		break;

	case XalanNode::ELEMENT_NODE:
		{
			const XalanElement&		theElement =
#if defined(XALAN_OLD_STYLE_CASTS)
				(const XalanElement&)node;
#else
				static_cast<const XalanElement&>(node);
#endif
			getNodeData(theElement, formatterListener, function);
		}
		break;

	case XalanNode::TEXT_NODE:
	case XalanNode::CDATA_SECTION_NODE:
		{
			const XalanText&	theTextNode =
#if defined(XALAN_OLD_STYLE_CASTS)
				(const XalanText&)node;
#else
				static_cast<const XalanText&>(node);
#endif

				getNodeData(theTextNode, formatterListener, function);
		}
		break;

	case XalanNode::ATTRIBUTE_NODE:
		{
			const XalanAttr&		theAttr =
#if defined(XALAN_OLD_STYLE_CASTS)
				(const XalanAttr&)node;
#else
				static_cast<const XalanAttr&>(node);
#endif
			getNodeData(theAttr, formatterListener, function);
		}
		break;

	case XalanNode::COMMENT_NODE:
		{
			const XalanComment&		theComment =
#if defined(XALAN_OLD_STYLE_CASTS)
				(const XalanComment&)node;
#else
				static_cast<const XalanComment&>(node);
#endif
			getNodeData(theComment, formatterListener, function);
		}
		break;

	case XalanNode::PROCESSING_INSTRUCTION_NODE:
		{
			const XalanProcessingInstruction&		thePI =
#if defined(XALAN_OLD_STYLE_CASTS)
				(const XalanProcessingInstruction&)node;
#else
				static_cast<const XalanProcessingInstruction&>(node);
#endif
			getNodeData(thePI, formatterListener, function);
		}
		break;

	default:
		// ignore
		break;
	}
}
Пример #7
0
void
DOMServices::doGetNodeData(
            const XalanNode&    node,
            ExecutionContext&   executionContext,
            FormatterListener&  formatterListener,
            MemberFunctionPtr   function)
{
    assert(executionContext.hasPreserveOrStripSpaceConditions() == true);

    switch(node.getNodeType())
    {
    case XalanNode::DOCUMENT_FRAGMENT_NODE:
        {
            const XalanDocumentFragment&        theDocumentFragment =
                static_cast<const XalanDocumentFragment&>(node);

            doGetNodeData(theDocumentFragment, executionContext, formatterListener, function);
        }
        break;

    case XalanNode::DOCUMENT_NODE:
        {
            const XalanDocument&    theDocument =
                static_cast<const XalanDocument&>(node);

            doGetNodeData(theDocument, executionContext, formatterListener, function);
        }
        break;

    case XalanNode::ELEMENT_NODE:
        {
            const XalanElement&     theElement =
                static_cast<const XalanElement&>(node);

            doGetNodeData(theElement, executionContext, formatterListener, function);
        }
        break;

    case XalanNode::TEXT_NODE:
    case XalanNode::CDATA_SECTION_NODE:
        {
            const XalanText&    theTextNode =
                static_cast<const XalanText&>(node);

                doGetNodeData(theTextNode, executionContext, formatterListener, function);
        }
        break;

    case XalanNode::ATTRIBUTE_NODE:
        {
            const XalanAttr&        theAttr =
                static_cast<const XalanAttr&>(node);

            getNodeData(theAttr, formatterListener, function);
        }
        break;

    case XalanNode::COMMENT_NODE:
        {
            const XalanComment&     theComment =
                static_cast<const XalanComment&>(node);

            getNodeData(theComment, formatterListener, function);
        }
        break;

    case XalanNode::PROCESSING_INSTRUCTION_NODE:
        {
            const XalanProcessingInstruction&       thePI =
                static_cast<const XalanProcessingInstruction&>(node);

            getNodeData(thePI, formatterListener, function);
        }
        break;

    default:
        // ignore
        break;
    }
}
Пример #8
0
void
DOMServices::getNodeData(
            const XalanNode&    node,
            XalanDOMString&     data)
{
    switch(node.getNodeType())
    {
    case XalanNode::DOCUMENT_FRAGMENT_NODE:
        {
            const XalanDocumentFragment&        theDocumentFragment =
                static_cast<const XalanDocumentFragment&>(node);

            getNodeData(theDocumentFragment, data);
        }
        break;

    case XalanNode::DOCUMENT_NODE:
        {
            const XalanDocument&    theDocument =
                static_cast<const XalanDocument&>(node);

            getNodeData(theDocument, data);
        }
        break;

    case XalanNode::ELEMENT_NODE:
        {
            const XalanElement&     theElement =
                static_cast<const XalanElement&>(node);

            getNodeData(theElement, data);
        }
        break;

    case XalanNode::TEXT_NODE:
    case XalanNode::CDATA_SECTION_NODE:
        {
            const XalanText&    theTextNode =
                static_cast<const XalanText&>(node);

                getNodeData(theTextNode, data);
        }
        break;

    case XalanNode::ATTRIBUTE_NODE:
        {
            const XalanAttr&        theAttr =
                static_cast<const XalanAttr&>(node);

            getNodeData(theAttr, data);
        }
        break;

    case XalanNode::COMMENT_NODE:
        {
            const XalanComment&     theComment =
                static_cast<const XalanComment&>(node);

            getNodeData(theComment, data);
        }
        break;

    case XalanNode::PROCESSING_INSTRUCTION_NODE:
        {
            const XalanProcessingInstruction&       thePI =
                static_cast<const XalanProcessingInstruction&>(node);

            getNodeData(thePI, data);
        }
        break;

    default:
        // ignore
        break;
    }
}
Пример #9
0
bool
DOMServices::isNodeAfterSibling(
            const XalanNode&    parent,
            const XalanNode&    child1,
            const XalanNode&    child2)
{
    bool    isNodeAfterSibling = false;

    const XalanNode::NodeType   child1type = child1.getNodeType();
    const XalanNode::NodeType   child2type = child2.getNodeType();

    if (XalanNode::ATTRIBUTE_NODE != child1type &&
        XalanNode::ATTRIBUTE_NODE == child2type)
    {
        // always sort attributes before non-attributes.
        isNodeAfterSibling = true;
    }
    else if (XalanNode::ATTRIBUTE_NODE == child1type &&
             XalanNode::ATTRIBUTE_NODE != child2type)
    {
        // always sort attributes before non-attributes.
        isNodeAfterSibling = false;
    }
    else if (XalanNode::ATTRIBUTE_NODE == child1type)
    {
        const XalanNamedNodeMap*    children = parent.getAttributes();
      
        const XalanSize_t   nNodes = children->getLength();

        bool                found1 = false;
        bool                found2 = false;

        for (XalanSize_t i = 0; i < nNodes; i++)
        {
            const XalanNode*    child = children->item(i);

            if (&child1 == child)
            {
                if (found2 == true)
                {
                    isNodeAfterSibling = true;
                    break;
                }
          
                found1 = true;
            }
            else if (&child2 == child)
            {
                if (found1 == true)
                {
                    isNodeAfterSibling = false;
                    break;
                }
          
                found2 = true;
            }
        }
    }
    else
    {
        const XalanNode*    child = parent.getFirstChild();

        bool    found1 = false;
        bool    found2 = false;

        while (child != 0)
        {
            if (&child1 == child)
            {
                if (found2 == true)
                {
                    isNodeAfterSibling = true;
                    break;
                }

                found1 = true;
            }
            else if (&child2 == child)
            {
                if (found1 == true)
                {
                    isNodeAfterSibling = false;
                    break;
                }

                found2 = true;
            }

            child = child->getNextSibling();
        }

        assert(found1 != found2);
    }

    return isNodeAfterSibling;
}
Пример #10
0
bool
DOMServices::isNodeAfter(
            const XalanNode&    node1,
            const XalanNode&    node2)
{
    assert(node1.getOwnerDocument() == node2.getOwnerDocument());
    assert(node1.getNodeType() != XalanNode::DOCUMENT_NODE &&
            node2.getNodeType() != XalanNode::DOCUMENT_NODE);

    if (node1.isIndexed() == true)
    {
        assert(node2.isIndexed() == true);

        return node1.getIndex() > node2.getIndex() ? true : false;
    }
    else
    {
        bool    isNodeAfter = false;

        const XalanNode*    parent1 = getParentOfNode(node1);

        const XalanNode*    parent2 = getParentOfNode(node2);

        // Optimize for most common case
        if (parent1 == parent2) // then we know they are siblings
        {
            isNodeAfter = isNodeAfterSibling(*parent1,
                                             node1,
                                             node2);
        }
        else
        {
            // General strategy: Figure out the lengths of the two 
            // ancestor chains, and walk up them looking for the 
            // first common ancestor, at which point we can do a 
            // sibling compare.  Edge condition where one is the 
            // ancestor of the other.

            // Count parents, so we can see if one of the chains 
            // needs to be equalized.
            XalanSize_t nParents1 = 2;
            XalanSize_t nParents2 = 2; // count node & parent obtained above

            while (parent1 != 0)
            {
                nParents1++;
                parent1 = getParentOfNode(*parent1);
            }

            while (parent2 != 0)
            {
                nParents2++;
                parent2 = getParentOfNode(*parent2);
            }

            // adjustable starting points
            const XalanNode*    startNode1 = &node1;
            const XalanNode*    startNode2 = &node2;

            // Do I have to adjust the start point in one of 
            // the ancesor chains?
            if (nParents1 < nParents2)
            {
                // adjust startNode2
                const XalanSize_t   adjust = nParents2 - nParents1;

                for (XalanSize_t i = 0; i < adjust; i++)
                {
                    startNode2 = getParentOfNode(*startNode2);
                }
            }
            else if(nParents1 > nParents2)
            {
                // adjust startNode1
                const XalanSize_t   adjust = nParents1 - nParents2;

                for (XalanSize_t i = 0; i < adjust; i++)
                {
                    startNode1 = getParentOfNode(*startNode1);
                }
            }

            // so we can "back up"
            const XalanNode*    prevChild1 = 0;
            const XalanNode*    prevChild2 = 0;
              
            // Loop up the ancestor chain looking for common parent.
            while (0 != startNode1)
            {
                if (startNode1 == startNode2) // common parent?
                {
                    if (0 == prevChild1) // first time in loop?
                    {
                        // Edge condition: one is the ancestor of the other.
                        isNodeAfter = (nParents1 < nParents2) ? true : false;

                        break; // from while loop
                    }
                    else
                    {
                        isNodeAfter = isNodeAfterSibling(*startNode1,
                                                         *prevChild1,
                                                         *prevChild2);

                        break; // from while loop
                    }
                }

                prevChild1 = startNode1;
                assert(prevChild1 != 0);

                startNode1 = getParentOfNode(*startNode1);
                assert(startNode1 != 0);

                prevChild2 = startNode2;
                assert(prevChild2 != 0);

                startNode2 = getParentOfNode(*startNode2);
                assert(startNode2 != 0);
            }
        }

        return isNodeAfter;
    }
}
Пример #11
0
bool
TestPredicateResult(
            XPathProcessor&         theXPathProcessor,
            XPathEnvSupport&        theXPathEnvSupport,
            DOMSupport&             theDOMSupport,
            XMLParserLiaison&       theLiaison,
            XPathFactory&           theXPathFactory,
            const XalanDOMString&   theXMLFileURL,
            const XalanDOMString&   theXSLFileURL,
            PrintWriter&            thePrintWriter,
            XPathExecutionContext&  theExecutionContext)
{
    bool                    fError = false;

    XalanDocument* const    theXMLDocument =
                ParseXML(theLiaison,
                         theXMLFileURL);

    MemoryManagerType&      theMemoryManager =
        theExecutionContext.getMemoryManager();

    if (theXMLDocument != 0)
    {
        XalanDOMString      theContextNodeMatchPattern(theMemoryManager);
        XalanDOMString      theXPathString(theMemoryManager);

        if (GetXSLInput(theLiaison,
                        theXSLFileURL,
                        theContextNodeMatchPattern,
                        theXPathString,
                        theMemoryManager) == true)
        {
            XalanNode* const    theContextNode =
                FindContextNode(theXPathProcessor,
                                theXPathEnvSupport,
                                theDOMSupport,
                                theXPathFactory,
                                theXMLDocument,
                                theContextNodeMatchPattern,
                                thePrintWriter,
                                theExecutionContext);

            if (theContextNode != 0)
            {
                XalanElement* const             theNamespaceContext = 0;
                ElementPrefixResolverProxy      thePrefixResolver(theNamespaceContext, theXPathEnvSupport, theDOMSupport);
                NodeRefList                     theContextNodeList(theMemoryManager);

                XPath* const    theXPath1 = theXPathFactory.create();

                XPathConstructionContextDefault     theXPathConstructionContext(theMemoryManager);

                XPathGuard  theGuard1(theXPathFactory,
                                      theXPath1);

                XalanDOMString  theResult(theMemoryManager);

                theXPathProcessor.initXPath(*theXPath1,
                                            theXPathConstructionContext,
                                            TranscodeFromLocalCodePage("following-sibling::*", theResult),
                                            thePrefixResolver);

                XPath* const    theXPath2 = theXPathFactory.create();

                XPathGuard  theGuard2(theXPathFactory,
                                      theXPath2);

                theXPathProcessor.initXPath(*theXPath2,
                                            theXPathConstructionContext,
                                            TranscodeFromLocalCodePage("descendant::*", theResult),
                                            thePrefixResolver);

                bool    fDump = false;

                if (fDump == true)
                {
                    thePrintWriter.println();
                    thePrintWriter.println();
                    theXPath1->getExpression().dumpOpCodeMap(thePrintWriter);
                    thePrintWriter.println();
                    theXPath1->getExpression().dumpTokenQueue(thePrintWriter);
                    thePrintWriter.println();
                    thePrintWriter.println();
                    theXPath2->getExpression().dumpOpCodeMap(thePrintWriter);
                    thePrintWriter.println();
                    theXPath2->getExpression().dumpTokenQueue(thePrintWriter);
                    thePrintWriter.println();
                    thePrintWriter.println();
                }

                XalanNode*  theContextNode = theXMLDocument->getFirstChild()->getFirstChild();

                for( ; theContextNode != 0; theContextNode = theContextNode->getNextSibling())
                {
                    if (theContextNode->getNodeType() != XalanNode::ELEMENT_NODE)
                    {
                        continue;
                    }

                    const XObjectPtr theResult1 =
                            theXPath1->execute(theExecutionContext);

                    try
                    {
                        assert(theResult1.null() == false);

                        const NodeRefListBase&  theResultList =
                                theResult1->nodeset();

                        const unsigned int  theLength = theResultList.getLength();

                        thePrintWriter.print("theResult1->str() == \"");
                        thePrintWriter.print(theResult1->str());
                        thePrintWriter.print("\"");
                        thePrintWriter.println();

                        if (theLength > 0)
                        {
                            for (unsigned int i = 0; i < theLength; i++)
                            {
                                thePrintWriter.print(theResultList.item(i)->getNodeName());
                                thePrintWriter.println();
                            }
                        }
                    }
                    catch(...)
                    {
                        thePrintWriter.print("Execution of XPath ");
                        thePrintWriter.print(theXPathString);
                        thePrintWriter.println(" failed!");
                    }

                    const XObjectPtr    theResult2 =
                            theXPath2->execute(theExecutionContext);

                    try
                    {
                        assert(theResult2.null() == false);

                        const NodeRefListBase&  theResultList =
                                theResult2->nodeset();

                        const int   theLength = theResultList.getLength();

                        thePrintWriter.print("theResult2->str() == \"");
                        thePrintWriter.print(theResult2->str());
                        thePrintWriter.print("\"");
                        thePrintWriter.println();

                        if (theLength > 0)
                        {
                            for (int i = 0; i < theLength; i++)
                            {
                                thePrintWriter.print(theResultList.item(i)->getNodeName());
                                thePrintWriter.println();
                            }
                        }
                    }
                    catch(...)
                    {
                        thePrintWriter.print("Execution of XPath ");
                        thePrintWriter.print(theXPathString);
                        thePrintWriter.println(" failed!");
                    }

                    if (theResult1->equals(*theResult2, theExecutionContext) == true)
                    {
                        thePrintWriter.print("theResult1 is equal to theResult2");
                        thePrintWriter.println();
                        thePrintWriter.print("theContextNode->getNodeName() == \"");
                        thePrintWriter.print(theContextNode->getNodeName());
                        thePrintWriter.print("\"  theContextNode->getNodeValue() == \"");
                        thePrintWriter.print(theContextNode->getNodeValue());
                        thePrintWriter.println("\"");
                    }
                }
            }
        }
    }

    return fError;
}