XMLTokenHandler::Result PrefsLoader::HandleToken(XMLToken &token) { switch (token.GetType()) { case XMLToken::TYPE_STag: case XMLToken::TYPE_ETag: case XMLToken::TYPE_EmptyElemTag: if (token.GetType() != XMLToken::TYPE_ETag) { HandleStartElement(token.GetName().GetLocalPart(), token.GetName().GetLocalPartLength(), token.GetAttributes(), token.GetAttributesCount()); } if (token.GetType() != XMLToken::TYPE_STag) HandleEndElement(token.GetName().GetLocalPart(), token.GetName().GetLocalPartLength()); } return RESULT_OK; }
/* virtual */ XMLTokenHandler::Result XMLToLanguageParserTokenHandler::HandleToken(XMLToken &token) { OP_STATUS status = OpStatus::OK; OpStatus::Ignore(status); if (finished) return RESULT_OK; if (ignore_element_depth != 0) { if (token.GetType() == XMLToken::TYPE_STag) ++ignore_element_depth; else if (token.GetType() == XMLToken::TYPE_ETag) --ignore_element_depth; } XMLParserImpl *xmlparser = (XMLParserImpl *) token.GetParser(); BOOL block = FALSE; if (ignore_element_depth == 0) { #ifdef XML_ERRORS XMLRange location; #endif // XML_ERRORS switch (token.GetType()) { case XMLToken::TYPE_PI: #ifdef XML_ERRORS token.GetTokenRange(location); parser->SetLocation(location); #endif // XML_ERRORS status = parser->AddProcessingInstruction(token.GetName().GetLocalPart(), token.GetName().GetLocalPartLength(), token.GetData(), token.GetDataLength()); break; case XMLToken::TYPE_CDATA: case XMLToken::TYPE_Text: case XMLToken::TYPE_Comment: { XMLLanguageParser::CharacterDataType cdatatype = XMLLanguageParser::CHARACTERDATA_TEXT; if (token.GetType() != XMLToken::TYPE_Comment) if (token.GetType() == XMLToken::TYPE_CDATA) cdatatype = XMLLanguageParser::CHARACTERDATA_CDATA_SECTION; else if (token.GetLiteralIsWhitespace()) { if (!entity_signalled) /* Don't generate calls to the language parser before the first call to StartEntity. */ break; cdatatype = XMLLanguageParser::CHARACTERDATA_TEXT_WHITESPACE; } const uni_char *simplevalue; uni_char *allocatedvalue; if ((simplevalue = token.GetLiteralSimpleValue()) == 0) { simplevalue = allocatedvalue = token.GetLiteralAllocatedValue(); if (!allocatedvalue) status = OpStatus::ERR_NO_MEMORY; } else allocatedvalue = 0; if (simplevalue) { #ifdef XML_ERRORS token.GetTokenRange(location); parser->SetLocation(location); #endif // XML_ERRORS if (token.GetType() == XMLToken::TYPE_Comment) status = parser->AddComment(simplevalue, token.GetLiteralLength()); else status = parser->AddCharacterData(cdatatype, simplevalue, token.GetLiteralLength()); OP_DELETEA(allocatedvalue); } break; } case XMLToken::TYPE_STag: case XMLToken::TYPE_ETag: case XMLToken::TYPE_EmptyElemTag: if (!(xmlparser->GetCurrentEntityUrl() == current_entity_url) && xmlparser->GetCurrentEntityDepth() <= current_entity_depth) status = parser->EndEntity(); if (OpStatus::IsSuccess(status) && (!(xmlparser->GetCurrentEntityUrl() == current_entity_url) || current_entity_url.IsEmpty() && !entity_signalled) && xmlparser->GetCurrentEntityDepth() > current_entity_depth) { status = parser->StartEntity(xmlparser->GetCurrentEntityUrl(), xmlparser->GetDocumentInformation(), xmlparser->GetCurrentEntityDepth() > 1); entity_signalled = TRUE; } current_entity_url = xmlparser->GetCurrentEntityUrl(); current_entity_depth = xmlparser->GetCurrentEntityDepth(); if (token.GetType() != XMLToken::TYPE_ETag) { if (OpStatus::IsSuccess(status)) { BOOL fragment_start = FALSE; if (!fragment_found) { if (!fragment_id) fragment_start = TRUE; else { XMLToken::Attribute *attributes = token.GetAttributes(); unsigned attributes_count = token.GetAttributesCount(); unsigned fragment_id_length = uni_strlen(fragment_id); for (unsigned index = 0; index < attributes_count; ++index) if (attributes[index].GetId()) if (attributes[index].GetValueLength() == fragment_id_length && uni_strncmp(attributes[index].GetValue(), fragment_id, fragment_id_length) == 0) { fragment_start = TRUE; break; } } if (fragment_start) fragment_found = TRUE; } #ifdef XML_ERRORS token.GetTokenRange(location); parser->SetLocation(location); #endif // XML_ERRORS BOOL ignore_element = FALSE; status = parser->StartElement(token.GetName(), fragment_start, ignore_element); if (ignore_element) { if (token.GetType() == XMLToken::TYPE_STag) ignore_element_depth = 1; } else { XMLToken::Attribute *attributes = token.GetAttributes(); unsigned attributes_count = token.GetAttributesCount(); for (unsigned index = 0; OpStatus::IsSuccess(status) && index < attributes_count; ++index) { #ifdef XML_ERRORS token.GetAttributeRange(location, index); parser->SetLocation(location); #endif // XML_ERRORS XMLToken::Attribute &attribute = attributes[index]; status = parser->AddAttribute(attribute.GetName(), attribute.GetValue(), attribute.GetValueLength(), attribute.GetSpecified(), attribute.GetId()); } if (OpStatus::IsSuccess(status)) status = parser->StartContent(); } } } if (OpStatus::IsSuccess(status) && token.GetType() != XMLToken::TYPE_STag) { #ifdef XML_ERRORS token.GetTokenRange(location); parser->SetLocation(location); #endif // XML_ERRORS status = parser->EndElement(block, finished); if (OpStatus::IsSuccess(status) && block) parser->SetSourceCallback(&sourcecallbackimpl); } break; case XMLToken::TYPE_Finished: status = parser->EndEntity(); } } if (OpStatus::IsSuccess(status)) if (block) return RESULT_BLOCK; else return RESULT_OK; else if (OpStatus::IsMemoryError(status)) return RESULT_OOM; else return RESULT_ERROR; }
OP_STATUS WebFeedStorage::HandleStartTagToken(const XMLToken& token) { // Fetch information about the element. const XMLCompleteNameN &elemname = token.GetName(); const uni_char *elm_name = elemname.GetLocalPart(); UINT elm_name_len = elemname.GetLocalPartLength(); if (STRN_MATCH(elm_name, "entry", elm_name_len)) { OP_ASSERT(m_current_feed); OP_ASSERT(!m_current_entry); m_current_entry = OP_NEW(WebFeedEntry, (m_current_feed)); if (!m_current_entry) return OpStatus::ERR_NO_MEMORY; if (OpStatus::IsError(m_current_entry->Init())) { m_current_entry->DecRef(); return OpStatus::ERR_NO_MEMORY; } const XMLToken::Attribute *attrs = token.GetAttributes(); for (UINT i = 0; i < token.GetAttributesCount(); i++) { const uni_char *attr_name = attrs[i].GetName().GetLocalPart(); UINT attr_name_len = attrs[i].GetName().GetLocalPartLength(); const uni_char *attr_value = attrs[i].GetValue(); UINT attr_value_len = attrs[i].GetValueLength(); if (STRN_MATCH(attr_name, "id", attr_name_len)) { OpString attr_val_str; RETURN_IF_ERROR(attr_val_str.Set(attr_value, attr_value_len)); m_current_entry->SetId((OpFeedEntry::EntryId)uni_atoi(attr_val_str.CStr())); } else if (STRN_MATCH(attr_name, "keep", attr_name_len)) { if (STRN_MATCH(attr_value, "yes", attr_value_len)) m_current_entry->SetKeep(TRUE); } else if (STRN_MATCH(attr_name, "read", attr_name_len)) { if (STRN_MATCH(attr_value, "yes", attr_value_len)) m_current_entry->SetReadStatus(OpFeedEntry::STATUS_READ); } else if (STRN_MATCH(attr_name, "guid", attr_name_len)) { OpString attr_val_str; RETURN_IF_ERROR(attr_val_str.Set(attr_value, attr_value_len)); m_current_entry->SetGuid(attr_val_str.CStr()); } } } else if (STRN_MATCH(elm_name, "feed", elm_name_len)) { OP_ASSERT(!m_current_feed); if (m_is_feed_file) { OP_STATUS status; if (m_current_feed) m_current_feed->DecRef(); m_current_feed = OP_NEW(WebFeed, ()); if (!m_current_feed) return OpStatus::ERR_NO_MEMORY; OP_ASSERT(m_current_stub); if (m_current_stub) status = m_current_feed->Init(m_current_stub); else return OpStatus::ERR; if (OpStatus::IsError(status)) { m_current_feed->DecRef(); m_current_feed = NULL; return OpStatus::ERR_NO_MEMORY; } else m_current_feed->IncRef(); } else {