1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363
|
/* This file is part of the wvWare 2 project
Copyright (C) 2002-2003 Werner Trobin <trobin@kde.org>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License version 2 as published by the Free Software Foundation.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.
*/
#include <parser.h>
#include <handlers.h>
#include <parserfactory.h>
#include <word97_generated.h>
#include <paragraphproperties.h>
#include <lists.h>
#include <ustring.h>
#include <fields.h>
#include <iostream>
#include <string>
class InlineReplacementTest : public wvWare::InlineReplacementHandler
{
public:
virtual wvWare::U8 tab();
virtual wvWare::U8 hardLineBreak();
virtual wvWare::U8 columnBreak();
virtual wvWare::U8 nonBreakingHyphen();
virtual wvWare::U8 nonRequiredHyphen();
virtual wvWare::U8 nonBreakingSpace();
};
class SubDocumentTest : public wvWare::SubDocumentHandler
{
public:
virtual void bodyStart();
virtual void bodyEnd();
virtual void footnoteStart();
virtual void footnoteEnd();
virtual void headersStart();
virtual void headersEnd();
virtual void headerStart( wvWare::HeaderData::Type type );
virtual void headerEnd();
};
class TableTest : public wvWare::TableHandler
{
public:
virtual void tableRowStart( wvWare::SharedPtr<const wvWare::Word97::TAP> tap );
virtual void tableRowEnd();
virtual void tableCellStart();
virtual void tableCellEnd();
};
class TextTest : public wvWare::TextHandler
{
public:
virtual void sectionStart( wvWare::SharedPtr<const wvWare::Word97::SEP> sep );
virtual void sectionEnd();
virtual void pageBreak();
virtual void headersFound( const wvWare::HeaderFunctor& parseHeaders );
virtual void paragraphStart( wvWare::SharedPtr<const wvWare::ParagraphProperties> paragraphProperties );
virtual void paragraphEnd();
virtual void runOfText( const wvWare::UString& text, wvWare::SharedPtr<const wvWare::Word97::CHP> chp );
virtual void specialCharacter( SpecialCharacter character, wvWare::SharedPtr<const wvWare::Word97::CHP> chp );
virtual void footnoteFound( wvWare::FootnoteData::Type type, wvWare::UChar character,
wvWare::SharedPtr<const wvWare::Word97::CHP> chp, const wvWare::FootnoteFunctor& parseFootnote );
virtual void footnoteAutoNumber( wvWare::SharedPtr<const wvWare::Word97::CHP> chp );
virtual void fieldStart( const wvWare::FLD* fld, wvWare::SharedPtr<const wvWare::Word97::CHP> chp );
virtual void fieldSeparator( const wvWare::FLD* fld, wvWare::SharedPtr<const wvWare::Word97::CHP> chp );
virtual void fieldEnd( const wvWare::FLD* fld, wvWare::SharedPtr<const wvWare::Word97::CHP> chp );
virtual void tableRowFound( const wvWare::TableRowFunctor& tableRow, wvWare::SharedPtr<const wvWare::Word97::TAP> tap );
};
using namespace wvWare;
std::string indent;
U8 InlineReplacementTest::tab()
{
std::cout << indent << "INLINE: tab" << std::endl;
return InlineReplacementHandler::tab();
}
U8 InlineReplacementTest::hardLineBreak()
{
std::cout << indent << "INLINE: hard line break" << std::endl;
return InlineReplacementHandler::hardLineBreak();
}
U8 InlineReplacementTest::columnBreak()
{
std::cout << indent << "INLINE: column break" << std::endl;
return InlineReplacementHandler::columnBreak();
}
U8 InlineReplacementTest::nonBreakingHyphen()
{
std::cout << indent << "INLINE: non breaking hyphen" << std::endl;
return InlineReplacementHandler::nonBreakingHyphen();
}
U8 InlineReplacementTest::nonRequiredHyphen()
{
std::cout << indent << "INLINE: non required hyphen" << std::endl;
return InlineReplacementHandler::nonRequiredHyphen();
}
U8 InlineReplacementTest::nonBreakingSpace()
{
std::cout << indent << "INLINE: non breaking space" << std::endl;
return InlineReplacementHandler::nonBreakingSpace();
}
void SubDocumentTest::bodyStart()
{
std::cout << indent << "SUBDOCUMENT: body start" << std::endl;
indent.push_back( ' ' );
SubDocumentHandler::bodyStart();
}
void SubDocumentTest::bodyEnd()
{
std::cout << indent << "SUBDOCUMENT: body end" << std::endl;
indent.erase( indent.size() - 1 );
SubDocumentHandler::bodyEnd();
}
void SubDocumentTest::footnoteStart()
{
std::cout << indent << "SUBDOCUMENT: footnote start" << std::endl;
indent.push_back( ' ' );
SubDocumentHandler::footnoteStart();
}
void SubDocumentTest::footnoteEnd()
{
std::cout << indent << "SUBDOCUMENT: footnote end" << std::endl;
indent.erase( indent.size() - 1 );
SubDocumentHandler::footnoteEnd();
}
void SubDocumentTest::headersStart()
{
std::cout << indent << "SUBDOCUMENT: headers start" << std::endl;
indent.push_back( ' ' );
SubDocumentHandler::headersStart();
}
void SubDocumentTest::headersEnd()
{
std::cout << indent << "SUBDOCUMENT: headers end" << std::endl;
indent.erase( indent.size() - 1 );
SubDocumentHandler::headersEnd();
}
void SubDocumentTest::headerStart( HeaderData::Type type )
{
std::cout << indent << "SUBDOCUMENT: header start " << static_cast<int>( type ) << std::endl;
indent.push_back( ' ' );
SubDocumentHandler::headerStart( type );
}
void SubDocumentTest::headerEnd()
{
std::cout << indent << "SUBDOCUMENT: header end" << std::endl;
indent.erase( indent.size() - 1 );
SubDocumentHandler::headerEnd();
}
void TableTest::tableRowStart( SharedPtr<const Word97::TAP> tap )
{
std::cout << indent << "TABLE: table row start" << std::endl;
indent.push_back( ' ' );
tap->dump();
TableHandler::tableRowStart( tap );
}
void TableTest::tableRowEnd()
{
std::cout << indent << "TABLE: table row end" << std::endl;
indent.erase( indent.size() - 1 );
TableHandler::tableRowEnd();
}
void TableTest::tableCellStart()
{
std::cout << indent << "TABLE: table cell start" << std::endl;
indent.push_back( ' ' );
TableHandler::tableCellStart();
}
void TableTest::tableCellEnd()
{
std::cout << indent << "TABLE: table cell end" << std::endl;
indent.erase( indent.size() - 1 );
TableHandler::tableCellEnd();
}
void TextTest::sectionStart( SharedPtr<const Word97::SEP> sep )
{
std::cout << indent << "TEXT: section start" << std::endl;
indent.push_back( ' ' );
sep->dump();
TextHandler::sectionStart( sep );
}
void TextTest::sectionEnd()
{
std::cout << indent << "TEXT: section end" << std::endl;
indent.erase( indent.size() - 1 );
TextHandler::sectionEnd();
}
void TextTest::pageBreak()
{
std::cout << indent << "TEXT: page break" << std::endl;
TextHandler::pageBreak();
}
void TextTest::headersFound( const HeaderFunctor& parseHeaders )
{
std::cout << indent << "TEXT: headers found" << std::endl;
TextHandler::headersFound( parseHeaders );
}
void TextTest::paragraphStart( SharedPtr<const ParagraphProperties> paragraphProperties )
{
std::cout << indent << "TEXT: paragraph start" << std::endl;
indent.push_back( ' ' );
paragraphProperties->pap().dump();
if ( paragraphProperties->listInfo() )
paragraphProperties->listInfo()->dump();
TextHandler::paragraphStart( paragraphProperties );
}
void TextTest::paragraphEnd()
{
std::cout << indent << "TEXT: paragraph end" << std::endl;
indent.erase( indent.size() - 1 );
TextHandler::paragraphEnd();
}
void TextTest::runOfText( const UString& text, SharedPtr<const Word97::CHP> chp )
{
std::cout << indent << "TEXT: run of text" << std::endl;
chp->dump();
std::cout << "TEXT: [";
for ( int i = 0; i < text.length(); ++i )
std::cout << "<" << text[ i ].unicode() << "|" << text[ i ].low() << ">";
std::cout << "]" << std::endl;
TextHandler::runOfText( text, chp );
}
void TextTest::specialCharacter( SpecialCharacter character, SharedPtr<const Word97::CHP> chp )
{
std::cout << indent << "TEXT: special character " << static_cast<int>( character ) << std::endl;
chp->dump();
TextHandler::specialCharacter( character, chp );
}
void TextTest::footnoteFound( FootnoteData::Type type, UChar character,
SharedPtr<const Word97::CHP> chp, const FootnoteFunctor& parseFootnote )
{
std::cout << indent << "TEXT: footnote found " << static_cast<int>( type )
<< " character " << character.unicode() << std::endl;
chp->dump();
TextHandler::footnoteFound( type, character, chp, parseFootnote );
}
void TextTest::footnoteAutoNumber( SharedPtr<const Word97::CHP> chp )
{
std::cout << indent << "TEXT: footnote auto-number" << std::endl;
chp->dump();
TextHandler::footnoteAutoNumber( chp );
}
void TextTest::fieldStart( const FLD* fld, SharedPtr<const Word97::CHP> chp )
{
std::cout << indent << "TEXT: field start " << static_cast<int>( fld->ch ) << std::endl;
indent.push_back( ' ' );
chp->dump();
TextHandler::fieldStart( fld, chp );
}
void TextTest::fieldSeparator( const FLD* fld, SharedPtr<const Word97::CHP> chp )
{
std::cout << indent << "TEXT: field separator " << static_cast<int>( fld->ch ) << std::endl;
chp->dump();
TextHandler::fieldSeparator( fld, chp );
}
void TextTest::fieldEnd( const FLD* fld, SharedPtr<const Word97::CHP> chp )
{
std::cout << indent << "TEXT: field end " << static_cast<int>( fld->ch ) << std::endl;
chp->dump();
indent.erase( indent.size() - 1 );
TextHandler::fieldEnd( fld, chp );
}
void TextTest::tableRowFound( const wvWare::TableRowFunctor& tableRow, wvWare::SharedPtr<const wvWare::Word97::TAP> tap )
{
std::cout << indent << "TEXT: table row found" << std::endl;
tap->dump();
TextHandler::tableRowFound( tableRow, tap );
}
int main( int argc, char** argv )
{
if ( argc != 2 ) {
std::cerr << "Usage: handlertest foo.doc" << std::endl;
::exit( 1 );
}
std::string document( argv[ 1 ] );
SharedPtr<Parser> parser( ParserFactory::createParser( document ) );
if ( !parser || !parser->isOk() ) {
std::cerr << "Error: Couldn't create a parser for this document" << std::endl;
::exit( 2 );
}
TextTest* textTest( new TextTest );
parser->setTextHandler( textTest );
InlineReplacementTest* replacementTest( new InlineReplacementTest );
parser->setInlineReplacementHandler( replacementTest );
if ( !parser->parse() ) {
std::cerr << "Error: The parser failed" << std::endl;
delete replacementTest;
delete textTest;
::exit( 3 );
}
std::cout << "Done." << std::endl;
delete replacementTest;
delete textTest;
return 0;
}
|