browserutilities/feedsengine/FeedsServer/Reconizer/src/FeedsRec.cpp
changeset 0 dd21522fd290
child 26 cb62a4f66ebe
equal deleted inserted replaced
-1:000000000000 0:dd21522fd290
       
     1 /*
       
     2 * Copyright (c) 2005 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of the License "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  Recognizer for the bowser supported MIME types.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include "FeedsRec.h"
       
    20 
       
    21 #include <ImplementationProxy.h>
       
    22 
       
    23 
       
    24 // Constants
       
    25 _LIT8(KMimeTypeRss,   "application/rss+xml");
       
    26 //_LIT8(KMimeTypeAtom,  "application/atom+xml");
       
    27 _LIT8(KMimeTypeXml1,  "application/xml");
       
    28 _LIT8(KMimeTypeXml2,  "text/xml");
       
    29 
       
    30 
       
    31 // -----------------------------------------------------------------------------
       
    32 // CFeedsRec::CFeedsRec
       
    33 //
       
    34 // Two-phased constructor.
       
    35 // -----------------------------------------------------------------------------
       
    36 //
       
    37 CFeedsRec::CFeedsRec()
       
    38         :CApaDataRecognizerType(KUidMimeFeedsRec, CApaDataRecognizerType::EHigh)
       
    39 	{
       
    40 	iCountDataTypes = KSupportedMimetypes;
       
    41 	}
       
    42 
       
    43 
       
    44 // -----------------------------------------------------------------------------
       
    45 // CFeedsRec::PreferredBufSize
       
    46 //
       
    47 // Returns the preferred buffer size.
       
    48 // -----------------------------------------------------------------------------
       
    49 //
       
    50 TUint CFeedsRec::PreferredBufSize()
       
    51 	{
       
    52 	return 0x100;
       
    53 	}
       
    54 
       
    55 
       
    56 // -----------------------------------------------------------------------------
       
    57 // CFeedsRec::SupportedDataTypeL
       
    58 //
       
    59 // Returns the index'ed supported mime-type.
       
    60 // -----------------------------------------------------------------------------
       
    61 //
       
    62 TDataType CFeedsRec::SupportedDataTypeL(TInt aIndex) const
       
    63 	{
       
    64 	__ASSERT_DEBUG((aIndex >= 0) && (aIndex < KSupportedMimetypes), User::Invariant());
       
    65 
       
    66 	switch (aIndex)
       
    67 		{
       
    68         case 0:
       
    69             return TDataType(KMimeTypeRss);
       
    70 
       
    71         default:
       
    72             return TDataType();
       
    73         }
       
    74 	}
       
    75 
       
    76 
       
    77 // -----------------------------------------------------------------------------
       
    78 // CFeedsRec::DoRecognizeL
       
    79 //
       
    80 // Given the buffer it examines the buffer and sets the inherited
       
    81 // member variable, iConfidence.
       
    82 // -----------------------------------------------------------------------------
       
    83 //
       
    84 void CFeedsRec::DoRecognizeL(const TDesC& aName, const TDesC8& aBuffer)
       
    85     {
       
    86     TInt  confidence;
       
    87 
       
    88     iConfidence = ENotRecognized;
       
    89 
       
    90     // Examine the buffer for RSS.
       
    91     if ((confidence = RecognizeRss(aName, aBuffer)) != ENotRecognized)
       
    92         {
       
    93         iDataType = TDataType(KMimeTypeRss);
       
    94         iConfidence = confidence;
       
    95         }
       
    96 
       
    97     // Examine the buffer for Atom.
       
    98     // TODO: in 3.1
       
    99 
       
   100     // Examine the buffer for Opml 1.0.
       
   101     // TODO: in 3.1
       
   102     }
       
   103 
       
   104 
       
   105 // -----------------------------------------------------------------------------
       
   106 // CFeedsRec::DoRecognizeRss
       
   107 //
       
   108 // Given the buffer it examines the buffer and returns the confidence level that
       
   109 // this document is rss.
       
   110 // -----------------------------------------------------------------------------
       
   111 //
       
   112 TInt CFeedsRec::RecognizeRss(const TDesC& /*aName*/, const TDesC8& aBuffer)
       
   113     {
       
   114     _LIT8(KRss, "<rss");
       
   115     _LIT8(KRdf, "<rdf:RDF");
       
   116     _LIT8(KChannel, "<channel");
       
   117     _LIT8(KRss1, "xmlns=\"http://purl.org/rss/1.0/\"");
       
   118     _LIT8(KXml, "<?xml");
       
   119     _LIT8(KDtd, "//DTD RSS");
       
   120     _LIT8(KOPML,  "<opml");
       
   121 
       
   122     TInt  confidence = ENotRecognized;
       
   123     TInt  count = 0;
       
   124 
       
   125     // TODO: Determine if there are common dot-extensions used for 
       
   126     //       this mime-type.  If so, add code to check for them in aName.
       
   127     //       If found set iConfidence to ECertain.
       
   128 
       
   129     if (aBuffer.FindF(KRss) != KErrNotFound)
       
   130         {
       
   131         count++;
       
   132         }
       
   133     if (aBuffer.FindF(KRdf) != KErrNotFound)
       
   134         {
       
   135         count++;
       
   136         }
       
   137     if (aBuffer.FindF(KChannel) != KErrNotFound)
       
   138         {
       
   139         count++;
       
   140         }
       
   141     if (aBuffer.FindF(KRss1) != KErrNotFound)
       
   142         {
       
   143         count++;
       
   144         }
       
   145     if (aBuffer.FindF(KXml) != KErrNotFound)
       
   146         {
       
   147         if (aBuffer.FindF(KOPML) == KErrNotFound)
       
   148         	{        	
       
   149 	        count++;
       
   150         	}
       
   151         }
       
   152     if (aBuffer.FindF(KDtd) != KErrNotFound)
       
   153         {
       
   154         count++;
       
   155         }
       
   156     
       
   157     if (count == 0)
       
   158         {
       
   159         confidence = ENotRecognized;
       
   160         }
       
   161     else if (count <= 2)
       
   162         {
       
   163         confidence = EProbable;
       
   164         }
       
   165     else
       
   166         {
       
   167         confidence = ECertain;
       
   168         }
       
   169 
       
   170     return confidence;
       
   171     }
       
   172 
       
   173 
       
   174 // Constants
       
   175 const TImplementationProxy ImplementationTable[] = 
       
   176 	{
       
   177     IMPLEMENTATION_PROXY_ENTRY(KFeedsRecImplUIDValue, CFeedsRec::CreateRecognizerL)
       
   178 	};
       
   179 
       
   180 
       
   181 // -----------------------------------------------------------------------------
       
   182 // ImplementationGroupProxy
       
   183 //
       
   184 // Returns the proxy.
       
   185 // -----------------------------------------------------------------------------
       
   186 //
       
   187 EXPORT_C const TImplementationProxy* ImplementationGroupProxy(TInt& aTableCount)
       
   188     {
       
   189     aTableCount = sizeof(ImplementationTable) / sizeof(TImplementationProxy);
       
   190 
       
   191     return ImplementationTable; 
       
   192     }
       
   193 
       
   194 
       
   195 // -----------------------------------------------------------------------------
       
   196 // CFeedsRec::CreateRecognizerL
       
   197 //
       
   198 // Creates an recognizer instance.
       
   199 // -----------------------------------------------------------------------------
       
   200 //
       
   201 CApaDataRecognizerType* CFeedsRec::CreateRecognizerL()
       
   202 	{
       
   203 	return new (ELeave) CFeedsRec();
       
   204 	}
       
   205