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 139 by Douglas Thrift, 2004-03-25T16:10:22-08:00 vs.
SiteMapperOld/SiteMapper.cpp (file contents), Revision 248 by Douglas Thrift, 2004-09-11T22:02:20-07: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"
13   #include "Page.hpp"
14  
15   string program;
16 < bool debug = false;
16 > bool debug(false);
17  
18   int main(int argc, char* argv[])
19   {
# Line 17 | Line 21 | int main(int argc, char* argv[])
21  
22          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]);
27                  Matcher matcher;
# 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 57 | Line 61 | int main(int argc, char* argv[])
61   SiteMapper::SiteMapper(const string& siteIndex, const string& siteMap)
62   {
63          oldMap(siteMap);
64 <        index(siteIndex);
64 >        newIndex(siteIndex);
65          newMap(siteMap);
66   }
67  
# 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) 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());
# Line 94 | Line 103 | void SiteMapper::oldMap(vector<Page>& pa
103   {
104          NodeRefList nodes = evaluator.selectNodeList(support, list, *item);
105  
106 <        for (int index = 0; index < nodes.getLength(); index++)
106 >        for (int index(0); index < nodes.getLength(); ++index)
107          {
108                  XalanNode* node = nodes.item(index);
109                  ostringstream url, title;
110 <                
110 >
111                  url << evaluator.evaluate(support, node, *address)->str();
112                  title << evaluator.evaluate(support, node, *link)->str();
113  
# Line 112 | Line 121 | void SiteMapper::oldMap(vector<Page>& pa
121          }
122   }
123  
124 < void SiteMapper::index(const string& siteIndex)
124 > void SiteMapper::newIndex(const string& siteIndex)
125   {
126          XalanDOMString file(siteIndex.c_str());
127          LocalFileInputSource source(file.c_str());
# Line 125 | Line 134 | void SiteMapper::index(const string& sit
134          port = evaluator.createXPath(XalanDOMString("port").c_str());
135          path = evaluator.createXPath(XalanDOMString("path").c_str());
136          title = evaluator.createXPath(XalanDOMString("title").c_str());
137 <        
137 >
138          NodeRefList nodes = evaluator.selectNodeList(support, document,
139                  XalanDOMString("/index/page").c_str());
140  
141 <        for (int index = 0; index < nodes.getLength(); index++)
141 >        for (int index(0); index < nodes.getLength(); ++index)
142          {
143                  XalanNode* node = nodes.item(index);
144                  ostringstream address;
# Line 143 | Line 152 | void SiteMapper::index(const string& sit
152                          address << ':' << int(port);
153                  }
154  
155 <                cerr << address.str() << '\n';
155 >                ostringstream path, title;
156 >
157 >                path << evaluator.evaluate(support, node, *(this->path))->str();
158 >                title << evaluator.evaluate(support, node, *(this->title))->str();
159 >
160 >                Page page(address.str(), path.str(), title.str());
161 >                Matcher matcher;
162 >
163 >                if (page == matcher(string("^Douglas\\sThrift's\\sWebsite\\s\\|\\sDou")
164 >                        + "glas\\sThrift's\\sBlog:\\s(.+)$"))
165 >                {
166 >                        if (Matcher("^\\w+\\s\\d{4}\\sArchives$") == matcher[1])
167 >                        {
168 >                                page.setTitle(matcher[1]);
169 >
170 >                                if (newIndex(pages, page)) continue;
171 >                        }
172 >                        else continue;
173 >                }
174 >                else if (page == matcher("^Douglas\\sThrift's.+Website\\s\\|\\s(.+)$"))
175 >                {
176 >                        page.setTitle(matcher[1]);
177 >
178 >                        if (newIndex(pages, page)) continue;
179 >                }
180 >                else continue;
181 >
182 >                multimap<string, Page> items;
183 >
184 >                newPages.insert(pair<string, multimap<string, Page>
185 >                        >(page.getAddress(), items)).first->second.insert(pair<string,
186 >                        Page>(page.getChildOf(), page));
187          }
188  
189          evaluator.destroyXPath(address);
# Line 152 | Line 192 | void SiteMapper::index(const string& sit
192          evaluator.destroyXPath(title);
193   }
194  
195 + bool SiteMapper::newIndex(vector<Page>& pages, Page& page)
196 + {
197 +        for (unsigned index(0); index < pages.size(); ++index)
198 +        {
199 +                if (pages[index] == page.getAddress())
200 +                {
201 +                        Matcher matcher;
202 +
203 +                        if (pages[index] == page)
204 +                        {
205 +                                page.setChildren(pages[index].getChildren());
206 +
207 +                                pages[index] = page;
208 +
209 +                                cout << "Updated: " << page.getUrl() << '\n';
210 +
211 +                                return true;
212 +                        }
213 +                        else if (matcher('^' + pages[index].getPath()) == page)
214 +                        {
215 +                                page.setChildOf(matcher[0]);
216 +
217 +                                if (matcher('^' + pages[index].getTitle() + "\\s\\|\\s(.+)$")
218 +                                        == page)
219 +                                {
220 +                                        page.setTitle(matcher[1]);
221 +                                }
222 +
223 +                                return newIndex(pages[index].getChildren(), page);
224 +                        }
225 +                }
226 +        }
227 +
228 +        return false;
229 + }
230 +
231   void SiteMapper::newMap(const string& siteMap)
232   {
233 <        //
233 >        ofstream fout(siteMap.c_str());
234 >
235 >        fout << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
236 >                << "<?xml-stylesheet type=\"text/xsl\" href=\"stylesheets/sitemap.xsl"
237 >                << "\"?>\n"
238 >                << "<!DOCTYPE page SYSTEM \"stylesheets/page.dtd\">\n"
239 >                << "<!--" << comment.str() << "-->\n"
240 >                << "<page>\n"
241 >                << "\t<title>Sitemap</title>\n"
242 >                << "\t<section>\n"
243 >                << "\t\t<list>\n";
244 >
245 >        for (unsigned index(0); index < pages.size(); ++index)
246 >        {
247 >                if (newPages.find(pages[index].getAddress()) != newPages.end())
248 >                {
249 >                        newMap(pages[index].getChildren(), pages[index].getPath(),
250 >                                newPages.find(pages[index].getAddress())->second);
251 >                }
252 >
253 >                fout << pages[index](3) << '\n';
254 >        }
255 >
256 >        fout << "\t\t</list>\n"
257 >                << "\t</section>\n"
258 >                << "</page>\n";
259 >
260 >        fout.close();
261 > }
262 >
263 > void SiteMapper::newMap(vector<Page>& pages, const string& childOf,
264 >        multimap<string, Page>& newPages)
265 > {
266 >        for (unsigned index(0); index < pages.size(); ++index)
267 >        {
268 >                newMap(pages[index].getChildren(), pages[index].getPath(), newPages);
269 >        }
270 >
271 >        for (multimap<string, Page>::iterator itor(newPages.lower_bound(childOf));
272 >                itor != newPages.upper_bound(childOf); itor++)
273 >        {
274 >                cout << "Added: " << itor->second.getUrl() << '\n';
275 >
276 >                pages.push_back(itor->second);
277 >        }
278  
279 < //      for (int index = 0; index < pages.size(); index++)
160 < //      {
161 < //              cout << pages[index] << '\n';
162 < //      }
279 >        newPages.erase(childOf);
280   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines