iaupdate/IAD/engine/controller/src/iaupdatexmlsubparser.cpp
changeset 0 ba25891c3a9e
equal deleted inserted replaced
-1:000000000000 0:ba25891c3a9e
       
     1 /*
       
     2 * Copyright (c) 2009 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 "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:   ?Description
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 #include <xml/documentparameters.h>
       
    21 #include <xml/taginfo.h>
       
    22 #include <xml/attribute.h>
       
    23 
       
    24 #include "iaupdatexmlsubparser.h"
       
    25 
       
    26 
       
    27 EXPORT_C CIAUpdateXmlSubParser::CIAUpdateXmlSubParser()
       
    28 : CBase(),
       
    29   iAcceptData( ETrue )
       
    30     {
       
    31     
       
    32     }
       
    33 
       
    34     
       
    35 EXPORT_C void CIAUpdateXmlSubParser::ConstructL( const TDesC8& aElementLocalName )
       
    36     {
       
    37     iElementLocalName = aElementLocalName.AllocL();
       
    38     }
       
    39 
       
    40 
       
    41 EXPORT_C CIAUpdateXmlSubParser::~CIAUpdateXmlSubParser()
       
    42     {
       
    43     // Notice, this array also owns the iCurrentSubParser.
       
    44     // So, do not delete it twice. ResetAndDestroy here is enough.
       
    45     iSubParsers.ResetAndDestroy();
       
    46 
       
    47     delete iElementLocalName;
       
    48     }
       
    49 
       
    50 
       
    51 EXPORT_C void CIAUpdateXmlSubParser::OnStartDocumentL( 
       
    52     const Xml::RDocumentParameters& aDocParam, 
       
    53     TInt aErrorCode )
       
    54     {
       
    55     iAcceptData = ETrue;
       
    56     iUnknownElementCounter = 0;
       
    57     iIsElementStarted = EFalse;
       
    58     iIsElementEnded = EFalse;
       
    59     for ( TInt i = 0; i < iSubParsers.Count(); ++i )
       
    60         {
       
    61         iSubParsers[ i ]->OnStartDocumentL( aDocParam, aErrorCode );
       
    62         }
       
    63     }
       
    64                                    
       
    65 EXPORT_C void CIAUpdateXmlSubParser::OnEndDocumentL( TInt /*aErrorCode*/ )
       
    66     {
       
    67     // Nothing to do here.
       
    68     // Child class may add more functionality in its own implementation
       
    69     // if necessary.    
       
    70     }
       
    71 
       
    72 EXPORT_C void CIAUpdateXmlSubParser::OnStartElementL( const Xml::RTagInfo& aElement, 
       
    73                                                       const Xml::RAttributeArray& aAttributes, 
       
    74                                                       TInt aErrorCode )
       
    75     {
       
    76     if ( CurrentSubParser() )
       
    77         {
       
    78         // Because current sub parser has been set, it is its responsibility to handle
       
    79         // the element.
       
    80         CurrentSubParser()->OnStartElementL( aElement, aAttributes, aErrorCode );
       
    81         }
       
    82     else if ( !IsElementStarted()
       
    83               && ElementTagInfoEquals( aElement ) )
       
    84         {
       
    85         // The starting element for this sub parser element was called.
       
    86         // Reset the flags just in case.
       
    87         // And, set the started flag to ETrue;
       
    88         iIsElementStarted = ETrue;
       
    89         iAcceptData = ETrue;
       
    90         iIsElementEnded = EFalse;
       
    91         iUnknownElementCounter = 0;
       
    92         }
       
    93     else if ( IsElementStarted()
       
    94               && AcceptData() )
       
    95         {
       
    96         // First time case has already been handled.
       
    97         // Because flags suggests that the handling of element is
       
    98         // job of the sub parser of this sub parser, try to check 
       
    99         // if we can delegate it to some sub parsers.
       
   100         // Also, set the AcceptData flag accordingly.
       
   101         // If sub parser is found then, then the job is its responsibility and
       
   102         // if sub parser is not found, then some unknown element is at hand.
       
   103         // So, in both cases set the flag to false.
       
   104         iAcceptData = EFalse;
       
   105         
       
   106         // Sub parser has not been set. So, check if we can find a subparser for the job.
       
   107         for ( TInt i = 0; i < iSubParsers.Count(); ++i )
       
   108             {
       
   109             if ( iSubParsers[ i ]->ElementTagInfoEquals( aElement ) )
       
   110                 {
       
   111                 // A correct sub parser was found because element tag matched
       
   112                 // to the given element.
       
   113                 iCurrentSubParser = iSubParsers[ i ];
       
   114                 
       
   115                 // Now, let the sub parser handle the element.
       
   116                 CurrentSubParser()->OnStartElementL( aElement, aAttributes, aErrorCode );
       
   117 
       
   118                 // No need to check sub parsers any more.
       
   119                 // Notice, that in the scheme there will be only one element of a kind but
       
   120                 // in action some elements may contain multiple instances of the same element.
       
   121                 // But, this will be handled inside container element separately.
       
   122                 break;
       
   123                 }
       
   124             }
       
   125 
       
   126         if ( !iCurrentSubParser )
       
   127             {
       
   128             // Element was unknown.
       
   129             ++iUnknownElementCounter;
       
   130             }
       
   131         }
       
   132     else
       
   133         {
       
   134         // If we got some unknown element. 
       
   135         // Set the AcceptData flag to EFalse. 
       
   136         iAcceptData = EFalse;
       
   137         ++iUnknownElementCounter;
       
   138         }
       
   139     }
       
   140     
       
   141 EXPORT_C void CIAUpdateXmlSubParser::OnEndElementL( const Xml::RTagInfo& aElement, 
       
   142                                                     TInt aErrorCode )
       
   143     {
       
   144     if ( CurrentSubParser() )
       
   145         {
       
   146         // Because current sub parser has been set
       
   147         // and it has not finished its job yet,
       
   148         // it is its responsibility to handle the element.
       
   149         CurrentSubParser()->OnEndElementL( aElement, aErrorCode );        
       
   150 
       
   151         if ( CurrentSubParser()->IsElementEnded() )
       
   152             {
       
   153             // Because current sub parser has finished its job.
       
   154             // This parser should not have any sub parser set any more.
       
   155             iCurrentSubParser = NULL;
       
   156             
       
   157             // Because the sub parser has finished it job,
       
   158             // this parser can now accept new sub elements if necessary.
       
   159             // Note, that this does not mean that this element would
       
   160             // finish next.
       
   161             iAcceptData = ETrue;
       
   162             }
       
   163         }
       
   164     else if( UnknownElementCounter() == 0 )
       
   165         {
       
   166         // This sub parser has finished its job.
       
   167         // Set accept flag to its default now because 
       
   168         // the element has been handled.
       
   169         iAcceptData = ETrue;
       
   170         iIsElementStarted = EFalse;
       
   171         iIsElementEnded = ETrue;
       
   172         }
       
   173     else if( UnknownElementCounter() == 1 )
       
   174         {
       
   175         --iUnknownElementCounter;
       
   176         // We have handled all the unknowns now.
       
   177         iAcceptData = ETrue;
       
   178         }
       
   179     else
       
   180         {
       
   181         // We got the unknown element end now for this sub parser.
       
   182         --iUnknownElementCounter;
       
   183         }
       
   184     }
       
   185 
       
   186 EXPORT_C void CIAUpdateXmlSubParser::OnContentL( const TDesC8& aBytes, 
       
   187                                                  TInt aErrorCode )
       
   188     {
       
   189     if ( CurrentSubParser() )
       
   190         {
       
   191         // Because current sub parser has been set, it is its responsibility to handle
       
   192         // the element.
       
   193         CurrentSubParser()->OnContentL( aBytes, aErrorCode );
       
   194         }
       
   195     }
       
   196     
       
   197 EXPORT_C void CIAUpdateXmlSubParser::OnStartPrefixMappingL( const RString& /*aPrefix*/, 
       
   198                                                             const RString& /*aUri*/, 
       
   199                                                             TInt /*aErrorCode*/ )
       
   200     {
       
   201     // Nothing to do here.
       
   202     // Child class may add more functionality in its own implementation
       
   203     // if necessary.    
       
   204     }
       
   205                                    
       
   206 EXPORT_C void CIAUpdateXmlSubParser::OnEndPrefixMappingL( const RString& /*aPrefix*/, 
       
   207                                                           TInt /*aErrorCode*/ )
       
   208     {
       
   209     // Nothing to do here.
       
   210     // Child class may add more functionality in its own implementation
       
   211     // if necessary.    
       
   212     }
       
   213                                    
       
   214 EXPORT_C void CIAUpdateXmlSubParser::OnIgnorableWhiteSpaceL( const TDesC8& /*aBytes*/, 
       
   215                                                              TInt /*aErrorCode*/ )
       
   216     {
       
   217     // Nothing to do here.
       
   218     // Child class may add more functionality in its own implementation
       
   219     // if necessary.    
       
   220     }
       
   221 
       
   222 EXPORT_C void CIAUpdateXmlSubParser::OnSkippedEntityL( const RString& /*aName*/, 
       
   223                                                        TInt /*aErrorCode*/ )
       
   224     {
       
   225     // Nothing to do here.
       
   226     // Child class may add more functionality in its own implementation
       
   227     // if necessary.    
       
   228     }
       
   229                                    
       
   230 EXPORT_C void CIAUpdateXmlSubParser::OnProcessingInstructionL( const TDesC8& /*aTarget*/, 
       
   231                                                                const TDesC8& /*aData*/, 
       
   232                                                                TInt /*aErrorCode*/ )
       
   233     {
       
   234     // Nothing to do here.
       
   235     // Child class may add more functionality in its own implementation
       
   236     // if necessary.    
       
   237     }
       
   238                                    
       
   239 EXPORT_C void CIAUpdateXmlSubParser::OnError( TInt /*aErrorCode*/ )
       
   240     {
       
   241     // Nothing to do here.
       
   242     // Child class may add more functionality in its own implementation
       
   243     // if necessary.    
       
   244     }
       
   245                                    
       
   246 EXPORT_C TAny* CIAUpdateXmlSubParser::GetExtendedInterface( const TInt32 /*aUid*/ )
       
   247     {
       
   248     // Nothing to do here.
       
   249     // Child class may add more functionality in its own implementation
       
   250     // if necessary.    
       
   251     return NULL;
       
   252     }
       
   253 
       
   254 
       
   255 EXPORT_C const TDesC8& CIAUpdateXmlSubParser::LocalName() const
       
   256     {
       
   257     return *iElementLocalName;
       
   258     }
       
   259     
       
   260     
       
   261 EXPORT_C CIAUpdateXmlSubParser* CIAUpdateXmlSubParser::CurrentSubParser() const
       
   262     {
       
   263     return iCurrentSubParser;    
       
   264     }
       
   265 
       
   266 
       
   267 EXPORT_C RPointerArray< CIAUpdateXmlSubParser >& CIAUpdateXmlSubParser::SubParsers()
       
   268     {
       
   269     return iSubParsers;
       
   270     }
       
   271 
       
   272 
       
   273 EXPORT_C TBool CIAUpdateXmlSubParser::ElementTagInfoEquals( const Xml::RTagInfo& aElement ) const
       
   274     {
       
   275     // Get the element local name from the given parameter.
       
   276     const TDesC8& element( aElement.LocalName().DesC() );
       
   277     
       
   278     // Now, chek if the given element has the same name with the element that this
       
   279     // parser is created for. Notice, that the element names are specified as case sensitive.
       
   280     // But, element values are not specified as case sensitive. 
       
   281     if ( element == LocalName() )
       
   282         {
       
   283         // The given element tag matched with the local name of this class object.
       
   284         return ETrue;
       
   285         }
       
   286     else
       
   287         {
       
   288         // The local names did not match.
       
   289         return EFalse;
       
   290         }
       
   291     }
       
   292 
       
   293 
       
   294 EXPORT_C TBool CIAUpdateXmlSubParser::AcceptData() const
       
   295     {
       
   296     return iAcceptData;
       
   297     }
       
   298 
       
   299 
       
   300 EXPORT_C TBool CIAUpdateXmlSubParser::IsElementStarted() const
       
   301     {
       
   302     return iIsElementStarted;
       
   303     }
       
   304 
       
   305 
       
   306 EXPORT_C TBool CIAUpdateXmlSubParser::IsElementEnded() const
       
   307     {
       
   308     return iIsElementEnded;
       
   309     }
       
   310 
       
   311 
       
   312 EXPORT_C TInt CIAUpdateXmlSubParser::UnknownElementCounter() const
       
   313     {
       
   314     return iUnknownElementCounter;
       
   315     }
       
   316