00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031 #include "BIOParser.h"
00032
00033
00034 CBioParser::CBioParser(CMsvEntry* aEntry)
00035 :iMsvEntry(aEntry)
00036 {
00037
00038 }
00039
00040 CBioParser::~CBioParser()
00041 {
00042 delete iMessageBody;
00043 if(iRegisteredParserDll)
00044 {
00045 delete iRegisteredParserDll;
00046 iRegisteredParserDll = NULL;
00047 }
00048 iFs.Close( );
00049 delete iBioDb;
00050 }
00051
00052 CBioParser* CBioParser::NewL(CMsvEntry* aEntry)
00053 {
00054 CBioParser* self= new (ELeave) CBioParser(aEntry);
00055 CleanupStack::PushL(self);
00056 self->ConstructL();
00057 CleanupStack::Pop();
00058 return self;
00059 }
00060
00061 void CBioParser::ConstructL()
00062 {
00063 iFs.Connect();
00064 iFs.SetSessionPath(KBifDir);
00065 iBioDb = CBIODatabase::NewL(iFs);
00066
00067 }
00068
00069 CBIOExampleParser* CBioParser::CreateParserL()
00070 {
00071 TUid messageUid;
00072 messageUid.iUid = iMsvEntry->Entry().iBioType;
00073
00074 TFileName parserDllName(iBioDb->GetBioParserNameL(messageUid));
00075
00076 if (iRegisteredParserDll)
00077 {
00078 delete iRegisteredParserDll;
00079 iRegisteredParserDll = NULL;
00080 }
00081
00082 iRegisteredParserDll = CRegisteredParserDll::NewL(parserDllName);
00083
00084 RLibrary parserlibrary;
00085 User::LeaveIfError(iRegisteredParserDll->GetLibrary(iFs, parserlibrary));
00086
00087 typedef CBIOExampleParser* (*NewParserL)(CRegisteredParserDll& aRegisteredParserDll, CMsvEntry& aEntry, RFs& aFs);
00088
00089 TInt entrypointordinalnumber=1;
00090 TLibraryFunction libFunc=parserlibrary.Lookup(entrypointordinalnumber);
00091 if (libFunc==NULL)
00092 User::Leave(KErrBadLibraryEntryPoint);
00093 NewParserL pFunc=(NewParserL) libFunc;
00094 TInt refcount=iRegisteredParserDll->DllRefCount();
00095 CBIOExampleParser* parser=NULL;
00096 TRAPD(ret,parser=((*pFunc)(*iRegisteredParserDll, *iMsvEntry, iFs)));
00097 if ((ret!=KErrNone) && (iRegisteredParserDll->DllRefCount()==refcount))
00098 iRegisteredParserDll->ReleaseLibrary();
00099
00100 User::LeaveIfError(ret);
00101
00102 return parser;
00103 }
00104
00105 void CBioParser::ParserL()
00106 {
00107 ExtractMessageBodyL();
00108
00109 CMsvOperationWait* wait = CMsvOperationWait::NewLC();
00110 wait->iStatus = KRequestPending;
00111 wait->Start();
00112
00113 CBIOExampleParser* parser = CreateParserL();
00114
00115 parser->ParseL(wait->iStatus, *iMessageBody);
00116 parser->Cancel();
00117 delete parser;
00118
00119
00120 CleanupStack::PopAndDestroy();
00121 }
00122
00126 void CBioParser::ExtractMessageBodyL()
00127 {
00128
00129 CParaFormatLayer* paraFormatLayer = CParaFormatLayer::NewL();
00130 CleanupStack::PushL(paraFormatLayer);
00131 CCharFormatLayer* charFormatLayer = CCharFormatLayer::NewL();
00132 CleanupStack::PushL(charFormatLayer);
00133 CRichText* richText = CRichText::NewL(paraFormatLayer, charFormatLayer);
00134 CleanupStack::PushL(richText);
00135
00136 CMsvStore* store = iMsvEntry->ReadStoreL();
00137 CleanupStack::PushL(store);
00138
00139 if (!store->HasBodyTextL())
00140 User::Leave(KErrNotFound);
00141
00142 store->RestoreBodyTextL(*richText);
00143
00144 TInt messageLength = richText->DocumentLength();
00145 if (iMessageBody)
00146 {
00147 delete iMessageBody;
00148 iMessageBody = NULL;
00149 }
00150 iMessageBody = HBufC::NewL(messageLength);
00151
00152 TPtr messDes = iMessageBody->Des();
00153 TInt length = messDes.Length();
00154 while (length < messageLength)
00155 {
00156 TPtrC desc = richText->Read(length, messageLength-length);
00157 messDes.Append(desc);
00158 length+=desc.Length();
00159 }
00160 CleanupStack::PopAndDestroy(4, paraFormatLayer);
00161 }
00162
00163