src/NPRStory.cpp
changeset 0 0049171ecffb
equal deleted inserted replaced
-1:000000000000 0:0049171ecffb
       
     1 /*
       
     2  ============================================================================
       
     3  Name	: NPRStory.cpp
       
     4  Author	: John Kern
       
     5  
       
     6  Copyright (c) 2009 Symbian Foundation Ltd
       
     7  This component and the accompanying materials are made available
       
     8  under the terms of the License "Eclipse Public License v1.0"
       
     9  which accompanies this distribution, and is available
       
    10  at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
    11 
       
    12  Initial Contributors:
       
    13  - Symbian Foundation Ltd - initial contribution.
       
    14  
       
    15  Contributors:
       
    16  - John Kern
       
    17  - Symsource
       
    18  
       
    19  Description : NPR's xml story parser
       
    20  ============================================================================
       
    21  */
       
    22 
       
    23 #include "NPRStory.h"
       
    24 
       
    25 const int KUrlLength = 256; 
       
    26 
       
    27 CNPRStory* CNPRStory::NewLC()
       
    28 	{
       
    29 	CNPRStory* self = new (ELeave) CNPRStory();
       
    30 	CleanupStack::PushL(self);
       
    31 	self->ConstructL();
       
    32 	return self;
       
    33 	}
       
    34 
       
    35 CNPRStory* CNPRStory::NewL()
       
    36 	{
       
    37 	CNPRStory* self = CNPRStory::NewLC();
       
    38 	CleanupStack::Pop(); // self;
       
    39 	return self;
       
    40 	}
       
    41 
       
    42 CNPRStory::CNPRStory()
       
    43 :iTitle(NULL),iTeaser(NULL),iMp3Url(NULL)
       
    44 	{
       
    45 	// No implementation required
       
    46 	}
       
    47 
       
    48 CNPRStory::~CNPRStory()
       
    49 	{
       
    50 	iTitle.Close();
       
    51 	iTeaser.Close();
       
    52 	iText.Close();
       
    53 	iMp3Url.Close(); 
       
    54 	iThumbnailUrl.Close();
       
    55 	}
       
    56 
       
    57 void CNPRStory::ConstructL()
       
    58 	{
       
    59 	}
       
    60 
       
    61 void CNPRStory::SetTitleL(const TDesC8& aTitle)
       
    62 	{
       
    63 	HBufC* temp = HBufC::NewLC(aTitle.Length());
       
    64 	// copy from 8 to 16 bit descriptor. 
       
    65 	temp->Des().Copy(aTitle);
       
    66 
       
    67 	if(iTitle.MaxLength() < temp->Length())
       
    68 		{
       
    69 		iTitle.ReAlloc(temp->Length());
       
    70 		}
       
    71 	iTitle.Copy(temp->Des());
       
    72 	CleanupStack::PopAndDestroy();
       
    73 	}
       
    74 
       
    75 void CNPRStory::SetTeaserL(const TDesC8& aTeaser)
       
    76 	{
       
    77 	HBufC* temp = HBufC::NewLC(aTeaser.Length());
       
    78 	// copy from 8 to 16 bit descriptor. 
       
    79 	temp->Des().Copy(aTeaser);
       
    80 
       
    81 	// append it 
       
    82 	const TInt newLength = iTeaser.Length() + temp->Length();
       
    83 	if(iTeaser.MaxLength() < newLength)
       
    84 		{
       
    85 		iTeaser.ReAlloc(newLength);
       
    86 		}
       
    87 	iTeaser.Append(temp->Des());
       
    88 	CleanupStack::PopAndDestroy();
       
    89 	}
       
    90 
       
    91 void CNPRStory::SetTextL(const TDesC8& aText)
       
    92 	{
       
    93 	HBufC* temp = HBufC::NewLC(aText.Length());
       
    94 	// copy from 8 to 16 bit descriptor. 
       
    95 	temp->Des().Copy(aText);
       
    96 	// append it 
       
    97 
       
    98 	const TInt newLength = iText.Length() + temp->Length();
       
    99 	if(iText.MaxLength() < newLength)
       
   100 		{
       
   101 		iText.ReAlloc(newLength);
       
   102 		}
       
   103 	iText.Append(temp->Des());
       
   104 
       
   105 	CleanupStack::PopAndDestroy();
       
   106 	}
       
   107 
       
   108 // The XML parser will call this multiple times to construct the mp3url. 
       
   109 void CNPRStory::SetMp3UrlL(const TDesC8& aMp3Url)
       
   110 	{
       
   111 	HBufC* temp = HBufC::NewLC(aMp3Url.Length());
       
   112 	// copy from 8 to 16 bit descriptor. 
       
   113 	temp->Des().Copy(aMp3Url);
       
   114 	
       
   115 	// append it 
       
   116 	const TInt newLength = iMp3Url.Length() + temp->Length();
       
   117 	if(iMp3Url.MaxLength() < newLength)
       
   118 		{
       
   119 		iMp3Url.ReAlloc(newLength);
       
   120 		}
       
   121 	iMp3Url.Append(temp->Des());
       
   122 	CleanupStack::PopAndDestroy();
       
   123 	}
       
   124 
       
   125 void CNPRStory::SetThumbnailUrlL(const TDesC8& aThumbUrl)
       
   126 	{
       
   127 	HBufC* temp = HBufC::NewLC(aThumbUrl.Length());
       
   128 	// copy from 8 to 16 bit descriptor. 
       
   129 	temp->Des().Copy(aThumbUrl);
       
   130 
       
   131 	if(iThumbnailUrl.MaxLength() < temp->Length())
       
   132 		{
       
   133 		iThumbnailUrl.ReAlloc(temp->Length());
       
   134 		}
       
   135 	iThumbnailUrl.Copy(temp->Des());
       
   136 	CleanupStack::PopAndDestroy();
       
   137 	}
       
   138 //End of file