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

Comparing SiteMapper/SiteMapper.cpp (file contents):
Revision 153 by Douglas Thrift, 2004-05-29T20:37:48-07:00 vs.
Revision 237 by Douglas Thrift, 2004-09-10T16:22:07-07:00

# Line 4 | Line 4
4   //
5   // $Id$
6  
7 #ifdef _WIN32
8 #pragma warning(disable:4503)
9 #endif
10
7   #include "SiteMapper.hpp"
8   #include "Matcher.hpp"
9   #include "Page.hpp"
# Line 40 | Line 36 | int main(int argc, char* argv[])
36                  }
37          }
38  
39 <        if (siteIndex != "" && siteMap != "")
39 >        if (!siteIndex.empty() && !siteMap.empty())
40          {
45                XMLPlatformUtils::Initialize();
46                XPathEvaluator::initialize();
47
41                  SiteMapper mapper(siteIndex, siteMap);
49
50                XPathEvaluator::terminate();
51                XMLPlatformUtils::Terminate();
42          }
43          else
44          {
# Line 67 | Line 57 | SiteMapper::SiteMapper(const string& sit
57  
58   void SiteMapper::oldMap(const string& siteMap)
59   {
60 <        support.setParserLiaison(&liaison);
61 <
72 <        XalanDOMString file(siteMap.c_str());
73 <        LocalFileInputSource source(file.c_str());
74 <
75 <        XalanDocument* document = liaison.parseXMLStream(source);
76 <
77 <        if (document == 0) return;
60 >        ext::Handle<xml::Document> document(xml::Parse(siteMap));
61 >        ext::Handle<xml::Node> list(*document/"page"/"section"/"list");
62  
63 <        XalanNode* list = evaluator.selectSingleNode(support, document,
80 <                XalanDOMString("/page/section/list").c_str());
81 <
82 <        if (list == 0) return;
83 <
84 <        comment << evaluator.evaluate(support, document,
85 <                XalanDOMString("comment()").c_str())->str();
86 <
87 <        item = evaluator.createXPath(XalanDOMString("item").c_str());
88 <        address = evaluator.createXPath(XalanDOMString("link/@address").c_str());
89 <        link = evaluator.createXPath(XalanDOMString("link").c_str());
90 <        this->list = evaluator.createXPath(XalanDOMString("list").c_str());
63 >        comment = ext::String(*document/"comment()");
64  
65          oldMap(pages, list);
93
94        evaluator.destroyXPath(item);
95        evaluator.destroyXPath(address);
96        evaluator.destroyXPath(link);
97        evaluator.destroyXPath(this->list);
66   }
67  
68 < void SiteMapper::oldMap(vector<Page>& pages, XalanNode* list)
68 > void SiteMapper::oldMap(vector<Page>& pages, xml::Node* list)
69   {
70 <        NodeRefList nodes = evaluator.selectNodeList(support, list, *item);
70 >        xml::NodeSet nodes(*list/"item");
71  
72 <        for (int index(0); index < nodes.getLength(); ++index)
72 >        for (xml::NodeSet::Iterator node(nodes.Begin()); node != nodes.End();
73 >                ++node)
74          {
75 <                XalanNode* node = nodes.item(index);
76 <                ostringstream url, title;
77 <
78 <                url << evaluator.evaluate(support, node, *address)->str();
110 <                title << evaluator.evaluate(support, node, *link)->str();
111 <
112 <                Page page(url.str(), title.str());
113 <                XalanNode* list = evaluator.selectSingleNode(support, node,
114 <                        *(this->list));
75 >                string url(ext::String(**node/"link"/"@address")),
76 >                        title(ext::String(**node/"link"));
77 >                Page page(url, title);
78 >                ext::Handle<xml::Node> list(**node/"list");
79  
80 <                if (list != 0) oldMap(page.getChildren(), list);
80 >                if (!list.IsEmpty()) oldMap(page.getChildren(), list);
81  
82                  pages.push_back(page);
83          }
# Line 121 | Line 85 | void SiteMapper::oldMap(vector<Page>& pa
85  
86   void SiteMapper::newIndex(const string& siteIndex)
87   {
88 <        XalanDOMString file(siteIndex.c_str());
89 <        LocalFileInputSource source(file.c_str());
88 >        ext::Handle<xml::Document> document(xml::Parse(siteIndex));
89 >        xml::NodeSet nodes(*document/"index"/"page");
90  
91 <        XalanDocument* document = liaison.parseXMLStream(source);
92 <
129 <        if (document == 0) return;
130 <
131 <        address = evaluator.createXPath(XalanDOMString("address").c_str());
132 <        port = evaluator.createXPath(XalanDOMString("port").c_str());
133 <        path = evaluator.createXPath(XalanDOMString("path").c_str());
134 <        title = evaluator.createXPath(XalanDOMString("title").c_str());
135 <
136 <        NodeRefList nodes = evaluator.selectNodeList(support, document,
137 <                XalanDOMString("/index/page").c_str());
138 <
139 <        for (int index(0); index < nodes.getLength(); ++index)
91 >        for (xml::NodeSet::Iterator node(nodes.Begin()); node != nodes.End();
92 >                ++node)
93          {
94 <                XalanNode* node = nodes.item(index);
95 <                ostringstream address;
143 <
144 <                address << evaluator.evaluate(support, node, *(this->address))->str();
145 <
146 <                double port = evaluator.evaluate(support, node, *(this->port))->num();
94 >                string address(ext::String(**node/"address"));
95 >                string port(ext::String(**node/"port"));
96  
97 <                if (port >= 0 && port <= 65535)
97 >                if (!port.empty())
98                  {
99 <                        address << ':' << int(port);
99 >                        address += ':' + port;
100                  }
101  
102 <                ostringstream path, title;
103 <
104 <                path << evaluator.evaluate(support, node, *(this->path))->str();
156 <                title << evaluator.evaluate(support, node, *(this->title))->str();
157 <
158 <                Page page(address.str(), path.str(), title.str());
102 >                string path(ext::String(**node/"path")),
103 >                        title(ext::String(**node/"title"));
104 >                Page page(address, path, title);
105                  Matcher matcher;
106  
107                  if (page == matcher(string("^Douglas\\sThrift's\\sWebsite\\s\\|\\sDou")
108                          + "glas\\sThrift's\\sBlog:\\s(.+)$"))
109                  {
110 <                        if (Matcher("^\\w+\\s\\d\\d\\d\\d\\sArchives$") == matcher[1])
110 >                        if (Matcher("^\\w+\\s\\d{4}\\sArchives$") == matcher[1])
111                          {
112                                  page.setTitle(matcher[1]);
113  
# Line 183 | Line 129 | void SiteMapper::newIndex(const string&
129                          >(page.getAddress(), items)).first->second.insert(pair<string,
130                          Page>(page.getChildOf(), page));
131          }
186
187        evaluator.destroyXPath(address);
188        evaluator.destroyXPath(port);
189        evaluator.destroyXPath(path);
190        evaluator.destroyXPath(title);
132   }
133  
134   bool SiteMapper::newIndex(vector<Page>& pages, Page& page)
# Line 204 | Line 145 | bool SiteMapper::newIndex(vector<Page>&
145  
146                                  pages[index] = page;
147  
148 +                                cout << "Updated: " << page.getUrl() << '\n';
149 +
150                                  return true;
151                          }
152                          else if (matcher('^' + pages[index].getPath()) == page)
# Line 232 | Line 175 | void SiteMapper::newMap(const string& si
175                  << "<?xml-stylesheet type=\"text/xsl\" href=\"stylesheets/sitemap.xsl"
176                  << "\"?>\n"
177                  << "<!DOCTYPE page SYSTEM \"stylesheets/page.dtd\">\n"
178 <                << "<!--" << comment.str() << "-->\n"
178 >                << "<!--" << comment << "-->\n"
179                  << "<page>\n"
180                  << "\t<title>Sitemap</title>\n"
181                  << "\t<section>\n"
# Line 267 | Line 210 | void SiteMapper::newMap(vector<Page>& pa
210          for (multimap<string, Page>::iterator itor(newPages.lower_bound(childOf));
211                  itor != newPages.upper_bound(childOf); itor++)
212          {
213 +                cout << "Added: " << itor->second.getUrl() << '\n';
214 +
215                  pages.push_back(itor->second);
216          }
217  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines