00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #include <e32base.h>
00019 #include <e32cons.h>
00020 #include <vcard.h>
00021 #include <versit.h>
00022 #include "VersitExample.h"
00023
00024
00025 static CConsoleBase* gConsole;
00026
00027
00028 _LIT(KVCardFileJIS,"\\Private\\E8000094\\charsetJIS.vcf");
00029
00030
00031 _LIT(KMsgPressAnyKey,"\n\nPress any key to continue\n");
00032
00033 CExampleVersit* CExampleVersit::NewL()
00034 {
00035 CExampleVersit* self = new (ELeave) CExampleVersit();
00036 CleanupStack::PushL(self);
00037 self->ConstructL();
00038 CleanupStack::Pop(self);
00039 return self;
00040 }
00041
00042 void CExampleVersit::ConstructL()
00043 {
00044 iParser = CParserVCard::NewL();
00045 }
00046
00047 CExampleVersit::~CExampleVersit()
00048 {
00049 delete iParser;
00050 iFsSession .Close();
00051 }
00052
00053
00054 void CExampleVersit::ExternalizeToFileL(const TDesC& aFileName)
00055 {
00056 RFile file;
00057 iFsSession.Connect();
00058
00059 User::LeaveIfError(iFsSession.CreatePrivatePath(RFs::GetSystemDrive()));
00060 User::LeaveIfError(file.Replace(iFsSession, aFileName, EFileWrite));
00061 CleanupClosePushL(file);
00062 iParser->ExternalizeL(file);
00063 CleanupStack::PopAndDestroy(&file);
00064 }
00065
00066
00067 void CExampleVersit::InternalizeFromFileL(RFile& aInputFile)
00068 {
00069 TInt size;
00070 if (aInputFile.Size(size)==KErrNone)
00071 {
00072 delete iParser;
00073 iParser = NULL;
00074
00075 iParser = CParserVCard::NewL();
00076 RFileReadStream stream(aInputFile);
00077 CleanupClosePushL(stream);
00078 iParser->InternalizeL(stream);
00079 CleanupStack::PopAndDestroy(&stream);
00080 }
00081 }
00082
00083
00084
00085 void CExampleVersit::CreateAndExternalizeVCardL()
00086 {
00087
00088 _LIT(KNote,"\x4e79\x4f19\x5032");
00089 CParserPropertyValue* value=CParserPropertyValueHBufC::NewL(KNote);
00090 CleanupStack::PushL(value);
00091
00092 CArrayPtr<CParserParam>* arrayOfParams = new(ELeave)CArrayPtrFlat<CParserParam>(5);
00093 CleanupStack::PushL(arrayOfParams);
00094
00095
00096 CParserParam* parserParam=CParserParam::NewL(KVersitTokenCHARSET,KVersitTokenJIS);
00097 CleanupStack::PushL(parserParam);
00098 arrayOfParams->AppendL(parserParam);
00099 CleanupStack::Pop(parserParam);
00100
00101
00102 CParserGroupedProperty* property=CParserGroupedProperty::NewL(*value,KVersitTokenNOTE,NULL,arrayOfParams);
00103
00104 CleanupStack::Pop(2,value);
00105 CleanupStack::PushL(property);
00106
00107
00108 iParser->AddPropertyL(property);
00109 CleanupStack::Pop(property);
00110
00111 iParser->SetDefaultCharSet(Versit::EJISCharSet);
00112 ExternalizeToFileL(KVCardFileJIS);
00113 }
00114
00115
00116 void CExampleVersit::InternalizeVCardL()
00117 {
00118 RFile file;
00119 TInt err=file.Open(iFsSession,KVCardFileJIS,EFileRead);
00120 User::LeaveIfError(err);
00121 CleanupClosePushL(file);
00122 InternalizeFromFileL(file);
00123 CleanupStack::PopAndDestroy(&file);
00124
00125 _LIT(KConsoleMessage1, "vCard has been successfully internalised from a file");
00126 gConsole->Printf(KConsoleMessage1);
00127 }
00128
00129 void CExampleVersit::EgVersitL()
00130 {
00131 CreateAndExternalizeVCardL();
00132 InternalizeVCardL();
00133 }
00134
00135 static void DoExampleL()
00136 {
00137
00138 _LIT(KConsoleMessageDisplay, "Versit Example");
00139 _LIT(KConsoleStars,"\n*************************\n");
00140 gConsole = Console::NewL(KConsoleMessageDisplay,TSize(KConsFullScreen,KConsFullScreen));
00141 CleanupStack::PushL(gConsole);
00142 gConsole->Printf(KConsoleMessageDisplay);
00143 gConsole->Printf(KConsoleStars);
00144
00145 CExampleVersit* egVersit= CExampleVersit::NewL();
00146 TRAPD(err, egVersit->EgVersitL());
00147 if (err)
00148 {
00149 _LIT(KFailed,"\n\nExample failed: leave code=%d");
00150 gConsole->Printf(KFailed, err);
00151 }
00152 delete egVersit;
00153
00154 gConsole->Printf(KMsgPressAnyKey);
00155 gConsole->Getch();
00156 CleanupStack::PopAndDestroy(gConsole);
00157 }
00158
00159
00160 TInt E32Main()
00161 {
00162 __UHEAP_MARK;
00163
00164 CActiveScheduler* scheduler=new CActiveScheduler;
00165
00166 if (scheduler)
00167 {
00168 CActiveScheduler::Install(scheduler);
00169
00170 CTrapCleanup* cleanup=CTrapCleanup::New();
00171 if (cleanup)
00172 {
00173 TRAP_IGNORE(DoExampleL());
00174 delete cleanup;
00175 }
00176 delete scheduler;
00177 }
00178 __UHEAP_MARKEND;
00179 return KErrNone;
00180 }