Exemple #1
0
XObjectPtr
FunctionGenerateID::execute(
			XPathExecutionContext&	executionContext,
			XalanNode*				context,
			const LocatorType*		locator) const
{
	if (context == 0)
	{
		executionContext.error(
				XalanMessageLoader::getMessage(XalanMessages::FunctionRequiresNonNullContextNode_1Param,"generate-id()"),
				context,
				locator);

		return XObjectPtr();
	}
	else
	{
		XPathExecutionContext::GetAndReleaseCachedString	theID(executionContext);

		theID.get() = XalanUnicode::charLetter_N;

		getSuffix(context, theID.get());

		return executionContext.getXObjectFactory().createString(theID);
	}
}
Exemple #2
0
XObjectPtr
FunctionFormatNumber::execute(
			XPathExecutionContext&	executionContext,
			XalanNode*				context,
			const XObjectPtr		arg1,
			const XObjectPtr		arg2,
			const XObjectPtr		arg3,
			const LocatorType*		locator) const
{
	assert(arg1.null() == false && arg2.null() == false && arg3.null() == false);
	
	const double						theNumber = arg1->num();
	const XalanDOMString&				thePattern = arg2->str();

	const XalanDOMString&				theDFSName = arg3->str();
	assert(length(theDFSName) != 0);
	
	typedef XPathExecutionContext::GetAndReleaseCachedString	GetAndReleaseCachedString;

	GetAndReleaseCachedString	theString(executionContext);

	executionContext.formatNumber(
		theNumber, 
		thePattern,
		theDFSName,
		theString.get(),
		context, 
		locator);

	return executionContext.getXObjectFactory().createString(theString);
}
Exemple #3
0
XObjectPtr
XalanEXSLTFunctionObjectType::execute(
			XPathExecutionContext&			executionContext,
			XalanNode*						context,
			const XObjectArgVectorType&		args,
			const LocatorType*				locator) const
{
	// Make sure nothing's happened to our strings and that
	// they were actually initialized...
	assert(XalanDOMString::equals(m_boolean, s_booleanString) == true);
	assert(XalanDOMString::equals(m_external, s_externalString) == true);
	assert(XalanDOMString::equals(m_nodeSet, s_nodeSetString) == true);
	assert(XalanDOMString::equals(m_number, s_numberString) == true);
	assert(XalanDOMString::equals(m_rtf, s_rtfString) == true);
	assert(XalanDOMString::equals(m_string, s_stringString) == true);

	if (args.size() != 1)
	{
		executionContext.error(getError(), context, locator);
	}

	assert(args[0].null() == false);

	const XalanDOMString*	theResult = &m_external;

	switch(args[0]->getType())
	{
	case XObject::eTypeBoolean:
		theResult = &m_boolean;
		break;

	case XObject::eTypeNodeSet:
		theResult = &m_nodeSet;
		break;

	case XObject::eTypeNumber:
		theResult = &m_number;
		break;

	case XObject::eTypeResultTreeFrag:
		theResult = &m_rtf;
		break;

	case XObject::eTypeString:
		theResult = &m_string;
		break;

	default:
		break;
	}

	assert(theResult != 0);

	return executionContext.getXObjectFactory().createStringReference(*theResult);
}
XObjectPtr
FunctionElementAvailable::execute(
            XPathExecutionContext&  executionContext,
            XalanNode*              /* context */,          
            const XObjectPtr        arg1,
            const LocatorType*      locator) const
{
    assert(arg1.null() == false);

    return executionContext.getXObjectFactory().createBoolean(
        executionContext.elementAvailable(arg1->str(), locator));
}
 CurrentNodePushAndPop(
         XPathExecutionContext&  theExecutionContext,
         XalanNode*              theNewNode) :
     m_executionContext(theExecutionContext)
 {
     theExecutionContext.pushCurrentNode(theNewNode);
 }
