src/NPRStationXmlParser.cpp
changeset 0 0049171ecffb
equal deleted inserted replaced
-1:000000000000 0:0049171ecffb
       
     1 /*
       
     2  ============================================================================
       
     3  Name	: NPRStationXmlParser.cpp
       
     4  Author	: Symsource
       
     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  - Symsource
       
    14  
       
    15  Contributors:
       
    16  - Symsource
       
    17  
       
    18  Description : Station xml parser
       
    19  ============================================================================
       
    20  */
       
    21 
       
    22 #include "NPRDocument.h"
       
    23 #include "NPRStationXmlParser.h"
       
    24 #include "NPRStation.h"
       
    25 
       
    26 CNPRStationXmlParser* CNPRStationXmlParser::NewLC(RPointerArray<CNPRStation>* aStationArray)
       
    27 	{
       
    28 	CNPRStationXmlParser* self = new (ELeave) CNPRStationXmlParser(aStationArray);
       
    29 	CleanupStack::PushL(self);
       
    30 	self->ConstructL();
       
    31 	return self;
       
    32 	}
       
    33 
       
    34 CNPRStationXmlParser* CNPRStationXmlParser::NewL(RPointerArray<CNPRStation>* aStationArray)
       
    35 	{
       
    36 	CNPRStationXmlParser* self = CNPRStationXmlParser::NewLC(aStationArray);
       
    37 	CleanupStack::Pop(); // self;
       
    38 	return self;
       
    39 	}
       
    40 
       
    41 CNPRStationXmlParser::CNPRStationXmlParser(RPointerArray<CNPRStation>* aStationArray)
       
    42 :iStationArray(aStationArray)
       
    43 	{
       
    44 	// No implementation required
       
    45 	}
       
    46 
       
    47 CNPRStationXmlParser::~CNPRStationXmlParser()
       
    48 	{
       
    49 	}
       
    50 
       
    51 void CNPRStationXmlParser::ConstructL()
       
    52 	{
       
    53 	iState = ENPRStationStateIdle;
       
    54 	}
       
    55 
       
    56 void CNPRStationXmlParser::OnStartDocumentL(const RDocumentParameters& /* aDocParam */, TInt aErrorCode)
       
    57 	{
       
    58 	User::LeaveIfError(aErrorCode);
       
    59 	}
       
    60 
       
    61 void CNPRStationXmlParser::OnEndDocumentL(TInt aErrorCode)
       
    62 	{
       
    63 	User::LeaveIfError(aErrorCode);
       
    64 	}
       
    65 
       
    66 HBufC* CNPRStationXmlParser::Copy8To16LC(const TDesC8& aDes)
       
    67         {
       
    68         HBufC* buf16 = HBufC::NewLC(aDes.Length());
       
    69         buf16->Des().Copy(aDes);
       
    70         return buf16;
       
    71         }
       
    72 
       
    73 void CNPRStationXmlParser::OnStartElementL(
       
    74 		const RTagInfo& aElement, 
       
    75 		const RAttributeArray& aAttributes, 
       
    76 		TInt  aErrorCode)
       
    77 	{
       
    78 	User::LeaveIfError(aErrorCode);
       
    79 	const TDesC8& tagName = aElement.LocalName().DesC();
       
    80 	if (tagName.CompareF(_L8("station"))==0)
       
    81 		{
       
    82 		iState = ENPRStationStateStation;
       
    83 		iCurrentStation = CNPRStation::NewL(); 
       
    84 		// find the story Id attribute
       
    85 		TInt count = aAttributes.Count();
       
    86 		for (TInt i = 0 ; i < count ; i++)
       
    87 			{
       
    88 			 const RAttribute& attribute = aAttributes[i];
       
    89 			 const RTagInfo& nameInfo = attribute.Attribute();
       
    90 
       
    91 			 const TDesC8& localName8 = nameInfo.LocalName().DesC();
       
    92 			 const TDesC8& value8 = attribute.Value().DesC();
       
    93 
       
    94 			 HBufC* localName16 = Copy8To16LC(localName8);
       
    95 			 HBufC* value16 = Copy8To16LC(value8);
       
    96 			 if (localName16->CompareF(_L("id")) == 0 )
       
    97 				 {
       
    98 				 TLex lex(value16->Des());
       
    99 				 TInt v = 0;
       
   100 				 lex.Val(v);
       
   101 				 iCurrentStation->SetStationId( v );
       
   102 				 }
       
   103 			 CleanupStack::PopAndDestroy(2); // value16 and localName16
       
   104 			}
       
   105 		}
       
   106 	else if (tagName.CompareF(_L8("name"))==0 && iState == ENPRStationStateStation)
       
   107 			{
       
   108 			iState = ENPRStationStateName;
       
   109 			}
       
   110 	else if (tagName.CompareF(_L8("frequency"))==0 && iState == ENPRStationStateNameEnd)
       
   111 			{
       
   112 			iState = ENPRStationStateFrequency;
       
   113 			}
       
   114 	else if (tagName.CompareF(_L8("marketCity"))==0 && iState == ENPRStationStateFrequencyEnd)
       
   115 			{
       
   116 			iState = ENPRStationStateMarketCity;
       
   117 			}
       
   118 	}
       
   119 
       
   120 void CNPRStationXmlParser::OnEndElementL(const RTagInfo& aElement, TInt aErrorCode )
       
   121 	{
       
   122 	User::LeaveIfError(aErrorCode);
       
   123 	const TDesC8& tagName = aElement.LocalName().DesC();
       
   124 	if (tagName.CompareF(_L8("station"))== 0 && iState == ENPRStationStateMarketCityEnd) 
       
   125 		{
       
   126 		iState = ENPRStationStateIdle; 
       
   127 		iStationArray->AppendL(iCurrentStation);
       
   128 		iCurrentStation = NULL;
       
   129 		} 
       
   130 	else if (tagName.CompareF(_L8("name"))== 0 && iState == ENPRStationStateName)
       
   131 		{ 
       
   132 		iState = ENPRStationStateNameEnd;
       
   133 		} 	
       
   134 	else if (tagName.CompareF(_L8("frequency"))== 0 && iState == ENPRStationStateFrequency)
       
   135 		{
       
   136 		iState = ENPRStationStateFrequencyEnd;
       
   137 		}	
       
   138 	else if (tagName.CompareF(_L8("marketCity"))== 0 && iState == ENPRStationStateMarketCity)
       
   139 		{
       
   140 		iState = ENPRStationStateMarketCityEnd;
       
   141 		}
       
   142 	}
       
   143 
       
   144 void CNPRStationXmlParser::OnContentL(const TDesC8&  aBytes, TInt aErrorCode)
       
   145 	{
       
   146 	User::LeaveIfError(aErrorCode);
       
   147 	
       
   148 	switch(iState)
       
   149 		{
       
   150 		case ENPRStationStateName:
       
   151 			{
       
   152 			iCurrentStation->SetNameL(aBytes);
       
   153 			break;
       
   154 			}
       
   155 		case ENPRStationStateFrequency:
       
   156 			{
       
   157 			iCurrentStation->SetFrequencyL(aBytes);
       
   158 			break; 
       
   159 			}
       
   160 		case ENPRStationStateMarketCity:
       
   161 			{
       
   162 			iCurrentStation->SetMarketCityL(aBytes);
       
   163 			break;
       
   164 			}
       
   165 		
       
   166 		default:
       
   167 			iState = iState; // for debugging. 
       
   168 			break;
       
   169 		}
       
   170 	}
       
   171 
       
   172 void CNPRStationXmlParser::OnStartPrefixMappingL(
       
   173 		const RString& /* aPrefix */, 
       
   174 		const RString& /* aUri */, 
       
   175 		TInt aErrorCode)
       
   176 	{
       
   177 	User::LeaveIfError(aErrorCode);
       
   178 	}
       
   179 
       
   180 void CNPRStationXmlParser::OnEndPrefixMappingL(const RString& /* aPrefix */, TInt aErrorCode)
       
   181 	{
       
   182 	User::LeaveIfError(aErrorCode);
       
   183 	}
       
   184 
       
   185 void CNPRStationXmlParser::OnIgnorableWhiteSpaceL(const TDesC8& /* aBytes */, TInt /* aErrorCode*/ )
       
   186 	{
       
   187 	}
       
   188 
       
   189 void CNPRStationXmlParser::OnSkippedEntityL(const RString& /* aName */, TInt aErrorCode)
       
   190 	{
       
   191 	User::LeaveIfError(aErrorCode);
       
   192 	}
       
   193 
       
   194 void CNPRStationXmlParser::OnProcessingInstructionL(
       
   195 		const TDesC8& /* aTarget */ , 
       
   196 		const TDesC8& /* aData */ , 
       
   197 		TInt aErrorCode)
       
   198 	{
       
   199 	User::LeaveIfError(aErrorCode);
       
   200 	}
       
   201 
       
   202 void CNPRStationXmlParser::OnError(TInt aErrorCode)
       
   203 	{
       
   204 	User::LeaveIfError(aErrorCode);
       
   205 	}
       
   206 
       
   207 TAny* CNPRStationXmlParser::GetExtendedInterface(const TInt32 /* aUid */ ) 
       
   208 	{
       
   209 	return NULL;
       
   210 	}