examples/Messaging/BIOMessageMgr/Src/BIOParser.cpp

00001 /*
00002 Copyright (c) 2005-2010 Nokia Corporation and/or its subsidiary(-ies). All rights reserved.
00003 
00004 Redistribution and use in source and binary forms, with or without
00005 modification, are permitted provided that the following conditions are met:
00006 
00007 * Redistributions of source code must retain the above copyright notice, this
00008   list of conditions and the following disclaimer.
00009 * Redistributions in binary form must reproduce the above copyright notice,
00010   this list of conditions and the following disclaimer in the documentation
00011   and/or other materials provided with the distribution.
00012 * Neither the name of Nokia Corporation nor the names of its contributors
00013   may be used to endorse or promote products derived from this software
00014   without specific prior written permission.
00015 
00016 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00017 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00018 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
00019 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
00020 FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00021 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
00022 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00023 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
00024 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
00025 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00026 
00027 Description:  
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         // Parsing the message
00115         parser->ParseL(wait->iStatus, *iMessageBody);
00116         parser->Cancel();
00117         delete parser;
00118 
00119 
00120         CleanupStack::PopAndDestroy();  // wait
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); // store, text, charFormatLayer, paraFormatLayer
00161         }
00162 
00163 

Generated by  doxygen 1.6.2