4 |
|
// |
5 |
|
// $Id$ |
6 |
|
|
7 |
< |
#include "Matcher.hpp" |
8 |
< |
#include "Page.hpp" |
7 |
> |
#include <cxx/standard.hh> |
8 |
|
|
9 |
< |
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); |
9 |
> |
#include <api/pcre/regex.hpp> |
10 |
|
|
11 |
< |
tab = 0; |
25 |
< |
} |
11 |
> |
#include "SiteMapper.hpp" |
12 |
|
|
13 |
< |
void Page::setUrl(const string& url) |
13 |
> |
void Page::SetUrl(const cse::String& url) |
14 |
|
{ |
15 |
< |
Matcher matcher("^http://(.+)(/.*)?$"); |
15 |
> |
static api::Pcre::RegEx url_(_B("^http://([^/]+)(/.*)?$")); |
16 |
|
|
17 |
< |
if (url == matcher) |
17 |
> |
if (api::Pcre::RegEx::Match match = url_(url)) |
18 |
|
{ |
19 |
< |
address = matcher[1]; |
20 |
< |
|
35 |
< |
if (matcher.size() > 2) |
36 |
< |
{ |
37 |
< |
path = matcher[2]; |
38 |
< |
} |
39 |
< |
else |
40 |
< |
{ |
41 |
< |
path = '/'; |
42 |
< |
} |
19 |
> |
address = match[1]; |
20 |
> |
path = !match[2].IsEmpty() ? match[2] : cse::String(_B("/")); |
21 |
|
} |
22 |
|
else |
23 |
< |
{ |
46 |
< |
cerr << program << ": Page.setUrl(" << url << ") failure.\n"; |
47 |
< |
|
48 |
< |
exit(1); |
49 |
< |
} |
23 |
> |
throw ext::StringException(url); |
24 |
|
} |
25 |
|
|
26 |
< |
bool Page::operator==(const string& thing) |
26 |
> |
bool Page::operator==(const cse::String& thing) |
27 |
|
{ |
28 |
< |
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; |
28 |
> |
return address == thing || path == thing || title == thing; |
29 |
|
} |
30 |
|
|
31 |
< |
bool Page::operator==(Page& page) |
31 |
> |
bool Page::operator==(const Page& page) const |
32 |
|
{ |
33 |
|
if (address == page.address) |
34 |
|
{ |
35 |
< |
if (path == page.path || title == page.title) return true; |
35 |
> |
return path == page.path || title == page.title; |
36 |
|
} |
37 |
|
|
38 |
|
return false; |
39 |
|
} |
40 |
|
|
41 |
< |
bool Page::operator<(Page& page) |
41 |
> |
xml::TextWriter& operator<<(xml::TextWriter& xml, Page& page) |
42 |
|
{ |
43 |
< |
if (address < page.address) if (path < page.path) return true; |
83 |
< |
|
84 |
< |
return false; |
85 |
< |
} |
43 |
> |
xml::ScopeElement item(xml, _B("item")); |
44 |
|
|
45 |
< |
bool Page::operator>(Page& page) |
46 |
< |
{ |
47 |
< |
if (address > page.address) if (path > page.path) return true; |
45 |
> |
xml.OpenElement(_B("link")); |
46 |
> |
xml.SetAttribute(_B("address"), page.GetUrl()); |
47 |
> |
xml.OutputText(page.title); |
48 |
> |
xml.CloseElement(); |
49 |
|
|
50 |
< |
return false; |
92 |
< |
} |
93 |
< |
|
94 |
< |
ostream& operator<<(ostream& output, Page& page) |
95 |
< |
{ |
96 |
< |
string tab(page.tab, '\t'); |
97 |
< |
|
98 |
< |
output << tab << "<item><link address=\"" << page.getUrl() << "\">" |
99 |
< |
<< page.title << "</link>\n"; |
100 |
< |
|
101 |
< |
if (!page.children.empty()) |
50 |
> |
if (!page.children.IsEmpty()) |
51 |
|
{ |
52 |
< |
output << tab << "\t<list>\n"; |
104 |
< |
|
105 |
< |
for (int index = 0; index < page.children.size(); index++) |
106 |
< |
{ |
107 |
< |
output << page.children[index](page.tab + 1) << '\n'; |
108 |
< |
} |
52 |
> |
xml::ScopeElement list(xml, _B("list")); |
53 |
|
|
54 |
< |
output << tab << "\t</list>\n"; |
54 |
> |
_foreach (ext::Vector<Page>, child, page.children) xml << *child; |
55 |
|
} |
56 |
|
|
57 |
< |
output << tab << "</item>"; |
114 |
< |
|
115 |
< |
return output; |
57 |
> |
return xml; |
58 |
|
} |