00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00027 #ifdef __GNUG__
00028 # pragma implementation
00029 #endif
00030
00031
00032 #include "xmlsimplemodel.h"
00033
00034
00042 #define SAFE_CALL_EMITTER(_x_) \
00043 if (saxEmitter) \
00044 saxEmitter->_x_;
00045
00046
00048 #define RESET_BUFFER \
00049 { \
00050 buffer[0] = 0; \
00051 bufferLength = 0; \
00052 }
00053
00054
00062 #define CHANGE_STATE(_s_) \
00063 { \
00064 stateChanged = false; \
00065 if (state != StructuralSymbols::KnownElement && \
00066 (state == StructuralSymbols::None || state == _s_)) \
00067 { \
00068 state = _s_; \
00069 stateChanged = true; \
00070 } \
00071 }
00072
00074 #define RESET_STATE state = StructuralSymbols::None
00075
00076
00085 #define APPEND_ALL_DATA_LENGTH(_gr_, _data_, _length_, _complete_) \
00086 { \
00087 CHECK_POINTER(_gr_); \
00088 \
00089 for (int _i_ = 0; _i_ < _length_; _i_++) \
00090 _gr_->append((TerminalValue)_data_[_i_]); \
00091 \
00092 if (_complete_) \
00093 _gr_->append(StructuralSymbols::EndOfBlock); \
00094 }
00095
00096
00104 #define APPEND_ALL_DATA(_gr_, _data_, _complete_) \
00105 { \
00106 CHECK_POINTER(_gr_); \
00107 \
00108 if (!_data_) \
00109 return false; \
00110 \
00111 for (int _i_ = 0; _data_[_i_]; _i_++) \
00112 _gr_->append((TerminalValue)_data_[_i_]); \
00113 \
00114 if (_complete_) \
00115 _gr_->append(StructuralSymbols::EndOfBlock); \
00116 }
00117
00118
00126 #define APPEND_BUFFER_DATA(_gr_, _buffer_, _nrItems_) \
00127 { \
00128 for (size_t _i_ = 0; _i_ < _nrItems_; _i_++) \
00129 { \
00130 _gr_->append(_buffer_[_i_]); \
00131 } \
00132 }
00133
00134
00135
00143 #define FINISH_ELEMENT_START(_elementName_) \
00144 { \
00145 if (!elementHasAttributes) \
00146 { \
00147 \
00148 \
00149 \
00150 elementStack->push(new unsigned long(elementId)); \
00151 \
00152 SAFE_CALL_EMITTER(startElement(userData, ec->name, 0)); \
00153 \
00154 \
00155 elementHasAttributes = false; \
00156 attributeListComplete = false; \
00157 } \
00158 else \
00159 if (attributeListComplete) \
00160 { \
00161 const XmlChar **attrs; \
00162 size_t attrPos = 0; \
00163 \
00164 NEW(attrs, const XmlChar *[dataQueue->count()+1]); \
00165 attrs[dataQueue->count()] = 0; \
00166 \
00167 while ((dataQueueItem = dataQueue->dequeue())) \
00168 { \
00169 \
00170 attrs[attrPos] = dataQueueItem->data; \
00171 attrPos++; \
00172 } \
00173 \
00174 elementStack->push(new unsigned long(elementId)); \
00175 SAFE_CALL_EMITTER(startElement(userData, _elementName_, attrs)); \
00176 \
00177 \
00178 \
00179 \
00180 for (attrPos = 0; attrs[attrPos]; attrPos += 2) \
00181 { \
00182 DELETE(attrs[attrPos+1]); \
00183 } \
00184 \
00185 DELETE_ARRAY(attrs); \
00186 \
00187 elementHasAttributes = false; \
00188 attributeListComplete = false; \
00189 } \
00190 else \
00191 { \
00192 \
00193 \
00194 NEW(dataQueueItem, DataQueueItem); \
00195 dataQueueItem->type = Characters; \
00196 dataQueueItem->data = ec->name; \
00197 dataQueue->enqueue(dataQueueItem); \
00198 } \
00199 RESET_STATE; \
00200 }
00201
00202
00203
00207 XmlSimpleModel::XmlSimpleModel(void)
00208 : XmlModelBase()
00209 {
00210 grammar = 0;
00211
00212 state = StructuralSymbols::None;
00213
00214 buffer = 0;
00215 bufferLength = 0;
00216
00217 fibBits = 0;
00218 fibCode = 0;
00219 fibLastWasOne = false;
00220
00221 NEW(dataQueue, DataQueue);
00222 dataQueue->setAutoDelete(true);
00223
00224 saxEmitter = 0;
00225 userData = 0;
00226
00227
00228
00229
00230 inCDATA = false;
00231 inDoctype = false;
00232 elementHasAttributes = false;
00233 attributeListComplete = false;
00234
00235
00236 NEW(elementStack, Stack<unsigned long>);
00237
00238 elementStack->setAutoDelete(true);
00239
00240 NEW(elementIds, ElementIds);
00241 elementIds->setAutoDelete(true);
00242
00243 NEW(elements, SimpleElementTable);
00244 elements->setAutoDelete(true);
00245
00246
00247
00248 NEW(elementNamesList, ElementNamesList);
00249 elementNamesList->setAutoDelete(true);
00250
00251 elementCounter = 1;
00252 }
00253
00254
00258 XmlSimpleModel::~XmlSimpleModel(void)
00259 {
00260 DELETE(elements);
00261 DELETE(elementStack);
00262
00263
00264
00265 if (ExaltOptions::getOption(ExaltOptions::Verbose) == ExaltOptions::Yes)
00266 {
00267 OUTPUTENL(" Number of elements/attributes:\t" << elementNamesList->count());
00268 OUTPUTEENDLINE;
00269 }
00270
00271
00272
00273 DELETE(elementNamesList);
00274
00275 DELETE(dataQueue);
00276 }
00277
00278
00285 void XmlSimpleModel::setSAXEmitter(SAXEmitter *emitter, void *data = 0)
00286 {
00287 saxEmitter = emitter;
00288 userData = data;
00289 }
00290
00291
00297 bool XmlSimpleModel::manageEvent(XmlModelEvent *event)
00298 {
00299 XmlStartElementEvent *startElementEvent;
00300 XmlEndElementEvent *endElementEvent;
00301 XmlCharactersEvent *charactersEvent;
00302 XmlCommentEvent *commentEvent;
00303 XmlPIEvent *piEvent;
00304 XmlDeclEvent *xmlDeclEvent;
00305 XmlStartDoctypeEvent *xmlStartDoctypeEvent;
00306
00307 XmlEntityDeclEvent *xmlEntityDeclEvent;
00308 XmlNotationDeclEvent *xmlNotationDeclEvent;
00309 XmlDefaultEvent *defaultEvent;
00310
00311 XmlChar *elName, *attrName;
00312 unsigned long *elId, *attrId;
00313 unsigned long elementId, attributeId;
00314
00315 SimpleElementContext *ec;
00316 size_t fibItems;
00317 XmlChar fibBuf[30];
00318 Encodings::MIB mib;
00319
00320
00321 switch (event->type)
00322 {
00323
00324 case XmlModelEvent::XmlDecl:
00325 xmlDeclEvent = (XmlDeclEvent *)event;
00326
00327 if (!textCodec)
00328
00329 createDefaultTextCodec();
00330
00331 mib = textCodec->getMIB(xmlDeclEvent->encoding);
00332
00333 grammar->setAlphabetBaseSize(textCodec->suggestAlphabetBaseSize(mib));
00334
00335 grammar->append(StructuralSymbols::XmlDecl);
00336
00337 APPEND_ALL_DATA(grammar, xmlDeclEvent->version, true);
00338
00339 if (xmlDeclEvent->encoding)
00340 {
00341 APPEND_ALL_DATA(grammar, xmlDeclEvent->encoding, true);
00342 }
00343 else
00344 grammar->append(StructuralSymbols::EndOfBlock);
00345
00346 if (xmlDeclEvent->standalone != -1)
00347 {
00348 if (xmlDeclEvent->standalone)
00349 grammar->append(StructuralSymbols::StandaloneYes);
00350 else
00351 grammar->append(StructuralSymbols::StandaloneNo);
00352 }
00353 else
00354 grammar->append(StructuralSymbols::StandaloneNotSpecified);
00355
00356 break;
00357
00358
00359
00360
00361 case XmlModelEvent::StartDoctype:
00362 xmlStartDoctypeEvent = (XmlStartDoctypeEvent *)event;
00363
00364 grammar->append(StructuralSymbols::Doctype);
00365
00366 if (xmlStartDoctypeEvent->doctypeName)
00367 {
00368 APPEND_ALL_DATA(grammar, xmlStartDoctypeEvent->doctypeName, true);
00369 }
00370 else
00371 grammar->append(StructuralSymbols::EndOfBlock);
00372
00373 if (xmlStartDoctypeEvent->publicId)
00374 {
00375 if (!xmlStartDoctypeEvent->publicId[0])
00376 {
00377 grammar->append(StructuralSymbols::EmptyString);
00378 grammar->append(StructuralSymbols::EndOfBlock);
00379 }
00380 else
00381 {
00382 APPEND_ALL_DATA(grammar, xmlStartDoctypeEvent->publicId, true);
00383 }
00384 }
00385 else
00386 grammar->append(StructuralSymbols::EndOfBlock);
00387
00388 if (xmlStartDoctypeEvent->systemId)
00389 {
00390 if (!xmlStartDoctypeEvent->systemId[0])
00391 {
00392 grammar->append(StructuralSymbols::EmptyString);
00393 grammar->append(StructuralSymbols::EndOfBlock);
00394 }
00395 else
00396 {
00397 APPEND_ALL_DATA(grammar, xmlStartDoctypeEvent->systemId, true);
00398 }
00399 }
00400 else
00401 grammar->append(StructuralSymbols::EndOfBlock);
00402
00403 if (xmlStartDoctypeEvent->hasInternalSubset)
00404 grammar->append(StructuralSymbols::HasInternalSubsetYes);
00405 else
00406 grammar->append(StructuralSymbols::HasInternalSubsetNo);
00407
00408
00409
00410
00411
00412 break;
00413
00414
00415 case XmlModelEvent::EndDoctype:
00416 grammar->append(StructuralSymbols::Doctype);
00417 break;
00418
00419
00420
00421 case XmlModelEvent::EntityDecl:
00422 xmlEntityDeclEvent = (XmlEntityDeclEvent *)event;
00423
00424 grammar->append(StructuralSymbols::EntityDecl);
00425
00426 if (xmlEntityDeclEvent->entityName)
00427 {
00428 APPEND_ALL_DATA(grammar, xmlEntityDeclEvent->entityName, true);
00429 }
00430 else
00431 grammar->append(StructuralSymbols::EndOfBlock);
00432
00433
00434 if (!xmlEntityDeclEvent->valueLength && xmlEntityDeclEvent->value)
00435 {
00436
00437 grammar->append(StructuralSymbols::EmptyString);
00438 grammar->append(StructuralSymbols::EndOfBlock);
00439 }
00440 else
00441 {
00442 if (xmlEntityDeclEvent->value)
00443 {
00444
00445 APPEND_ALL_DATA_LENGTH(grammar, xmlEntityDeclEvent->value, xmlEntityDeclEvent->valueLength, true);
00446 }
00447 else
00448
00449 grammar->append(StructuralSymbols::EndOfBlock);
00450 }
00451
00452
00453 if (xmlEntityDeclEvent->systemId)
00454 {
00455 if (!xmlEntityDeclEvent->systemId[0])
00456 {
00457 grammar->append(StructuralSymbols::EmptyString);
00458 grammar->append(StructuralSymbols::EndOfBlock);
00459 }
00460 else
00461 {
00462 APPEND_ALL_DATA(grammar, xmlEntityDeclEvent->systemId, true);
00463 }
00464 }
00465 else
00466 grammar->append(StructuralSymbols::EndOfBlock);
00467
00468 if (xmlEntityDeclEvent->publicId)
00469 {
00470 if (!xmlEntityDeclEvent->publicId[0])
00471 {
00472 grammar->append(StructuralSymbols::EmptyString);
00473 grammar->append(StructuralSymbols::EndOfBlock);
00474 }
00475 else
00476 {
00477 APPEND_ALL_DATA(grammar, xmlEntityDeclEvent->publicId, true);
00478 }
00479 }
00480 else
00481 grammar->append(StructuralSymbols::EndOfBlock);
00482
00483 if (xmlEntityDeclEvent->notationName)
00484 {
00485 if (!xmlEntityDeclEvent->notationName[0])
00486 {
00487 grammar->append(StructuralSymbols::EmptyString);
00488 grammar->append(StructuralSymbols::EndOfBlock);
00489 }
00490 else
00491 {
00492 APPEND_ALL_DATA(grammar, xmlEntityDeclEvent->notationName, true);
00493 }
00494 }
00495 else
00496 grammar->append(StructuralSymbols::EndOfBlock);
00497
00498 if (xmlEntityDeclEvent->isParameterEntity)
00499 grammar->append(StructuralSymbols::IsParameterEntityYes);
00500 else
00501 grammar->append(StructuralSymbols::IsParameterEntityNo);
00502
00503 break;
00504
00505
00506
00507 case XmlModelEvent::NotationDecl:
00508 xmlNotationDeclEvent = (XmlNotationDeclEvent *)event;
00509
00510 grammar->append(StructuralSymbols::NotationDecl);
00511
00512 if (xmlNotationDeclEvent->notationName)
00513 {
00514 APPEND_ALL_DATA(grammar, xmlNotationDeclEvent->notationName, true);
00515 }
00516 else
00517 grammar->append(StructuralSymbols::EndOfBlock);
00518
00519
00520
00521 if (xmlNotationDeclEvent->systemId)
00522 {
00523 if (!xmlNotationDeclEvent->systemId[0])
00524 {
00525 grammar->append(StructuralSymbols::EmptyString);
00526 grammar->append(StructuralSymbols::EndOfBlock);
00527 }
00528 else
00529 {
00530 APPEND_ALL_DATA(grammar, xmlNotationDeclEvent->systemId, true);
00531 }
00532 }
00533 else
00534 grammar->append(StructuralSymbols::EndOfBlock);
00535
00536 if (xmlNotationDeclEvent->publicId)
00537 {
00538 if (!xmlNotationDeclEvent->publicId[0])
00539 {
00540 grammar->append(StructuralSymbols::EmptyString);
00541 grammar->append(StructuralSymbols::EndOfBlock);
00542 }
00543 else
00544 {
00545 APPEND_ALL_DATA(grammar, xmlNotationDeclEvent->publicId, true);
00546 }
00547 }
00548 else
00549 grammar->append(StructuralSymbols::EndOfBlock);
00550
00551
00552 break;
00553
00554
00555
00556 case XmlModelEvent::StartElement:
00557 startElementEvent = (XmlStartElementEvent *)event;
00558
00559 if (startElementEvent->attr[0])
00560 {
00561
00562
00563 grammar->append(StructuralSymbols::Attributes);
00564
00565
00566 for (size_t i = 0; startElementEvent->attr[i]; i += 2)
00567 {
00568 if (!(attrId = elementIds->find((XmlChar *)startElementEvent->attr[i])))
00569 {
00570
00571
00572
00573
00574
00575 NEW(attrName, XmlChar[xmlchar_strlen(startElementEvent->attr[i]) + 1]);
00576 xmlchar_strcpy(attrName, startElementEvent->attr[i]);
00577 elementNamesList->append(attrName);
00578
00579
00580
00581 attributeId = elementCounter;
00582 elementIds->insert(attrName, new unsigned long(attributeId));
00583
00584
00585
00586 NEW(ec, SimpleElementContext);
00587
00588
00589 ec->name = attrName;
00590
00591
00592
00593 elements->insert(attributeId, ec);
00594
00595
00596
00597 elementCounter++;
00598
00599
00600
00601
00602 grammar->append(StructuralSymbols::NewElement);
00603
00604
00605
00606 APPEND_ALL_DATA(grammar, attrName, true);
00607 }
00608 else
00609 {
00610
00611
00612 ec = elements->find(*attrId);
00613 CHECK_POINTER(ec);
00614
00615 attributeId = *attrId;
00616
00617
00618
00619 grammar->append(StructuralSymbols::KnownElement);
00620 fibItems = Fibonacci::encodeToBuffer(fibBuf, SIZEOF_XML_CHAR, attributeId);
00621 APPEND_BUFFER_DATA(grammar, fibBuf, fibItems);
00622 }
00623
00624
00625 if (startElementEvent->attr[i+1][0] == 0)
00626 grammar->append(StructuralSymbols::EmptyString);
00627 else
00628 APPEND_ALL_DATA(grammar, startElementEvent->attr[i+1], true);
00629 }
00630
00631
00632 grammar->append(StructuralSymbols::EndOfBlock);
00633
00634 }
00635
00636 if (!(elId = elementIds->find((XmlChar *)startElementEvent->name)))
00637 {
00638
00639
00640
00641
00642
00643 NEW(elName, XmlChar[xmlchar_strlen(startElementEvent->name) + 1]);
00644 xmlchar_strcpy(elName, startElementEvent->name);
00645 elementNamesList->append(elName);
00646
00647
00648
00649 elementId = elementCounter;
00650 elementIds->insert(elName, new unsigned long(elementId));
00651
00652
00653
00654
00655 NEW(ec, SimpleElementContext);
00656
00657
00658 ec->name = elName;
00659
00660
00661
00662
00663 elements->insert(elementId, ec);
00664
00665
00666
00667 elementCounter++;
00668
00669
00670
00671
00672 grammar->append(StructuralSymbols::NewElement);
00673
00674
00675
00676 APPEND_ALL_DATA(grammar, startElementEvent->name, true);
00677
00678
00679 }
00680 else
00681 {
00682
00683
00684 ec = elements->find(*elId);
00685 CHECK_POINTER(ec);
00686
00687 elementId = *elId;
00688
00689
00690
00691
00692
00693 grammar->append(StructuralSymbols::KnownElement);
00694
00695 fibItems = Fibonacci::encodeToBuffer(fibBuf, SIZEOF_XML_CHAR, elementId);
00696 APPEND_BUFFER_DATA(grammar, fibBuf, fibItems);
00697
00698
00699
00700
00701
00702
00703 }
00704
00705
00706 elementStack->push(new unsigned long(elementId));
00707
00708 break;
00709
00710
00711
00712
00713 case XmlModelEvent::EndElement:
00714 endElementEvent = (XmlEndElementEvent *)event;
00715
00716
00717
00718 if (!(elId = elementIds->find((XmlChar *)endElementEvent->name)))
00719 {
00720
00721
00722 FATAL("End of unknown element acurred: " << (const char *)endElementEvent->name);
00723 }
00724 else
00725 {
00726
00727
00728
00729 }
00730
00731 elementStack->pop();
00732
00733
00734 grammar->append(StructuralSymbols::EndElement);
00735
00736
00737 break;
00738
00739
00740
00741
00742 case XmlModelEvent::Characters:
00743 charactersEvent = (XmlCharactersEvent *)event;
00744
00745
00746
00747
00748
00749 APPEND_ALL_DATA_LENGTH(grammar, charactersEvent->data, charactersEvent->length, true);
00750 break;
00751
00752
00753 case XmlModelEvent::Default:
00754 defaultEvent = (XmlDefaultEvent *)event;
00755
00756
00757 grammar->append(StructuralSymbols::Default);
00758 APPEND_ALL_DATA_LENGTH(grammar, defaultEvent->data, defaultEvent->length, true);
00759 break;
00760
00761
00762
00763 case XmlModelEvent::Comment:
00764 commentEvent = (XmlCommentEvent *)event;
00765
00766
00767 grammar->append(StructuralSymbols::Comment);
00768
00769 APPEND_ALL_DATA(grammar, commentEvent->data, true);
00770 break;
00771
00772
00773
00774 case XmlModelEvent::StartCDATA:
00775
00776
00777
00778 grammar->append(StructuralSymbols::CDATA);
00779 break;
00780
00781
00782 case XmlModelEvent::EndCDATA:
00783
00784
00785
00786 grammar->append(StructuralSymbols::CDATA);
00787 break;
00788
00789
00790
00791
00792 case XmlModelEvent::PI:
00793 piEvent = (XmlPIEvent *)event;
00794
00795
00796 grammar->append(StructuralSymbols::PI);
00797
00798 if (piEvent->target)
00799 {
00800
00801 APPEND_ALL_DATA(grammar, piEvent->target, true);
00802
00803 if (piEvent->data)
00804 {
00805
00806 APPEND_ALL_DATA(grammar, piEvent->data, true);
00807 }
00808 else
00809 grammar->append(StructuralSymbols::EndOfBlock);
00810 }
00811 else
00812 grammar->append(StructuralSymbols::EndOfBlock);
00813
00814 break;
00815
00816 default:
00817 WRN("Unknown XML event: " << event->type);
00818 DELETE(event);
00819 return false;
00820 }
00821
00822
00823 DELETE(event);
00824 return true;
00825 }
00826
00827
00828
00835 void XmlSimpleModel::receiveData(XmlChar *data, size_t size)
00836 {
00837 bool stateChanged = false;
00838 DataQueueItem *dataQueueItem;
00839 SimpleElementContext *ec;
00840 XmlChar *elName;
00841 unsigned long elementId;
00842 unsigned long *elId;
00843
00844
00845 unsigned char fibTmpChar, fibMask;
00846 bool fibFinished = false;
00847
00848
00849 if (!buffer)
00850 {
00851 NEW(buffer, XmlChar[XML_MODEL_BUFFER_DEFAULT_SIZE]);
00852 RESET_BUFFER;
00853 }
00854
00855 for (size_t i = 0; i < size; i++)
00856 {
00857
00858 if (state != StructuralSymbols::KnownElement)
00859 {
00860 switch (data[i])
00861 {
00862
00863
00864
00865
00866
00867 case StructuralSymbols::XmlDecl:
00868
00869
00870 CHANGE_STATE(StructuralSymbols::XmlDecl);
00871 if (stateChanged)
00872 {
00873 continue;
00874 }
00875 break;
00876
00877 case StructuralSymbols::Attributes:
00878
00879 elementHasAttributes = true;
00880
00881
00882
00883
00884
00885
00886
00887
00888
00889
00890 continue;
00891 break;
00892
00893 case StructuralSymbols::NewElement:
00894
00895
00896 CHANGE_STATE(StructuralSymbols::NewElement);
00897 if (stateChanged)
00898 {
00899 continue;
00900 }
00901 break;
00902
00903 case StructuralSymbols::KnownElement:
00904
00905
00906 CHANGE_STATE(StructuralSymbols::KnownElement);
00907 if (stateChanged)
00908 {
00909 continue;
00910 }
00911 break;
00912
00913 case StructuralSymbols::EndElement:
00914
00915
00916 CHANGE_STATE(StructuralSymbols::None);
00917
00918 if (stateChanged)
00919 {
00920 elId = elementStack->pop();
00921 CHECK_POINTER(elId);
00922 ec = elements->find(*elId);
00923
00924
00925
00926 SAFE_CALL_EMITTER(endElement(userData, ec->name));
00927 continue;
00928 }
00929 else
00930 {
00931
00932
00933 }
00934
00935 break;
00936
00937 case StructuralSymbols::Default:
00938
00939 CHANGE_STATE(StructuralSymbols::Default);
00940 if (stateChanged)
00941 {
00942 continue;
00943 }
00944 break;
00945
00946
00947 case StructuralSymbols::Comment:
00948
00949 CHANGE_STATE(StructuralSymbols::Comment);
00950 if (stateChanged)
00951 {
00952 continue;
00953 }
00954 break;
00955
00956 case StructuralSymbols::CDATA:
00957
00958 if (!inCDATA)
00959 {
00960 CHANGE_STATE(StructuralSymbols::CDATA);
00961 if (stateChanged)
00962 {
00963 SAFE_CALL_EMITTER(startCDATASection(userData));
00964 inCDATA = true;
00965 continue;
00966 }
00967 }
00968 else
00969 {
00970 CHANGE_STATE(StructuralSymbols::None);
00971 if (stateChanged)
00972 {
00973 SAFE_CALL_EMITTER(endCDATASection(userData));
00974 inCDATA = false;
00975 continue;
00976 }
00977 }
00978 break;
00979
00980 case StructuralSymbols::PI:
00981
00982 CHANGE_STATE(StructuralSymbols::PI);
00983 if (stateChanged)
00984 {
00985 continue;
00986 }
00987 break;
00988
00989 case StructuralSymbols::EntityDecl:
00990
00991 CHANGE_STATE(StructuralSymbols::EntityDecl);
00992 if (stateChanged)
00993 {
00994 continue;
00995 }
00996 break;
00997
00998 case StructuralSymbols::NotationDecl:
00999
01000 CHANGE_STATE(StructuralSymbols::NotationDecl);
01001 if (stateChanged)
01002 {
01003 continue;
01004 }
01005 break;
01006
01007 case StructuralSymbols::Doctype:
01008
01009 if (!inDoctype)
01010 {
01011 CHANGE_STATE(StructuralSymbols::Doctype);
01012 inDoctype = true;
01013
01014 if (stateChanged)
01015 {
01016 continue;
01017 }
01018 }
01019 else
01020 {
01021 SAFE_CALL_EMITTER(endDoctypeDecl(userData));
01022 inDoctype = false;
01023 continue;
01024 }
01025 break;
01026
01027 default:
01028 if (!data[i] && !bufferLength && elementHasAttributes)
01029 {
01030
01031 attributeListComplete = true;
01032 continue;
01033 }
01034 }
01035 }
01036
01037 switch (state)
01038 {
01039
01040
01041
01042
01043 case StructuralSymbols::XmlDecl:
01044
01045 if (data[i] == StructuralSymbols::StandaloneYes || data[i] == StructuralSymbols::StandaloneNo
01046 || (data[i] == StructuralSymbols::StandaloneNotSpecified && dataQueue->count() == 2))
01047 {
01048
01049
01050 XmlChar *version;
01051 XmlChar *encoding;
01052 int standalone;
01053
01054 switch(data[i])
01055 {
01056 case StructuralSymbols::StandaloneYes:
01057 standalone = 1;
01058 break;
01059
01060 case StructuralSymbols::StandaloneNo:
01061 standalone = 0;
01062 break;
01063
01064 default:
01065 standalone = -1;
01066 }
01067
01068 version = dataQueue->dequeue()->data;
01069 encoding = dataQueue->dequeue()->data;
01070
01071 SAFE_CALL_EMITTER(xmlDecl(userData, version, encoding, standalone));
01072
01073 if (version)
01074 DELETE(version);
01075
01076 if (encoding)
01077 DELETE(encoding);
01078
01079 RESET_STATE;
01080 RESET_BUFFER;
01081 }
01082 else
01083 if (data[i] == StructuralSymbols::EndOfBlock)
01084 {
01085
01086
01087 NEW(dataQueueItem, DataQueueItem);
01088 dataQueueItem->type = Characters;
01089
01090 if (bufferLength)
01091 {
01092 buffer[bufferLength] = 0;
01093 NEW(dataQueueItem->data, XmlChar[xmlchar_strlen(buffer)+1]);
01094 xmlchar_strcpy(dataQueueItem->data, buffer);
01095 }
01096 else
01097
01098 dataQueueItem->data = 0;
01099
01100 dataQueue->enqueue(dataQueueItem);
01101
01102 RESET_BUFFER;
01103
01104 }
01105 else
01106 {
01107
01108 buffer[bufferLength] = data[i];
01109 bufferLength++;
01110 }
01111 break;
01112
01113 case StructuralSymbols::PI:
01114 if (data[i] == StructuralSymbols::EndOfBlock && dataQueue->count() == 1)
01115 {
01116 XmlChar *target;
01117
01118 target = dataQueue->dequeue()->data;
01119
01120 buffer[bufferLength] = 0;
01121
01122 SAFE_CALL_EMITTER(processingInstruction(userData, target, buffer));
01123
01124 if (target)
01125 DELETE(target);
01126
01127 RESET_BUFFER;
01128 RESET_STATE;
01129 }
01130 else
01131 if (data[i] == StructuralSymbols::EndOfBlock)
01132 {
01133
01134 NEW(dataQueueItem, DataQueueItem);
01135 dataQueueItem->type = Characters;
01136
01137 if (bufferLength)
01138 {
01139 buffer[bufferLength] = 0;
01140 NEW(dataQueueItem->data, XmlChar[xmlchar_strlen(buffer)+1]);
01141 xmlchar_strcpy(dataQueueItem->data, buffer);
01142 }
01143 else
01144
01145 dataQueueItem->data = 0;
01146
01147 dataQueue->enqueue(dataQueueItem);
01148
01149 RESET_BUFFER;
01150
01151 }
01152 else
01153 {
01154
01155 buffer[bufferLength] = data[i];
01156 bufferLength++;
01157 }
01158 break;
01159
01160 case StructuralSymbols::NewElement:
01161 if (data[i] == StructuralSymbols::EndOfBlock)
01162 {
01163
01164
01165
01166
01167 buffer[bufferLength] = 0;
01168 bufferLength++;
01169
01170
01171 NEW(elName, XmlChar[bufferLength]);
01172 xmlchar_strcpy(elName, buffer);
01173 elementNamesList->append(elName);
01174
01175
01176 NEW(ec, SimpleElementContext);
01177
01178
01179 ec->name = elName;
01180
01181 elementId = elementCounter;
01182
01183
01184
01185 elements->insert(elementCounter, ec);
01186
01187
01188 elementCounter++;
01189
01190
01191 FINISH_ELEMENT_START(elName);
01192
01193
01194 RESET_BUFFER;
01195 }
01196 else
01197 {
01198
01199 buffer[bufferLength] = data[i];
01200 bufferLength++;
01201 }
01202 break;
01203
01204 case StructuralSymbols::KnownElement:
01205
01206
01207
01208
01209
01210 fibMask = 1 << (SIZEOF_CHAR*8 - 1);
01211
01212
01213 fibTmpChar = (unsigned char)data[i];
01214
01215
01216 while (fibMask)
01217 {
01218 fibCode >>= 1;
01219 fibBits++;
01220
01221 if (fibTmpChar & fibMask)
01222 {
01223 fibCode = fibCode | ((unsigned long)1) << (SIZEOF_UNSIGNED_LONG*8-1);
01224
01225 if (!fibLastWasOne)
01226 fibLastWasOne = true;
01227 else
01228 {
01229
01230
01231 fibCode >>= (SIZEOF_UNSIGNED_LONG*8 - fibBits);
01232 elementId = Fibonacci::decode(fibCode);
01233 fibFinished = true;
01234 break;
01235 }
01236 }
01237 else
01238 fibLastWasOne = false;
01239
01240 fibMask >>= 1;
01241 }
01242
01243 if (fibFinished)
01244 {
01245
01246 ec = elements->find(elementId);
01247
01248 CHECK_POINTER(ec);
01249
01250
01251 FINISH_ELEMENT_START(ec->name);
01252
01253
01254
01255
01256 fibCode = 0;
01257 fibBits = 0;
01258 fibLastWasOne = false;
01259
01260 RESET_BUFFER;
01261 RESET_STATE;
01262 }
01263
01264 break;
01265
01266 case StructuralSymbols::Default:
01267
01268 if (data[i] == StructuralSymbols::EndOfBlock)
01269 {
01270
01271 SAFE_CALL_EMITTER(defaultHandler(userData, buffer, bufferLength));
01272 RESET_STATE;
01273 RESET_BUFFER;
01274 }
01275 else
01276 {
01277
01278 buffer[bufferLength] = data[i];
01279 bufferLength++;
01280
01281 if (bufferLength == XML_MODEL_BUFFER_DEFAULT_SIZE)
01282 {
01283
01284 SAFE_CALL_EMITTER(defaultHandler(userData, buffer, bufferLength));
01285 RESET_BUFFER;
01286 }
01287 }
01288
01289 break;
01290
01291 case StructuralSymbols::Comment:
01292
01293 if (data[i] == StructuralSymbols::EndOfBlock)
01294 {
01295 buffer[bufferLength] = 0;
01296 SAFE_CALL_EMITTER(comment(userData, buffer));
01297 RESET_STATE;
01298 RESET_BUFFER;
01299 }
01300 else
01301 {
01302
01303 buffer[bufferLength] = data[i];
01304 bufferLength++;
01305
01306 if (bufferLength == XML_MODEL_BUFFER_DEFAULT_SIZE)
01307 {
01308
01309 SAFE_CALL_EMITTER(comment(userData, buffer));
01310 RESET_BUFFER;
01311 }
01312 }
01313
01314 break;
01315
01316
01317
01318
01319
01320 case StructuralSymbols::Doctype:
01321 if ( dataQueue->count() == 3)
01322 {
01323 XmlChar *doctype, *publicId, *systemId;
01324
01325 doctype = dataQueue->dequeue()->data;
01326 publicId = dataQueue->dequeue()->data;
01327 systemId = dataQueue->dequeue()->data;
01328
01329 SAFE_CALL_EMITTER(startDoctypeDecl(userData, doctype, systemId, publicId,
01330 data[0] == StructuralSymbols::HasInternalSubsetYes));
01331
01332 if (doctype)
01333 DELETE(doctype);
01334
01335 if (publicId)
01336 DELETE(publicId);
01337
01338 if (systemId)
01339 DELETE(systemId);
01340
01341 RESET_BUFFER;
01342 RESET_STATE;
01343 }
01344 else
01345 if (data[i] == StructuralSymbols::EndOfBlock)
01346 {
01347
01348 NEW(dataQueueItem, DataQueueItem);
01349 dataQueueItem->type = Characters;
01350
01351 if (bufferLength)
01352 {
01353 if (buffer[0] == StructuralSymbols::EmptyString)
01354
01355 buffer[0] = 0;
01356 else
01357 buffer[bufferLength] = 0;
01358
01359 NEW(dataQueueItem->data, XmlChar[xmlchar_strlen(buffer)+1]);
01360 xmlchar_strcpy(dataQueueItem->data, buffer);
01361 }
01362 else
01363
01364 dataQueueItem->data = 0;
01365
01366 dataQueue->enqueue(dataQueueItem);
01367
01368 RESET_BUFFER;
01369 }
01370 else
01371 {
01372
01373 buffer[bufferLength] = data[i];
01374 bufferLength++;
01375 }
01376 break;
01377
01378
01379 case StructuralSymbols::EntityDecl:
01380 if (dataQueue->count() == 5)
01381 {
01382
01383 XmlChar *entityName, *value, *publicId, *systemId, *notationName;
01384 int valueLength;
01385
01386 entityName = dataQueue->dequeue()->data;
01387 value = dataQueue->dequeue()->data;
01388
01389 systemId = dataQueue->dequeue()->data;
01390 publicId = dataQueue->dequeue()->data;
01391 notationName = dataQueue->dequeue()->data;
01392
01393
01394 if (!value)
01395 valueLength = 0;
01396 else
01397 valueLength = xmlchar_strlen(value);
01398
01399 SAFE_CALL_EMITTER(entityDecl(userData, entityName, data[0] == StructuralSymbols::IsParameterEntityYes,
01400 value, valueLength, 0, systemId, publicId, notationName));
01401
01402 if (entityName)
01403 DELETE(entityName);
01404
01405 if (value)
01406 DELETE(value);
01407
01408
01409
01410
01411 if (systemId)
01412 DELETE(systemId);
01413
01414 if (publicId)
01415 DELETE(publicId);
01416
01417 if (notationName)
01418 DELETE(notationName);
01419
01420 RESET_BUFFER;
01421 RESET_STATE;
01422 }
01423 else
01424 if (data[i] == StructuralSymbols::EndOfBlock)
01425 {
01426
01427 NEW(dataQueueItem, DataQueueItem);
01428 dataQueueItem->type = Characters;
01429
01430 if (bufferLength)
01431 {
01432 if (buffer[0] == StructuralSymbols::EmptyString)
01433
01434 buffer[0] = 0;
01435 else
01436 buffer[bufferLength] = 0;
01437
01438 NEW(dataQueueItem->data, XmlChar[xmlchar_strlen(buffer)+1]);
01439 xmlchar_strcpy(dataQueueItem->data, buffer);
01440 }
01441 else
01442
01443 dataQueueItem->data = 0;
01444
01445 dataQueue->enqueue(dataQueueItem);
01446
01447 RESET_BUFFER;
01448 }
01449 else
01450 {
01451
01452 buffer[bufferLength] = data[i];
01453 bufferLength++;
01454 }
01455
01456 break;
01457
01458 case StructuralSymbols::NotationDecl:
01459 if (data[i] == StructuralSymbols::EndOfBlock)
01460 {
01461
01462 NEW(dataQueueItem, DataQueueItem);
01463 dataQueueItem->type = Characters;
01464
01465 if (bufferLength)
01466 {
01467 if (buffer[0] == StructuralSymbols::EmptyString)
01468
01469 buffer[0] = 0;
01470 else
01471 buffer[bufferLength] = 0;
01472
01473 NEW(dataQueueItem->data, XmlChar[xmlchar_strlen(buffer)+1]);
01474 xmlchar_strcpy(dataQueueItem->data, buffer);
01475 }
01476 else
01477
01478 dataQueueItem->data = 0;
01479
01480 dataQueue->enqueue(dataQueueItem);
01481
01482 RESET_BUFFER;
01483
01484
01485 if (dataQueue->count() == 3)
01486 {
01487
01488 XmlChar *notationName, *publicId, *systemId;
01489
01490 notationName = dataQueue->dequeue()->data;
01491
01492 systemId = dataQueue->dequeue()->data;
01493 publicId = dataQueue->dequeue()->data;
01494
01495 SAFE_CALL_EMITTER(notationDecl(userData, notationName, 0, systemId, publicId));
01496
01497 if (notationName)
01498 DELETE(notationName);
01499
01500
01501
01502
01503 if (systemId)
01504 DELETE(systemId);
01505
01506 if (publicId)
01507 DELETE(publicId);
01508
01509 if (notationName)
01510 DELETE(notationName);
01511
01512 RESET_STATE;
01513 }
01514 }
01515 else
01516 {
01517
01518 buffer[bufferLength] = data[i];
01519 bufferLength++;
01520 }
01521
01522 break;
01523
01524 default:
01525
01526 if (data[i] == StructuralSymbols::EmptyString)
01527 {
01528
01529 if (elementHasAttributes)
01530 {
01531
01532 XmlChar *attrValue;
01533
01534
01535 NEW(attrValue, XmlChar[1]);
01536 attrValue[0] = 0;
01537
01538 NEW(dataQueueItem, DataQueueItem);
01539 dataQueueItem->type = Characters;
01540 dataQueueItem->data = attrValue;
01541 dataQueue->enqueue(dataQueueItem);
01542 }
01543 }
01544 else
01545 if (data[i] == StructuralSymbols::EndOfBlock)
01546 {
01547 if (elementHasAttributes)
01548 {
01549
01550 XmlChar *attrValue;
01551
01552
01553 NEW(attrValue, XmlChar[bufferLength + 1]);
01554 buffer[bufferLength] = 0;
01555 xmlchar_strcpy(attrValue, buffer);
01556
01557 NEW(dataQueueItem, DataQueueItem);
01558 dataQueueItem->type = Characters;
01559 dataQueueItem->data = attrValue;
01560 dataQueue->enqueue(dataQueueItem);
01561 }
01562 else
01563 {
01564 if (bufferLength)
01565
01566 SAFE_CALL_EMITTER(characterData(userData, buffer, bufferLength));
01567 }
01568
01569 RESET_BUFFER;
01570 RESET_STATE;
01571 }
01572 else
01573 {
01574 buffer[bufferLength] = data[i];
01575 bufferLength++;
01576
01577 if (bufferLength == XML_MODEL_BUFFER_DEFAULT_SIZE)
01578 {
01579
01580 SAFE_CALL_EMITTER(characterData(userData, buffer, bufferLength));
01581 RESET_BUFFER;
01582 }
01583 }
01584 }
01585 }
01586 }