videofeeds/mrssplugin/inc/CIptv3XmlContentHandler.h
branchRCL_3
changeset 23 befca0ec475f
parent 0 96612d01cf9f
equal deleted inserted replaced
22:839377eedc2b 23:befca0ec475f
       
     1 /*
       
     2 * Copyright (c) 2007-2008 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:    XML Parser handler*
       
    15 */
       
    16 
       
    17 
       
    18 
       
    19 
       
    20 #ifndef CIPTV3XMLCONTENTHANDLER_H
       
    21 #define CIPTV3XMLCONTENTHANDLER_H
       
    22 
       
    23 #include <e32std.h>
       
    24 #include <xml/contenthandler.h>
       
    25 
       
    26 class MIptvEpgVodCallback;
       
    27 class CIptvEpgCategory;
       
    28 class CIptvEpgContent;
       
    29 class CIptvRssPlugin;
       
    30 class CIptvMediaContent;
       
    31 class CIptvTerminalVideoSupport;
       
    32 
       
    33 // This is for MContentHandler XML parser.
       
    34 using namespace Xml;
       
    35 
       
    36 /**
       
    37  *  XML Parser handler
       
    38  *
       
    39  *  Implements parser callbacks and support functions.
       
    40  *  Stores interpreted XML content using given callback (SetVodCallback).
       
    41  *
       
    42  *  @lib IptvRssPlugin.dll
       
    43  *  @since S60 v3.1 rel3
       
    44  */
       
    45 class CIptvXmlContentHandler : public CBase,
       
    46                                public MContentHandler
       
    47     {
       
    48 
       
    49 public:
       
    50 
       
    51     /**
       
    52      * RSS Parser states.
       
    53      */
       
    54     enum TParserState
       
    55         {
       
    56         EIptvRssIdleState,
       
    57         EIptvRssState,
       
    58         EIptvRssChannelState,
       
    59         EIptvRssChannelDescriptionState,
       
    60         EIptvRssChannelLinkState,
       
    61         EIptvRssChannelTitleState,
       
    62         EIptvRssChannelImageState,
       
    63         EIptvRssChannelImageUrlState,
       
    64         EIptvRssItemState,
       
    65         EIptvRssItemDescriptionState,
       
    66         EIptvRssItemLinkState,
       
    67         EIptvRssItemTitleState,
       
    68         EIptvRssItemGuidState,
       
    69         EIptvRssItemEnclosureState,
       
    70         EIptvRssItemPubDate,
       
    71         EIptvRssItemMediaGroupState,
       
    72         EIptvRssItemMediaContentState,
       
    73         EIptvRssItemMediaThumbnailState,
       
    74         EIptvRssItemAuthorState,
       
    75         EIptvRssItemMediaCopyrightState,
       
    76         EIptvRssItemRatingState,
       
    77         EIptvRssItemMediaCategoryState,
       
    78         EIptvRssItemMediaCategoryEnclosureState
       
    79         };
       
    80 
       
    81     /**
       
    82      * Parent rating interpretation scheme.
       
    83      */
       
    84     enum TMediaRatingScheme
       
    85         {
       
    86         EMediaRatingNotSet,
       
    87         EMediaRatingSimple,
       
    88         EMediaRatingNum,
       
    89         EMediaRatingIcra,
       
    90         EMediaRatingMpaa,
       
    91         EMediaRatingVChip
       
    92         };
       
    93 
       
    94     /**
       
    95      * Control interpretation of categories and channels.
       
    96      */
       
    97     enum TCategoryState
       
    98         {
       
    99         ENoChannel,             // Initial value
       
   100         EChannelNoItem,         // Inside first channel, no items found yet
       
   101         EItemsWithCategory,     // Inside first channel, all items found
       
   102                                 //   contains a category
       
   103         EItemsNoCategory,       // Inside first channel, all items found do
       
   104                                 //   not contain a category
       
   105         EItemsBoth,             // Inside channel, both itmes with and
       
   106                                 //   without category found
       
   107         ESkipFurtherChannels,   // A channel with categories processed.
       
   108                                 //   No more channels will be accepted.
       
   109         ESkipFurtherCategories  // A channel without categories processed.
       
   110                                 //   No categories inside further channels
       
   111                                 //   will be accepted.
       
   112         };
       
   113 
       
   114     /**
       
   115      * Category state transition events.
       
   116      */
       
   117     enum TCategoryStateEvent
       
   118         {
       
   119         EChannelFound,
       
   120         EChannelCompleted,
       
   121         EItemFound,
       
   122         ECategoryFound,
       
   123         EItemCompleted
       
   124         };
       
   125 
       
   126     static CIptvXmlContentHandler* NewL(CIptvRssPlugin& aPlugin);
       
   127 
       
   128     ~CIptvXmlContentHandler();
       
   129 
       
   130     /**
       
   131      * Set callback for storing XML parse results.
       
   132      *
       
   133      * @param aVodCallback Pointer to callback interface.
       
   134      */
       
   135     void SetVodCallback( MIptvEpgVodCallback* aVodCallback );
       
   136 
       
   137 // From base class MContentHandler
       
   138 
       
   139     /**
       
   140      * Callback to indicate the start of the document.
       
   141      *
       
   142      * @param aDocParam     Specifies the various parameters of the document.
       
   143      * @param aErrorCode    Parser error code.
       
   144      */
       
   145     void OnStartDocumentL(
       
   146         const RDocumentParameters& aDocParam,
       
   147         TInt aErrorCode );
       
   148 
       
   149     /**
       
   150      * Callback to indicate the end of the document.
       
   151      *
       
   152      * @param aErrorCode    Parser error code.
       
   153      */
       
   154     void OnEndDocumentL( TInt aErrorCode );
       
   155 
       
   156     /**
       
   157      * Callback to indicate an element parsing start.
       
   158      *
       
   159      * @param aElement      Handle to the element's details.
       
   160      * @param aAttributes   Contains the attributes for the element.
       
   161      * @param aErrorCode    Parser error code.
       
   162      */
       
   163     void OnStartElementL( const RTagInfo& aElement,
       
   164                           const RAttributeArray& aAttributes,
       
   165                           TInt aErrorCode );
       
   166 
       
   167     /**
       
   168      * Callback to indicate the element parsing completion.
       
   169      *
       
   170      * @param aElement      Handle to the element's details.
       
   171      * @param aErrorCode    Parser error code.
       
   172      */
       
   173     void OnEndElementL( const RTagInfo& aElement, TInt aErrorCode );
       
   174 
       
   175     /**
       
   176      * Callback that sends the content of the element.
       
   177      * Not all the content may be returned in one go. The data may be sent in
       
   178      * chunks. When an OnEndElementL is received this means there is no more
       
   179      * content to be sent.
       
   180      *
       
   181      * @param aBytes        Raw content data for the element.
       
   182      *                      The client is responsible for converting the data
       
   183      *                      to the required character set if necessary.
       
   184      *                      In some instances the content may be binary and
       
   185      *                      must not be converted.
       
   186      * @param aErrorCode    Parser error code.
       
   187      */
       
   188     void OnContentL( const TDesC8& aBytes, TInt aErrorCode );
       
   189 
       
   190     /**
       
   191      * Notification of the beginning of the scope of a prefix-URI Namespace
       
   192      * mapping.
       
   193      * This method is always called before the corresponding OnStartElementL
       
   194      * method.
       
   195      *
       
   196      * @param aPrefix       Namespace prefix being declared.
       
   197      * @param aUri          Namespace URI the prefix is mapped to.
       
   198      * @param aErrorCode    Parser error code.
       
   199      */
       
   200     void OnStartPrefixMappingL( const RString& aPrefix,
       
   201                                 const RString& aUri,
       
   202                                 TInt aErrorCode );
       
   203 
       
   204     /**
       
   205      * Notification of the end of the scope of a prefix-URI mapping.
       
   206      * This method is called after the corresponding DoEndElementL method.
       
   207      *
       
   208      * @param aPrefix       Namespace prefix that was mapped.
       
   209      * @param aErrorCode    Parser error code.
       
   210      */
       
   211     void OnEndPrefixMappingL( const RString& aPrefix, TInt aErrorCode );
       
   212 
       
   213     /**
       
   214      * Notification of ignorable whitespace in element content.
       
   215      *
       
   216      * @param aBytes        Ignored bytes from the document being parsed.
       
   217      * @param aErrorCode    Parser error code.
       
   218      */
       
   219     void OnIgnorableWhiteSpaceL( const TDesC8& aBytes, TInt aErrorCode );
       
   220 
       
   221     /**
       
   222      * Notification of a skipped entity. If the parser encounters an
       
   223      * external entity it does not need to expand it - it can return the
       
   224      * entity as aName for the client to deal with.
       
   225      *
       
   226      * @param aName         Name of the skipped entity.
       
   227      * @param aErrorCode    Parser error code.
       
   228      */
       
   229     void OnSkippedEntityL( const RString& aName, TInt aErrorCode );
       
   230 
       
   231     /**
       
   232      * Notification of a processing instruction.
       
   233      *
       
   234      * @param aTarget       Processing instruction target.
       
   235      * @param aData         Processing instruction data. If empty none was
       
   236      *                      supplied.
       
   237      * @param aErrorCode    Parser error code.
       
   238      */
       
   239     void OnProcessingInstructionL( const TDesC8& aTarget,
       
   240                                    const TDesC8& aData,
       
   241                                    TInt aErrorCode );
       
   242 
       
   243     /**
       
   244      * Notification of XML file parsing is failure.
       
   245      *
       
   246      * @param aErrorCode    Parser error code.
       
   247      */
       
   248     void OnError( TInt aErrorCode );
       
   249 
       
   250     /**
       
   251      * Obtains the interface matching the specified uid.
       
   252      *
       
   253      * @param aUid          Uid identifying the required interface.
       
   254      * @return              0 if no interface matching the uid is found.
       
   255      *                      Otherwise, the this pointer cast to that
       
   256      *                      interface.
       
   257      */
       
   258     TAny* GetExtendedInterface( const TInt32 aUid );
       
   259 
       
   260 private:
       
   261 
       
   262     CIptvXmlContentHandler( CIptvRssPlugin& aPlugin );
       
   263 
       
   264     void ConstructL();
       
   265 
       
   266     /**
       
   267      * Handles item copyright value.
       
   268      */
       
   269     void CompleteCopyright();
       
   270 
       
   271     /**
       
   272      * Handles parent rating value.
       
   273      */
       
   274     void CompleteRating();
       
   275 
       
   276     /**
       
   277      * Handles item category value.
       
   278      */
       
   279     void CompleteCategoryL();
       
   280 
       
   281     /**
       
   282      * Handles item category value.
       
   283      * @param aName Name canditate for this category.
       
   284      */
       
   285     void CompleteCategoryL( const HBufC* aName );
       
   286 
       
   287     /**
       
   288      * Handles item author value.
       
   289      */
       
   290     void CompleteAuthor();
       
   291 
       
   292     /**
       
   293      * Handles item and category description value.
       
   294      */
       
   295     void CompleteDescription();
       
   296 
       
   297     /**
       
   298      * Handles item and category title value.
       
   299      */
       
   300     void CompleteTitle();
       
   301 
       
   302     /**
       
   303      * Handles item url link value.
       
   304      */
       
   305     void CompleteLink();
       
   306 
       
   307     /**
       
   308      * Handles item publish time value.
       
   309      */
       
   310     void CompletePubDate();
       
   311 
       
   312     /**
       
   313      * Handles item guid value.
       
   314      */
       
   315     void CompleteGuid();
       
   316 
       
   317     /**
       
   318      * Handles element attributes.
       
   319      *
       
   320      * @param aAttributeList  Parses element attributes..
       
   321      */
       
   322     void HandleEnclosureL(
       
   323         const RAttributeArray& aAttributeList );
       
   324 
       
   325     /**
       
   326      * Create a new category descriptor.
       
   327      *
       
   328      * @return              New empty category descriptor.
       
   329      */
       
   330     CIptvEpgCategory* CreateCategoryL() const;
       
   331 
       
   332     /**
       
   333      * Set a category for current item.
       
   334      * When category has been used for some other item it already exists and
       
   335      * is restored, Otherwise a new one is created and a key value given.
       
   336      *
       
   337      * @param aName         Name canditate to new category.
       
   338      */
       
   339     void SetItemCategoryL( const HBufC* aName );
       
   340 
       
   341     /**
       
   342      * Set channel as default category for current Item.
       
   343      * When channel category has already been used, restore it,
       
   344      * Otherwise save it and give a key value.
       
   345      */
       
   346     void SetChannelCategoryL();
       
   347 
       
   348     /**
       
   349      * Stores all categories used by current itam to database.
       
   350      */
       
   351     void AddCategories();
       
   352 
       
   353     /**
       
   354      * Add current content to dabase and link it to categories.
       
   355      */
       
   356     void AddContentL();
       
   357 
       
   358     /**
       
   359      * Create a new itme content descriptor.
       
   360      */
       
   361     void CreateContentL();
       
   362 
       
   363     /**
       
   364      * Adjust download type according to Mime type.
       
   365      *
       
   366      * @param aContent      Item descriptor.
       
   367      */
       
   368     void SetDownloadTypeFromMimeType(
       
   369         CIptvMediaContent& aContent ) const;
       
   370 
       
   371     /**
       
   372      * Item containing thumbnails is added to download queue.
       
   373      *
       
   374      * @param contentKey    Item identifier in database.
       
   375      * @param aThumbnailUrl Url to download thumbnail images.
       
   376      */
       
   377     void AddContentToDlQueueL(
       
   378         TUint32 contentKey,
       
   379         const TDesC& aThumbnailUrl );
       
   380 
       
   381     /**
       
   382      * Service thumbnail is added to download queue.
       
   383      *
       
   384      * @param aThumbnailUrl Url to download thumbnail images.
       
   385      */
       
   386     void AddServiceToDlQueueL(
       
   387         const TDesC& aThumbnailUrl );
       
   388 
       
   389     /**
       
   390      * Priorize item by type.
       
   391      */
       
   392     void PriorizeL();
       
   393 
       
   394     /**
       
   395      * Advances category state according to given event and decides whether
       
   396      * current object should be processed.
       
   397      *
       
   398      * @param aEvent        State transition event.
       
   399      * @return              Process or skip current object.
       
   400      */
       
   401     TBool SetCategoryState( TCategoryStateEvent aEvent );
       
   402 
       
   403 private: // Data members
       
   404 
       
   405     /**
       
   406      * Calling class.
       
   407      */
       
   408     CIptvRssPlugin& iPlugin;
       
   409 
       
   410     /**
       
   411      * Callback for storing XML parse results.
       
   412      * Not own.
       
   413      */
       
   414     MIptvEpgVodCallback* iVodCallback;
       
   415 
       
   416     /**
       
   417      * Descriptor of current channel.
       
   418      * Own.
       
   419      */
       
   420     CIptvEpgCategory* iChannelCategory;
       
   421 
       
   422     /**
       
   423      * Category index key of current channel descriptor.
       
   424      * Value 0 means that channel has not been associated to any item
       
   425      * as category.
       
   426      */
       
   427     TUint32 iChannelCategoryKey;
       
   428 
       
   429     /**
       
   430      * Category index keys for current content.
       
   431      */
       
   432     RArray<TUint32> iCurrentCategoryKeys;
       
   433 
       
   434     /**
       
   435      * Descriptor of current item content.
       
   436      * Own.
       
   437      */
       
   438     CIptvEpgContent* iContent;
       
   439 
       
   440     /**
       
   441      * Xml parsing state.
       
   442      */
       
   443     TParserState iState;
       
   444 
       
   445     /**
       
   446      * Current xml content.
       
   447      * Own.
       
   448      */
       
   449     HBufC* iBuffer;
       
   450 
       
   451     /**
       
   452      * Indicates that we have accepted a channel thumbnail image as
       
   453      * service image to be downloaded.
       
   454      */
       
   455     TBool iServiceThumbnailAdded;
       
   456 
       
   457     /**
       
   458      * Indicates that we have found rss content from current feed.
       
   459      */
       
   460     TBool iRSSContentFound;
       
   461 
       
   462     /**
       
   463      * Total number of categories handled from xml.
       
   464      */
       
   465     TInt iCategoryCount;
       
   466 
       
   467     /**
       
   468      * Total number of content items handled from xml.
       
   469      */
       
   470     TInt iContentCount;
       
   471 
       
   472     /**
       
   473      * Media group descriptor found and we are prosessing group.
       
   474      */
       
   475     TBool iMediaGroup;
       
   476 
       
   477     /**
       
   478      * Current element name has media prefix.
       
   479      */
       
   480     TBool iMediaPrefix;
       
   481 
       
   482     /**
       
   483      * Description has been set with Media group or prefix value.
       
   484      * This shall not be overwritten by other values.
       
   485      */
       
   486     TBool iMediaDescriptionFixed;
       
   487 
       
   488     /**
       
   489      * Title has been set with Media group or prefix value.
       
   490      * This shall not be overwritten by other values.
       
   491      */
       
   492     TBool iMediaTitleFixed;
       
   493 
       
   494     /**
       
   495      * Rating has been set with Media group or prefix value.
       
   496      * This shall not be overwritten by other values.
       
   497      */
       
   498     TBool iMediaRatingFixed;
       
   499 
       
   500     /**
       
   501      * Copyrigth has been set with Media group or prefix value.
       
   502      * This shall not be overwritten by other values.
       
   503      */
       
   504     TBool iMediaCopyrightFixed;
       
   505 
       
   506     /**
       
   507      * Rating has been set with Media group or prefix value.
       
   508      * This shall not be overwritten by other values.
       
   509      */
       
   510     TBool iMediaThumbnailFixed;
       
   511 
       
   512     /**
       
   513      * Yahoo service is used.
       
   514      */
       
   515     TBool iYahoo;
       
   516 
       
   517     /**
       
   518      * Attribute set of current item.
       
   519      * Own.
       
   520      */
       
   521     RPointerArray<CIptvMediaContent> iMediaContents;
       
   522 
       
   523     /**
       
   524      * Priorized content set.
       
   525      * Not own.
       
   526      */
       
   527     RPointerArray<CIptvMediaContent> iMediaContentSet;
       
   528 
       
   529     /**
       
   530      * CIptvTerminalVideoSupport.
       
   531      * Own
       
   532      */
       
   533     CIptvTerminalVideoSupport* iTerminalVideoSupport;
       
   534 
       
   535     /**
       
   536      * Scheme to interpret current parent rating descriptor.
       
   537      */
       
   538     TMediaRatingScheme iMediaRatingScheme;
       
   539 
       
   540     /**
       
   541      * State to control handling of channel and item specific categories.
       
   542      */
       
   543     TCategoryState iCategoryState;
       
   544 
       
   545     /**
       
   546      * There is a specific category descriptor in current item.
       
   547      */
       
   548     TBool iCategoryFound;
       
   549 
       
   550     /**
       
   551      * Table to hold all valid categories.
       
   552      * Own.
       
   553      */
       
   554     RPointerArray<CIptvEpgCategory> iCategoryTable;
       
   555 
       
   556     };
       
   557 
       
   558 #endif // CIPTV3XMLCONTENTHANDLER_H