bool BinTreeNodeReader::nextTreeInternal(ProtocolTreeNode& node, QDataStream &in) { quint8 b; in >> b; int size = readListSize(b,in); in >> b; if (b == 2) return false; QByteArray tag; readString(b, tag, in); int attribCount = (size - 2 + size % 2) / 2; AttributeList attribs; readAttributes(attribs,attribCount,in); node.setTag(tag); node.setAttributes(attribs); if ((size % 2) == 1) return true; in >> b; if (isListTag(b)) { readList(b,node,in); return true; } QByteArray data; readString(b,data,in); node.setData(data); return true; }
bool BinTreeNodeReader::nextTreeInternal(ProtocolTreeNode& node) { quint8 b; if (!readInt8(b)) return false; int size = -1; if (!readListSize(b, size)) return false; if (size < 0) return false; if (!readInt8(b)) return false; if (b == 2) return false; QByteArray tag; if (!readString(b, tag)) return false; int attribCount = (size - 2 + size % 2) / 2; AttributeList attribs; if (!readAttributes(attribs,attribCount)) return false; node.setTag(tag); node.setAttributes(attribs); if ((size % 2) == 1) return true; if (!readInt8(b)) return false; if (isListTag(b)) { return readList(b,node); } QByteArray data; if (!readString(b,data)) return false; node.setData(data); return true; }
bool HTMLParser :: isBlockLevelTag() { if ( isPTag() || isListTag() || isPreTag() || isBodyStyleTag() || isFormTag() || isEmptyBlockTag() || isTableTag() ) { return true; } return false; }
void HTMLParser :: blockLevelTag( TElementShared aParent, bool aInsideForm ) { if ( isPTag() ) { pTag( aParent ); return; } if ( isListTag() ) { listTag( aParent ); skipTag(); return; } if ( isPreTag() ) { preTag( aParent ); return; } if ( isBodyStyleTag() ) { bodyStyleTag( aParent ); return; } if ( isFormTag() ) { if ( aInsideForm ) { // Not allowed here cout << "blockLevel: Illegal tag found. Skipping...\n"; skipTag(); return; } else { bodyStyleTag( aParent, true ); return; } } if ( isEmptyBlockTag() ) { emptyElementTag( aParent ); return; } if ( isTableTag() ) { tableTag( aParent ); return; } }
ProtocolTreeNode* BinTreeNodeReader::nextTreeInternal() { int b = this->in->read(); int size = readListSize(b); b = this->in->read(); if (b == 2) return NULL; std::string* tag = this->readStringAsString(b); if ((size == 0) || (tag == NULL)) throw WAException("nextTree sees 0 list or null tag", WAException::CORRUPT_STREAM_EX, -1); int attribCount = (size - 2 + size % 2) / 2; std::map<string, string>* attribs = readAttributes(attribCount); if (size % 2 == 1) { ProtocolTreeNode* ret = new ProtocolTreeNode(*tag); ret->attributes = attribs; delete tag; return ret; } b = this->in->read(); if (isListTag(b)) { ProtocolTreeNode* ret = new ProtocolTreeNode(*tag, NULL, readList(b)); ret->attributes = attribs; delete tag; return ret; } ReadData* obj = this->readString(b); std::vector<unsigned char>* data; if (obj->type == STRING) { std::string* s = (std::string*) obj->data; data = new std::vector<unsigned char>(s->begin(), s->end()); delete s; } else data = (std::vector<unsigned char>*) obj->data; ProtocolTreeNode* ret = new ProtocolTreeNode(*tag, data); ret->attributes = attribs; delete obj; delete tag; return ret; }
void HTMLParser :: pTag( TElementShared aParent ) { cout << "p tag found\n"; // Add to parent TElementShared element = mDocument->createElement( "p" ); aParent->appendChild( element ); bool insideP = true; string attribute; while ( insideP ) { string data = getString(); switch ( mStringType ) { case ATTR : { attribute = data; if ( mAttrNoValue ) { element->setAttribute( attribute, "" ); attribute = ""; } break; } case ATTRVALUE : { if ( attribute.compare( "" ) ) { // Attribute has a name // I'll declare it legal element->setAttribute( attribute, data ); attribute = ""; } break; } case TAG : { if ( !isStartTag() ) { if ( isPTag() ) { cout << "p closing tag found\n"; insideP = false; continue; } if ( isAdressTag() || isBodyStyleTag() || isFormTag() || isListTag() ) { cout << "p closed implicitly\n"; insideP = false; backPedal(); continue; } cout << "p: Unexpected closing tag found: " << mTag << ". Skipping...\n"; } else { if ( isBlockLevelTag() || isHeadingTag() || isLITag() ) { cout << "p closed implicitly\n"; insideP = false; backPedal(); continue; } if ( isTextLevelTag() ) { textLevelTag( element ); continue; } if ( isCommentTag() ) { commentTag( element ); continue; } // Not a known tag cout << "p: Unexpected tag found: " << mTag << ". Skipping...\n"; skipTag(); } break; } case TEXT : { if ( data.compare( " " ) && data.compare( "" ) ) { cout << "Text is:" << endl << data << endl; TTextShared text = mDocument->createText( data ); element->appendChild( text ); } break; } } } }
void HTMLParser :: flowLevelTag( TElementShared aParent ) { cout << mTag << " tag found\n"; // Save the tag name string tag = mTag; // Add to parent TElementShared element = mDocument->createElement( mTag ); aParent->appendChild( element ); bool insideFlow = true; string attribute; while ( insideFlow ) { // Warning: more possible than a tag only string data = getString(); switch ( mStringType ) { case ATTR : { attribute = data; if ( mAttrNoValue ) { element->setAttribute( attribute, "" ); attribute = ""; } break; } case ATTRVALUE : { if ( attribute.compare( "" ) ) { // Attribute has a name // I'll declare it legal element->setAttribute( attribute, data ); attribute = ""; } break; } case TAG : { if ( isStartTag() ) { if ( isBlockLevelTag() ) { blockLevelTag( element ); continue; } if ( isTextLevelTag() ) { textLevelTag( element ); continue; } if ( !mTag.compare( tag ) ) { cout << mTag << " closed implicitly\n"; // End the while loop insideFlow = false; backPedal(); continue; } // Not a known tag cout << "flowLevel: Unexpected tag found: " << mTag << ". Skipping...\n"; skipTag(); } else { if ( !mTag.compare( tag ) ) { cout << mTag << " closing tag found\n"; // End the while loop insideFlow = false; continue; } if ( isListTag() ) { cout << mTag << " closed implicitly\n"; // End the while loop insideFlow = false; backPedal(); continue; } cout << "flowLevel: Unexpected closing tag found: " << mTag << ". Skipping...\n"; } break; } case TEXT : { if ( data.compare( " " ) && data.compare( "" ) ) { cout << "Text is:" << endl << data << endl; TTextShared text = mDocument->createText( data ); element->appendChild( text ); } break; } } } }