ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/repos/SiteMapper/Page.cpp
(Generate patch)

Comparing SiteMapper/Page.cpp (file contents):
Revision 128 by Douglas Thrift, 2004-03-23T22:15:08-08:00 vs.
Revision 423 by douglas, 2005-03-09T19:23:17-08:00

# Line 4 | Line 4
4   //
5   // $Id$
6  
7 < #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 >        Matcher matcher("^http://(.+)(/.*)?$", (PCRE_UNGREEDY | PCRE_DOTALL));
13 >
14 >        if (url == matcher)
15 >        {
16 >                address = matcher[1];
17 >
18 >                if (matcher.size() > 2) path = matcher[2]; else path = "/";
19 >        }
20 >        else
21 >        {
22 >                api::Cerr << SiteMapper::program << ": Page.setUrl(" << url << ") failure.\n";
23 >
24 >                throw;
25 >        }
26   }
27  
28 < Page::Page(const string& url)
28 > bool Page::operator==(const ext::String& thing)
29   {
30 <        setUrl(url);
30 >        return address == thing || path == thing || title == thing;
31   }
32  
33 < void Page::setUrl(const string& url)
33 > bool Page::operator==(Matcher& matcher)
34   {
35 <        Matcher matcher("^http://(.+)(/.*)?$");
35 >        return address == matcher || path == matcher || title == matcher;
36 > }
37  
38 <        if (url == matcher)
38 > bool Page::operator==(const Page& page) const
39 > {
40 >        if (address == page.address)
41          {
42 <                address = matcher[1];
28 <
29 <                if (matcher.size() > 2)
30 <                {
31 <                        path = matcher[2];
32 <                }
33 <                else
34 <                {
35 <                        path = '/';
36 <                }
42 >                return path == page.path || title == page.title;
43          }
44 <        else
44 >
45 >        return false;
46 > }
47 >
48 > xml::TextWriter& operator<<(xml::TextWriter& xml, Page& page)
49 > {
50 >        xml::ScopeElement item(xml, "item");
51 >
52 >        xml.OpenElement("link");
53 >        xml.SetAttribute("address", page.getUrl());
54 >        xml.OutputText(page.title);
55 >        xml.CloseElement();
56 >
57 >        if (!page.children.IsEmpty())
58          {
59 <                cerr << program << ": Page.setUrl(" << url << ") failure.\n";
59 >                xml::ScopeElement list(xml, "list");
60 >
61 >                _foreach (ext::Vector<Page>, child, page.children) xml << *child;
62          }
63 +
64 +        return xml;
65   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines