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 139 by Douglas Thrift, 2004-03-25T16:10:22-08:00 vs.
Revision 143 by Douglas Thrift, 2004-03-31T22:55:16-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"
13   #include "Page.hpp"
# 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 98 | Line 102 | void SiteMapper::oldMap(vector<Page>& pa
102          {
103                  XalanNode* node = nodes.item(index);
104                  ostringstream url, title;
105 <                
105 >
106                  url << evaluator.evaluate(support, node, *address)->str();
107                  title << evaluator.evaluate(support, node, *link)->str();
108  
# Line 112 | Line 116 | void SiteMapper::oldMap(vector<Page>& pa
116          }
117   }
118  
119 < void SiteMapper::index(const string& siteIndex)
119 > void SiteMapper::newIndex(const string& siteIndex)
120   {
121          XalanDOMString file(siteIndex.c_str());
122          LocalFileInputSource source(file.c_str());
# Line 125 | Line 129 | void SiteMapper::index(const string& sit
129          port = evaluator.createXPath(XalanDOMString("port").c_str());
130          path = evaluator.createXPath(XalanDOMString("path").c_str());
131          title = evaluator.createXPath(XalanDOMString("title").c_str());
132 <        
132 >
133          NodeRefList nodes = evaluator.selectNodeList(support, document,
134                  XalanDOMString("/index/page").c_str());
135  
# Line 143 | Line 147 | void SiteMapper::index(const string& sit
147                          address << ':' << int(port);
148                  }
149  
150 <                cerr << address.str() << '\n';
150 >                ostringstream path, title;
151 >
152 >                path << evaluator.evaluate(support, node, *(this->path))->str();
153 >                title << evaluator.evaluate(support, node, *(this->title))->str();
154 >
155 >                Page page(address.str(), path.str(), title.str());
156 >                Matcher matcher;
157 >
158 >                if (page == matcher(string("^Douglas\\sThrift's\\sWebsite\\s\\|\\sDou")
159 >                        + "glas\\sThrift's\\sBlog:\\s(.+)$"))
160 >                {
161 >                        if (Matcher("^\\w+\\s\\d\\d\\d\\d\\sArchives$") == matcher[1])
162 >                        {
163 >                                page.setTitle(matcher[1]);
164 >
165 >                                if (newIndex(pages, page)) continue;
166 >                        }
167 >                        else continue;
168 >                }
169 >                else if (page == matcher("^Douglas\\sThrift's.+Website\\s\\|\\s(.+)$"))
170 >                {
171 >                        page.setTitle(matcher[1]);
172 >
173 >                        if (newIndex(pages, page)) continue;
174 >                }
175 >                else continue;
176 >
177 >                multimap<string, Page> items;
178 >
179 >                newPages.insert(pair<string, multimap<string, Page>
180 >                        >(page.getAddress(), items)).first->second.insert(pair<string,
181 >                        Page>(page.getChildOf(), page));
182          }
183  
184          evaluator.destroyXPath(address);
# Line 152 | Line 187 | void SiteMapper::index(const string& sit
187          evaluator.destroyXPath(title);
188   }
189  
190 + bool SiteMapper::newIndex(vector<Page>& pages, Page& page)
191 + {
192 +        for (unsigned index = 0; index < pages.size(); index++)
193 +        {
194 +                if (pages[index] == page.getAddress())
195 +                {
196 +                        Matcher matcher;
197 +
198 +                        if (pages[index] == page)
199 +                        {
200 +                                page.setChildren(pages[index].getChildren());
201 +
202 +                                pages[index] = page;
203 +
204 +                                return true;
205 +                        }
206 +                        else if (matcher('^' + pages[index].getPath()) == page)
207 +                        {
208 +                                page.setChildOf(matcher[0]);
209 +
210 +                                if (matcher('^' + pages[index].getTitle() + "\\s\\|\\s(.+)$")
211 +                                        == page)
212 +                                {
213 +                                        page.setTitle(matcher[1]);
214 +                                }
215 +
216 +                                return newIndex(pages[index].getChildren(), page);
217 +                        }
218 +                }
219 +        }
220 +
221 +        return false;
222 + }
223 +
224   void SiteMapper::newMap(const string& siteMap)
225   {
226 <        //
226 >        for (unsigned index = 0; index < pages.size(); index++)
227 >        {
228 >                if (newPages.find(pages[index].getAddress()) != newPages.end())
229 >                {
230 >                        newMap(pages[index].getChildren(), pages[index].getPath(),
231 >                                newPages.find(pages[index].getAddress())->second);
232 >                }
233 >
234 >                cout << pages[index] << '\n';
235 >        }
236 > }
237 >
238 > void SiteMapper::newMap(vector<Page>& pages, const string& childOf,
239 >        multimap<string, Page>& newPages)
240 > {
241 >        for (unsigned index = 0; index < pages.size(); index++)
242 >        {
243 >                newMap(pages[index].getChildren(), pages[index].getPath(), newPages);
244 >        }
245 >
246 >        for (multimap<string, Page>::iterator itor = newPages.lower_bound(childOf);
247 >                itor != newPages.upper_bound(childOf); itor++)
248 >        {
249 >                pages.push_back(itor->second);
250 >        }
251  
252 < //      for (int index = 0; index < pages.size(); index++)
160 < //      {
161 < //              cout << pages[index] << '\n';
162 < //      }
252 >        newPages.erase(childOf);
253   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines