#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 )
{ }
CContentHandler::~CContentHandler()
{
}
{
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 (45 != pBuffer->length) {
m_cpConsole->writeStdout("case 0: Expected 45 but got [ %1$ ]\n",&args[0],1,NULL);
}
err = m_cpStr->strncmp( "\n Now is the time for all good men to spend ", pBuffer->pStart, 45, &iResult );
if (0 != iResult) {
m_cpConsole->writeStdout("case 0: Expected 0 but got [ %1$ ]\n",&args[0],1,NULL);
}
break;
case 1:
if (12 != pBuffer->length) {
m_cpConsole->writeStdout("case 1: Expected 12 but got [ %1$ ]\n",&args[0],1,NULL);
}
err = m_cpStr->strncmp( "55 <dollars>", pBuffer->pStart, 12, &iResult );
if (0 != iResult) {
m_cpConsole->writeStdout("case 1: Expected 0 but got [ %1$ ]\n",&args[0],1,NULL);
}
break;
case 2:
if (6 != pBuffer->length) {
m_cpConsole->writeStdout("case 2: Expected 6 but got [ %1$ ]\n",&args[0],1,NULL);
}
err = m_cpStr->strncmp( "on \n ", pBuffer->pStart, 6, &iResult );
if (0 != iResult) {
m_cpConsole->writeStdout("case 2: Expected 0 but got [ %1$ ]\n",&args[0],1,NULL);
}
break;
case 3:
if (2 != pBuffer->length) {
m_cpConsole->writeStdout("case 3: Expected 2 but got [ %1$ ]\n",&args[0],1,NULL);
}
err = m_cpStr->strncmp( "33", pBuffer->pStart, 2, &iResult );
if (0 != iResult) {
m_cpConsole->writeStdout("case 3: Expected 0 but got [ %1$ ]\n",&args[0],1,NULL);
}
break;
case 4:
if (24 != pBuffer->length) {
m_cpConsole->writeStdout("case 4: Expected 2 but got [ %1$ ]\n",&args[0],1,NULL);
}
err = m_cpStr->strncmp( "now that we are open.\n ", pBuffer->pStart, 24, &iResult );
if (0 != iResult) {
m_cpConsole->writeStdout("case 4: Expected 0 but got [ %1$ ]\n",&args[0],1,NULL);
}
break;
case 5:
if (24 != pBuffer->length) {
m_cpConsole->writeStdout("case 5: Expected 24 but got [ %1$ ]\n",&args[0],1,NULL);
}
err = m_cpStr->strncmp( " using a namespace here ", pBuffer->pStart, 24, &iResult );
if (0 != iResult) {
m_cpConsole->writeStdout("case 5: 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 (5 != pLocalName->length) {
m_cpConsole->writeStdout("case 0: Expected 5 but got [ %1$ ]\n",&args[0],1,NULL);
}
err = m_cpStr->strncmp( "money", pLocalName->pStart, 5, &iResult );
if (0 != iResult) {
m_cpConsole->writeStdout("case 0: Expected 0 but got [ %1$ ]\n",&args[0],1,NULL);
}
break;
case 1:
if (4 != pLocalName->length) {
m_cpConsole->writeStdout("case 1: Expected 4 but got [ %1$ ]\n",&args[0],1,NULL);
}
err = m_cpStr->strncmp( "item", pLocalName->pStart, 4, &iResult );
if (0 != iResult) {
m_cpConsole->writeStdout("case 1: Expected 0 but got [ %1$ ]\n",&args[0],1,NULL);
}
break;
case 2:
if (5 != pLocalName->length) {
m_cpConsole->writeStdout("case 2: Expected 5 but got [ %1$ ]\n",&args[0],1,NULL);
}
err = m_cpStr->strncmp( "short", pLocalName->pStart, 5, &iResult );
if (0 != iResult) {
m_cpConsole->writeStdout("case 2: Expected 0 but got [ %1$ ]\n",&args[0],1,NULL);
}
break;
case 3:
if (7 != pLocalName->length) {
m_cpConsole->writeStdout("case 3: Expected 7 but got [ %1$ ]\n",&args[0],1,NULL);
}
err = m_cpStr->strncmp( "comment", pLocalName->pStart, 5, &iResult );
if (0 != iResult) {
m_cpConsole->writeStdout("case 3: Expected 0 but got [ %1$ ]\n",&args[0],1,NULL);
}
break;
case 4:
if (5 != pLocalName->length) {
m_cpConsole->writeStdout("case 4: Expected 5 but got [ %1$ ]\n",&args[0],1,NULL);
}
err = m_cpStr->strncmp( "mixed", pLocalName->pStart, 5, &iResult );
if (0 != iResult) {
m_cpConsole->writeStdout("case 4: Expected 0 but got [ %1$ ]\n",&args[0],1,NULL);
}
break;
case 5:
if (5 != pLocalName->length) {
m_cpConsole->writeStdout("case 5: 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("case 5: 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 );
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,
)
{
if (!m_bInitialized) return eNotInitialized;
if (NULL == pURI || NULL == pLocalName || NULL == pQName) return eInvalidArg;
if (m_startDoc != 1) {
m_cpConsole->writeStdout("Expected 1 but got %1$",&args[0],1,NULL);
}
switch( m_startState ) {
case 0:
if (5 != pLocalName->length) {
m_cpConsole->writeStdout("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("case 0: Expected 0 but got [ %1$ ]\n",&args[0],1,NULL);
}
break;
case 1:
if (5 != pLocalName->length) {
m_cpConsole->writeStdout("case 1: Expected 5 but got [ %1$ ]\n",&args[0],1,NULL);
}
err = m_cpStr->strncmp( "mixed", pLocalName->pStart, 5, &iResult );
if (0 != iResult) {
m_cpConsole->writeStdout("case 1: Expected 0 but got [ %1$ ]\n",&args[0],1,NULL);
}
break;
case 2:
if (5 != pLocalName->length) {
m_cpConsole->writeStdout("case 2: Expected 5 but got [ %1$ ]\n",&args[0],1,NULL);
}
err = m_cpStr->strncmp( "money", pLocalName->pStart, 5, &iResult );
if (0 != iResult) {
m_cpConsole->writeStdout("case 2: Expected 0 but got [ %1$ ]\n",&args[0],1,NULL);
}
break;
case 3:
if (4 != pLocalName->length) {
m_cpConsole->writeStdout("case 3: Expected 4 but got [ %1$ ]\n",&args[0],1,NULL);
}
err = m_cpStr->strncmp( "item", pLocalName->pStart, 4, &iResult );
if (0 != iResult) {
m_cpConsole->writeStdout("case 3: Expected 0 but got [ %1$ ]\n",&args[0],1,NULL);
}
break;
case 4:
if (5 != pLocalName->length) {
m_cpConsole->writeStdout("case 4: Expected 5 but got [ %1$ ]\n",&args[0],1,NULL);
}
err = m_cpStr->strncmp( "short", pLocalName->pStart, 5, &iResult );
if (0 != iResult) {
m_cpConsole->writeStdout("case 4: Expected 0 but got [ %1$ ]\n",&args[0],1,NULL);
}
break;
case 5:
if (7 != pLocalName->length) {
m_cpConsole->writeStdout("case 5: Expected 7 but got [ %1$ ]\n",&args[0],1,NULL);
}
err = m_cpStr->strncmp( "comment", pLocalName->pStart, 5, &iResult );
if (0 != iResult) {
m_cpConsole->writeStdout("case 5: Expected 0 but got [ %1$ ]\n",&args[0],1,NULL);
}
break;
default:
m_cpConsole->writeStdout("Error: 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 );
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 );
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);
}
}
}