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
00032
00033
00034
00035 #include <e32base.h>
00036 #include <e32cons.h>
00037
00038 #include "exampleInetProtUtil.h"
00039
00040 _LIT ( KTest, "InetProtUtil Example" );
00041 _LIT ( KInetProtUtilExamplePanic, "EXAMPLES");
00042 _LIT ( KDisplayAll, "\n%d %S %d %S " );
00043 _LIT ( KLeaveALine, "\n" );
00044
00045 CExampleInetProtUtil::CExampleInetProtUtil()
00046 {
00047 }
00048
00049 CExampleInetProtUtil::~CExampleInetProtUtil()
00050 {
00051 delete iConsole;
00052 }
00053
00054 void CExampleInetProtUtil::NewL()
00055 {
00056 CExampleInetProtUtil *self = new (ELeave) CExampleInetProtUtil;
00057 CleanupStack::PushL(self);
00058 self->ConstructL();
00059 CleanupStack::PopAndDestroy(self);
00060 }
00061
00062 void CExampleInetProtUtil::ConstructL()
00063 {
00064
00065 iConsole = Console::NewL(KTest,TSize(KConsFullScreen,KConsFullScreen));
00066 iConsole->Printf ( KTest );
00067 _LIT(KTextStart, "\nPress any key to step through the example");
00068 iConsole->Printf ( KTextStart );
00069 iConsole->Getch ();
00070
00071
00072 CreateUriL();
00073
00074
00075 ModifyUriComponentsL();
00076
00077
00078 ResolveUriL();
00079
00080
00081 ParseUriL();
00082
00083
00084 ValidateUriComponentsL();
00085
00086
00087 ExtractUriComponentsL();
00088
00089
00090 RetrieveFileNameL();
00091
00092
00093 ModifyDelimiterL();
00094
00095
00096 WhiteSpaceRemover();
00097
00098
00099 EscapeEncodeDecodeL();
00100 }
00101
00102
00103
00104 void CExampleInetProtUtil::CreateUriL()
00105 {
00106
00107
00108 _LIT(KText1, "\n\n\nThe Physical location of the file is....");
00109 iConsole->Printf ( KText1 );
00110
00111 _LIT(KFullUriName, "K:\\ws\\direct\\direct.mmp");
00112
00113
00114 TBuf<40> desFullUriName(KFullUriName);
00115 iConsole->Printf ( KLeaveALine );
00116 iConsole->Printf ( KFullUriName );
00117
00118
00119 CUri8* uri8 = CUri8::CreateFileUriL(desFullUriName);
00120
00121 const TDesC8& desUriDisplay = uri8->Uri().UriDes();
00122 TBuf16<100> desCreateUri;
00123 desCreateUri.Copy (desUriDisplay);
00124
00125
00126 _LIT(KText2, "And its Uri is....");
00127 iConsole->Printf ( KLeaveALine );
00128 iConsole->Printf ( KText2 );
00129
00130 iConsole->Printf ( KLeaveALine );
00131 iConsole->Printf ( desCreateUri );
00132
00133 delete uri8;
00134
00135 iConsole->Getch ();
00136 }
00137
00138
00139 void CExampleInetProtUtil::ModifyUriComponentsL()
00140 {
00141 TUriParser8 parser1;
00142 CUri8* aUri = CUri8::NewL(parser1);
00143
00144 _LIT(KText3, "\n\n\nAdding Uri components one by one....");
00145 iConsole->Printf ( KText3 );
00146
00147
00148
00149
00150 _LIT8(KScheme, "http");
00151 _LIT(KScheme1, "\nSCHEME : http");
00152 iConsole->Printf ( KScheme1 );
00153 aUri->SetComponentL(KScheme, EUriScheme);
00154
00155
00156 _LIT8(KHost, "www.nokia.com");
00157 _LIT(KHost1, "\nHOST : www.nokia.com");
00158 iConsole->Printf ( KHost1 );
00159 aUri->SetComponentL(KHost, EUriHost);
00160
00161
00162 _LIT8(KPort, "80");
00163 _LIT(KPort1, "\nPORT : 80");
00164 iConsole->Printf ( KPort1 );
00165 aUri->SetComponentL(KPort, EUriPort);
00166
00167
00168 _LIT8(KPath, "/developer/techlib/turic8class.html");
00169 _LIT(KPath1, "\nPATH : /developer/techlib/turic8class.html");
00170 iConsole->Printf ( KPath1 );
00171 aUri->SetComponentL(KPath, EUriPath);
00172
00173
00174 _LIT(KText4, "\nThe fully constructed Uri....");
00175 iConsole->Printf ( KText4 );
00176 const TDesC8& desUriDisplay = aUri->Uri().UriDes();
00177 TBuf16<100> desFullUri;
00178 desFullUri.Copy (desUriDisplay);
00179
00180 iConsole->Printf( KLeaveALine );
00181 iConsole->Printf ( desFullUri );
00182
00183
00184 iConsole->Getch ();
00185 _LIT(KText5, "\n\nUri with the Port number removed....\n");
00186 iConsole->Printf ( KText5 );
00187 aUri->RemoveComponentL(EUriPort);
00188
00189
00190 const TDesC8& desRemovedComponentDisplay =aUri->Uri().UriDes();
00191 TBuf16<100> desRemovedComponent;
00192 desRemovedComponent.Copy (desRemovedComponentDisplay);
00193 iConsole->Printf ( desRemovedComponent );
00194
00195 delete aUri;
00196
00197 iConsole->Getch ();
00198 }
00199
00200
00201
00202 void CExampleInetProtUtil::ParseUriL()
00203 {
00204
00205 _LIT(KText6, "\n\n\nParsing the Uri for....\n");
00206 iConsole->Printf ( KText6 );
00207
00208 _LIT(KFullUriName,"K:\\ws\\direct\\direct.mmp");
00209 TBuf<40> desFullUriName(KFullUriName);
00210 iConsole->Printf ( desFullUriName );
00211
00212
00213 HBufC8* convert8 = EscapeUtils::ConvertFromUnicodeToUtf8L(desFullUriName);
00214 TUriParser8 parser;
00215
00216
00217 TInt errResult = parser.Parse(*convert8);
00218
00219 if (errResult==KErrNone)
00220 {
00221 _LIT(KTextParsing, "\nThis Uri has been parsed successfully");
00222 iConsole->Printf ( KTextParsing );
00223 }
00224
00225 delete convert8;
00226
00227 iConsole->Getch();
00228 }
00229
00230
00231 void CExampleInetProtUtil::ValidateUriComponentsL()
00232 {
00233 TUriParser8 parser1;
00234 CUri8* aUri = CUri8::NewL(parser1);
00235
00236 _LIT(KTextf, "\n\n\nValidating the Uri....\n");
00237 iConsole->Printf ( KTextf );
00238
00239
00240
00241
00242 _LIT8(KScheme, "http");
00243 aUri->SetComponentL(KScheme,EUriScheme);
00244
00245
00246 _LIT8(KHost, "waterlang.org");
00247 aUri->SetComponentL(KHost,EUriHost);
00248
00249
00250 _LIT8(KPort, "90");
00251 aUri->SetComponentL(KPort,EUriPort);
00252
00253
00254 _LIT8(KPath, "/turic8class.html");
00255 aUri->SetComponentL(KPath,EUriPath);
00256
00257
00258 _LIT8(KQuery, "bar=2&x=3");
00259 aUri->SetComponentL(KQuery,EUriQuery);
00260
00261
00262 _LIT8(KFragment, "fragment");
00263 aUri->SetComponentL(KFragment,EUriFragment);
00264
00265
00266 const TDesC8& desUriDisplays =aUri->Uri().UriDes();
00267 TBuf16<100> desValidate;
00268 desValidate.Copy (desUriDisplays);
00269 iConsole->Printf ( desValidate );
00270
00271
00272
00273
00274 TInt res = parser1.Parse(desUriDisplays);
00275 if (res==KErrNone)
00276 {
00277 _LIT(KText8, "\nThis Uri is VALID");
00278 iConsole->Printf ( KText8 );
00279 }
00280
00281 delete aUri;
00282
00283 iConsole->Getch();
00284 }
00285
00286
00287 void CExampleInetProtUtil::ExtractUriComponentsL()
00288 {
00289 _LIT(KTextExtract, "\n\n\nExtracting from....\n");
00290 iConsole->Printf ( KTextExtract );
00291
00292
00293 _LIT(KUriName, "K:\\ws\\direct\\direct.mmp");
00294 TBuf<40> desUriName(KUriName);
00295 CUri8* uriName = CUri8::CreateFileUriL(desUriName);
00296
00297
00298 const TDesC8& uriDisplay = uriName->Uri().UriDes();
00299 TBuf16<100> desExtract;
00300 desExtract.Copy (uriDisplay);
00301 iConsole->Printf ( desExtract );
00302
00303
00304 TUriParser8* uriComponent = new(ELeave) TUriParser8();
00305 uriComponent->Parse(uriDisplay);
00306
00307
00308 const TDesC8& host = uriComponent->Extract(EUriScheme);
00309 TBuf16<100> desEx;
00310 desEx.Copy (host);
00311
00312
00313 _LIT(KTextEx, "\nThe extracted Scheme component is....\n");
00314 iConsole->Printf ( KTextEx );
00315 iConsole->Printf ( desEx );
00316
00317
00318 delete uriComponent;
00319 delete uriName;
00320
00321 iConsole->Getch();
00322 }
00323
00324
00325
00326 void CExampleInetProtUtil::RetrieveFileNameL()
00327 {
00328 _LIT(KTextRet, "\n\n\nRetrieving filename from....\n");
00329 iConsole->Printf ( KTextRet );
00330
00331
00332 _LIT(KUriRetName, "K:\\ws\\direct\\direct.mmp");
00333 TBuf<40> desUriRetName(KUriRetName);
00334 CUri8* uriRetName = CUri8::CreateFileUriL(desUriRetName);
00335
00336
00337 const TDesC8& uriDisp = uriRetName->Uri().UriDes();
00338 TBuf16<100> desRetrieve;
00339 desRetrieve.Copy (uriDisp);
00340 iConsole->Printf ( desRetrieve );
00341
00342
00343 TUriParser8* uriComp = new(ELeave) TUriParser8();
00344 uriComp->Parse(uriDisp);
00345
00346
00347 _LIT(KTextGetFilename, "\nGetting the filename....\n");
00348 iConsole->Printf ( KTextGetFilename );
00349
00350 HBufC* fileName = uriComp->GetFileNameL();
00351 TPtr uriFileNameDisplay = fileName->Des();
00352 TBuf16<100> desFileName;
00353 desFileName.Copy (uriFileNameDisplay);
00354 iConsole->Printf ( desFileName );
00355
00356 delete fileName;
00357 delete uriComp;
00358 delete uriRetName;
00359
00360 iConsole->Getch();
00361 }
00362
00363
00364 void CExampleInetProtUtil::ModifyDelimiterL()
00365 {
00366
00367 _LIT(KTextDelimit1, "\n\n\nThe Delimiter is...\n");
00368 iConsole->Printf ( KTextDelimit1 );
00369 CExampleDelimiterModifier* delimiterModifyingObj = new(ELeave) CExampleDelimiterModifier;
00370 delimiterModifyingObj->SetDelimiter(TChar(';'));
00371
00372
00373 _LIT(KTextDelimit2, ";\n");
00374 iConsole->Printf ( KTextDelimit2 );
00375
00376 _LIT(KTextDelimit, "to be checked in...\n");
00377 iConsole->Printf ( KTextDelimit );
00378 _LIT(KFullUriName,"K:\\ws\\direct\\direct.mmp;");
00379 TBuf<40> desFullUriName(KFullUriName);
00380 iConsole->Printf ( desFullUriName );
00381
00382
00383 HBufC8* convert8 = EscapeUtils::ConvertFromUnicodeToUtf8L(desFullUriName);
00384 delimiterModifyingObj->Parse(*convert8);
00385
00386
00387 TBool checkFrontDelimiter = delimiterModifyingObj->CheckFrontDelimiter();
00388
00389
00390 TBool checkBackDelimiter = delimiterModifyingObj->CheckBackDelimiter();
00391
00392
00393 if (!checkFrontDelimiter)
00394 {
00395 _LIT(KTextDelimit3, "\nNo delimiter in the front");
00396 iConsole->Printf ( KTextDelimit3 );
00397 }
00398 else
00399 {
00400 _LIT(KTextDelimit4, "\nDelimiter is present in the front");
00401 iConsole->Printf ( KTextDelimit4 );
00402 }
00403 if (!checkBackDelimiter)
00404 {
00405 _LIT(KTextDelimit5, "\nNo delimiter at the back");
00406 iConsole->Printf ( KTextDelimit5 );
00407 }
00408 else
00409 {
00410 _LIT(KTextDelimit6, "\nDelimiter is present at the back");
00411 iConsole->Printf ( KTextDelimit6 );
00412 }
00413
00414 delete convert8;
00415 delete delimiterModifyingObj;
00416
00417 iConsole->Getch();
00418 }
00419
00420
00421 void CExampleInetProtUtil::WhiteSpaceRemover()
00422 {
00423
00424 _LIT(KTextWhiteSpace, "\n\n\nThe Uri containing white spaces....\n");
00425 iConsole->Printf ( KTextWhiteSpace );
00426
00427 _LIT(KFullUriPath," K:\\ws\\direct\\direct.mmp ");
00428 TBuf<40> desFullUriPath(KFullUriPath);
00429 iConsole->Printf ( desFullUriPath );
00430
00431
00432 TPtrC desFullUriName(KFullUriPath);
00433
00434
00435 TInt consumedWhiteSpacesLeft = InetProtTextUtils::RemoveWhiteSpace(desFullUriName,InetProtTextUtils::ERemoveLeft);
00436
00437
00438 TInt consumedWhiteSpacesRight = InetProtTextUtils::RemoveWhiteSpace(desFullUriName,InetProtTextUtils::ERemoveRight);
00439 _LIT(KTextAnd, " and ");
00440 _LIT(KTextInfo, " white spaces have been removed from the Uri");
00441
00442
00443 iConsole->Printf ( KDisplayAll,consumedWhiteSpacesLeft,&KTextAnd,consumedWhiteSpacesRight, &KTextInfo);
00444
00445 iConsole->Getch();
00446 }
00447
00448
00449 void CExampleInetProtUtil::EscapeEncodeDecodeL()
00450 {
00451
00452 _LIT(KFullUriName,"K:\\ws\\direct\\direct.mmp");
00453 TBuf<40> desFullUriName(KFullUriName);
00454
00455
00456 HBufC8* convert = EscapeUtils::ConvertFromUnicodeToUtf8L(desFullUriName);
00457
00458
00459 _LIT(KTextEncode, "\n\n\nThe Encoded Uri is....\n");
00460 iConsole->Printf ( KTextEncode );
00461 HBufC16* encode = EscapeUtils::EscapeEncodeL(desFullUriName,EscapeUtils::EEscapeNormal);
00462 TPtr uriEncoded = encode->Des();
00463 TBuf16<100> desEncodedUri;
00464 desEncodedUri.Copy (uriEncoded);
00465 iConsole->Printf ( _L("%S"), &desEncodedUri );
00466
00467
00468 _LIT(KTextDecode, "\nThe Decoded Uri is....\n");
00469 iConsole->Printf ( KTextDecode );
00470
00471 HBufC16* decode = EscapeUtils::EscapeDecodeL(desFullUriName);
00472 TPtr uriDecoded = decode->Des();
00473 TBuf16<100> desDecodedUri;
00474 desDecodedUri.Copy (uriDecoded);
00475 iConsole->Printf ( _L("%S"), &desDecodedUri );
00476
00477 delete decode;
00478 delete encode;
00479 delete convert;
00480
00481 iConsole->Getch();
00482 iConsole->Printf ( KLeaveALine );
00483 }
00484
00485
00486 void CExampleInetProtUtil::ResolveUriL()
00487 {
00488 _LIT(KTextResolve1, "\n\n\nThe Base and reference Uris are\n");
00489 iConsole->Printf ( KTextResolve1 );
00490
00491 TUriParser8 parserResolve1;
00492 CUri8* aUriBase = CUri8::NewL(parserResolve1);
00493
00494
00495 _LIT8(KScheme, "http");
00496 aUriBase->SetComponentL(KScheme,EUriScheme);
00497
00498
00499 _LIT8(KHost, "nokia.com");
00500 aUriBase->SetComponentL(KHost,EUriHost);
00501
00502
00503 _LIT8(KPort, "90");
00504 aUriBase->SetComponentL(KPort,EUriPort);
00505
00506
00507 _LIT8(KPath, "/resolve.aspx");
00508 aUriBase->SetComponentL(KPath,EUriPath);
00509
00510 const TDesC8& desBaseUri =aUriBase->Uri().UriDes();
00511 TBuf16<100> desBase;
00512 desBase.Copy (desBaseUri);
00513 iConsole->Printf ( desBase );
00514
00515 iConsole->Printf( KLeaveALine );
00516
00517 CUri8* aUriRef = CUri8::NewL(parserResolve1);
00518
00519
00520 _LIT8(KPath1, "/uris/base/reference/resolve.aspx");
00521 aUriRef->SetComponentL(KPath1,EUriPath);
00522
00523
00524 _LIT8(KQuery1, "bar=2&x=3");
00525 aUriRef->SetComponentL(KQuery1,EUriQuery);
00526
00527 const TDesC8& desRefUri =aUriRef->Uri().UriDes();
00528 TBuf16<100> desRef;
00529 desRef.Copy (desRefUri);
00530 iConsole->Printf ( desRef );
00531
00532 _LIT(KTextResolve, "\nThe Resolved Uri is....\n");
00533 iConsole->Printf ( KTextResolve );
00534
00535
00536 CUri8* Uri8 = CUri8::ResolveL(aUriBase->Uri(),aUriRef->Uri());
00537
00538
00539 const TDesC8& desDisplayReslovedUri = Uri8->Uri().UriDes();
00540 TBuf16<100> desResolve;
00541 desResolve.Copy (desDisplayReslovedUri);
00542 iConsole->Printf ( desResolve );
00543
00544 delete Uri8;
00545 delete aUriRef;
00546 delete aUriBase;
00547
00548 iConsole->Getch ();
00549 }
00550
00551
00553
00555
00556 GLDEF_C TInt E32Main()
00557 {
00558 __UHEAP_MARK;
00559 CTrapCleanup* tc = CTrapCleanup::New();
00560 TRAPD(err, CExampleInetProtUtil::NewL());
00561 if (err != KErrNone)
00562 User::Panic(KInetProtUtilExamplePanic,err);
00563 delete tc;
00564 __UHEAP_MARKEND;
00565 return KErrNone;
00566 }
00567
00568