servicediscoveryandcontrol/pnp/test/upnp/upnpdescription/src/parsehandlerbase.cpp
changeset 0 f5a58ecadc66
equal deleted inserted replaced
-1:000000000000 0:f5a58ecadc66
       
     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 "parsehandlerbase.h"
       
    17 CParseHandlerBase::~CParseHandlerBase()
       
    18 	{
       
    19 	delete iChildParser;
       
    20 	iString.Close();
       
    21 	}
       
    22 	
       
    23 void CParseHandlerBase::StartChildParserL(CParseHandlerBase* aChildParser, const RTagInfo& aElement, const RAttributeArray& aAttributes)
       
    24 	{
       
    25 	if(iChildParser)
       
    26 		{
       
    27 		User::Leave(KErrCorrupt);
       
    28 		}
       
    29 	else
       
    30 		{
       
    31 		delete iChildParser;
       
    32 		iChildParser = aChildParser;
       
    33 		iChildParser->ParseStartElementL(aElement, aAttributes);		
       
    34 		}
       
    35 	}
       
    36 
       
    37 void CParseHandlerBase::OnContentL(const TDesC8& aBytes, TInt aErrorCode)
       
    38 	{
       
    39 	if(iChildParser)
       
    40 		{
       
    41 		iChildParser->OnContentL(aBytes, aErrorCode);
       
    42 		}
       
    43 	else
       
    44 		{
       
    45 		User::LeaveIfError(aErrorCode);
       
    46 		ParseContentL(aBytes);
       
    47 		}
       
    48 	}
       
    49 	
       
    50 	
       
    51 void CParseHandlerBase::OnStartElementL(const RTagInfo& aElement, const RAttributeArray& aAttributes, TInt aErrorCode)
       
    52 	{
       
    53 	if(iChildParser)
       
    54 		{
       
    55 		// If the child handler is present get it to parse the tags
       
    56 		iChildParser->OnStartElementL(aElement, aAttributes, aErrorCode);
       
    57 		}
       
    58 	else
       
    59 		{
       
    60 		User::LeaveIfError(aErrorCode);
       
    61 		ParseStartElementL(aElement, aAttributes);	
       
    62 		}
       
    63 	}
       
    64 	
       
    65 void CParseHandlerBase::OnEndElementL(const RTagInfo& aElement, TInt aErrorCode)
       
    66 	{
       
    67 	if(iChildParser)
       
    68 		{
       
    69 		iChildParser->OnEndElementL(aElement, aErrorCode);
       
    70 		if(!iChildParser->SiblingCount())
       
    71 			{
       
    72 			// finished with child parser handler
       
    73 			delete iChildParser;
       
    74 			iChildParser = NULL;
       
    75 			}
       
    76 		}	
       
    77 	else
       
    78 		{
       
    79 		// Overriden by derived classes to implement specific behavior for an end tag
       
    80 		User::LeaveIfError(aErrorCode);
       
    81 		ParseEndElementL(aElement);
       
    82 		}
       
    83 	}
       
    84 
       
    85 void CParseHandlerBase::OnStartPrefixMappingL(const RString& aPrefix, const RString& aUri, TInt aErrorCode)
       
    86 	{
       
    87 	User::LeaveIfError(aErrorCode);
       
    88 	if(iChildParser)
       
    89 		{
       
    90 		iChildParser->OnStartPrefixMappingL( aPrefix , aUri, aErrorCode );
       
    91 		}
       
    92 	else
       
    93 		ParsePrefixL( aPrefix , aUri );
       
    94 	}
       
    95 
       
    96 TBool CParseHandlerBase::IsBlankSpace(const TDesC8& aBytes)
       
    97 	{
       
    98 	RBuf8 trimBuf;
       
    99 	TBool retValue = EFalse;
       
   100 	trimBuf.Create(aBytes);
       
   101 	trimBuf.Trim();
       
   102 	
       
   103 	if(!trimBuf.Length())
       
   104 		retValue = ETrue;
       
   105 	trimBuf.Close();
       
   106 	
       
   107 	return retValue;
       
   108 	}
       
   109 
       
   110