Exemplo n.º 1
0
UnicodeString ClilocLoader::get(unsigned int id, const UnicodeString& paramString) {
    static UnicodeString params[9];
    static UnicodeString paramRegex[9] = {
        "~1_[^~]+~", "~2_[^~]+~", "~3_[^~]+~", "~4_[^~]+~", "~5_[^~]+~",
        "~6_[^~]+~", "~7_[^~]+~", "~8_[^~]+~", "~9_[^~]+~",
    };

    UnicodeString str = get(id);

    if (paramString.length() > 0) {
        UErrorCode status = U_ZERO_ERROR;
        RegexMatcher paramSplitter("\\t", 0, status);
        unsigned int paramCount = paramSplitter.split(paramString, params, 9, status);

        for (unsigned int i = 0; i < paramCount; ++i) {
            RegexMatcher curParamMatcher(paramRegex[i], str, 0, status);

            str = curParamMatcher.replaceAll(params[i], status);
        }
    }

    return str;
}
RoutingCondition::RoutingCondition( const ROUTING_CONDITION conditionType, const string& text )
{
	if ( text.length() > 0 )
		DEBUG( "Condition text : [" << text << "]" );

	//DEBUG_STREAM( "Size : " ) << text.length() << "; first char : " << ( ( int )( text[ 0 ] ) ) << endl;
	m_ConditionType = conditionType;
	m_Text = text;

	switch( m_ConditionType )
	{
		case ALWAYS :
			break;

		case METADATA :
			
			DEBUG( "ConditionType : METADATA" );
			m_Evaluator = ExpressionEvaluator( text );
			
			{ // local vars block
				string cond = StringUtil::ToUpper( m_Evaluator.getFirstOp() );
				if ( cond == "REQUESTOR" )
				{
					m_EvalMetadata = RoutingCondition::REQUESTOR;
				}
				else if ( cond == "RESPONDER" )
				{
					m_EvalMetadata = RoutingCondition::RESPONDER;
				}
				else if ( cond == "ORIGINALREQUESTOR" )
				{
					m_EvalMetadata = RoutingCondition::ORIGINALREQUESTOR;
				}
				else if ( cond == "FEEDBACKCODE" )
				{
					m_EvalMetadata = RoutingCondition::FEEDBACKCODE;
				}
				else if ( cond == "REQUESTTYPE" )
				{
					m_EvalMetadata = RoutingCondition::REQUESTTYPE;
				}
				else if ( cond == "NS" )
				{
					m_EvalMetadata = RoutingCondition::NAMESPACE;
				}
				else
				{
					stringstream errorMessage;
					errorMessage << "Unsupported message condition : [" << cond << "]";
					
					TRACE( errorMessage.str() );
					throw logic_error( errorMessage.str() );
				}
			}
			
			break;
						
		case MESSAGE :
		
			DEBUG( "ConditionType : MESSAGE" );
			// expect MT in '103, 102, ... '
			m_Evaluator = ExpressionEvaluator( text );
			
			{ // local vars block
				// first token is function( param [,param] )
				string cond = StringUtil::ToUpper( m_Evaluator.getFirstOp() );
				if ( cond == "MT" )
				{
					m_EvalMessage = RoutingCondition::MT;
				}
				else if ( cond.substr( 0, 8 ) == "KEYWORD " )
				{
					m_EvalMessage = RoutingCondition::KEYWORD;
				}
				else if ( cond == "FINCOPY" )
				{
					m_EvalMessage = RoutingCondition::FINCOPY;
				}
				else if ( cond.substr( 0, 6 ) == "XPATH " )
				{
					m_EvalMessage = RoutingCondition::XPATH;
				}
				else if ( cond == "ORIGINALMT" )
				{
					m_EvalMessage = RoutingCondition::ORIGINALMT;
				}
				else
				{
					stringstream errorMessage;
					errorMessage << "Unsupported message condition : [" << cond << "]";
					
					TRACE( errorMessage.str() );
					throw logic_error( errorMessage.str() );
				}
			}
			
			break;
			
		case FUNCTION :
	
			DEBUG ( "ConditionType : FUNCTION" );
			// expect function( param [,param] ) = true/false
			m_Evaluator = ExpressionEvaluator( text );
			
			{ // local vars block
				// first token is function( param [,param] )
				StringUtil functionSplitter( m_Evaluator.getFirstOp() );
				functionSplitter.Split( "(" );
				
				string functionName = StringUtil::ToUpper( functionSplitter.NextToken() );
				
				// check function name here
				if ( functionName == "VALIDATETOXSD" )
					m_EvalFunction = RoutingCondition::VALIDATE_TO_XSD;
				else if ( functionName == "VALIDATE" )
					m_EvalFunction = RoutingCondition::VALIDATE;
				else if ( functionName == "ISACK" )
					m_EvalFunction = RoutingCondition::IS_ACK;
				else if ( functionName == "ISNACK" )
					m_EvalFunction = RoutingCondition::IS_NACK;		
				else if ( functionName == "ISREPLY" )
					m_EvalFunction = RoutingCondition::IS_REPLY;		
				else
				{
					stringstream errorMessage;
					errorMessage << "Unsupported function : [" << functionName << "]";
					
					TRACE( errorMessage.str() );
					throw logic_error( errorMessage.str() );
				}
				
				// second token are the params :  param [,param] )
				string strParams = StringUtil::Trim( functionSplitter.NextToken() );
				
				// remove last )
				StringUtil paramSplitter( strParams.substr( 0, strParams.length() - 1 ) );
				paramSplitter.Split( "," );
				while( paramSplitter.MoreTokens() )
				{
					string crtParam = StringUtil::Trim( paramSplitter.NextToken() );
					if ( crtParam.length() > 0 )
						m_EvalFunctionParams.push_back( crtParam );
				};
			}
			
			break;
			
		default :
			throw invalid_argument( "condition type" );
	}
}