1 |
Douglas Thrift |
128 |
// Site Mapper |
2 |
|
|
// |
3 |
|
|
// Douglas Thrift |
4 |
|
|
// |
5 |
|
|
// $Id$ |
6 |
|
|
|
7 |
douglas |
328 |
#include "SiteMapper.hpp" |
8 |
|
|
#include "Matcher/Matcher.hpp" |
9 |
Douglas Thrift |
128 |
|
10 |
douglas |
285 |
void Page::setUrl(const ext::String& url) |
11 |
Douglas Thrift |
128 |
{ |
12 |
douglas |
330 |
api::Cerr << PCRE_MULTILINE << " = " << Matcher::defaults << ios::NewLine; |
13 |
Douglas Thrift |
128 |
|
14 |
douglas |
330 |
Matcher matcher("^http://(.+)(/.*)?$", (PCRE_UNGREEDY | PCRE_DOTALL)); |
15 |
|
|
|
16 |
|
|
api::Cerr << (PCRE_UNGREEDY | PCRE_DOTALL) << " = " << matcher.options << ios::NewLine; |
17 |
|
|
|
18 |
Douglas Thrift |
128 |
if (url == matcher) |
19 |
|
|
{ |
20 |
|
|
address = matcher[1]; |
21 |
|
|
|
22 |
douglas |
287 |
if (matcher.size() > 2) path = matcher[2]; else path = "/"; |
23 |
Douglas Thrift |
128 |
} |
24 |
|
|
else |
25 |
|
|
{ |
26 |
douglas |
285 |
api::Cerr << program << ": Page.setUrl(" << url << ") failure.\n"; |
27 |
Douglas Thrift |
129 |
|
28 |
douglas |
330 |
throw; |
29 |
Douglas Thrift |
128 |
} |
30 |
|
|
} |
31 |
Douglas Thrift |
129 |
|
32 |
douglas |
285 |
bool Page::operator==(const ext::String& thing) |
33 |
Douglas Thrift |
129 |
{ |
34 |
douglas |
287 |
return address == thing || path == thing || title == thing; |
35 |
Douglas Thrift |
129 |
} |
36 |
|
|
|
37 |
Douglas Thrift |
140 |
bool Page::operator==(Matcher& matcher) |
38 |
Douglas Thrift |
129 |
{ |
39 |
douglas |
287 |
return address == matcher || path == matcher || title == matcher; |
40 |
Douglas Thrift |
140 |
} |
41 |
|
|
|
42 |
|
|
bool Page::operator==(const Page& page) const |
43 |
|
|
{ |
44 |
Douglas Thrift |
132 |
if (address == page.address) |
45 |
|
|
{ |
46 |
Douglas Thrift |
142 |
return path == page.path || title == page.title; |
47 |
Douglas Thrift |
132 |
} |
48 |
Douglas Thrift |
129 |
|
49 |
|
|
return false; |
50 |
|
|
} |
51 |
|
|
|
52 |
douglas |
285 |
xml::TextWriter& operator<<(xml::TextWriter& xml, Page& page) |
53 |
Douglas Thrift |
135 |
{ |
54 |
douglas |
285 |
xml::ScopeElement item(xml, "item"); |
55 |
Douglas Thrift |
135 |
|
56 |
douglas |
285 |
xml.OpenElement("link"); |
57 |
|
|
xml.SetAttribute("address", page.getUrl()); |
58 |
|
|
xml.OutputText(page.title); |
59 |
|
|
xml.CloseElement(); |
60 |
Douglas Thrift |
135 |
|
61 |
douglas |
285 |
if (!page.children.IsEmpty()) |
62 |
Douglas Thrift |
135 |
{ |
63 |
douglas |
285 |
xml::ScopeElement list(xml, "list"); |
64 |
Douglas Thrift |
135 |
|
65 |
douglas |
285 |
_mforeach (ext::Vector<Page>, child, page.children) xml << *child; |
66 |
Douglas Thrift |
135 |
} |
67 |
|
|
|
68 |
douglas |
285 |
return xml; |
69 |
Douglas Thrift |
135 |
} |