4 |
|
// |
5 |
|
// $Id$ |
6 |
|
|
7 |
< |
#include "Matcher.hpp" |
8 |
< |
#include "Page.hpp" |
7 |
> |
#include <menes/cxx/standard.hh> |
8 |
|
|
9 |
< |
void Page::setUrl(const ext::String& url) |
11 |
< |
{ |
12 |
< |
Matcher matcher("^http://(.+)(/.*)?$"); |
9 |
> |
#include <menes/api/pcre/regex.hpp> |
10 |
|
|
11 |
< |
if (url == matcher) |
15 |
< |
{ |
16 |
< |
address = matcher[1]; |
11 |
> |
#include "SiteMapper.hpp" |
12 |
|
|
13 |
< |
if (matcher.size() > 2) |
19 |
< |
{ |
20 |
< |
path = matcher[2]; |
21 |
< |
} |
22 |
< |
else |
23 |
< |
{ |
24 |
< |
path = "/"; |
25 |
< |
} |
26 |
< |
} |
27 |
< |
else |
28 |
< |
{ |
29 |
< |
api::Cerr << program << ": Page.setUrl(" << url << ") failure.\n"; |
30 |
< |
|
31 |
< |
std::exit(1); |
32 |
< |
} |
33 |
< |
} |
34 |
< |
|
35 |
< |
bool Page::operator==(const ext::String& thing) |
13 |
> |
void Page::SetUrl(const cse::String& url) |
14 |
|
{ |
15 |
< |
if (address == thing) |
16 |
< |
{ |
17 |
< |
return true; |
40 |
< |
} |
41 |
< |
else if (path == thing) |
42 |
< |
{ |
43 |
< |
return true; |
44 |
< |
} |
45 |
< |
else if (title == thing) |
15 |
> |
static api::Pcre::RegEx url_(_B("^http://([^/]+)(/.*)?$")); |
16 |
> |
|
17 |
> |
if (api::Pcre::RegEx::Match match = url_(url)) |
18 |
|
{ |
19 |
< |
return true; |
19 |
> |
address = match[1]; |
20 |
> |
path = !match[2].IsEmpty() ? match[2] : cse::String(_B("/")); |
21 |
|
} |
22 |
< |
|
23 |
< |
return false; |
22 |
> |
else |
23 |
> |
throw ext::StringException(url); |
24 |
|
} |
25 |
|
|
26 |
< |
bool Page::operator==(Matcher& matcher) |
26 |
> |
bool Page::operator==(const cse::String& thing) |
27 |
|
{ |
28 |
< |
if (address == matcher) |
56 |
< |
{ |
57 |
< |
return true; |
58 |
< |
} |
59 |
< |
else if (path == matcher) |
60 |
< |
{ |
61 |
< |
return true; |
62 |
< |
} |
63 |
< |
else if (title == matcher) |
64 |
< |
{ |
65 |
< |
return true; |
66 |
< |
} |
67 |
< |
|
68 |
< |
return false; |
28 |
> |
return address == thing || path == thing || title == thing; |
29 |
|
} |
30 |
|
|
31 |
|
bool Page::operator==(const Page& page) const |
40 |
|
|
41 |
|
xml::TextWriter& operator<<(xml::TextWriter& xml, Page& page) |
42 |
|
{ |
43 |
< |
xml::ScopeElement item(xml, "item"); |
43 |
> |
xml::ScopeElement item(xml, _B("item")); |
44 |
|
|
45 |
< |
xml.OpenElement("link"); |
46 |
< |
xml.SetAttribute("address", page.getUrl()); |
45 |
> |
xml.OpenElement(_B("link")); |
46 |
> |
xml.SetAttribute(_B("address"), page.GetUrl()); |
47 |
|
xml.OutputText(page.title); |
48 |
|
xml.CloseElement(); |
49 |
|
|
50 |
|
if (!page.children.IsEmpty()) |
51 |
|
{ |
52 |
< |
xml::ScopeElement list(xml, "list"); |
52 |
> |
xml::ScopeElement list(xml, _B("list")); |
53 |
|
|
54 |
< |
_mforeach (ext::Vector<Page>, child, page.children) xml << *child; |
54 |
> |
_foreach (ext::Vector<Page>, child, page.children) xml << *child; |
55 |
|
} |
56 |
|
|
57 |
|
return xml; |