examples/Messaging/BIOMessageMgr/Src/BIOParser.cpp

00001 // Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies).
00002 // All rights reserved.
00003 // This component and the accompanying materials are made available
00004 // under the terms of "Eclipse Public License v1.0"
00005 // which accompanies this distribution, and is available
00006 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
00007 //
00008 // Initial Contributors:
00009 // Nokia Corporation - initial contribution.
00010 //
00011 // Contributors:
00012 //
00013 // Description:
00014 //
00015 
00016 #include "BIOParser.h"
00017 
00018 
00019 CBioParser::CBioParser(CMsvEntry* aEntry)
00020                 :iMsvEntry(aEntry)
00021         {
00022 
00023         }
00024 
00025 CBioParser::~CBioParser()
00026         {
00027         delete iMessageBody;
00028         if(iRegisteredParserDll)
00029                 {
00030                 delete iRegisteredParserDll;
00031                 iRegisteredParserDll = NULL;
00032                 }
00033         iFs.Close( );
00034         delete iBioDb;
00035         }
00036 
00037 CBioParser* CBioParser::NewL(CMsvEntry* aEntry)
00038         {
00039         CBioParser* self= new (ELeave) CBioParser(aEntry);
00040         CleanupStack::PushL(self);
00041         self->ConstructL();
00042         CleanupStack::Pop();
00043         return self;
00044         }
00045 
00046 void CBioParser::ConstructL()
00047         {
00048         iFs.Connect();
00049         iFs.SetSessionPath(KBifDir);
00050         iBioDb = CBIODatabase::NewL(iFs);
00051 
00052         }
00053 
00054 CBIOExampleParser* CBioParser::CreateParserL()
00055         {
00056         TUid messageUid;
00057         messageUid.iUid = iMsvEntry->Entry().iBioType;
00058 
00059         TFileName parserDllName(iBioDb->GetBioParserNameL(messageUid));
00060 
00061         if (iRegisteredParserDll)
00062                 {
00063                 delete iRegisteredParserDll;
00064                 iRegisteredParserDll = NULL;
00065                 }
00066 
00067     iRegisteredParserDll = CRegisteredParserDll::NewL(parserDllName);
00068 
00069     RLibrary parserlibrary;
00070     User::LeaveIfError(iRegisteredParserDll->GetLibrary(iFs, parserlibrary));
00071 
00072     typedef CBIOExampleParser* (*NewParserL)(CRegisteredParserDll& aRegisteredParserDll, CMsvEntry& aEntry, RFs& aFs);
00073 
00074     TInt entrypointordinalnumber=1;
00075     TLibraryFunction libFunc=parserlibrary.Lookup(entrypointordinalnumber);
00076     if (libFunc==NULL)
00077         User::Leave(KErrBadLibraryEntryPoint);
00078     NewParserL pFunc=(NewParserL) libFunc;
00079     TInt refcount=iRegisteredParserDll->DllRefCount();
00080     CBIOExampleParser* parser=NULL;
00081     TRAPD(ret,parser=((*pFunc)(*iRegisteredParserDll, *iMsvEntry, iFs)));
00082     if ((ret!=KErrNone) && (iRegisteredParserDll->DllRefCount()==refcount))
00083         iRegisteredParserDll->ReleaseLibrary();
00084 
00085         User::LeaveIfError(ret);
00086 
00087     return parser;
00088         }
00089 
00090 void CBioParser::ParserL()
00091         {
00092         ExtractMessageBodyL();
00093 
00094         CMsvOperationWait* wait = CMsvOperationWait::NewLC();
00095         wait->iStatus = KRequestPending;
00096         wait->Start();
00097 
00098         CBIOExampleParser* parser = CreateParserL();
00099         // Parsing the message
00100         parser->ParseL(wait->iStatus, *iMessageBody);
00101         parser->Cancel();
00102         delete parser;
00103 
00104 
00105         CleanupStack::PopAndDestroy();  // wait
00106         }
00107 
00111 void CBioParser::ExtractMessageBodyL()
00112         {
00113 
00114         CParaFormatLayer* paraFormatLayer = CParaFormatLayer::NewL();
00115     CleanupStack::PushL(paraFormatLayer);
00116     CCharFormatLayer* charFormatLayer = CCharFormatLayer::NewL();
00117     CleanupStack::PushL(charFormatLayer);
00118     CRichText* richText = CRichText::NewL(paraFormatLayer, charFormatLayer);
00119     CleanupStack::PushL(richText);
00120 
00121     CMsvStore* store = iMsvEntry->ReadStoreL();
00122         CleanupStack::PushL(store);
00123 
00124     if (!store->HasBodyTextL())
00125         User::Leave(KErrNotFound);
00126 
00127     store->RestoreBodyTextL(*richText);
00128 
00129         TInt messageLength = richText->DocumentLength();
00130         if (iMessageBody)
00131                 {
00132                 delete iMessageBody;
00133                 iMessageBody = NULL;
00134                 }
00135         iMessageBody = HBufC::NewL(messageLength);
00136 
00137         TPtr messDes = iMessageBody->Des();
00138         TInt length = messDes.Length();
00139         while (length < messageLength)
00140                 {
00141                 TPtrC desc = richText->Read(length, messageLength-length);
00142                 messDes.Append(desc);
00143                 length+=desc.Length();
00144                 }
00145         CleanupStack::PopAndDestroy(4, paraFormatLayer); // store, text, charFormatLayer, paraFormatLayer
00146         }
00147 
00148 

Generated by  doxygen 1.6.2