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