Пример #1
0
XObjectPtr
Function::execute(
            XPathExecutionContext&          executionContext,
            XalanNode*                      context,
            const XObjectArgVectorType&     args,
            const Locator*                  locator) const
{
    const XObjectArgVectorType::size_type   theArgCount = args.size();

    if (theArgCount == 0)
    {
        return execute(executionContext, context, locator);
    }
    else if (theArgCount == 1)
    {
        return execute(executionContext, context, args[0], locator);
    }
    else if (theArgCount == 2)
    {
        return execute(executionContext, context, args[0], args[1], locator);
    }
    else if (theArgCount == 3)
    {
        return execute(executionContext, context, args[0], args[1], args[2], locator);
    }
    else
    {
        generalError(
            executionContext,
            context,
            locator);

        return XObjectPtr(0);
    }
}
Пример #2
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
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);
}
Пример #4
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 ) );
}
Пример #5
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() ) );
}