xml/xmlfw/test/rtest/tsrc/t_parser.cpp
changeset 0 e35f40988205
equal deleted inserted replaced
-1:000000000000 0:e35f40988205
       
     1 // Copyright (c) 2003-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 <e32std.h>
       
    17 #include <ecom/implementationproxy.h>
       
    18 
       
    19 #include <xml/xmlframeworkerrors.h>
       
    20 #include <xml/wbxmlextensionhandler.h>
       
    21 #include <xml/stringdictionarycollection.h>
       
    22 #include <xml/taginfo.h>
       
    23 #include <xml/attribute.h>
       
    24 #include <xml/documentparameters.h>
       
    25 #include <xml/contenthandler.h>
       
    26 #include <xml/plugins/parserinterface.h>
       
    27 #include <xml/plugins/parserinitparams.h>
       
    28 
       
    29 #include "t_testconstants.h"
       
    30 
       
    31 using namespace Xml;
       
    32 
       
    33 class CDummyParser : public CBase, public MParser
       
    34 	{
       
    35 public:
       
    36 
       
    37 	static MParser* NewL(TAny* aInitParams);
       
    38 	virtual ~CDummyParser();
       
    39 
       
    40 	// From MParser
       
    41 
       
    42 	TInt EnableFeature(TInt /*aParserFeature*/)
       
    43 		{
       
    44 		return KErrNotSupported;
       
    45 		}
       
    46 	TInt DisableFeature(TInt /*aParserFeature*/)
       
    47 		{
       
    48 		return KErrNone;
       
    49 		}
       
    50 	TBool IsFeatureEnabled(TInt /*aParserFeature*/) const
       
    51 		{
       
    52 		return EFalse;
       
    53 		}
       
    54 	void Release();
       
    55 	void ParseChunkL (const TDesC8& aDescriptor);
       
    56 	void ParseLastChunkL(const TDesC8& aDescriptor);
       
    57 
       
    58 	// From MContentSouce
       
    59 	
       
    60 	void SetContentSink (MContentHandler& aContentHandler);
       
    61 
       
    62 	RStringPool& StringPool();
       
    63 
       
    64 private:
       
    65 
       
    66 	CDummyParser(TParserInitParams* aInitParams);
       
    67 	void DoParseL();
       
    68 
       
    69 	inline void OnStartDocumentL();
       
    70 	inline void OnEndDocumentL();
       
    71 	inline void OnStartElementL();
       
    72 	inline void OnEndElementL();
       
    73 	inline void OnContentL();
       
    74 	inline void OnStartPrefixMappingL();
       
    75 	inline void OnEndPrefixMappingL();
       
    76 	inline void OnIgnorableWhiteSpaceL();
       
    77 	inline void OnSkippedEntityL();
       
    78 	inline void OnProcessingInstructionL();
       
    79 	inline void OnExtensionL();
       
    80 	inline void OnError(TInt aError);
       
    81 
       
    82 private:
       
    83 	MContentHandler*	iContentHandler;
       
    84 	RStringDictionaryCollection*		iStringDictionaryCollection;
       
    85 	CCharSetConverter* iCharSetConverter;
       
    86 	RElementStack* iElementStack;
       
    87 	};
       
    88 
       
    89 MParser* CDummyParser::NewL(TAny* aInitParams)
       
    90 	{
       
    91 
       
    92 	CDummyParser* self = new(ELeave) CDummyParser(reinterpret_cast<TParserInitParams*>(aInitParams));
       
    93 	return (static_cast<MParser*>(self));
       
    94 	}
       
    95 
       
    96 
       
    97 
       
    98 CDummyParser::CDummyParser(TParserInitParams* aInitParams)
       
    99 :	iContentHandler (reinterpret_cast<MContentHandler*>(aInitParams->iContentHandler)),
       
   100 	iStringDictionaryCollection (reinterpret_cast<RStringDictionaryCollection*>(aInitParams->iStringDictionaryCollection)),
       
   101 	iCharSetConverter (reinterpret_cast<CCharSetConverter*>(aInitParams->iCharSetConverter)),
       
   102 	iElementStack (reinterpret_cast<RElementStack*>(aInitParams->iElementStack))
       
   103 	{
       
   104 	}
       
   105 
       
   106 
       
   107 void CDummyParser::Release()
       
   108 	{
       
   109 	delete (this);
       
   110 	}
       
   111 
       
   112 
       
   113 
       
   114 CDummyParser::~CDummyParser()
       
   115 	{
       
   116 	// We don't own this
       
   117 	iContentHandler = NULL;
       
   118 	iStringDictionaryCollection = NULL;
       
   119 	iCharSetConverter = NULL;
       
   120 	iElementStack = NULL;
       
   121 	}
       
   122 
       
   123 
       
   124 void CDummyParser::ParseChunkL (const TDesC8& /*aDescriptor*/)
       
   125 	{
       
   126 	DoParseL();
       
   127 	}
       
   128 	
       
   129 	
       
   130 void CDummyParser::ParseLastChunkL(const TDesC8& /*aDescriptor*/)
       
   131 	{
       
   132 	DoParseL();
       
   133 	}
       
   134 
       
   135 
       
   136 RStringPool& CDummyParser::StringPool()
       
   137 	{
       
   138 	return iStringDictionaryCollection->StringPool();
       
   139 	}
       
   140 	
       
   141 
       
   142 
       
   143 void CDummyParser::SetContentSink (MContentHandler& aContentHandler)
       
   144 /**
       
   145 This method allows for the correct streaming of data to another plugin in the chain.
       
   146 
       
   147 @post				the next plugin in the chain is set to receive our callbacks.
       
   148 
       
   149 */
       
   150 	{
       
   151 	iContentHandler = &aContentHandler;
       
   152 	}
       
   153 
       
   154 
       
   155 
       
   156 void CDummyParser::DoParseL()
       
   157 	{
       
   158 	OnStartDocumentL();
       
   159 	OnEndDocumentL();
       
   160 	OnStartElementL();
       
   161 	OnEndElementL();
       
   162 	OnContentL();
       
   163 	OnStartPrefixMappingL();
       
   164 	OnEndPrefixMappingL();
       
   165 	OnIgnorableWhiteSpaceL();
       
   166 	OnSkippedEntityL();
       
   167 	OnProcessingInstructionL();
       
   168 	OnExtensionL();
       
   169 	//OnError(KErrEof);
       
   170 	}
       
   171 
       
   172 
       
   173 
       
   174 void CDummyParser::OnStartDocumentL()
       
   175 	{
       
   176 	RDocumentParameters documentParameters;
       
   177 
       
   178 	iContentHandler->OnStartDocumentL(documentParameters, KErrorCodeOnStartDocument);
       
   179 	}
       
   180 
       
   181 
       
   182 void CDummyParser::OnEndDocumentL()
       
   183 	{
       
   184 	iContentHandler->OnEndDocumentL(KErrorCodeOnEndDocument);
       
   185 	}
       
   186 
       
   187 
       
   188 
       
   189 void CDummyParser::OnStartElementL()
       
   190 	{
       
   191 	RTagInfo element;
       
   192 	RAttributeArray attributes;
       
   193 
       
   194 	iContentHandler->OnStartElementL(element, attributes, KErrorCodeOnStartElement);
       
   195 	}
       
   196 	
       
   197 
       
   198 void CDummyParser::OnEndElementL()
       
   199 	{
       
   200 	RTagInfo element;
       
   201 
       
   202 	iContentHandler->OnEndElementL(element, KErrorCodeOnEndElement);
       
   203 	}
       
   204 
       
   205 
       
   206 
       
   207 void CDummyParser::OnContentL()
       
   208 	{
       
   209 	const TBuf8<2> bytes;
       
   210 
       
   211 	iContentHandler->OnContentL(bytes, KErrorCodeOnContent);
       
   212 	}
       
   213 
       
   214 
       
   215 
       
   216 void CDummyParser::OnStartPrefixMappingL()
       
   217 	{
       
   218 	RString prefix;
       
   219 	RString uri;
       
   220 
       
   221 	iContentHandler->OnStartPrefixMappingL(prefix, uri, KErrorCodeOnStartPrefixMapping);
       
   222 	}
       
   223 
       
   224 
       
   225 void CDummyParser::OnEndPrefixMappingL()
       
   226 	{
       
   227 	RString prefix;
       
   228 
       
   229 	iContentHandler->OnEndPrefixMappingL(prefix, KErrorCodeOnEndPrefixMapping);
       
   230 	}
       
   231 
       
   232 
       
   233 
       
   234 void CDummyParser::OnIgnorableWhiteSpaceL()
       
   235 	{
       
   236 	const TBuf8<2> bytes;
       
   237 
       
   238 	iContentHandler->OnIgnorableWhiteSpaceL(bytes, KErrorCodeOnIgnorableWhiteSpace);
       
   239 	}
       
   240 
       
   241 
       
   242 
       
   243 void CDummyParser::OnSkippedEntityL()
       
   244 	{
       
   245 	RString name;
       
   246 
       
   247 	iContentHandler->OnSkippedEntityL(name, KErrorCodeOnSkippedEntity);
       
   248 	}
       
   249 
       
   250 
       
   251 
       
   252 void CDummyParser::OnProcessingInstructionL()
       
   253 	{
       
   254 	TBuf8<2> target;
       
   255 	TBuf8<2> data;
       
   256 
       
   257 	iContentHandler->OnProcessingInstructionL(target, data, KErrorCodeOnProcessingInstruction);
       
   258 	}
       
   259 
       
   260 
       
   261 void CDummyParser::OnExtensionL()
       
   262 	{
       
   263 	RString data;
       
   264 	TInt token = 0;
       
   265 
       
   266 	MWbxmlExtensionHandler* ptr = 
       
   267 		static_cast<MWbxmlExtensionHandler*>
       
   268 			(iContentHandler->GetExtendedInterface(MWbxmlExtensionHandler::EExtInterfaceUid));
       
   269 
       
   270 	if (!ptr)
       
   271 		{
       
   272 		User::Leave(KErrXmlUnsupportedExtInterface);
       
   273 		}
       
   274 		
       
   275 	ptr->OnExtensionL(data, token, KErrorCodeOnExtension);	
       
   276 	}
       
   277 
       
   278 
       
   279 void CDummyParser::OnError(TInt aError)
       
   280 	{
       
   281 	iContentHandler->OnError(aError);
       
   282 	}
       
   283 
       
   284 
       
   285 // __________________________________________________________________________
       
   286 // Exported proxy for instantiation method resolution
       
   287 // Define the interface UIDs
       
   288 const TImplementationProxy ImplementationTable[] = {
       
   289 	IMPLEMENTATION_PROXY_ENTRY(0x101FBE53,CDummyParser::NewL)
       
   290 };
       
   291 
       
   292 EXPORT_C const TImplementationProxy* ImplementationGroupProxy(TInt& aTableCount)
       
   293 	{
       
   294 	aTableCount = sizeof(ImplementationTable) / sizeof(TImplementationProxy);
       
   295 
       
   296 	return ImplementationTable;
       
   297 	}
       
   298