contextframework/cfw/src/basicoperationsplugin/cfcontains.cpp
changeset 0 2e3d3ce01487
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/contextframework/cfw/src/basicoperationsplugin/cfcontains.cpp	Tue Feb 02 10:12:00 2010 +0200
@@ -0,0 +1,193 @@
+/*
+* Copyright (c) 2002-2008 Nokia Corporation and/or its subsidiary(-ies). 
+* All rights reserved.
+* This component and the accompanying materials are made available
+* under the terms of "Eclipse Public License v1.0"
+* which accompanies this distribution, and is available
+* at the URL "http://www.eclipse.org/legal/epl-v10.html".
+*
+* Initial Contributors:
+* Nokia Corporation - initial contribution.
+*
+* Contributors:
+*
+* Description:  CCFContains class implementation.
+*
+*/
+
+
+
+// INCLUDES
+#include "cfcontains.h"
+#include "cfcontextobject.h"
+#include "cfcontextoperationutils.h"
+#include "cfbasicoptrace.h"
+
+#include <gmxmlnode.h>
+
+// CONSTANTS
+_LIT( KScriptContainsName, "contains" );
+
+// ============================ MEMBER FUNCTIONS ===============================
+
+// -----------------------------------------------------------------------------
+// CCFContains::CCFContains
+// C++ default constructor can NOT contain any code, that
+// might leave.
+// -----------------------------------------------------------------------------
+//
+CCFContains::CCFContains( MCFOperationServices& aServices,
+    CCFOperationNode* aParent,
+    HBufC* aName,
+    HBufC* aSource )
+    :   CCFContextOperation( aServices, aParent, aName, aSource )
+    {
+    FUNC_LOG;
+    }
+
+// -----------------------------------------------------------------------------
+// CCFContains::ConstructL
+// Symbian 2nd phase constructor can leave.
+// -----------------------------------------------------------------------------
+//
+void CCFContains::ConstructL( const TDesC& aCmpVal )
+    {
+    FUNC_LOG;
+
+    iCmpValue = aCmpVal.AllocL();
+    }
+
+// -----------------------------------------------------------------------------
+// CCFContains::NewL
+// Two-phased constructor.
+// -----------------------------------------------------------------------------
+//
+CCFContains* CCFContains::NewL( MCFOperationServices& aServices,
+    CCFOperationNode* aParent,
+    TDesC& aName,
+    TDesC& aSource,
+    const TDesC& aCmpVal )
+    {
+    FUNC_LOG;
+
+    CCFContains* self = NewLC( aServices, aParent, aName, aSource, aCmpVal );
+    CleanupStack::Pop( self );
+    return self;
+    }
+
+// -----------------------------------------------------------------------------
+// CCFContains::NewLC
+// Two-phased constructor.
+// -----------------------------------------------------------------------------
+//
+CCFContains* CCFContains::NewLC( MCFOperationServices& aServices,
+    CCFOperationNode* aParent,
+    TDesC& aName,
+    TDesC& aSource,
+    const TDesC& aCmpVal )
+    {
+    FUNC_LOG;
+
+    HBufC* name = aName.AllocLC();
+    HBufC* source = aSource.AllocLC();
+    CCFContains* self
+        = new( ELeave ) CCFContains( aServices, aParent, name, source );
+    CleanupStack::PushL( self );
+    self->ConstructL( aCmpVal );
+
+    // Cleanup
+    CleanupStack::Pop( self );
+    CleanupStack::Pop( source );
+    CleanupStack::Pop( name );
+
+    CleanupStack::PushL( self );
+    return self;
+    }
+
+// -----------------------------------------------------------------------------
+// CCFContains::ParseL
+// Construction with parsing from a DOM node.
+// -----------------------------------------------------------------------------
+//
+CCFContains* CCFContains::ParseL( MCFOperationServices& aServices,
+    CCFOperationNode* aParent,
+    CMDXMLNode& aNode )
+    {
+    FUNC_LOG;
+
+    if ( aNode.NodeName().CompareF( KScriptContainsName ) != 0 )
+        {
+        return NULL; // Cannot create contains operation from the given node.
+        }
+
+    TPtrC contextSource;
+    TPtrC contextType;
+    TCmpType cmpType( CCFContextOperation::EInvalidCmpType );
+    TPtrC cmpValue;
+    TInt contextLevelDelay( 0 );
+    TBool argsOK = CFContextOperationUtils::ParseTwoComparisonArgs( aNode,
+            contextSource,
+            contextType,
+            cmpType,
+            cmpValue,
+            contextLevelDelay );
+    if ( cmpType != CCFContextOperation::EStringCmp )
+        {
+        argsOK = EFalse;
+        }
+
+    CCFContains* self = NULL;
+    if ( argsOK )
+        {
+        self = NewL( aServices,
+                aParent,
+                contextType,
+                contextSource,
+                cmpValue );
+        if ( contextLevelDelay )
+            {
+            self->iContextLevelDelay = contextLevelDelay;
+            }
+        }
+    else
+        {
+        INFO( "CCFContains::ParseL - Unsupported arguments" );
+        }
+
+    CREATE_DOM_INFO( self, aNode );
+
+    return self;
+    }
+
+
+// Destructor
+CCFContains::~CCFContains()
+    {
+    FUNC_LOG;
+
+    delete iCmpValue;
+    }
+
+// -----------------------------------------------------------------------------
+// CCFContains::IsTrueL
+// Returns ETrue if this operation is true.
+// (other items were commented in a header).
+// -----------------------------------------------------------------------------
+//
+TBool CCFContains::IsTrueL( const CCFContextObject& aContextObject )
+    {
+    FUNC_LOG;
+
+    TBool value( EFalse );
+    TInt err( KErrNone );
+
+    err = aContextObject.Value().Find( *iCmpValue );
+
+    // Value was found
+    if ( err != KErrNotFound )
+        {
+        value = ETrue;
+        }
+
+    return value;
+    }