applayerpluginsandutils/uripermissionservices/server/src/urilistinitializer.cpp
changeset 0 b16258d2340f
equal deleted inserted replaced
-1:000000000000 0:b16258d2340f
       
     1 // Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 //
       
    15 
       
    16 #include "urilistinitializer.h"
       
    17 #include "urischema.h"
       
    18 #include "urilistinterface.h"
       
    19 #include "ineturiimpl.h"
       
    20 
       
    21 using namespace Xml;
       
    22 
       
    23 
       
    24 CUriListInitializer* CUriListInitializer::NewL ( CUriListInterface& aListInterface )
       
    25 	{
       
    26 	CUriListInitializer* self = new ( ELeave ) CUriListInitializer ( aListInterface );
       
    27 	CleanupStack::PushL ( self );
       
    28 	self->ConstructL ();
       
    29 	CleanupStack::Pop ();
       
    30 	return self;
       
    31 	}
       
    32 
       
    33 CUriListInitializer::~CUriListInitializer ()
       
    34 	{
       
    35 	iContent.Close ();
       
    36 	iStringPool.Close ();
       
    37 	delete iInetUriImpl;
       
    38 	}
       
    39 
       
    40 
       
    41 CUriListInitializer::CUriListInitializer ( CUriListInterface& aListInterface )
       
    42 : iListInterface ( aListInterface ),
       
    43 iParserState ( EInitial )
       
    44 	{
       
    45 		
       
    46 	}
       
    47 
       
    48 void CUriListInitializer::ConstructL ()
       
    49 	{
       
    50 	const TInt KMaxContentSize = 4 * 1024;
       
    51 	iContent.CreateL (KMaxContentSize);
       
    52 	iStringPool.OpenL ( URIXMLTAGS::Table ); // Open the schema table
       
    53 	iInetUriImpl = CInetUriImpl::NewL (); // Create an empty object
       
    54 	}
       
    55 
       
    56 void CUriListInitializer::ParseDocumentL ( const TDesC& aFile )
       
    57 	{
       
    58 	_LIT8( KXmlParserDataType, "text/xml" );
       
    59 	
       
    60 	RFs myFs;
       
    61 	CleanupClosePushL ( myFs );
       
    62 	User::LeaveIfError ( myFs.Connect () );
       
    63 	
       
    64 	CParser* myParser = CParser::NewLC ( KXmlParserDataType(), *this );
       
    65 	ParseL ( *myParser, myFs, aFile );
       
    66 	CleanupStack::PopAndDestroy ( 2 ); // myParser, myFs
       
    67 	}
       
    68 
       
    69 // Virtual functions from MContentHandler
       
    70 void CUriListInitializer::OnStartDocumentL ( const Xml::RDocumentParameters& /* aDocParam */, TInt aErrorCode )
       
    71 	{
       
    72 	User::LeaveIfError ( aErrorCode );
       
    73 	}
       
    74 	
       
    75 void CUriListInitializer::OnEndDocumentL ( TInt aErrorCode )
       
    76 	{
       
    77 	User::LeaveIfError ( aErrorCode );		
       
    78 	}
       
    79 
       
    80 void CUriListInitializer::OnStartElementL ( const Xml::RTagInfo& aElement, const Xml::RAttributeArray& /* aAttributes */, TInt aErrorCode )
       
    81 	{	
       
    82 	User::LeaveIfError ( aErrorCode );		
       
    83 	SetParserState ( ParserStateL( aElement.LocalName() ) );
       
    84 	}
       
    85 
       
    86 void CUriListInitializer::OnEndElementL ( const Xml::RTagInfo& aElement, TInt aErrorCode )
       
    87 	{
       
    88 	User::LeaveIfError ( aErrorCode );
       
    89 	SetParserState ( ParserStateL( aElement.LocalName(), ETrue ) );		
       
    90 	SetValueL ( KNullDesC8() );
       
    91 	if (!iInetUriImpl->IsDirty()) 
       
    92 		{
       
    93 		if( iParserState == EEndOfRecord )
       
    94 		    {
       
    95 		    // Insert the record	
       
    96 		    iListInterface.InsertL ( *iInetUriImpl );
       
    97 		    iInetUriImpl->Clear ();
       
    98 		    }
       
    99 		}
       
   100 	}
       
   101 
       
   102 void CUriListInitializer::OnContentL ( const TDesC8& aBytes, TInt aErrorCode )
       
   103 	{
       
   104 	User::LeaveIfError ( aErrorCode );	
       
   105 	SetValueL ( aBytes );
       
   106 	}
       
   107 
       
   108 TInt CUriListInitializer::ConvertToInteger ( const TDesC8& aValue )
       
   109 	{
       
   110 	TInt num = -1;
       
   111 	TLex8 lexRead (aValue);
       
   112 	lexRead.Val ( num );
       
   113 	return num;
       
   114 	}
       
   115 
       
   116 void CUriListInitializer::SetParserState ( TParserState aNewState )
       
   117 	{
       
   118 	switch ( aNewState )
       
   119 		{
       
   120 		case EInitial:
       
   121 		iParserState = EInitial;
       
   122 		break;
       
   123 		
       
   124 		case EStartOfServicetype:
       
   125 		__ASSERT_DEBUG ( iParserState == EInitial, User::Invariant() );
       
   126 		iParserState = aNewState;
       
   127 		break;
       
   128 		
       
   129 		case EEndOfServicetype:
       
   130 		__ASSERT_DEBUG ( iParserState == EEndOfListtype, User::Invariant() );
       
   131 		iParserState = aNewState;
       
   132 		break;
       
   133 		
       
   134 		case EStartOfListtype:
       
   135 		__ASSERT_DEBUG ( (iParserState == EStartOfServicetype) || (iParserState == EEndOfListtype), User::Invariant() );
       
   136 		iParserState = aNewState;
       
   137 		break;
       
   138 		
       
   139 		case EEndOfListtype:
       
   140 		__ASSERT_DEBUG ( iParserState == EEndOfRecord, User::Invariant() );
       
   141 		iParserState = aNewState;		
       
   142 		break;
       
   143 		
       
   144 		case EStartOfRecord:
       
   145 		__ASSERT_DEBUG ( (iParserState == EStartOfListtype) || (iParserState == EEndOfRecord), User::Invariant() );
       
   146 		iParserState = aNewState;				
       
   147 		break;
       
   148 		
       
   149 		case EEndOfRecord:
       
   150 		__ASSERT_DEBUG ( (iParserState == EEndOfUri) || (iParserState == EEndOfPermission) || (iParserState == EEndOfFavouriteName), User::Invariant() );
       
   151 		iParserState = aNewState;				
       
   152 		break;
       
   153 		
       
   154 		case EStartOfUri:
       
   155 		case EStartOfPermission:
       
   156 		case EStartOfFavouriteName:		
       
   157 		iParserState = aNewState;				
       
   158 		break;
       
   159 		
       
   160 		case EEndOfUri:
       
   161 		__ASSERT_DEBUG ( (iParserState == EStartOfUri), User::Invariant() );
       
   162 		iParserState = aNewState;
       
   163 		break;
       
   164 		
       
   165 		case EEndOfPermission:
       
   166 		__ASSERT_DEBUG ( (iParserState == EStartOfPermission), User::Invariant() );			
       
   167 		iParserState = aNewState;		
       
   168 		break;
       
   169 		
       
   170 		case EEndOfFavouriteName:
       
   171 		__ASSERT_DEBUG ( (iParserState == EStartOfFavouriteName), User::Invariant() );
       
   172 		iParserState = aNewState;		
       
   173 		break;
       
   174 
       
   175 		default:
       
   176 
       
   177 		// Do nothing
       
   178 		break;
       
   179 		}	
       
   180 	}
       
   181 
       
   182 CUriListInitializer::TParserState CUriListInitializer::ParserStateL ( const RString& aTag, TBool aEndElement /* =EFalse */ )
       
   183 	{	
       
   184 	// Open a RString from the string pool
       
   185 	RString myTagString = iStringPool.OpenStringL ( aTag.DesC() );
       
   186 	TInt tblIndex = myTagString.Index ( URIXMLTAGS::Table );
       
   187 	TParserState parserState = EInitial;
       
   188 	switch ( tblIndex )
       
   189 		{
       
   190 		case URIXMLTAGS::EWapPush:
       
   191 		case URIXMLTAGS::EBrowser:
       
   192 		case URIXMLTAGS::EDevPro:
       
   193 		case URIXMLTAGS::EPushEMail:
       
   194 		case URIXMLTAGS::EVoip:
       
   195 		parserState = aEndElement ? EEndOfServicetype : EStartOfServicetype;
       
   196 		SetServiceType ( tblIndex );
       
   197 		break;
       
   198 		case URIXMLTAGS::EWhitelist:
       
   199 		case URIXMLTAGS::EBlacklist:
       
   200 		parserState = aEndElement ? EEndOfListtype : EStartOfListtype;
       
   201 		SetListType ( tblIndex );
       
   202 		break;
       
   203 		
       
   204 		case URIXMLTAGS::ERecord:
       
   205 		parserState = aEndElement ? EEndOfRecord : EStartOfRecord;
       
   206 		break;
       
   207 		
       
   208 		case URIXMLTAGS::EUri:
       
   209 		parserState = aEndElement ? EEndOfUri : EStartOfUri;
       
   210 		break;
       
   211 
       
   212 		case URIXMLTAGS::EPermission:
       
   213 		parserState = aEndElement ? EEndOfPermission : EStartOfPermission;		
       
   214 		break;
       
   215 
       
   216 		case URIXMLTAGS::EFavouriteName:
       
   217 		parserState = aEndElement ? EEndOfFavouriteName : EStartOfFavouriteName;
       
   218 		break;
       
   219 		
       
   220 		default:
       
   221 		// Do nothing
       
   222 		break;
       
   223 		}	
       
   224 	myTagString.Close ();
       
   225 	return parserState;	
       
   226 	}
       
   227 
       
   228 void CUriListInitializer::SetServiceType ( TInt aIndex )
       
   229 	{
       
   230 	switch ( aIndex )
       
   231 		{
       
   232 		case URIXMLTAGS::EWapPush:
       
   233 		iInetUriImpl->Properties().SetServiceType (InetUriList::EWapPush);
       
   234 		break;
       
   235 		case URIXMLTAGS::EBrowser:
       
   236 		iInetUriImpl->Properties().SetServiceType (InetUriList::EBrowser);		
       
   237 		break;
       
   238 		case URIXMLTAGS::EDevPro:
       
   239 		iInetUriImpl->Properties().SetServiceType (InetUriList::EDevProv);		
       
   240 		break;
       
   241 		case URIXMLTAGS::EPushEMail:
       
   242 		iInetUriImpl->Properties().SetServiceType (InetUriList::EPushEMail);
       
   243 		break;
       
   244 		case URIXMLTAGS::EVoip:
       
   245 		iInetUriImpl->Properties().SetServiceType (InetUriList::EVoip);
       
   246 		break;
       
   247 		default:
       
   248 		User::Invariant ();				
       
   249 		}
       
   250 	}
       
   251 
       
   252 void CUriListInitializer::SetListType ( TInt aIndex )
       
   253 	{
       
   254 	switch ( aIndex )	
       
   255 		{
       
   256 		case URIXMLTAGS::EWhitelist:
       
   257 		iInetUriImpl->Properties().SetListType (InetUriList::EWhiteList);
       
   258 		break;
       
   259 		
       
   260 		case URIXMLTAGS::EBlacklist:
       
   261 		iInetUriImpl->Properties().SetListType (InetUriList::EBlackList);
       
   262 		break;
       
   263 		
       
   264 		default:
       
   265 		User::Invariant ();
       
   266 		}
       
   267 	}
       
   268 
       
   269 void CUriListInitializer::SetValueL ( const TDesC8& aValue )
       
   270 	{	
       
   271 	switch ( iParserState )		
       
   272 		{
       
   273 		case EStartOfUri:
       
   274 		case EStartOfFavouriteName:
       
   275 		iContent.Append ( aValue );
       
   276 		break;
       
   277 		
       
   278 		case EStartOfPermission:
       
   279 		iInetUriImpl->Properties().SetPermission (static_cast <InetUriList::TPermission> ( ConvertToInteger ( aValue ) ) );
       
   280 		break;
       
   281 				
       
   282 		case EEndOfUri:
       
   283 		if ( iContent.Length() > 0 )
       
   284 			{
       
   285 			iInetUriImpl->SetUriL ( iContent );
       
   286 			iContent.Zero ();			
       
   287 			}
       
   288 		break;
       
   289 		
       
   290 		case EEndOfFavouriteName:
       
   291 		if ( iContent.Length() > 0 )
       
   292 			{
       
   293 			iInetUriImpl->Properties().SetFavouriteNameL ( iContent );		
       
   294 			iContent.Zero ();		
       
   295 			}
       
   296 			break;
       
   297 			
       
   298 		default:
       
   299 		break;	// do nothing
       
   300 		}
       
   301 	}