Exemple #6
0
XObjectPtr CExternalFunction::execute( XPathExecutionContext&   executionContext,
                                    XalanNode*              /* context */,
                                    const XObjectPtr        arg1,
                                    const Locator*          /* locator */) const
{
    assert(arg1.null() == false);
    const XalanDOMString& arg = arg1->str();

    //convert XalanDOMString (implemented as unsigned short*) into StringBuffer
    StringBuffer sbInput;
    sbInput.ensureCapacity(arg.length()+1);

    size32_t len = arg.length();
    for (size32_t i=0; i < len; i++)
        sbInput.append( (char) arg[i]);

    StringBuffer sbOutput;

    try
    {
        (*m_userFunction)(sbOutput, sbInput.str(), m_pTransform);
    }
    catch (IException* e)
    {
        StringBuffer msg;
        e->errorMessage(msg);
        e->Release();
    }
    catch (...)
    {
    }

    XalanDOMString xdsOutput( sbOutput.str() );
    return executionContext.getXObjectFactory().createString( xdsOutput );
}
 PrefixResolverSetAndRestore(
         XPathExecutionContext&  theExecutionContext,
         const PrefixResolver*   theResolver) :
     m_executionContext(theExecutionContext),
     m_savedResolver(theExecutionContext.getPrefixResolver())
 {
     m_executionContext.setPrefixResolver(theResolver);
 }
XObjectPtr
FunctionLang::execute(
            XPathExecutionContext&  executionContext,
            XalanNode*              context,
            const XObjectPtr        arg1,
            const LocatorType*      /* locator */) const
{
    assert(arg1.null() == false);   

    const XalanNode*        parent = context;

    bool                    fMatch = false;

    const XalanDOMString&   lang = arg1->str();

    while(0 != parent)
    {
        if(XalanNode::ELEMENT_NODE == parent->getNodeType())
        {
            const XalanElement* const   theElementNode =
#if defined(XALAN_OLD_STYLE_CASTS)
                (const XalanElement*)parent;
#else
                static_cast<const XalanElement*>(parent);
#endif

            const XalanDOMString&       langVal =
                theElementNode->getAttributeNS(
                    DOMServices::s_XMLNamespaceURI,
                    s_attributeName);

            if(0 != length(langVal))
            {
                XPathExecutionContext::GetAndReleaseCachedString theGuard1(executionContext);
                XPathExecutionContext::GetAndReleaseCachedString theGuard2(executionContext);

                if(startsWith(toLowerCaseASCII(langVal, theGuard1.get()), toLowerCaseASCII(lang, theGuard2.get())))
                {
                    const XalanDOMString::size_type     valLen = length(lang);

                    if(length(langVal) == valLen ||
                       charAt(langVal, valLen) == XalanUnicode::charHyphenMinus)
                    {
                        fMatch = true;

                        break;
                    }
                }
            }
        }

        parent = DOMServices::getParentOfNode(*parent);
    }

    return executionContext.getXObjectFactory().createBoolean(fMatch);
}
void
TestStringResults(
            XPathFactory&           theXPathFactory,
            XPathProcessor&         theXPathProcessor,
            XPathEnvSupport&        theXPathEnvSupport,
            DOMSupport&             theDOMSupport,
            PrintWriter&            thePrintWriter,
            XPathExecutionContext&  theExecutionContext)
{
    assert(sizeof(theStringTestInput) == sizeof(theStringTestExpectedOutput));

    MemoryManagerType&      theMemoryManager =
        theExecutionContext.getMemoryManager();

    for(int i = 0; theStringTestInput[i] != 0; i++)
    {
        try
        {
            XPath* const    theXPath = theXPathFactory.create();

            XPathConstructionContextDefault     theXPathConstructionContext(theMemoryManager);

            const XPathGuard    theGuard(
                                    theXPathFactory,
                                    theXPath);

            XalanDOMString  theInputString(theMemoryManager);
            XalanDOMString  theResult(theMemoryManager);

            const ElementPrefixResolverProxy    thePrefixResolver(
                                                    0,
                                                    theXPathEnvSupport,
                                                    theDOMSupport);

            const NodeRefList   theDummyNodeList(theMemoryManager);

            TestStringResult(
                theXPathProcessor,
                *theXPath,
                theXPathConstructionContext,
                TranscodeFromLocalCodePage(theStringTestInput[i], theInputString),
                thePrintWriter,
                TranscodeFromLocalCodePage(theStringTestExpectedOutput[i], theResult),
                0,
                thePrefixResolver,
                theDummyNodeList,
                theExecutionContext);
        }
        catch(...)
        {
            thePrintWriter.print("Exception caught evaluating XPath \"");
            thePrintWriter.print(theStringTestInput[i]);
            thePrintWriter.println();
        }
    }
}
XObjectPtr
FunctionHasSameNodes::execute(
            XPathExecutionContext&          executionContext,
            XalanNode*                      context,
            const XObjectArgVectorType&     args,
            const LocatorType*              locator) const
{
    if (args.size() != 2)
    {
        XPathExecutionContext::GetAndReleaseCachedString    theGuard(executionContext);

        executionContext.error(getError(theGuard.get()), context, locator);
    }

    assert(args[0].null() == false && args[1].null() == false);

    const NodeRefListBase&  nodeset1 = args[0]->nodeset();
    const NodeRefListBase&  nodeset2 = args[1]->nodeset();

    const NodeRefListBase::size_type    theLength = nodeset1.getLength();

    bool    fResult = true;

    if (theLength != nodeset2.getLength())
    {
        fResult = false;
    }
    else
    {
        for (NodeRefListBase::size_type i = 0; i < theLength && fResult == true; ++i)
        {
            XalanNode* const    theNode = nodeset1.item(i);
            assert(theNode != 0);

            if (nodeset2.indexOf(theNode) == NodeRefListBase::npos)
            {
                fResult = false;
            }
        }
    }

    return executionContext.getXObjectFactory().createBoolean(fResult);
}
Exemple #11
0
XALAN_CPP_NAMESPACE_USE

