7 |
|
#include "Matcher.hpp" |
8 |
|
#include "Page.hpp" |
9 |
|
|
10 |
< |
Page::Page(const string& address, const string& path, const string& title) |
11 |
< |
{ |
12 |
< |
setAddress(address); |
13 |
< |
setPath(path); |
14 |
< |
setTitle(title); |
15 |
< |
} |
16 |
< |
|
17 |
< |
Page::Page(const string& url) |
18 |
< |
{ |
19 |
< |
setUrl(url); |
20 |
< |
} |
21 |
< |
|
22 |
< |
void Page::setUrl(const string& url) |
10 |
> |
void Page::setUrl(const ext::String& url) |
11 |
|
{ |
12 |
|
Matcher matcher("^http://(.+)(/.*)?$"); |
13 |
|
|
21 |
|
} |
22 |
|
else |
23 |
|
{ |
24 |
< |
path = '/'; |
24 |
> |
path = "/"; |
25 |
|
} |
26 |
|
} |
27 |
|
else |
28 |
|
{ |
29 |
< |
cerr << program << ": Page.setUrl(" << url << ") failure.\n"; |
29 |
> |
api::Cerr << program << ": Page.setUrl(" << url << ") failure.\n"; |
30 |
|
|
31 |
< |
exit(1); |
31 |
> |
std::exit(1); |
32 |
|
} |
33 |
|
} |
34 |
|
|
35 |
< |
bool Page::operator==(const string& thing) |
35 |
> |
bool Page::operator==(const ext::String& thing) |
36 |
|
{ |
37 |
< |
// |
37 |
> |
if (address == thing) |
38 |
> |
{ |
39 |
> |
return true; |
40 |
> |
} |
41 |
> |
else if (path == thing) |
42 |
> |
{ |
43 |
> |
return true; |
44 |
> |
} |
45 |
> |
else if (title == thing) |
46 |
> |
{ |
47 |
> |
return true; |
48 |
> |
} |
49 |
|
|
50 |
|
return false; |
51 |
|
} |
52 |
|
|
53 |
< |
bool Page::operator==(Page& page) |
53 |
> |
bool Page::operator==(Matcher& matcher) |
54 |
|
{ |
55 |
< |
// |
55 |
> |
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; |
69 |
|
} |
70 |
|
|
71 |
< |
bool Page::operator<(Page& page) |
71 |
> |
bool Page::operator==(const Page& page) const |
72 |
|
{ |
73 |
< |
// |
73 |
> |
if (address == page.address) |
74 |
> |
{ |
75 |
> |
return path == page.path || title == page.title; |
76 |
> |
} |
77 |
|
|
78 |
|
return false; |
79 |
|
} |
80 |
|
|
81 |
< |
bool Page::operator>(Page& page) |
81 |
> |
xml::TextWriter& operator<<(xml::TextWriter& xml, Page& page) |
82 |
|
{ |
83 |
< |
// |
83 |
> |
xml::ScopeElement item(xml, "item"); |
84 |
|
|
85 |
< |
return false; |
85 |
> |
xml.OpenElement("link"); |
86 |
> |
xml.SetAttribute("address", page.getUrl()); |
87 |
> |
xml.OutputText(page.title); |
88 |
> |
xml.CloseElement(); |
89 |
> |
|
90 |
> |
if (!page.children.IsEmpty()) |
91 |
> |
{ |
92 |
> |
xml::ScopeElement list(xml, "list"); |
93 |
> |
|
94 |
> |
_mforeach (ext::Vector<Page>, child, page.children) xml << *child; |
95 |
> |
} |
96 |
> |
|
97 |
> |
return xml; |
98 |
|
} |