// Site Mapper // // Douglas Thrift // // $Id$ #include #include #include "SiteMapper.hpp" void Page::SetUrl(const cse::String &url) { static api::Pcre::RegEx url_(_B("^http://([^/]+)(/.*)?$")); if (api::Pcre::RegEx::Match match = url_(url)) { address = match[1]; path = !match[2].IsEmpty() ? match[2] : cse::String(_B("/")); } else throw ext::StringException(url); } bool Page::operator==(const cse::String &thing) { return address == thing || path == thing || title == thing; } bool Page::operator==(const Page &page) const { if (address == page.address) { return path == page.path || title == page.title; } return false; } xml::TextWriter &operator<<(xml::TextWriter &xml, Page &page) { xml::ScopeElement item(xml, _B("item")); xml.OpenElement(_B("link")); xml.SetAttribute(_B("address"), page.GetUrl()); xml.OutputText(page.title); xml.CloseElement(); if (!page.children.IsEmpty()) { xml::ScopeElement list(xml, _B("list")); _foreach (ext::Vector, child, page.children) xml << *child; } return xml; }