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

Comparing:
SiteMapper/SiteMapper.cpp (file contents), Revision 142 by Douglas Thrift, 2004-03-31T20:53:28-08:00 vs.
SiteMapperOld/SiteMapper.cpp (file contents), Revision 425 by douglas, 2005-03-10T20:06:50-08:00

# Line 4 | Line 4
4   //
5   // $Id$
6  
7 + #ifdef _WIN32
8 + #pragma warning(disable:4503)
9 + #endif
10 +
11   #include "SiteMapper.hpp"
12 < #include "Matcher.hpp"
12 > #include "Matcher/Matcher.hpp"
13   #include "Page.hpp"
14  
15 < string program;
16 < bool debug = false;
15 > std::string program;
16 > bool debug(false);
17  
18   int main(int argc, char* argv[])
19   {
20          program = argv[0];
21  
22 <        string siteIndex, siteMap;
22 >        std::string siteIndex, siteMap;
23  
24 <        for (int index = 1; index < argc; index++)
24 >        for (int index(1); index < argc; ++index)
25          {
26 <                string arg(argv[index]);
26 >                std::string arg(argv[index]);
27                  Matcher matcher;
28  
29                  if (arg == matcher("^-index=(.*)$"))
# Line 36 | Line 40 | int main(int argc, char* argv[])
40                  }
41          }
42  
43 <        if (siteIndex != "" && siteMap != "")
43 >        if (!siteIndex.empty() && !siteMap.empty())
44          {
45                  XMLPlatformUtils::Initialize();
46                  XPathEvaluator::initialize();
# Line 48 | Line 52 | int main(int argc, char* argv[])
52          }
53          else
54          {
55 <                cout << "Usage: " << program << " -index=index -map=map [-D]\n";
55 >                std::cout << "Usage: " << program << " -index=index -map=map [-D]\n";
56          }
57  
58          return 0;
59   }
60  
61 < SiteMapper::SiteMapper(const string& siteIndex, const string& siteMap)
61 > SiteMapper::SiteMapper(const std::string& siteIndex, const std::string& siteMap)
62   {
63          oldMap(siteMap);
64          newIndex(siteIndex);
65          newMap(siteMap);
66   }
67  
68 < void SiteMapper::oldMap(const string& siteMap)
68 > void SiteMapper::oldMap(const std::string& siteMap)
69   {
70          support.setParserLiaison(&liaison);
71  
# Line 77 | Line 81 | void SiteMapper::oldMap(const string& si
81  
82          if (list == 0) return;
83  
84 +        comment << evaluator.evaluate(support, document,
85 +                XalanDOMString("comment()").c_str())->str();
86 +
87 +        if (debug) std::cerr << "comment = " << comment.str() << '\n';
88 +
89          item = evaluator.createXPath(XalanDOMString("item").c_str());
90          address = evaluator.createXPath(XalanDOMString("link/@address").c_str());
91          link = evaluator.createXPath(XalanDOMString("link").c_str());
92 <        list_ = evaluator.createXPath(XalanDOMString("list").c_str());
92 >        this->list = evaluator.createXPath(XalanDOMString("list").c_str());
93  
94          oldMap(pages, list);
95  
96          evaluator.destroyXPath(item);
97          evaluator.destroyXPath(address);
98          evaluator.destroyXPath(link);
99 <        evaluator.destroyXPath(list_);
99 >        evaluator.destroyXPath(this->list);
100   }
101  
102 < void SiteMapper::oldMap(vector<Page>& pages, XalanNode* list_)
102 > void SiteMapper::oldMap(std::vector<Page>& pages, XalanNode* list)
103   {
104 <        NodeRefList nodes = evaluator.selectNodeList(support, list_, *item);
104 >        NodeRefList nodes;
105 >        
106 >        evaluator.selectNodeList(nodes, support, list, *item);
107  
108 <        for (int index = 0; index < nodes.getLength(); index++)
108 >        for (int index(0); index < nodes.getLength(); ++index)
109          {
110                  XalanNode* node = nodes.item(index);
111 <                ostringstream url, title;
111 >                std::ostringstream url, title;
112  
113                  url << evaluator.evaluate(support, node, *address)->str();
114                  title << evaluator.evaluate(support, node, *link)->str();
115  
116                  Page page(url.str(), title.str());
117 <                XalanNode* list = evaluator.selectSingleNode(support, node,
107 <                        *(this->list_));
117 >                XalanNode* list = evaluator.selectSingleNode(support, node, *(this->list));
118  
119                  if (list != 0) oldMap(page.getChildren(), list);
120  
# Line 112 | Line 122 | void SiteMapper::oldMap(vector<Page>& pa
122          }
123   }
124  
125 < void SiteMapper::newIndex(const string& siteIndex)
125 > void SiteMapper::newIndex(const std::string& siteIndex)
126   {
127          XalanDOMString file(siteIndex.c_str());
128          LocalFileInputSource source(file.c_str());
# Line 126 | Line 136 | void SiteMapper::newIndex(const string&
136          path = evaluator.createXPath(XalanDOMString("path").c_str());
137          title = evaluator.createXPath(XalanDOMString("title").c_str());
138  
139 <        NodeRefList nodes = evaluator.selectNodeList(support, document,
130 <                XalanDOMString("/index/page").c_str());
139 >        NodeRefList nodes;
140  
141 <        for (int index = 0; index < nodes.getLength(); index++)
141 >        evaluator.selectNodeList(nodes, support, document, XalanDOMString("/index/page").c_str());
142 >
143 >        for (int index(0); index < nodes.getLength(); ++index)
144          {
145                  XalanNode* node = nodes.item(index);
146 <                ostringstream address;
146 >                std::ostringstream address;
147  
148                  address << evaluator.evaluate(support, node, *(this->address))->str();
149  
# Line 143 | Line 154 | void SiteMapper::newIndex(const string&
154                          address << ':' << int(port);
155                  }
156  
157 <                ostringstream path, title;
157 >                std::ostringstream path, title;
158  
159                  path << evaluator.evaluate(support, node, *(this->path))->str();
160                  title << evaluator.evaluate(support, node, *(this->title))->str();
# Line 151 | Line 162 | void SiteMapper::newIndex(const string&
162                  Page page(address.str(), path.str(), title.str());
163                  Matcher matcher;
164  
165 <                if (page == matcher(string("^Douglas\\sThrift's\\sWebsite\\s\\|\\sDou")
155 <                        + "glas\\sThrift's\\sBlog:\\s(.+)$"))
165 >                if (page == matcher("^Douglas\\sThrift's\\sWebsite\\s\\|\\sDouglas\\sThrift's\\sBlog:\\s(.+)$"))
166                  {
167 <                        if (Matcher("^\\w+\\s\\d\\d\\d\\d\\sArchives$") == matcher[1])
167 >                        if (Matcher("^\\w+\\s\\d{4}\\sArchives$") == matcher[1])
168                          {
169                                  page.setTitle(matcher[1]);
170  
# Line 170 | Line 180 | void SiteMapper::newIndex(const string&
180                  }
181                  else continue;
182  
183 <                cerr << page.getTitle() << ' ' << page.getChildOf() << '\n';
184 < //              newPages.insert(page);
183 >                std::multimap<std::string, Page> items;
184 >
185 >                newPages.insert(std::pair<std::string, std::multimap<std::string, Page> >(page.getAddress(), items)).first->second.insert(std::pair<std::string, Page>(page.getChildOf(), page));
186          }
187  
188          evaluator.destroyXPath(address);
# Line 180 | Line 191 | void SiteMapper::newIndex(const string&
191          evaluator.destroyXPath(title);
192   }
193  
194 < bool SiteMapper::newIndex(vector<Page>& pages, Page& page)
194 > bool SiteMapper::newIndex(std::vector<Page>& pages, Page& page)
195   {
196 <        for (unsigned index = 0; index < pages.size(); index++)
196 >        for (unsigned index(0); index < pages.size(); ++index)
197          {
198                  if (pages[index] == page.getAddress())
199                  {
# Line 194 | Line 205 | bool SiteMapper::newIndex(vector<Page>&
205  
206                                  pages[index] = page;
207  
208 +                                std::cout << "Updated: " << page.getUrl() << '\n';
209 +
210                                  return true;
211                          }
212                          else if (matcher('^' + pages[index].getPath()) == page)
# Line 211 | Line 224 | bool SiteMapper::newIndex(vector<Page>&
224                  }
225          }
226  
214        cerr << "Here!\n";
215
227          return false;
228   }
229  
230 < void SiteMapper::newMap(const string& siteMap)
230 > void SiteMapper::newMap(const std::string& siteMap)
231   {
232 <        //
232 >        std::ofstream fout(siteMap.c_str());
233 >
234 >        fout << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
235 >                << "<?xml-stylesheet type=\"text/xsl\" href=\"stylesheets/sitemap.xsl"
236 >                << "\"?>\n"
237 >                << "<!DOCTYPE page SYSTEM \"stylesheets/page.dtd\">\n"
238 >                << "<!--" << comment.str() << "-->\n"
239 >                << "<page>\n"
240 >                << "\t<title>Sitemap</title>\n"
241 >                << "\t<section>\n"
242 >                << "\t\t<list>\n";
243  
244 <        for (unsigned index = 0; index < pages.size(); index++)
244 >        for (unsigned index(0); index < pages.size(); ++index)
245          {
246 <                cout << pages[index] << '\n';
246 >                if (newPages.find(pages[index].getAddress()) != newPages.end())
247 >                {
248 >                        newMap(pages[index].getChildren(), pages[index].getPath(),
249 >                                newPages.find(pages[index].getAddress())->second);
250 >                }
251 >
252 >                fout << pages[index](3) << '\n';
253          }
254 +
255 +        fout << "\t\t</list>\n"
256 +                << "\t</section>\n"
257 +                << "</page>\n";
258 +
259 +        fout.close();
260 + }
261 +
262 + void SiteMapper::newMap(std::vector<Page>& pages, const std::string& childOf, std::multimap<std::string, Page>& newPages)
263 + {
264 +        for (unsigned index(0); index < pages.size(); ++index)
265 +        {
266 +                newMap(pages[index].getChildren(), pages[index].getPath(), newPages);
267 +        }
268 +
269 +        for (std::multimap<std::string, Page>::iterator itor(newPages.lower_bound(childOf)); itor != newPages.upper_bound(childOf); itor++)
270 +        {
271 +                std::cout << "Added: " << itor->second.getUrl() << '\n';
272 +
273 +                pages.push_back(itor->second);
274 +        }
275 +
276 +        newPages.erase(childOf);
277   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines