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 |
< |
tab = 0; |
17 |
< |
} |
18 |
< |
|
19 |
< |
Page::Page(const string& url, const string& title) |
20 |
< |
{ |
21 |
< |
setUrl(url); |
22 |
< |
setTitle(title); |
23 |
< |
|
24 |
< |
tab = 0; |
25 |
< |
} |
26 |
< |
|
27 |
< |
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 |
|
if (address == thing) |
38 |
|
{ |
50 |
|
return false; |
51 |
|
} |
52 |
|
|
53 |
< |
bool Page::operator==(Page& page) |
53 |
> |
bool Page::operator==(Matcher& matcher) |
54 |
|
{ |
55 |
< |
if (address == page.address) |
55 |
> |
if (address == matcher) |
56 |
|
{ |
57 |
< |
if (path == page.path || title == page.title) return true; |
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) |
81 |
< |
{ |
82 |
< |
if (address < page.address) if (path < page.path) return true; |
83 |
< |
|
84 |
< |
return false; |
85 |
< |
} |
86 |
< |
|
87 |
< |
bool Page::operator>(Page& page) |
71 |
> |
bool Page::operator==(const Page& page) const |
72 |
|
{ |
73 |
< |
if (address > page.address) if (path > page.path) return true; |
73 |
> |
if (address == page.address) |
74 |
> |
{ |
75 |
> |
return path == page.path || title == page.title; |
76 |
> |
} |
77 |
|
|
78 |
|
return false; |
79 |
|
} |
80 |
|
|
81 |
< |
ostream& operator<<(ostream& output, Page& page) |
81 |
> |
xml::TextWriter& operator<<(xml::TextWriter& xml, Page& page) |
82 |
|
{ |
83 |
< |
string tab(page.tab, '\t'); |
83 |
> |
xml::ScopeElement item(xml, "item"); |
84 |
|
|
85 |
< |
output << tab << "<item><link address=\"" << page.getUrl() << "\">" |
86 |
< |
<< page.title << "</link>\n"; |
85 |
> |
xml.OpenElement("link"); |
86 |
> |
xml.SetAttribute("address", page.getUrl()); |
87 |
> |
xml.OutputText(page.title); |
88 |
> |
xml.CloseElement(); |
89 |
|
|
90 |
< |
if (!page.children.empty()) |
90 |
> |
if (!page.children.IsEmpty()) |
91 |
|
{ |
92 |
< |
output << tab << "\t<list>\n"; |
92 |
> |
xml::ScopeElement list(xml, "list"); |
93 |
|
|
94 |
< |
for (int index = 0; index < page.children.size(); index++) |
106 |
< |
{ |
107 |
< |
output << page.children[index](page.tab + 1) << '\n'; |
108 |
< |
} |
109 |
< |
|
110 |
< |
output << tab << "\t</list>\n"; |
94 |
> |
_mforeach (ext::Vector<Page>, child, page.children) xml << *child; |
95 |
|
} |
96 |
|
|
97 |
< |
output << tab << "</item>"; |
114 |
< |
|
115 |
< |
return output; |
97 |
> |
return xml; |
98 |
|
} |