/**
* Execute an XPath function object.  The function must return a valid
* XObject.
*
* @param executionContext executing context
* @param context          current context node
* @param opPos            current op position
* @param args             vector of pointers to XObject arguments
* @return                 pointer to the result XObject
*/
XObjectPtr FunctionBase64::execute( XPathExecutionContext& executionContext, XalanNode* context, const XObjectArgVectorType& args, const LocatorType* locator ) const
{
	XALAN_USING_XALAN( XalanDOMString );

	if ( args.size() != 3 )
	{
		stringstream errorMessage;
		errorMessage << "The Base64() function takes 3 arguments [ nodeset, trailer, envelope ], but received " << args.size();
#if (_XALAN_VERSION >= 11100)
		executionContext.problem( XPathExecutionContext::eXPath, XPathExecutionContext::eError, XalanDOMString( errorMessage.str().c_str() ), locator, context); 
#else
		executionContext.error( XalanDOMString( errorMessage.str().c_str() ), context );
#endif
	}

	stringstream stringToEncode;
	string envelopeName = localForm( ( const XMLCh* )( args[ 2 ]->str().data() ) );

	stringToEncode << "<" << envelopeName << ">";
	for( unsigned int i=0; i<args[ 0 ]->nodeset().getLength(); i++ )
	{
		stringToEncode << XPathHelper::SerializeToString( args[ 0 ]->nodeset().item( i ) );
	}
	stringToEncode << localForm( ( const XMLCh* )( args[ 1 ]->str().data() ) ) << "</" << envelopeName << ">";

	string encodedString = Base64::encode( stringToEncode.str() ); 

	return executionContext.getXObjectFactory().createString( unicodeForm( encodedString ) );
}
Exemple #12
0
XObjectPtr
FunctionSubstringBefore::execute(
			XPathExecutionContext&	executionContext,
			XalanNode*				/* context */,
			const XObjectPtr		arg1,
			const XObjectPtr		arg2,
			const LocatorType*		/* locator */) const
{
	assert(arg1.null() == false && arg2.null() == false);

	const XalanDOMString&				theFirstString = arg1->str();

	const XalanDOMString::size_type		theFirstStringLength = length(theFirstString);

	if (theFirstStringLength == 0)
	{
		return createEmptyString(executionContext);
	}
	else
	{
		const XalanDOMString&				theSecondString = arg2->str();

		const XalanDOMString::size_type		theSecondStringLength = length(theSecondString);

		if (theSecondStringLength == 0)
		{
			return createEmptyString(executionContext);
		}
		else
		{
			const XalanDOMString::size_type		theIndex = indexOf(theFirstString,
													   theSecondString);

			if (theIndex == theFirstStringLength)
			{
				return createEmptyString(executionContext);
			}
			else
			{
				XPathExecutionContext::GetAndReleaseCachedString	theResult(executionContext);

				XalanDOMString&		theString = theResult.get();

				theString.assign(
						toCharArray(theFirstString),
						theIndex);

				// Create a string of the appropriate length...
				return executionContext.getXObjectFactory().createString(theResult);
			}
		}
	}
}
XObjectPtr
FunctionString::execute(
            XPathExecutionContext&  executionContext,
            XalanNode*              context,
            const LocatorType*      locator) const
{
    if (context == 0)
    {
        XPathExecutionContext::GetAndReleaseCachedString    theGuard(executionContext);
        XalanDOMString&     theResult = theGuard.get();

        executionContext.error(
            XalanMessageLoader::getMessage(
                theResult,
                XalanMessages::FunctionRequiresNonNullContextNode_1Param,
                "string"),
            context,
            locator);

        // Dummy return value...
        return XObjectPtr();
    }
    else
    {
        // The XPath standard says that if there are no arguments,
        // the argument defaults to a node set with the context node
        // as the only member.  The string value of a node set is the
        // string value of the first node in the node set.
        // DOMServices::getNodeData() will give us the data.

        // Get a cached string...
        XPathExecutionContext::GetAndReleaseCachedString    theData(executionContext);

        XalanDOMString&     theString = theData.get();

        DOMServices::getNodeData(*context, theString);

        return executionContext.getXObjectFactory().createString(theData);
    }
}
Exemple #14
0
XALAN_CPP_NAMESPACE_USE

/**
* Execute an XPath function object.  The function must return a valid
* XObject.
*
* @param executionContext executing context
* @param context          current context node
* @param opPos            current op position
* @param args             vector of pointers to XObject arguments
* @return                 pointer to the result XObject
*/
XObjectPtr FunctionHash::execute( XPathExecutionContext& executionContext, XalanNode* context, const XObjectArgVectorType& args, const LocatorType* locator ) const
{
	if ( args.size() != 1 )
	{
		stringstream errorMessage;
		errorMessage << "The Hash() function takes one argument! [ stringToCRC ], but received " << args.size();
#if (_XALAN_VERSION >= 11100)
		executionContext.problem( XPathExecutionContext::eXPath, XPathExecutionContext::eError, XalanDOMString( errorMessage.str().c_str() ), locator, context); 
#else
		executionContext.error( XalanDOMString( errorMessage.str().c_str() ), context );
#endif
	}

	string stringToCalculateCRC = localForm( ( const XMLCh* )( args[0]->str().data() ) );

	//DEBUG( "Expression to calculate crc for : [" << stringToCalculateCRC << "]" );
	stringstream messageHash;

	/*MD5 md5Value;
	md5Value.update( ( unsigned char* )&stringToCalculateCRC , stringToCalculateCRC.length() );
	md5Value.finalize ();
*/
	//DEBUG( "MD5 = [" << md5Value.hex_digest() << "]" );

	//return executionContext.getXObjectFactory().createString( unicodeForm( md5Value.hex_digest() ) );
	return executionContext.getXObjectFactory().createString( unicodeForm( md5( stringToCalculateCRC ).c_str() ) );
}
Exemple #15
0
XObjectPtr
FunctionStartsWith::execute(
            XPathExecutionContext&  executionContext,
            XalanNode*              /* context */,
            const XObjectPtr        arg1,
            const XObjectPtr        arg2,
            const Locator* const    /* locator */) const
{
    assert(arg1.null() == false && arg2.null() == false);   

    const bool  fStartsWith =
        startsWith(
            arg1->str(executionContext), 
            arg2->str(executionContext));

    return executionContext.getXObjectFactory().createBoolean(fStartsWith);
}
Exemple #16
0
XObjectPtr
FunctionGenerateID::execute(
			XPathExecutionContext&	executionContext,
			XalanNode*				/* context */,
			const XObjectPtr		arg1,
			const LocatorType*		locator) const
{
	assert(arg1.null() == false);

	const NodeRefListBase&	theNodeList = arg1->nodeset();

	if (theNodeList.getLength() == 0)
	{
		return executionContext.getXObjectFactory().createStringReference(s_emptyString);
	}
	else
	{
		return execute(executionContext, theNodeList.item(0), locator);
	}
}
XObjectPtr
FunctionString::execute(
            XPathExecutionContext&  executionContext,
            XalanNode*              /* context */,          
            const XObjectPtr        arg1,
            const LocatorType*      /* locator */) const
{
    assert(arg1.null() == false);   

    if (arg1->getType() == XObject::eTypeString)
    {
        // Since XObjects are reference counted, just return the
        // argument.
        return arg1;
    }
    else
    {
        return executionContext.getXObjectFactory().createStringAdapter(arg1);
    }
}
Exemple #18
0
void
Function::generalError(
            XPathExecutionContext&  executionContext,
            const XalanNode*        context,
            const Locator*          locator) const
{
    const GetCachedString   theGuard(executionContext);

    XalanDOMString&     theErrorString = theGuard.get();

    executionContext.problem(
        XPathExecutionContext::eXPath,
        XPathExecutionContext::eError,
        getError(theErrorString),
        locator,
        context);

    throw XalanXPathException(
            theErrorString,
            theErrorString.getMemoryManager(),
            locator);
}
Exemple #19
0
XALAN_CPP_NAMESPACE_BEGIN



