Developer's Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
ccontenthandler.cpp
#include "ccontenthandler.h"
using namespace P6R;
P6DECLARE_IID( IContentHandlerInit );
namespace P6EXAMPLES {
CContentHandler::CContentHandler() : m_bInitialized( P6FALSE ),
m_cpStr(),
m_cpConsole(),
m_charState( 0 ),
m_startState( 0 ),
m_endState( 0 ),
m_startDoc( 0 ),
m_endDoc( 0 ),
m_startMapping( 0 ),
m_endMapping( 0 )
{ }
//
CContentHandler::~CContentHandler()
{
if (1 != m_endDoc && P6TRUE == m_bInitialized) {
P6ARG args[1];
P6AI_UINT32(&args[0],m_endDoc);
m_cpConsole->writeStdout("\nend of document - expected 1 but got %d\n",&args[0],1,NULL);
}
}
//
// P6COM Helper macro to provide the implementation
// of standard COM Methods:
//
// createInstance() - Used to easily create instance of this component.
// Using this method to create components is preferred
// because it returns an interface which provides
// a well defined API for this component and prevents
// access to the classes internals.
// queryInterface() - Used to query the component for interfaces
// addref() - Increased the interfaces reference count
// release() - Decreases the interfaces reference count
// and destroys the component when the count
// reaches zero.
//
// These helper macros are provided for convenience and currently support
// up to 17 interfaces (this example exposes 2 interfaces). The implementation
// provided by these macros are threadsafe. You can find the defintions
// in p6comhlpr.h. If you need something more that what they provide,
// you are always free implement your own methods.
//
// See CConsoleStream in this example (in ex-load-jsn.cpp) for a non-threadsafe
// example of implementing these methods.
//
// Please note that these macros may only be used in code that is called
// after p6InitializeLoader() has been called.
//
P6_IMPLEMENT_ICOM2(CContentHandler,IContentHandlerInit,p6ISAX2ContentHandler);
//
P6COMMETHODIMPL CContentHandler::initialize( P6R::p6IConsole *pConsole, P6R::p6ISafeString* pStr )
{
if (m_bInitialized) return eAlreadyInitialized;
if (NULL == pStr ) return eInvalidArg;
//
// p6ComPtr<> automatcally calls
// addref() on assignment.
//
m_cpConsole = pConsole;
m_cpStr = pStr;
m_bInitialized= P6TRUE;
return eOk;
}
//
P6COMMETHODIMPL CContentHandler::characters( P6SAX2STRING* pBuffer, P6SAX2METADATA meta )
{
P6INT32 iResult = -1;
P6ERR err = eOk;
P6ARG args[1];
if (!m_bInitialized) return eNotInitialized;
if (NULL == pBuffer) return eInvalidArg;
switch( m_charState ) {
case 0:
if (14 != pBuffer->length) {
P6AI_UINT32(&args[0],pBuffer->length);
m_cpConsole->writeStdout("characters() case 0: Expected 14 but got %d\n",&args[0],1,NULL);
}
err = m_cpStr->strncmp( " one two three", pBuffer->pStart, 14, &iResult );
if (0 != iResult) {
P6AI_INT32(&args[0],iResult);
m_cpConsole->writeStdout("characters() case 0: Expected 0 but got [ %1$ ]\n",&args[0],1,NULL);
}
break;
case 1:
if (22 != pBuffer->length) {
P6AI_UINT32(&args[0],pBuffer->length);
m_cpConsole->writeStdout("characters() case 1: Expected 22 but got %d\n",&args[0],1,NULL);
}
err = m_cpStr->strncmp( " four five si", pBuffer->pStart, 22, &iResult );
if (0 != iResult) {
P6AI_INT32(&args[0],iResult);
m_cpConsole->writeStdout("characters() case 1: Expected 0 but got [ %1$ ]\n",&args[0],1,NULL);
}
break;
case 2:
if (7 != pBuffer->length) {
P6AI_UINT32(&args[0],pBuffer->length);
m_cpConsole->writeStdout("characters() case 2: Expected 7 but got %d\n",&args[0],1,NULL);
}
err = m_cpStr->strncmp( "x seven", pBuffer->pStart, 7, &iResult );
if (0 != iResult) {
P6AI_INT32(&args[0],iResult);
m_cpConsole->writeStdout("characters() case 2: Expected 0 but got [ %1$ ]\n",&args[0],1,NULL);
}
break;
case 3:
if (5 != pBuffer->length) {
P6AI_UINT32(&args[0],pBuffer->length);
m_cpConsole->writeStdout("characters() case 3: Expected 5 but got %d\n",&args[0],1,NULL);
}
err = m_cpStr->strncmp( " ", pBuffer->pStart, 5, &iResult );
if (0 != iResult) {
P6AI_INT32(&args[0],iResult);
m_cpConsole->writeStdout("characters() case 3: Expected 0 but got [ %1$ ]\n",&args[0],1,NULL);
}
break;
case 4:
if (15 != pBuffer->length) {
P6AI_UINT32(&args[0],pBuffer->length);
m_cpConsole->writeStdout("characters() case 4: Expected 15 but got %d\n",&args[0],1,NULL);
}
err = m_cpStr->strncmp( "Now is the time", pBuffer->pStart, 15, &iResult );
if (0 != iResult) {
P6AI_INT32(&args[0],iResult);
m_cpConsole->writeStdout("characters() case 4: Expected 0 but got [ %1$ ]\n",&args[0],1,NULL);
}
break;
case 5:
if (16 != pBuffer->length) {
P6AI_UINT32(&args[0],pBuffer->length);
m_cpConsole->writeStdout("characters() case 5: Expected 16 but got %d\n",&args[0],1,NULL);
}
err = m_cpStr->strncmp( " for <all >good ", pBuffer->pStart, 16, &iResult );
if (0 != iResult) {
P6AI_INT32(&args[0],iResult);
m_cpConsole->writeStdout("characters() case 5: Expected 0 but got [ %1$ ]\n",&args[0],1,NULL);
}
break;
case 6:
if (23 != pBuffer->length) {
P6AI_UINT32(&args[0],pBuffer->length);
m_cpConsole->writeStdout("characters() case 6: Expected 23 but got %d\n",&args[0],1,NULL);
}
err = m_cpStr->strncmp( "men to come to the aid ", pBuffer->pStart, 23, &iResult );
if (0 != iResult) {
P6AI_INT32(&args[0],iResult);
m_cpConsole->writeStdout("characters() case 6: Expected 0 but got [ %1$ ]\n",&args[0],1,NULL);
}
break;
case 7:
if (1 != pBuffer->length) {
P6AI_UINT32(&args[0],pBuffer->length);
m_cpConsole->writeStdout("characters() case 7: Expected 1 but got %d\n",&args[0],1,NULL);
}
err = m_cpStr->strncmp( "&", pBuffer->pStart, 1, &iResult );
if (0 != iResult) {
P6AI_INT32(&args[0],iResult);
m_cpConsole->writeStdout("characters() case 7: Expected 0 but got [ %1$ ]\n",&args[0],1,NULL);
}
break;
case 8:
if (9 != pBuffer->length) {
P6AI_UINT32(&args[0],pBuffer->length);
m_cpConsole->writeStdout("characters() case 8: Expected 9 but got %d\n",&args[0],1,NULL);
}
err = m_cpStr->strncmp( " support.", pBuffer->pStart, 9, &iResult );
if (0 != iResult) {
P6AI_INT32(&args[0],iResult);
m_cpConsole->writeStdout("characters() case 9: Expected 0 but got [ %1$ ]\n",&args[0],1,NULL);
}
break;
default:
P6AI_UINT32(&args[0],m_charState);
m_cpConsole->writeStdout("Error: charState out of range got [ %1$ ]\n",&args[0],1,NULL);
break;
}
m_charState++;
P6AI_CHARPTR(&args[0],(1 == meta ? "CDATA" : "NONE"));
m_cpConsole->writeStdout("\n-> TOKEN_ELEMENT_VALUE meta:%1$\n",&args[0],1,NULL);
debugPrint( "-> TOKEN_ELEMENT_VALUE\n", pBuffer );
return err;
}
//
P6COMMETHODIMPL CContentHandler::endDocument()
{
if (!m_bInitialized) return eNotInitialized;
m_endDoc++;
m_cpConsole->writeStdout("-> TOKEN_END_DOCUMENT\n",NULL,0,NULL);
return eOk;
}
//
P6COMMETHODIMPL CContentHandler::endElement( P6SAX2STRING* pURI, P6SAX2STRING* pLocalName, P6SAX2STRING* pQName )
{
P6INT32 iResult = -1;
P6ERR err = eOk;
P6ARG args[1];
if (!m_bInitialized) return eNotInitialized;
if (NULL == pURI || NULL == pLocalName || NULL == pQName) return eInvalidArg;
switch( m_endState ) {
case 0:
if (7 != pQName->length) {
P6AI_UINT32(&args[0],pQName->length);
m_cpConsole->writeStdout("endElement() case 0: Expected 7 but got [ %1$ ]\n",&args[0],1,NULL);
}
err = m_cpStr->strncmp( "xslt:if", pQName->pStart, 7, &iResult );
if (0 != iResult) {
P6AI_INT32(&args[0],iResult);
m_cpConsole->writeStdout("endElement() case 0: Expected 0 but got [ %1$ ]\n",&args[0],1,NULL);
}
if (2 != pLocalName->length) {
P6AI_UINT32(&args[0],pLocalName->length);
m_cpConsole->writeStdout("endElement() case 0: Expected 2 but got [ %1$ ]\n",&args[0],1,NULL);
}
err = m_cpStr->strncmp( "if", pLocalName->pStart, 2, &iResult );
if (0 != iResult) {
P6AI_INT32(&args[0],iResult);
m_cpConsole->writeStdout("endElement() case 0: Expected 0 but got [ %1$ ]\n",&args[0],1,NULL);
}
if (36 != pURI->length) {
P6AI_UINT32(&args[0],pURI->length);
m_cpConsole->writeStdout("endElement() case 0: Expected 36 but got [ %1$ ]\n",&args[0],1,NULL);
}
err = m_cpStr->strncmp( "http://www.w3.org/1999/XSL/Transform", pURI->pStart, 36, &iResult );
if (0 != iResult) {
P6AI_INT32(&args[0],iResult);
m_cpConsole->writeStdout("endElement() case 0: Expected 0 but got [ %1$ ]\n",&args[0],1,NULL);
}
break;
case 1:
if (6 != pLocalName->length) {
P6AI_UINT32(&args[0],pLocalName->length);
m_cpConsole->writeStdout("endElement() case 1: Expected 6 but got [ %1$ ]\n",&args[0],1,NULL);
}
err = m_cpStr->strncmp( "second", pLocalName->pStart, 6, &iResult );
if (0 != iResult) {
P6AI_INT32(&args[0],iResult);
m_cpConsole->writeStdout("endElement() case 0: Expected 0 but got [ %1$ ]\n",&args[0],1,NULL);
}
break;
case 2:
if (5 != pLocalName->length) {
P6AI_UINT32(&args[0],pLocalName->length);
m_cpConsole->writeStdout("endElement() case 2: Expected 5 but got [ %1$ ]\n",&args[0],1,NULL);
}
err = m_cpStr->strncmp( "third", pLocalName->pStart, 5, &iResult );
if (0 != iResult) {
P6AI_INT32(&args[0],iResult);
m_cpConsole->writeStdout("endElement() case 0: Expected 0 but got [ %1$ ]\n",&args[0],1,NULL);
}
break;
case 3:
if (4 != pLocalName->length) {
P6AI_UINT32(&args[0],pLocalName->length);
m_cpConsole->writeStdout("endElement() case 3: Expected 5 but got [ %1$ ]\n",&args[0],1,NULL);
}
err = m_cpStr->strncmp( "test", pLocalName->pStart, 4, &iResult );
if (0 != iResult) {
P6AI_INT32(&args[0],iResult);
m_cpConsole->writeStdout("endElement() case 0: Expected 0 but got [ %1$ ]\n",&args[0],1,NULL);
}
break;
case 4:
if (5 != pLocalName->length) {
P6AI_UINT32(&args[0],pLocalName->length);
m_cpConsole->writeStdout("endElement() case 4: Expected 5 but got [ %1$ ]\n",&args[0],1,NULL);
}
err = m_cpStr->strncmp( "first", pLocalName->pStart, 5, &iResult );
if (0 != iResult) {
P6AI_INT32(&args[0],iResult);
m_cpConsole->writeStdout("endElement() case 0: Expected 0 but got [ %1$ ]\n",&args[0],1,NULL);
}
break;
default:
P6AI_UINT32(&args[0],m_endState);
m_cpConsole->writeStdout("Error: endState out of range got [ %1$ ]\n",&args[0],1,NULL);
break;
}
debugPrint( "\n-> TOKEN_END_ELEMENT QName ", pQName );
debugPrint( "-> TOKEN_END_ELEMENT localName ", pLocalName );
debugPrint( "-> TOKEN_END_ELEMENT URI ", pURI );
m_endState++;
return eOk;
}
//
P6COMMETHODIMPL CContentHandler::endPrefixMapping( P6SAX2STRING* pPrefix )
{
P6INT32 iResult = 0;
P6ERR err = eOk;
P6ARG args[1];
if (!m_bInitialized) return eNotInitialized;
if (NULL == pPrefix) return eInvalidArg;
debugPrint( "\n-> endPrefixMapping prefix ", pPrefix );
switch( m_endMapping ) {
case 0:
if (1 != pPrefix->length) {
P6AI_UINT32(&args[0],pPrefix->length);
m_cpConsole->writeStdout("endPrefixMapping() case 0: Expected 1 but got [ %1$ ]\n",&args[0],1,NULL);
}
err = m_cpStr->strncmp( "X", pPrefix->pStart, 1, &iResult );
if (0 != iResult) {
P6AI_INT32(&args[0],iResult);
m_cpConsole->writeStdout("endPrefixMapping() case 0: Expected 0 but got [ %1$ ]\n",&args[0],1,NULL);
}
break;
case 1:
if (4 != pPrefix->length) {
P6AI_UINT32(&args[0],pPrefix->length);
m_cpConsole->writeStdout("endPrefixMapping() case 1: Expected 4 but got [ %1$ ]\n",&args[0],1,NULL);
}
err = m_cpStr->strncmp( "xslt", pPrefix->pStart, 4, &iResult );
if (0 != iResult)
P6AI_INT32(&args[0],iResult);
m_cpConsole->writeStdout("endPrefixMapping() case 1: Expected 0 but got [ %1$ ]\n",&args[0],1,NULL);
break;
default:
P6AI_UINT32(&args[0],m_endState);
m_cpConsole->writeStdout("Error: endPrefixMapping() endState out of range got [ %1$ ]\n",&args[0],1,NULL);
break;
}
m_endMapping++;
return eOk;
}
//
P6COMMETHODIMPL CContentHandler::ignorableWhitespace( const P6CHAR* pBuffer, P6UINT32 start, P6UINT32 length )
{
P6ARG args[1];
if (!m_bInitialized) return eNotInitialized;
P6AI_UINT32(&args[0],length);
m_cpConsole->writeStdout("-> ignorableWhitespace, length:%1$\n",&args[0],1,NULL);
return eOk;
}
//
P6COMMETHODIMPL CContentHandler::processingInstruction( P6SAX2STRING* pTarget, P6SAX2STRING* pData )
{
if (!m_bInitialized) return eNotInitialized;
if (NULL == pTarget || NULL == pData) return eInvalidArg;
debugPrint( "\n-> processingInstruction target ", pTarget );
debugPrint( "-> processingInstruction target ", pData );
return eOk;
}
// p6ISax2Locator has several uses, one is to tell this content handler approximately what line
// and what character is the parser into the XML stream it is parsing. This can be used for
// error logging.
//
P6COMMETHODIMPL CContentHandler::setDocumentLocator( p6ISAX2Locator* pObject )
{
if (!m_bInitialized) return eNotInitialized;
if (NULL == pObject) return eInvalidArg;
m_cpConsole->writeStdout("-> setDocumentLocator\n",NULL,0,NULL);
return eOk;
}
//
P6COMMETHODIMPL CContentHandler::skippedEntity( P6SAX2STRING* pName )
{
if (!m_bInitialized) return eNotInitialized;
if (NULL == pName ) return eInvalidArg;
debugPrint( "-> skippedEntity ", pName );
return eOk;
}
//
P6COMMETHODIMPL CContentHandler::startDocument()
{
if (!m_bInitialized) return eNotInitialized;
m_startDoc++;
m_cpConsole->writeStdout("-> TOKEN_START_DOCUMENT\n",NULL,0,NULL);
return eOk;
}
//
P6COMMETHODIMPL CContentHandler::startElement( P6SAX2STRING* pURI,
P6SAX2STRING* pLocalName,
P6SAX2STRING* pQName,
P6SAX2STRING* pRawElement,
)
{
P6ERR err = eOk;
P6UINT32 attribCount = 0;
P6INT32 iResult = -1;
P6SAX2STRING value;
P6ARG args[1];
if (!m_bInitialized) return eNotInitialized;
if (NULL == pURI || NULL == pLocalName || NULL == pQName) return eInvalidArg;
if (m_startDoc != 1) {
P6AI_UINT32(&args[0],m_startDoc);
m_cpConsole->writeStdout("startElement() Expected 1 but got %1$",&args[0],1,NULL);
}
switch( m_startState ) {
case 0:
if (5 != pLocalName->length) {
P6AI_UINT32(&args[0],pLocalName->length);
m_cpConsole->writeStdout("startElement() case 0: Expected 5 but got [ %1$ ]\n",&args[0],1,NULL);
}
err = m_cpStr->strncmp( "first", pLocalName->pStart, 5, &iResult );
if (0 != iResult) {
P6AI_INT32(&args[0],iResult);
m_cpConsole->writeStdout("startElement() case 0: Expected 0 but got [ %1$ ]\n",&args[0],1,NULL);
}
break;
case 1:
if (6 != pLocalName->length) {
P6AI_UINT32(&args[0],pLocalName->length);
m_cpConsole->writeStdout("startElement() case 1: Expected 6 but got [ %1$ ]\n",&args[0],1,NULL);
}
err = m_cpStr->strncmp( "second", pLocalName->pStart, 5, &iResult );
if (0 != iResult) {
P6AI_INT32(&args[0],iResult);
m_cpConsole->writeStdout("startElement() case 1: Expected 0 but got [ %1$ ]\n",&args[0],1,NULL);
}
break;
case 2:
if (2 != pLocalName->length) {
P6AI_UINT32(&args[0],pLocalName->length);
m_cpConsole->writeStdout("startElement() case 2: Expected 2 but got [ %1$ ]\n",&args[0],1,NULL);
}
err = m_cpStr->strncmp( "if", pLocalName->pStart, 5, &iResult );
if (0 != iResult) {
P6AI_INT32(&args[0],iResult);
m_cpConsole->writeStdout("startElement() case 2: Expected 0 but got [ %1$ ]\n",&args[0],1,NULL);
}
break;
case 3:
if (5 != pLocalName->length) {
P6AI_UINT32(&args[0],pLocalName->length);
m_cpConsole->writeStdout("startElement() case 3: Expected 5 but got [ %1$ ]\n",&args[0],1,NULL);
}
err = m_cpStr->strncmp( "third", pLocalName->pStart, 4, &iResult );
if (0 != iResult) {
P6AI_INT32(&args[0],iResult);
m_cpConsole->writeStdout("startElement() case 3: Expected 0 but got [ %1$ ]\n",&args[0],1,NULL);
}
break;
case 4:
if (4 != pLocalName->length) {
P6AI_UINT32(&args[0],pLocalName->length);
m_cpConsole->writeStdout("startElement() case 4: Expected 4 but got [ %1$ ]\n",&args[0],1,NULL);
}
err = m_cpStr->strncmp( "test", pLocalName->pStart, 5, &iResult );
if (0 != iResult) {
P6AI_INT32(&args[0],iResult);
m_cpConsole->writeStdout("startElement() case 4: Expected 0 but got [ %1$ ]\n",&args[0],1,NULL);
}
break;
default:
P6AI_UINT32(&args[0],m_startState);
m_cpConsole->writeStdout("Error: startElement() startState out of range got [ %1$ ]\n",&args[0],1,NULL);
break;
}
debugPrint( "\n-> TOKEN_START_ELEMENT QName ", pQName );
debugPrint( "-> TOKEN_START_ELEMENT localName ", pLocalName );
debugPrint( "-> TOKEN_START_ELEMENT URI ", pURI );
// -> verify attributes on the start of am element, if any
if (NULL != pAtts)
{
if (P6FAILED( err = pAtts->getLength( &attribCount ))) return err;
for( P6UINT32 i=0; i < attribCount; i++ )
{
if (P6FAILED( err = pAtts->getQName( i, &name ))) return err;
if (P6FAILED( err = pAtts->getValueByIndex( i, &value ))) return err;
switch( m_startState ) {
case 0:
if (0 != i) {
P6AI_UINT32(&args[0],i);
m_cpConsole->writeStdout("out of range got %1$",&args[0],1,NULL);
}
if (10 != name.length) {
P6AI_UINT32(&args[0],name.length);
m_cpConsole->writeStdout("Expected 10 but got %1$",&args[0],1,NULL);
}
err = m_cpStr->strncmp( "xmlns:xslt", name.pStart, 10, &iResult );
if (0 != iResult) {
P6AI_INT32(&args[0],iResult);
m_cpConsole->writeStdout("startElement() verify attributes case 0: Expected 0 but got [ %1$ ]\n",&args[0],1,NULL);
}
if (36 != value.length) {
P6AI_UINT32(&args[0],value.length);
m_cpConsole->writeStdout("Expected 36 but got %1$",&args[0],1,NULL);
}
err = m_cpStr->strncmp( "http://www.w3.org/1999/XSL/Transform", value.pStart, 36, &iResult );
if (0 != iResult) {
P6AI_INT32(&args[0],iResult);
m_cpConsole->writeStdout("startElement() verify attributes case 0: Expected 0 but got [ %1$ ]\n",&args[0],1,NULL);
}
break;
case 1:
if (0 == i)
{
if (4 != name.length) {
P6AI_UINT32(&args[0],name.length);
m_cpConsole->writeStdout("Expected 4 but got %1$",&args[0],1,NULL);
}
err = m_cpStr->strncmp( "temp", name.pStart, 4, &iResult );
if (0 != iResult) {
P6AI_INT32(&args[0],iResult);
m_cpConsole->writeStdout("startElement() verify attributes case 1: Expected 0 but got [ %1$ ]\n",&args[0],1,NULL);
}
if (2 != value.length) {
P6AI_UINT32(&args[0],value.length);
m_cpConsole->writeStdout("Expected 2 but got %1$",&args[0],1,NULL);
}
err = m_cpStr->strncmp( "55", value.pStart, 2, &iResult );
if (0 != iResult) {
P6AI_INT32(&args[0],iResult);
m_cpConsole->writeStdout("startElement() verify attributes case 1: Expected 0 but got [ %1$ ]\n",&args[0],1,NULL);
}
}
else if (1 == i)
{
if (7 != name.length) {
P6AI_UINT32(&args[0],name.length);
m_cpConsole->writeStdout("Expected 7 but got %1$",&args[0],1,NULL);
}
err = m_cpStr->strncmp( "xmlns:X", name.pStart, 7, &iResult );
if (0 != iResult) {
P6AI_INT32(&args[0],iResult);
m_cpConsole->writeStdout("startElement() verify attributes case 1: Expected 0 but got [ %1$ ]\n",&args[0],1,NULL);
}
if (31 != value.length) {
P6AI_UINT32(&args[0],value.length);
m_cpConsole->writeStdout("Expected 31 but got %1$",&args[0],1,NULL);
}
err = m_cpStr->strncmp( "http://www.w3.org/TR/REC-html40", value.pStart, 31, &iResult );
if (0 != iResult) {
P6AI_INT32(&args[0],iResult);
m_cpConsole->writeStdout("startElement() verify attributes case 1: Expected 0 but got [ %1$ ]\n",&args[0],1,NULL);
}
}
break;
case 2:
if (0 != i) {
P6AI_UINT32(&args[0],i);
m_cpConsole->writeStdout("out of range got %1$",&args[0],1,NULL);
}
if (4 != name.length) {
P6AI_UINT32(&args[0],name.length);
m_cpConsole->writeStdout("Expected 4 but got %1$",&args[0],1,NULL);
}
err = m_cpStr->strncmp( "test", name.pStart, 4, &iResult );
if (0 != iResult) {
P6AI_INT32(&args[0],iResult);
m_cpConsole->writeStdout("startElement() verify attributes case 2: Expected 0 but got [ %1$ ]\n",&args[0],1,NULL);
}
if (3 != value.length) {
P6AI_UINT32(&args[0],value.length);
m_cpConsole->writeStdout("Expected 3 but got %1$",&args[0],1,NULL);
}
err = m_cpStr->strncmp( "123", value.pStart, 3, &iResult );
if (0 != iResult) {
P6AI_INT32(&args[0],iResult);
m_cpConsole->writeStdout("startElement() verify attributes case 2: Expected 0 but got [ %1$ ]\n",&args[0],1,NULL);
}
break;
case 3:
if (0 == i)
{
if (5 != name.length) {
P6AI_UINT32(&args[0],name.length);
m_cpConsole->writeStdout("Expected 5 but got %1$",&args[0],1,NULL);
}
err = m_cpStr->strncmp( "color", name.pStart, 5, &iResult );
if (0 != iResult) {
P6AI_INT32(&args[0],iResult);
m_cpConsole->writeStdout("startElement() verify attributes case 3: Expected 0 but got [ %1$ ]\n",&args[0],1,NULL);
}
if (7 != value.length) {
P6AI_UINT32(&args[0],value.length);
m_cpConsole->writeStdout("Expected 7 but got %1$",&args[0],1,NULL);
}
err = m_cpStr->strncmp( "> green", value.pStart, 7, &iResult );
if (0 != iResult) {
P6AI_INT32(&args[0],iResult);
m_cpConsole->writeStdout("startElement() verify attributes case 3: Expected 0 but got [ %1$ ]\n",&args[0],1,NULL);
}
}
else if (1 == i)
{
if (4 != name.length) {
P6AI_UINT32(&args[0],name.length);
m_cpConsole->writeStdout("Expected 4 but got %1$",&args[0],1,NULL);
}
err = m_cpStr->strncmp( "name", name.pStart, 4, &iResult );
if (0 != iResult) {
P6AI_INT32(&args[0],iResult);
m_cpConsole->writeStdout("startElement() verify attributes case 3: Expected 0 but got [ %1$ ]\n",&args[0],1,NULL);
}
if (9 != value.length) {
P6AI_UINT32(&args[0],value.length);
m_cpConsole->writeStdout("Expected 9 but got %1$",&args[0],1,NULL);
}
err = m_cpStr->strncmp( "Jon Smith", value.pStart, 9, &iResult );
if (0 != iResult) {
P6AI_INT32(&args[0],iResult);
m_cpConsole->writeStdout("startElement() verify attributes case 3: Expected 0 but got [ %1$ ]\n",&args[0],1,NULL);
}
}
else if (2 == i)
{
if (6 != name.length) {
P6AI_UINT32(&args[0],name.length);
m_cpConsole->writeStdout("Expected 6 but got %1$",&args[0],1,NULL);
}
err = m_cpStr->strncmp( "weight", name.pStart, 6, &iResult );
if (0 != iResult) {
P6AI_INT32(&args[0],iResult);
m_cpConsole->writeStdout("startElement() verify attributes case 3: Expected 0 but got [ %1$ ]\n",&args[0],1,NULL);
}
if (4 != value.length) {
P6AI_UINT32(&args[0],value.length);
m_cpConsole->writeStdout("Expected 4 but got %1$",&args[0],1,NULL);
}
err = m_cpStr->strncmp( "3453", value.pStart, 4, &iResult );
if (0 != iResult) {
P6AI_INT32(&args[0],iResult);
m_cpConsole->writeStdout("startElement() verify attributes case 3: Expected 0 but got [ %1$ ]\n",&args[0],1,NULL);
}
}
else
{
P6AI_UINT32(&args[0],i);
m_cpConsole->writeStdout("attribs - out of range got %1$",&args[0],1,NULL);
}
break;
default:
P6AI_UINT32(&args[0],m_startState);
m_cpConsole->writeStdout("Error: startState out of range got [ %1$ ]\n",&args[0],1,NULL);
break;
}
debugPrint( "startElement: attribute QName ", &name );
debugPrint( "startElement: attribute value ", &value );
}
}
m_startState++;
return eOk;
}
//
P6COMMETHODIMPL CContentHandler::startPrefixMapping( P6SAX2STRING* pPrefix, P6SAX2STRING* pURI )
{
P6INT32 iResult = 0;
P6ERR err = eOk;
P6ARG args[1];
if (!m_bInitialized) return eNotInitialized;
if (NULL == pPrefix || NULL == pURI) return eInvalidArg;
debugPrint( "\n-> startPrefixMapping prefix ", pPrefix );
debugPrint( "-> startPrefixMapping URI ", pURI );
switch( m_startMapping ) {
case 0:
if (4 != pPrefix->length) {
P6AI_UINT32(&args[0],pPrefix->length);
m_cpConsole->writeStdout("Expected 4 but got %1$",&args[0],1,NULL);
}
err = m_cpStr->strncmp( "xslt", pPrefix->pStart, 4, &iResult );
if (0 != iResult) {
P6AI_INT32(&args[0],iResult);
m_cpConsole->writeStdout("startPrefixMapping() case 0: Expected 0 but got [ %1$ ]\n",&args[0],1,NULL);
}
if (36 != pURI->length) {
P6AI_UINT32(&args[0],pURI->length);
m_cpConsole->writeStdout("Expected 36 but got %1$",&args[0],1,NULL);
}
err = m_cpStr->strncmp( "http://www.w3.org/1999/XSL/Transform", pURI->pStart, 36, &iResult );
if (0 != iResult) {
P6AI_INT32(&args[0],iResult);
m_cpConsole->writeStdout("startPrefixMapping() case 0: Expected 0 but got [ %1$ ]\n",&args[0],1,NULL);
}
break;
case 1:
if (1 != pPrefix->length) {
P6AI_UINT32(&args[0],pPrefix->length);
m_cpConsole->writeStdout("Expected 1 but got %1$",&args[0],1,NULL);
}
err = m_cpStr->strncmp( "X", pPrefix->pStart, 1, &iResult );
if (0 != iResult) {
P6AI_INT32(&args[0],iResult);
m_cpConsole->writeStdout("startPrefixMapping() case 1: Expected 0 but got [ %1$ ]\n",&args[0],1,NULL);
}
if (31 != pURI->length) {
P6AI_UINT32(&args[0],pURI->length);
m_cpConsole->writeStdout("Expected 31 but got %1$",&args[0],1,NULL);
}
err = m_cpStr->strncmp( "http://www.w3.org/TR/REC-html40", pURI->pStart, 31, &iResult );
if (0 != iResult) {
P6AI_INT32(&args[0],iResult);
m_cpConsole->writeStdout("startPrefixMapping() case 1: Expected 0 but got [ %1$ ]\n",&args[0],1,NULL);
}
break;
default:
P6AI_UINT32(&args[0],m_startMapping);
m_cpConsole->writeStdout("Error: startMapping out of range got [ %1$ ]\n",&args[0],1,NULL);
break;
}
m_startMapping++;
return eOk;
}
// The P6SAX2STRING pointers point into the original XML documents so the tokens passed to this
// content handler are NOT NULL terminated strings. This function just prints out the token without the
// trailing rest of the XML input.
//
P6R::P6VOID CContentHandler::debugPrint( const P6CHAR* pHeader, P6SAX2STRING* pString )
{
P6BCSTR bStr;
P6ARG args[3];
if ( NULL != pString && NULL != pString->pStart) {
P6AI_CHARPTR(&args[0],pHeader);
bStr.pString = (const P6UCHAR*)pString->pStart;
bStr.length = pString->length;
P6AI_BCSTR(&args[1],&bStr);
P6AI_SIZE(&args[2],bStr.length);
m_cpConsole->writeStdout("%1$ [%2$] (%3$)\n",&args[0],3,NULL);
}
else {
P6AI_CHARPTR(&args[0],pHeader);
m_cpConsole->writeStdout("%1$ []\n",&args[0],1,NULL);
}
}
} // namespace