#include "ccontenthandler.h"
using namespace P6R;
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) {
m_cpConsole->writeStdout("\nend of document - expected 1 but got %d\n",&args[0],1,NULL);
}
}
{
if (m_bInitialized) return eAlreadyInitialized;
if (NULL == pStr ) return eInvalidArg;
m_cpConsole = pConsole;
m_cpStr = pStr;
return eOk;
}
{
if (!m_bInitialized) return eNotInitialized;
if (NULL == pBuffer) return eInvalidArg;
switch( m_charState ) {
case 0:
if (14 != 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) {
m_cpConsole->writeStdout("characters() case 0: Expected 0 but got [ %1$ ]\n",&args[0],1,NULL);
}
break;
case 1:
if (22 != 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) {
m_cpConsole->writeStdout("characters() case 1: Expected 0 but got [ %1$ ]\n",&args[0],1,NULL);
}
break;
case 2:
if (7 != 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) {
m_cpConsole->writeStdout("characters() case 2: Expected 0 but got [ %1$ ]\n",&args[0],1,NULL);
}
break;
case 3:
if (5 != 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) {
m_cpConsole->writeStdout("characters() case 3: Expected 0 but got [ %1$ ]\n",&args[0],1,NULL);
}
break;
case 4:
if (15 != 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) {
m_cpConsole->writeStdout("characters() case 4: Expected 0 but got [ %1$ ]\n",&args[0],1,NULL);
}
break;
case 5:
if (16 != 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) {
m_cpConsole->writeStdout("characters() case 5: Expected 0 but got [ %1$ ]\n",&args[0],1,NULL);
}
break;
case 6:
if (23 != 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) {
m_cpConsole->writeStdout("characters() case 6: Expected 0 but got [ %1$ ]\n",&args[0],1,NULL);
}
break;
case 7:
if (1 != 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) {
m_cpConsole->writeStdout("characters() case 7: Expected 0 but got [ %1$ ]\n",&args[0],1,NULL);
}
break;
case 8:
if (9 != 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) {
m_cpConsole->writeStdout("characters() case 9: Expected 0 but got [ %1$ ]\n",&args[0],1,NULL);
}
break;
default:
m_cpConsole->writeStdout("Error: charState out of range got [ %1$ ]\n",&args[0],1,NULL);
break;
}
m_charState++;
m_cpConsole->writeStdout("\n-> TOKEN_ELEMENT_VALUE meta:%1$\n",&args[0],1,NULL);
debugPrint( "-> TOKEN_ELEMENT_VALUE\n", pBuffer );
return err;
}
{
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 )
{
if (!m_bInitialized) return eNotInitialized;
if (NULL == pURI || NULL == pLocalName || NULL == pQName) return eInvalidArg;
switch( m_endState ) {
case 0:
if (7 != 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) {
m_cpConsole->writeStdout("endElement() case 0: Expected 0 but got [ %1$ ]\n",&args[0],1,NULL);
}
if (2 != 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) {
m_cpConsole->writeStdout("endElement() case 0: Expected 0 but got [ %1$ ]\n",&args[0],1,NULL);
}
if (36 != 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) {
m_cpConsole->writeStdout("endElement() case 0: Expected 0 but got [ %1$ ]\n",&args[0],1,NULL);
}
break;
case 1:
if (6 != 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) {
m_cpConsole->writeStdout("endElement() case 0: Expected 0 but got [ %1$ ]\n",&args[0],1,NULL);
}
break;
case 2:
if (5 != 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) {
m_cpConsole->writeStdout("endElement() case 0: Expected 0 but got [ %1$ ]\n",&args[0],1,NULL);
}
break;
case 3:
if (4 != 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) {
m_cpConsole->writeStdout("endElement() case 0: Expected 0 but got [ %1$ ]\n",&args[0],1,NULL);
}
break;
case 4:
if (5 != 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) {
m_cpConsole->writeStdout("endElement() case 0: Expected 0 but got [ %1$ ]\n",&args[0],1,NULL);
}
break;
default:
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;
}
{
if (!m_bInitialized) return eNotInitialized;
if (NULL == pPrefix) return eInvalidArg;
debugPrint( "\n-> endPrefixMapping prefix ", pPrefix );
switch( m_endMapping ) {
case 0:
if (1 != 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) {
m_cpConsole->writeStdout("endPrefixMapping() case 0: Expected 0 but got [ %1$ ]\n",&args[0],1,NULL);
}
break;
case 1:
if (4 != 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)
m_cpConsole->writeStdout("endPrefixMapping() case 1: Expected 0 but got [ %1$ ]\n",&args[0],1,NULL);
break;
default:
m_cpConsole->writeStdout("Error: endPrefixMapping() endState out of range got [ %1$ ]\n",&args[0],1,NULL);
break;
}
m_endMapping++;
return eOk;
}
{
if (!m_bInitialized) return eNotInitialized;
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;
}
{
if (!m_bInitialized) return eNotInitialized;
if (NULL == pObject) return eInvalidArg;
m_cpConsole->writeStdout("-> setDocumentLocator\n",NULL,0,NULL);
return eOk;
}
{
if (!m_bInitialized) return eNotInitialized;
if (NULL == pName ) return eInvalidArg;
debugPrint( "-> skippedEntity ", pName );
return eOk;
}
{
if (!m_bInitialized) return eNotInitialized;
m_startDoc++;
m_cpConsole->writeStdout("-> TOKEN_START_DOCUMENT\n",NULL,0,NULL);
return eOk;
}
P6SAX2STRING* pLocalName,
P6SAX2STRING* pQName,
P6SAX2STRING* pRawElement,
)
{
P6SAX2STRING name;
P6SAX2STRING value;
if (!m_bInitialized) return eNotInitialized;
if (NULL == pURI || NULL == pLocalName || NULL == pQName) return eInvalidArg;
if (m_startDoc != 1) {
m_cpConsole->writeStdout("startElement() Expected 1 but got %1$",&args[0],1,NULL);
}
switch( m_startState ) {
case 0:
if (5 != 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) {
m_cpConsole->writeStdout("startElement() case 0: Expected 0 but got [ %1$ ]\n",&args[0],1,NULL);
}
break;
case 1:
if (6 != 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) {
m_cpConsole->writeStdout("startElement() case 1: Expected 0 but got [ %1$ ]\n",&args[0],1,NULL);
}
break;
case 2:
if (2 != 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) {
m_cpConsole->writeStdout("startElement() case 2: Expected 0 but got [ %1$ ]\n",&args[0],1,NULL);
}
break;
case 3:
if (5 != 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) {
m_cpConsole->writeStdout("startElement() case 3: Expected 0 but got [ %1$ ]\n",&args[0],1,NULL);
}
break;
case 4:
if (4 != 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) {
m_cpConsole->writeStdout("startElement() case 4: Expected 0 but got [ %1$ ]\n",&args[0],1,NULL);
}
break;
default:
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 );
if (NULL != pAtts)
{
for(
P6UINT32 i=0; i < attribCount; i++ )
{
switch( m_startState ) {
case 0:
if (0 != i) {
m_cpConsole->writeStdout("out of range got %1$",&args[0],1,NULL);
}
if (10 != 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) {
m_cpConsole->writeStdout("startElement() verify attributes case 0: Expected 0 but got [ %1$ ]\n",&args[0],1,NULL);
}
if (36 != 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) {
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) {
m_cpConsole->writeStdout("Expected 4 but got %1$",&args[0],1,NULL);
}
err = m_cpStr->strncmp( "temp", name.pStart, 4, &iResult );
if (0 != iResult) {
m_cpConsole->writeStdout("startElement() verify attributes case 1: Expected 0 but got [ %1$ ]\n",&args[0],1,NULL);
}
if (2 != 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) {
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) {
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) {
m_cpConsole->writeStdout("startElement() verify attributes case 1: Expected 0 but got [ %1$ ]\n",&args[0],1,NULL);
}
if (31 != 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) {
m_cpConsole->writeStdout("startElement() verify attributes case 1: Expected 0 but got [ %1$ ]\n",&args[0],1,NULL);
}
}
break;
case 2:
if (0 != i) {
m_cpConsole->writeStdout("out of range got %1$",&args[0],1,NULL);
}
if (4 != 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) {
m_cpConsole->writeStdout("startElement() verify attributes case 2: Expected 0 but got [ %1$ ]\n",&args[0],1,NULL);
}
if (3 != 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) {
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) {
m_cpConsole->writeStdout("Expected 5 but got %1$",&args[0],1,NULL);
}
err = m_cpStr->strncmp( "color", name.pStart, 5, &iResult );
if (0 != iResult) {
m_cpConsole->writeStdout("startElement() verify attributes case 3: Expected 0 but got [ %1$ ]\n",&args[0],1,NULL);
}
if (7 != 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) {
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) {
m_cpConsole->writeStdout("Expected 4 but got %1$",&args[0],1,NULL);
}
err = m_cpStr->strncmp( "name", name.pStart, 4, &iResult );
if (0 != iResult) {
m_cpConsole->writeStdout("startElement() verify attributes case 3: Expected 0 but got [ %1$ ]\n",&args[0],1,NULL);
}
if (9 != 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) {
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) {
m_cpConsole->writeStdout("Expected 6 but got %1$",&args[0],1,NULL);
}
err = m_cpStr->strncmp( "weight", name.pStart, 6, &iResult );
if (0 != iResult) {
m_cpConsole->writeStdout("startElement() verify attributes case 3: Expected 0 but got [ %1$ ]\n",&args[0],1,NULL);
}
if (4 != 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) {
m_cpConsole->writeStdout("startElement() verify attributes case 3: Expected 0 but got [ %1$ ]\n",&args[0],1,NULL);
}
}
else
{
m_cpConsole->writeStdout("attribs - out of range got %1$",&args[0],1,NULL);
}
break;
default:
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 )
{
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) {
m_cpConsole->writeStdout("Expected 4 but got %1$",&args[0],1,NULL);
}
err = m_cpStr->strncmp( "xslt", pPrefix->pStart, 4, &iResult );
if (0 != iResult) {
m_cpConsole->writeStdout("startPrefixMapping() case 0: Expected 0 but got [ %1$ ]\n",&args[0],1,NULL);
}
if (36 != 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) {
m_cpConsole->writeStdout("startPrefixMapping() case 0: Expected 0 but got [ %1$ ]\n",&args[0],1,NULL);
}
break;
case 1:
if (1 != 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) {
m_cpConsole->writeStdout("startPrefixMapping() case 1: Expected 0 but got [ %1$ ]\n",&args[0],1,NULL);
}
if (31 != 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) {
m_cpConsole->writeStdout("startPrefixMapping() case 1: Expected 0 but got [ %1$ ]\n",&args[0],1,NULL);
}
break;
default:
m_cpConsole->writeStdout("Error: startMapping out of range got [ %1$ ]\n",&args[0],1,NULL);
break;
}
m_startMapping++;
return eOk;
}
P6R::P6VOID CContentHandler::debugPrint(
const P6CHAR* pHeader, P6SAX2STRING* pString )
{
if ( NULL != pString && NULL != pString->pStart) {
bStr.
length = pString->length;
m_cpConsole->writeStdout("%1$ [%2$] (%3$)\n",&args[0],3,NULL);
}
else {
m_cpConsole->writeStdout("%1$ []\n",&args[0],1,NULL);
}
}
}