Пример #1
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 ) );
}
Пример #2
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() ) );
}
Пример #3
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);
}