4 |
|
// |
5 |
|
// $Id$ |
6 |
|
|
7 |
< |
#include "Matcher.hpp" |
8 |
< |
#include "Page.hpp" |
7 |
> |
#include "SiteMapper.hpp" |
8 |
> |
#include "Matcher/Matcher.hpp" |
9 |
|
|
10 |
< |
Page::Page(const string& address, const string& path, const string& title) |
10 |
> |
void Page::setUrl(const ext::String& url) |
11 |
|
{ |
12 |
< |
setAddress(address); |
13 |
< |
setPath(path); |
14 |
< |
setTitle(title); |
12 |
> |
api::Cerr << PCRE_MULTILINE << " = " << Matcher::defaults << ios::NewLine; |
13 |
|
|
14 |
< |
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 |
< |
} |
14 |
> |
Matcher matcher("^http://(.+)(/.*)?$", (PCRE_UNGREEDY | PCRE_DOTALL)); |
15 |
|
|
16 |
< |
void Page::setUrl(const string& url) |
28 |
< |
{ |
29 |
< |
Matcher matcher("^http://(.+)(/.*)?$"); |
16 |
> |
api::Cerr << (PCRE_UNGREEDY | PCRE_DOTALL) << " = " << matcher.options << ios::NewLine; |
17 |
|
|
18 |
|
if (url == matcher) |
19 |
|
{ |
20 |
|
address = matcher[1]; |
21 |
|
|
22 |
< |
if (matcher.size() > 2) |
36 |
< |
{ |
37 |
< |
path = matcher[2]; |
38 |
< |
} |
39 |
< |
else |
40 |
< |
{ |
41 |
< |
path = '/'; |
42 |
< |
} |
22 |
> |
if (matcher.size() > 2) path = matcher[2]; else path = "/"; |
23 |
|
} |
24 |
|
else |
25 |
|
{ |
26 |
< |
cerr << program << ": Page.setUrl(" << url << ") failure.\n"; |
26 |
> |
api::Cerr << program << ": Page.setUrl(" << url << ") failure.\n"; |
27 |
|
|
28 |
< |
exit(1); |
28 |
> |
throw; |
29 |
|
} |
30 |
|
} |
31 |
|
|
32 |
< |
bool Page::operator==(const string& thing) |
32 |
> |
bool Page::operator==(const ext::String& thing) |
33 |
|
{ |
34 |
< |
if (address == thing) |
55 |
< |
{ |
56 |
< |
return true; |
57 |
< |
} |
58 |
< |
else if (path == thing) |
59 |
< |
{ |
60 |
< |
return true; |
61 |
< |
} |
62 |
< |
else if (title == thing) |
63 |
< |
{ |
64 |
< |
return true; |
65 |
< |
} |
66 |
< |
|
67 |
< |
return false; |
34 |
> |
return address == thing || path == thing || title == thing; |
35 |
|
} |
36 |
|
|
37 |
|
bool Page::operator==(Matcher& matcher) |
38 |
|
{ |
39 |
< |
if (address == matcher) |
73 |
< |
{ |
74 |
< |
return true; |
75 |
< |
} |
76 |
< |
else if (path == matcher) |
77 |
< |
{ |
78 |
< |
return true; |
79 |
< |
} |
80 |
< |
else if (title == matcher) |
81 |
< |
{ |
82 |
< |
return true; |
83 |
< |
} |
84 |
< |
|
85 |
< |
return false; |
39 |
> |
return address == matcher || path == matcher || title == matcher; |
40 |
|
} |
41 |
|
|
42 |
|
bool Page::operator==(const Page& page) const |
43 |
|
{ |
44 |
|
if (address == page.address) |
45 |
|
{ |
46 |
< |
if (path == page.path || title == page.title) return true; |
46 |
> |
return path == page.path || title == page.title; |
47 |
|
} |
48 |
|
|
49 |
|
return false; |
50 |
|
} |
51 |
|
|
52 |
< |
bool Page::operator<(const Page& page) const |
52 |
> |
xml::TextWriter& operator<<(xml::TextWriter& xml, Page& page) |
53 |
|
{ |
54 |
< |
if (address == page.address) |
101 |
< |
{ |
102 |
< |
return path < page.path; |
103 |
< |
} |
54 |
> |
xml::ScopeElement item(xml, "item"); |
55 |
|
|
56 |
< |
return address < page.address; |
57 |
< |
} |
56 |
> |
xml.OpenElement("link"); |
57 |
> |
xml.SetAttribute("address", page.getUrl()); |
58 |
> |
xml.OutputText(page.title); |
59 |
> |
xml.CloseElement(); |
60 |
|
|
61 |
< |
bool Page::operator>(const Page& page) const |
109 |
< |
{ |
110 |
< |
if (address == page.address) |
61 |
> |
if (!page.children.IsEmpty()) |
62 |
|
{ |
63 |
< |
return path > page.path; |
113 |
< |
} |
63 |
> |
xml::ScopeElement list(xml, "list"); |
64 |
|
|
65 |
< |
return address > page.address; |
116 |
< |
} |
117 |
< |
|
118 |
< |
ostream& operator<<(ostream& output, Page& page) |
119 |
< |
{ |
120 |
< |
string tab(page.tab, '\t'); |
121 |
< |
|
122 |
< |
output << tab << "<item><link address=\"" << page.getUrl() << "\">" |
123 |
< |
<< page.title << "</link>\n"; |
124 |
< |
|
125 |
< |
if (!page.children.empty()) |
126 |
< |
{ |
127 |
< |
output << tab << "\t<list>\n"; |
128 |
< |
|
129 |
< |
for (unsigned index = 0; index < page.children.size(); index++) |
130 |
< |
{ |
131 |
< |
output << page.children[index](page.tab + 1) << '\n'; |
132 |
< |
} |
133 |
< |
|
134 |
< |
output << tab << "\t</list>\n"; |
65 |
> |
_mforeach (ext::Vector<Page>, child, page.children) xml << *child; |
66 |
|
} |
67 |
|
|
68 |
< |
output << tab << "</item>"; |
138 |
< |
|
139 |
< |
return output; |
68 |
> |
return xml; |
69 |
|
} |