--- SiteMapper/Page.cpp 2004/04/01 06:55:16 143 +++ SiteMapper/Page.cpp 2004/12/14 04:50:07 332 @@ -4,85 +4,35 @@ // // $Id$ -#include "Matcher.hpp" -#include "Page.hpp" +#include "SiteMapper.hpp" +#include "Matcher/Matcher.hpp" -Page::Page(const string& address, const string& path, const string& title) +void Page::setUrl(const ext::String& url) { - setAddress(address); - setPath(path); - setTitle(title); - - tab = 0; -} - -Page::Page(const string& url, const string& title) -{ - setUrl(url); - setTitle(title); - - tab = 0; -} - -void Page::setUrl(const string& url) -{ - Matcher matcher("^http://(.+)(/.*)?$"); + Matcher matcher("^http://(.+)(/.*)?$", (PCRE_UNGREEDY | PCRE_DOTALL)); if (url == matcher) { address = matcher[1]; - if (matcher.size() > 2) - { - path = matcher[2]; - } - else - { - path = '/'; - } + if (matcher.size() > 2) path = matcher[2]; else path = "/"; } else { - cerr << program << ": Page.setUrl(" << url << ") failure.\n"; + api::Cerr << program << ": Page.setUrl(" << url << ") failure.\n"; - exit(1); + throw; } } -bool Page::operator==(const string& thing) +bool Page::operator==(const ext::String& thing) { - if (address == thing) - { - return true; - } - else if (path == thing) - { - return true; - } - else if (title == thing) - { - return true; - } - - return false; + return address == thing || path == thing || title == thing; } bool Page::operator==(Matcher& matcher) { - if (address == matcher) - { - return true; - } - else if (path == matcher) - { - return true; - } - else if (title == matcher) - { - return true; - } - - return false; + return address == matcher || path == matcher || title == matcher; } bool Page::operator==(const Page& page) const @@ -95,26 +45,21 @@ bool Page::operator==(const Page& page) return false; } -ostream& operator<<(ostream& output, Page& page) +xml::TextWriter& operator<<(xml::TextWriter& xml, Page& page) { - string tab(page.tab, '\t'); + xml::ScopeElement item(xml, "item"); - output << tab << "" - << page.title << "\n"; + xml.OpenElement("link"); + xml.SetAttribute("address", page.getUrl()); + xml.OutputText(page.title); + xml.CloseElement(); - if (!page.children.empty()) + if (!page.children.IsEmpty()) { - output << tab << "\t\n"; - - for (unsigned index = 0; index < page.children.size(); index++) - { - output << page.children[index](page.tab + 1) << '\n'; - } + xml::ScopeElement list(xml, "list"); - output << tab << "\t\n"; + _mforeach (ext::Vector, child, page.children) xml << *child; } - output << tab << ""; - - return output; + return xml; }