contenthandling/webrecognisers/weburlrec/weburlrec.cpp
changeset 0 2e3d3ce01487
equal deleted inserted replaced
-1:000000000000 0:2e3d3ce01487
       
     1 // Copyright (c) 2000-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 // RECScheme.CPP
       
    15 // 
       
    16 //
       
    17 
       
    18 #include <apmrec.h>
       
    19 #include <apmstd.h>
       
    20 #include <f32file.h>
       
    21 #include "weburlrec.h"
       
    22 
       
    23 #ifdef __UI_FRAMEWORKS_V2__
       
    24 #include <ecom/implementationproxy.h>
       
    25 #endif //__UI_FRAMEWORKS_V2__
       
    26 
       
    27 const TInt KMimeWebUrlRecognizerValue = 0x100064DE;
       
    28 const TUid KUidWebUrlRecognizer = {KMimeWebUrlRecognizerValue};
       
    29 const TInt KSchemeNumMimeTypes = 6; // http, https, file, mailto, sms, mms are recognised by this plugin
       
    30 
       
    31 _LIT( KHttpScheme , "http" );       _LIT8( KHttpUrlDataType , "X-Epoc-Url/http" ) ;		//may be either web or wap
       
    32 _LIT( KHttpsScheme , "https" );     _LIT8( KHttpsUrlDataType , "X-Epoc-Url/https" );	//may be either web or wap
       
    33 _LIT( KFileScheme , "file" );       _LIT8( KFileUrlDataType , "X-Epoc-Url/file" );		//may be either web or wap
       
    34 //Messaging schemes
       
    35 _LIT( KMailtoScheme , "mailto" );	_LIT8( KMailtoUrlDataType , "X-Epoc-Url/mailto" ); 
       
    36 _LIT( KSmsScheme , "sms" );			_LIT8( KSmsUrlDataType , "X-Epoc-Url/sms" );
       
    37 _LIT( KMmsScheme , "mms" );			_LIT8( KMmsUrlDataType , "X-Epoc-Url/mms" );
       
    38 
       
    39 const TInt KWebUrlRecognizerStringLength = 255;
       
    40 
       
    41 
       
    42 CApaSchemeRecognizer::CApaSchemeRecognizer()
       
    43 	:CApaDataRecognizerType(KUidWebUrlRecognizer,CApaDataRecognizerType::ENormal)
       
    44 	{
       
    45 	iConfidence = ENotRecognized;
       
    46 	iCountDataTypes = KSchemeNumMimeTypes;
       
    47 	}
       
    48 
       
    49 TUint CApaSchemeRecognizer::PreferredBufSize()
       
    50 	{
       
    51 	return KWebUrlRecognizerStringLength;
       
    52 	}
       
    53 
       
    54 TDataType CApaSchemeRecognizer::SupportedDataTypeL(TInt aIndex) const
       
    55 	// this is a special supported data type X-EPOC-Scheme for urls
       
    56 	{
       
    57 	__ASSERT_DEBUG(aIndex>=0 && aIndex<KSchemeNumMimeTypes,User::Invariant());//assert if out of range
       
    58 
       
    59 	switch (aIndex)
       
    60 		{
       
    61 	case 0:
       
    62 		return TDataType(KHttpUrlDataType);
       
    63 	case 1:
       
    64 		return TDataType(KHttpsUrlDataType);
       
    65 	case 2:
       
    66 		return TDataType(KFileUrlDataType);
       
    67 	case 3:
       
    68 		return TDataType(KMailtoUrlDataType);
       
    69 	case 4:
       
    70 		return TDataType(KSmsUrlDataType);
       
    71 	case 5:
       
    72 		return TDataType(KMmsUrlDataType);
       
    73 	default:
       
    74 		User::Leave(KErrNotSupported);
       
    75 		}
       
    76 	return TDataType();
       
    77 	}
       
    78 
       
    79 void CApaSchemeRecognizer::DoRecognizeL(const TDesC& aName, const TDesC8& /*aBuffer*/)
       
    80 	{
       
    81 	iConfidence = ECertain;
       
    82 	if (FindScheme(KHttpScheme, aName))
       
    83 		{
       
    84 		iDataType = TDataType(KHttpUrlDataType);
       
    85 		return;
       
    86 		}
       
    87 	if (FindScheme(KHttpsScheme, aName))
       
    88 		{
       
    89 		iDataType = TDataType(KHttpsUrlDataType);
       
    90 		return;
       
    91 		}
       
    92 	if (FindScheme(KFileScheme, aName))
       
    93 		{
       
    94 		iDataType = TDataType(KFileUrlDataType);
       
    95 		return;
       
    96 		}
       
    97 	if (FindScheme(KMailtoScheme, aName))
       
    98 		{
       
    99 		iDataType = TDataType(KMailtoUrlDataType);
       
   100 		return;
       
   101 		}
       
   102 	if (FindScheme(KSmsScheme, aName))
       
   103 		{
       
   104 		iDataType = TDataType(KSmsUrlDataType);
       
   105 		return;
       
   106 		}
       
   107 	if (FindScheme(KMmsScheme, aName))
       
   108 		{
       
   109 		iDataType = TDataType(KMmsUrlDataType);
       
   110 		return;
       
   111 		}
       
   112 	iConfidence = ENotRecognized;
       
   113 	}
       
   114 
       
   115 TBool CApaSchemeRecognizer::FindScheme(const TDesC& aScheme, const TDesC& aUrl)
       
   116 	{
       
   117 	TInt colonPos = aUrl.Locate(':');
       
   118 	TInt schemePos = KErrNotFound;
       
   119 	schemePos = aUrl.FindF(aScheme);
       
   120 
       
   121 	if (schemePos >= 0 && aScheme.Length() == colonPos) // we have found a scheme that is the bit before the ':'
       
   122         {
       
   123 		return ETrue;
       
   124         }
       
   125 
       
   126 	return EFalse;
       
   127 	}
       
   128 
       
   129 
       
   130 #ifdef __UI_FRAMEWORKS_V2__
       
   131 
       
   132 const TImplementationProxy ImplementationTable[] =
       
   133 	{
       
   134     IMPLEMENTATION_PROXY_ENTRY(0x100064DE,CApaSchemeRecognizer::NewL)
       
   135 	};
       
   136 
       
   137 EXPORT_C const TImplementationProxy* ImplementationGroupProxy(TInt& aTableCount)
       
   138     {
       
   139     aTableCount = sizeof(ImplementationTable) / sizeof(TImplementationProxy);
       
   140     return ImplementationTable;
       
   141     }
       
   142 
       
   143 CApaDataRecognizerType* CApaSchemeRecognizer::NewL()
       
   144 	{
       
   145     return new (ELeave) CApaSchemeRecognizer();
       
   146     }
       
   147 
       
   148 #else
       
   149 
       
   150 EXPORT_C CApaDataRecognizerType* CreateRecognizer()
       
   151 // The gate function - ordinal 1
       
   152 //
       
   153 	{
       
   154 	CApaDataRecognizerType* thing = new CApaSchemeRecognizer();
       
   155 	return thing; // NULL if new failed
       
   156 	}
       
   157 
       
   158 #endif //__UI_FRAMEWORKS_V2__
       
   159 
       
   160 
       
   161 #ifndef EKA2
       
   162 GLDEF_C TInt E32Dll(TDllReason /*aReason*/)
       
   163 //
       
   164 // DLL entry point
       
   165 //
       
   166 	{
       
   167 	return KErrNone;
       
   168 	}
       
   169 #endif // EKA2