backupandrestore/backupengine/src/sbeparserproxy.cpp
changeset 0 d0791faffa3f
equal deleted inserted replaced
-1:000000000000 0:d0791faffa3f
       
     1 // Copyright (c) 2006-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 // Implementation of CBackupRegistrationParser
       
    15 // 
       
    16 //
       
    17 
       
    18 /**
       
    19  @file
       
    20 */
       
    21 #include "sbeparserproxy.h"
       
    22 
       
    23 // System includes
       
    24 #include <charconv.h>
       
    25 
       
    26 // User includes
       
    27 #include "sbeparserdefs.h"
       
    28 #include "sblog.h"
       
    29 
       
    30 namespace conn
       
    31 	{
       
    32 	CSBEParserProxy::CSBEParserProxy( RFs& aFsSession )
       
    33         : iFsSession( aFsSession )
       
    34 	/** Standard C++ constructor
       
    35 
       
    36 	@param aSID secure id of data owner
       
    37 	@param apDataOwnerManager data owner manager to access resources
       
    38 	*/
       
    39 		{
       
    40 		}
       
    41 
       
    42 	CSBEParserProxy::~CSBEParserProxy()
       
    43 	/** Standard C++ destructor
       
    44 	*/
       
    45 		{
       
    46 		delete iConverter;
       
    47 		delete iParser;
       
    48 		}
       
    49 
       
    50 	void CSBEParserProxy::ConstructL()
       
    51 	/** Symbian 2nd stage constructor */
       
    52 		{
       
    53 		iParser = CParser::NewL(KMimeType, *this);
       
    54 
       
    55 		// We only convert from UTF-8 to UTF-16
       
    56 		iConverter = CCnvCharacterSetConverter::NewL();
       
    57 		if  ( iConverter->PrepareToConvertToOrFromL( KCharacterSetIdentifierUtf8, iFsSession ) == CCnvCharacterSetConverter::ENotAvailable )
       
    58 			{
       
    59 			User::Leave(KErrNotFound);
       
    60 			}
       
    61 		}
       
    62 		
       
    63 	CSBEParserProxy* CSBEParserProxy::NewL( RFs& aFsSession )
       
    64 	/** Symbian OS static constructor
       
    65 
       
    66 	@param aSID secure id of data owner
       
    67 	@param apDataOwnerManager data owner manager to access resources
       
    68 	@return a CBackupRegistrationParser object
       
    69 	*/
       
    70 		{
       
    71 		CSBEParserProxy* self = new(ELeave) CSBEParserProxy( aFsSession );
       
    72 		CleanupStack::PushL(self);
       
    73 		self->ConstructL();
       
    74 		CleanupStack::Pop(self);
       
    75 
       
    76 		return self;
       
    77 		}
       
    78 
       
    79 	void CSBEParserProxy::ParseL( const TDesC& aFileName, MContentHandler& aObserver )
       
    80 	/** Parsing API */
       
    81         {
       
    82         // Store transient observer (the entity that we will route callbacks to)
       
    83         iTransientParsingError = KErrNone;
       
    84         iTransientObserver = &aObserver;
       
    85 
       
    86         // Do XML parsing of the specified file. Callbacks will occur to client via the XML
       
    87         // callback API.
       
    88 		Xml::ParseL( *iParser, iFsSession, aFileName );
       
    89 
       
    90         // Handle any errors received during callbacks
       
    91 		User::LeaveIfError( iTransientParsingError );
       
    92         }
       
    93 
       
    94 	TInt CSBEParserProxy::ConvertToUnicodeL( TDes16& aUnicode, const TDesC8& aForeign )
       
    95         {
       
    96         const TInt error = iConverter->ConvertToUnicode( aUnicode, aForeign, iConverterState );
       
    97 
       
    98 #ifdef SBE_LOGGING_ENABLED
       
    99         if  ( error != KErrNone )
       
   100             {
       
   101             HBufC* copy = HBufC::NewL( aForeign.Length() * 2 );
       
   102             copy->Des().Copy( aForeign );
       
   103 			__LOG2("CSBEParserProxy::ConvertToUnicode() - error: %d when converting: %S", error, copy );
       
   104             delete copy;
       
   105             }
       
   106 #endif
       
   107 
       
   108         return error;
       
   109         }
       
   110 		
       
   111 	//	
       
   112 	//  MContentHandler Implementaion //
       
   113 	//
       
   114 
       
   115 	/** MContentHandler::OnStartDocumentL()
       
   116 	*/
       
   117 	void CSBEParserProxy::OnStartDocumentL(const RDocumentParameters& aDocParam, TInt aErrorCode)
       
   118 		{
       
   119 		if (aErrorCode != KErrNone)
       
   120 			{
       
   121 			__LOG1("CBackupRegistrationParser::OnStartDocumentL() - error = %d", aErrorCode);
       
   122 			User::Leave(aErrorCode);
       
   123 			}
       
   124 
       
   125         iTransientObserver->OnStartDocumentL( aDocParam, aErrorCode );
       
   126 		}
       
   127 		
       
   128 	/** MContentHandler::OnEndDocumentL()
       
   129 	*/
       
   130 	void CSBEParserProxy::OnEndDocumentL(TInt aErrorCode)
       
   131 		{
       
   132 		if (aErrorCode != KErrNone)
       
   133 			{
       
   134 			// just to satifsy UREL compiler
       
   135 			(void) aErrorCode;
       
   136 			__LOG1("CBackupRegistrationParser::OnEndDocumentL() - error = %d", aErrorCode);
       
   137 			}
       
   138 
       
   139         iTransientObserver->OnEndDocumentL( aErrorCode );
       
   140 		}
       
   141 		
       
   142 	/** MContentHandler::OnStartElementL()
       
   143 
       
   144 	@leave KErrUnknown an unknown element
       
   145 	*/		
       
   146 	void CSBEParserProxy::OnStartElementL(const RTagInfo& aElement, const RAttributeArray& aAttributes, TInt aErrorCode)
       
   147 		{
       
   148 		if (aErrorCode != KErrNone)
       
   149 			{
       
   150 			__LOG1("CBackupRegistrationParser::OnStartElementL() - error = %d", aErrorCode);
       
   151 			User::LeaveIfError(aErrorCode);
       
   152 			}
       
   153 
       
   154         iTransientObserver->OnStartElementL( aElement, aAttributes, aErrorCode );
       
   155 		}
       
   156 
       
   157 	/** MContentHandler::OnEndElementL()
       
   158 	*/
       
   159 	void CSBEParserProxy::OnEndElementL(const RTagInfo& aElement, TInt aErrorCode)
       
   160 		{
       
   161 		if (aErrorCode != KErrNone)
       
   162 			{
       
   163 			__LOG1("CBackupRegistrationParser::OnEndElementL() - error = %d", aErrorCode);
       
   164 			User::Leave(aErrorCode);
       
   165 			}
       
   166 
       
   167         iTransientObserver->OnEndElementL( aElement, aErrorCode );
       
   168 		}
       
   169 
       
   170 	/** MContentHandler::OnContentL()
       
   171 	*/
       
   172 	void CSBEParserProxy::OnContentL(const TDesC8& aBytes, TInt aErrorCode)
       
   173 		{
       
   174         iTransientObserver->OnContentL( aBytes, aErrorCode );
       
   175 		}
       
   176 
       
   177 	/** MContentHandler::OnStartPrefixMappingL()
       
   178 	*/
       
   179 	void CSBEParserProxy::OnStartPrefixMappingL(const RString& aPrefix, const RString& aUri, TInt aErrorCode)
       
   180 		{
       
   181         iTransientObserver->OnStartPrefixMappingL( aPrefix, aUri, aErrorCode );
       
   182 		}
       
   183 
       
   184 	/** MContentHandler::OnEndPrefixMappingL()
       
   185 	*/
       
   186 	void CSBEParserProxy::OnEndPrefixMappingL(const RString& aPrefix, TInt aErrorCode)
       
   187 		{
       
   188         iTransientObserver->OnEndPrefixMappingL( aPrefix, aErrorCode );
       
   189 		}
       
   190 
       
   191 	/** MContentHandler::OnIgnorableWhiteSpaceL()
       
   192 	*/
       
   193 	void CSBEParserProxy::OnIgnorableWhiteSpaceL(const TDesC8& aBytes, TInt aErrorCode)
       
   194 		{
       
   195         iTransientObserver->OnIgnorableWhiteSpaceL( aBytes, aErrorCode );
       
   196 		}
       
   197 
       
   198 	/** MContentHandler::OnSkippedEntityL()
       
   199 	*/
       
   200 	void CSBEParserProxy::OnSkippedEntityL(const RString& aName, TInt aErrorCode)
       
   201 		{
       
   202         iTransientObserver->OnSkippedEntityL( aName, aErrorCode );
       
   203 		}
       
   204 
       
   205 	/** MContentHandler::OnProcessingInstructionL()
       
   206 	*/
       
   207 	void CSBEParserProxy::OnProcessingInstructionL(const TDesC8& aTarget, const TDesC8& aData, TInt aErrorCode)
       
   208 		{
       
   209         iTransientObserver->OnProcessingInstructionL( aTarget, aData, aErrorCode );
       
   210 		}
       
   211 
       
   212 	/** MContentHandler::OnError()
       
   213 
       
   214 	@leave aErrorCode
       
   215 	*/
       
   216 	void CSBEParserProxy::OnError(TInt aErrorCode)
       
   217 		{
       
   218 		__LOG1("CBackupRegistrationParser::OnError() - error = %d", aErrorCode);
       
   219 		iTransientParsingError = aErrorCode;
       
   220         iTransientObserver->OnError( aErrorCode );
       
   221 		}
       
   222 
       
   223 	/** MContentHandler::OnEndPrefixMappingL()
       
   224 	*/
       
   225 	TAny* CSBEParserProxy::GetExtendedInterface(const TInt32 aUid)
       
   226 		{
       
   227         return iTransientObserver->GetExtendedInterface( aUid );
       
   228 		}
       
   229 
       
   230     } // namespace conn