XObjectPtr
XalanEXSLTFunctionEvaluate::execute(
			XPathExecutionContext&			executionContext,
			XalanNode*						context,
			const XObjectArgVectorType&		args,
			const LocatorType*				locator) const
{
	try
	{
		return ParentType::execute(executionContext, context, args, locator);
	}
	catch(const XSLException&)
	{
	}

	XPathExecutionContext::BorrowReturnMutableNodeRefList	theGuard(executionContext);

	return executionContext.getXObjectFactory().createNodeSet(theGuard);
}
XObjectPtr
FunctionSample::execute(
            XPathExecutionContext&  executionContext,
            XalanNode*              /* context */,          
            const XObjectPtr        arg1,
            const XObjectPtr        arg2,
            const Locator*          /* locator */) const
{
   assert(arg1.null() == false);
   assert(arg2.null() == false);

   XalanDOMString path;
   arg1->str(path);
   const bool bLinux = arg2->boolean();

   XalanDOMChar dchOld;
   XalanDOMChar dchNew;

   if (bLinux)
   {
      dchOld = '\\';
      dchNew = '/';
   }
   else
   {
      dchOld = '/';
      dchOld = '\\';
   }

    int len = path.length();
   for (int i=0; i<len; i++)
      if (path[i] == dchOld)
         path[i] = dchNew;

    return executionContext.getXObjectFactory().createString(path); 
}
 GetCachedNodeList(XPathExecutionContext&    executionContext) :
     m_xpathExecutionContext(&executionContext),
     m_mutableNodeRefList(executionContext.borrowMutableNodeRefList())
 {
     assert(m_mutableNodeRefList != 0);
 }
