ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/repos/SiteMapperOld/Page.cpp
Revision: 425
Committed: 2005-03-10T20:06:50-08:00 (20 years, 3 months ago) by douglas
File size: 1721 byte(s)
Log Message:
Wow, not that I even use this one anymore!

File Contents

# User Rev Content
1 Douglas Thrift 128 // Site Mapper
2     //
3     // Douglas Thrift
4     //
5     // $Id$
6    
7 douglas 425 #include "Matcher/Matcher.hpp"
8     #include "SiteMapper.hpp"
9 Douglas Thrift 128
10 douglas 425 Page::Page(const std::string& address, const std::string& path, const std::string& title) : address(address), path(path), title(title), tab(0) {}
11 Douglas Thrift 135
12 douglas 425 Page::Page(const std::string& url, const std::string& title) : title(title), tab(0)
13 Douglas Thrift 128 {
14     setUrl(url);
15     }
16    
17 douglas 425 void Page::setUrl(const std::string& url)
18 Douglas Thrift 128 {
19     Matcher matcher("^http://(.+)(/.*)?$");
20    
21     if (url == matcher)
22     {
23     address = matcher[1];
24    
25     if (matcher.size() > 2)
26     {
27     path = matcher[2];
28     }
29     else
30     {
31     path = '/';
32     }
33     }
34     else
35     {
36 douglas 425 std::cerr << program << ": Page.setUrl(" << url << ") failure.\n";
37 Douglas Thrift 129
38     exit(1);
39 Douglas Thrift 128 }
40     }
41 Douglas Thrift 129
42 douglas 425 bool Page::operator==(const std::string& thing)
43 Douglas Thrift 129 {
44 Douglas Thrift 132 if (address == thing)
45     {
46     return true;
47     }
48     else if (path == thing)
49     {
50     return true;
51     }
52     else if (title == thing)
53     {
54     return true;
55     }
56 Douglas Thrift 129
57     return false;
58     }
59    
60 Douglas Thrift 140 bool Page::operator==(Matcher& matcher)
61 Douglas Thrift 129 {
62 Douglas Thrift 140 if (address == matcher)
63     {
64     return true;
65     }
66     else if (path == matcher)
67     {
68     return true;
69     }
70     else if (title == matcher)
71     {
72     return true;
73     }
74    
75     return false;
76     }
77    
78     bool Page::operator==(const Page& page) const
79     {
80 Douglas Thrift 132 if (address == page.address)
81     {
82 Douglas Thrift 142 return path == page.path || title == page.title;
83 Douglas Thrift 132 }
84 Douglas Thrift 129
85     return false;
86     }
87    
88 douglas 425 std::ostream& operator<<(std::ostream& output, Page& page)
89 Douglas Thrift 135 {
90 douglas 425 std::string tab(page.tab, '\t');
91 Douglas Thrift 135
92 Douglas Thrift 136 output << tab << "<item><link address=\"" << page.getUrl() << "\">"
93 Douglas Thrift 135 << page.title << "</link>\n";
94    
95     if (!page.children.empty())
96     {
97     output << tab << "\t<list>\n";
98    
99 douglas 425 for (unsigned index(0); index < page.children.size(); ++index)
100 Douglas Thrift 135 {
101 Douglas Thrift 144 output << page.children[index](page.tab + 2) << '\n';
102 Douglas Thrift 135 }
103    
104     output << tab << "\t</list>\n";
105     }
106    
107     output << tab << "</item>";
108    
109     return output;
110     }

Properties

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