ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/repos/SiteMapper/Page.cpp
Revision: 285
Committed: 2004-11-28T03:01:11-08:00 (20 years, 6 months ago) by douglas
File size: 1368 byte(s)
Log Message:
Wow, that's pretty big!

File Contents

# User Rev Content
1 Douglas Thrift 128 // Site Mapper
2     //
3     // Douglas Thrift
4     //
5     // $Id$
6    
7 Douglas Thrift 129 #include "Matcher.hpp"
8 Douglas Thrift 128 #include "Page.hpp"
9    
10 douglas 285 void Page::setUrl(const ext::String& url)
11 Douglas Thrift 128 {
12     Matcher matcher("^http://(.+)(/.*)?$");
13    
14     if (url == matcher)
15     {
16     address = matcher[1];
17    
18     if (matcher.size() > 2)
19     {
20     path = matcher[2];
21     }
22     else
23     {
24 douglas 285 path = "/";
25 Douglas Thrift 128 }
26     }
27     else
28     {
29 douglas 285 api::Cerr << program << ": Page.setUrl(" << url << ") failure.\n";
30 Douglas Thrift 129
31 douglas 285 std::exit(1);
32 Douglas Thrift 128 }
33     }
34 Douglas Thrift 129
35 douglas 285 bool Page::operator==(const ext::String& thing)
36 Douglas Thrift 129 {
37 Douglas Thrift 132 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 Douglas Thrift 129
50     return false;
51     }
52    
53 Douglas Thrift 140 bool Page::operator==(Matcher& matcher)
54 Douglas Thrift 129 {
55 Douglas Thrift 140 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==(const Page& page) const
72     {
73 Douglas Thrift 132 if (address == page.address)
74     {
75 Douglas Thrift 142 return path == page.path || title == page.title;
76 Douglas Thrift 132 }
77 Douglas Thrift 129
78     return false;
79     }
80    
81 douglas 285 xml::TextWriter& operator<<(xml::TextWriter& xml, Page& page)
82 Douglas Thrift 135 {
83 douglas 285 xml::ScopeElement item(xml, "item");
84 Douglas Thrift 135
85 douglas 285 xml.OpenElement("link");
86     xml.SetAttribute("address", page.getUrl());
87     xml.OutputText(page.title);
88     xml.CloseElement();
89 Douglas Thrift 135
90 douglas 285 if (!page.children.IsEmpty())
91 Douglas Thrift 135 {
92 douglas 285 xml::ScopeElement list(xml, "list");
93 Douglas Thrift 135
94 douglas 285 _mforeach (ext::Vector<Page>, child, page.children) xml << *child;
95 Douglas Thrift 135 }
96    
97 douglas 285 return xml;
98 Douglas Thrift 135 }

Properties

Name Value
svn:eol-style native
svn:keywords Id