bool
TestAxisResult(
            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    theXPath = theXPathFactory.create();

                XPathConstructionContextDefault     theXPathConstructionContext(theMemoryManager);

                XPathGuard      theGuard(theXPathFactory,
                                         theXPath);

                theXPathProcessor.initXPath(*theXPath,
                                            theXPathConstructionContext,
                                            theXPathString,
                                            thePrefixResolver);

                bool    fDump = false;

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

                const XObjectPtr theResult =
                    theXPath->execute(theContextNode, thePrefixResolver, theContextNodeList, theExecutionContext);

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

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

                    const unsigned int  theLength = theResultList.getLength();

                    if (theLength == 0)
                    {
                        thePrintWriter.println("<out/>");
                    }
                    else
                    {
                        thePrintWriter.print("<out>");

                        for (unsigned int i = 0; i < theLength; i++)
                        {
                            thePrintWriter.print(theResultList.item(i)->getNodeName());
                            thePrintWriter.print(" ");
                        }

                        thePrintWriter.println("</out>");
                    }
                }
                catch(...)
                {
                    thePrintWriter.print("Execution of XPath ");
                    thePrintWriter.print(theXPathString);
                    thePrintWriter.println(" failed!");
                }
            }
        }
    }

    theLiaison.reset();

    return fError;
}
XObjectPtr
FunctionSubstringAfter::execute(
            XPathExecutionContext&  executionContext,
            XalanNode*              /* context */,
            const XObjectPtr        arg1,
            const XObjectPtr        arg2,
            const LocatorType*      /* locator */) const
{
    assert(arg1.null() == false && arg2.null() == false);

    const XalanDOMString&               theFirstString = arg1->str();

    const XalanDOMString::size_type     theFirstStringLength = length(theFirstString);

    if (theFirstStringLength == 0)
    {
        return createEmptyString(executionContext);
    }
    else
    {
        const XalanDOMString&   theSecondString = arg2->str();

        const XalanDOMString::size_type     theSecondStringLength = length(theSecondString);

        if (theSecondStringLength == 0)
        {
            return arg1;
        }
        else
        {
            const XalanDOMString::size_type     theIndex = indexOf(theFirstString,
                                                       theSecondString);

            if (theIndex == theFirstStringLength)
            {
                return createEmptyString(executionContext);
            }
            else
            {
                const XalanDOMString::size_type     theSecondStringLength = length(theSecondString);

                // Find the first character, which will be the offset of the index of the
                // beginning of the second string, plus the length of the second string.
                const XalanDOMChar* const   theFirstCharacter =
                    toCharArray(theFirstString) + theIndex + theSecondStringLength;

                // The remaining length is just the opposite -- the length of the string,
                // minus the index, minus the length of the second string.
                const XalanDOMString::size_type     theSubstringLength =
                    theFirstStringLength  - theIndex - theSecondStringLength;

                XPathExecutionContext::GetAndReleaseCachedString    theResult(executionContext);

                XalanDOMString&     theString = theResult.get();

                assign(
                        theString,
                        theFirstCharacter,
                        theSubstringLength);

                return executionContext.getXObjectFactory().createString(theResult);
            }
        }
    }
}
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;
}
Exemple #25
0
inline XObjectPtr
createEmptyString(XPathExecutionContext&	executionContext)
{
	return executionContext.getXObjectFactory().createStringReference(theEmptyString);
}
Exemple #26
0
XObjectPtr
FunctionSubstring::execute(
			XPathExecutionContext&	executionContext,
			XalanNode*				/* context */,
			const XObjectPtr		arg1,
			const XObjectPtr		arg2,
			const XObjectPtr		arg3,
			const LocatorType*		/* locator */) const
{
	assert(arg1.null() == false && arg2.null() == false);	

	const XalanDOMString&				theSourceString = arg1->str();
	const XalanDOMString::size_type		theSourceStringLength = length(theSourceString);

	if (theSourceStringLength == 0)
	{
		return createEmptyString(executionContext);
	}
	else
	{
		// Get the value of the second argument...
		const double	theSecondArgValue =
			DoubleSupport::round(arg2->num());

		// XPath indexes from 1, so this is the first XPath index....
		const XalanDOMString::size_type		theStartIndex = getStartIndex(theSecondArgValue, theSourceStringLength);

		if (theStartIndex >= theSourceStringLength)
		{
			return createEmptyString(executionContext);
		}
		else
		{
			const double	theTotal =
				getTotal(theSourceStringLength, theSecondArgValue, arg3);

			if (DoubleSupport::isNaN(theSecondArgValue) == true ||
				DoubleSupport::isNaN(theTotal) == true ||
				DoubleSupport::isNegativeInfinity(theTotal) == true ||
				theTotal == 0.0 ||
				theTotal < double(theStartIndex))
			{
				return createEmptyString(executionContext);
			}
			else
			{
				const XalanDOMString::size_type		theSubstringLength =
					getSubstringLength(
						theSourceStringLength,
						theStartIndex,
						theTotal);

				XPathExecutionContext::GetAndReleaseCachedString	theResult(executionContext);

				XalanDOMString&		theString = theResult.get();

				assign(
						theString,
						toCharArray(theSourceString) + theStartIndex,
						theSubstringLength);

				return executionContext.getXObjectFactory().createString(theResult);
			}
		}
	}
}
 GetCachedString(XPathExecutionContext&  theExecutionContext) :
     m_executionContext(&theExecutionContext),
     m_string(&theExecutionContext.getCachedString())
 {
 }