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 |
|
{ |
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; |
84 |
|
item = evaluator.createXPath(XalanDOMString("item").c_str()); |
85 |
|
address = evaluator.createXPath(XalanDOMString("link/@address").c_str()); |
86 |
|
link = evaluator.createXPath(XalanDOMString("link").c_str()); |
87 |
< |
list_ = evaluator.createXPath(XalanDOMString("list").c_str()); |
87 |
> |
this->list = evaluator.createXPath(XalanDOMString("list").c_str()); |
88 |
|
|
89 |
|
oldMap(pages, list); |
90 |
|
|
91 |
|
evaluator.destroyXPath(item); |
92 |
|
evaluator.destroyXPath(address); |
93 |
|
evaluator.destroyXPath(link); |
94 |
< |
evaluator.destroyXPath(list_); |
94 |
> |
evaluator.destroyXPath(this->list); |
95 |
|
} |
96 |
|
|
97 |
< |
void SiteMapper::oldMap(vector<Page>& pages, XalanNode* list_) |
97 |
> |
void SiteMapper::oldMap(vector<Page>& pages, XalanNode* list) |
98 |
|
{ |
99 |
< |
NodeRefList nodes = evaluator.selectNodeList(support, list_, *item); |
99 |
> |
NodeRefList nodes = evaluator.selectNodeList(support, list, *item); |
100 |
|
|
101 |
|
for (int index = 0; index < nodes.getLength(); index++) |
102 |
|
{ |
108 |
|
|
109 |
|
Page page(url.str(), title.str()); |
110 |
|
XalanNode* list = evaluator.selectSingleNode(support, node, |
111 |
< |
*(this->list_)); |
111 |
> |
*(this->list)); |
112 |
|
|
113 |
|
if (list != 0) oldMap(page.getChildren(), list); |
114 |
|
|
174 |
|
} |
175 |
|
else continue; |
176 |
|
|
177 |
< |
cerr << page.getTitle() << ' ' << page.getChildOf() << '\n'; |
178 |
< |
// newPages.insert(page); |
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); |
218 |
|
} |
219 |
|
} |
220 |
|
|
214 |
– |
cerr << "Here!\n"; |
215 |
– |
|
221 |
|
return false; |
222 |
|
} |
223 |
|
|
224 |
|
void SiteMapper::newMap(const string& siteMap) |
225 |
|
{ |
226 |
< |
// |
226 |
> |
ofstream fout(siteMap.c_str()); |
227 |
> |
|
228 |
> |
fout << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" |
229 |
> |
<< "<?xml-stylesheet type=\"text/xsl\" href=\"stylesheets/sitemap.xsl" |
230 |
> |
<< "\"?>\n" |
231 |
> |
<< "<!DOCTYPE page SYSTEM \"stylesheets/page.dtd\">\n" |
232 |
> |
<< "<!-- $Id$ -->\n" |
233 |
> |
<< "<page>\n" |
234 |
> |
<< "\t<title>Sitemap</title>\n" |
235 |
> |
<< "\t<section>\n" |
236 |
> |
<< "\t\t<list>\n"; |
237 |
|
|
238 |
|
for (unsigned index = 0; index < pages.size(); index++) |
239 |
|
{ |
240 |
< |
cout << pages[index] << '\n'; |
240 |
> |
if (newPages.find(pages[index].getAddress()) != newPages.end()) |
241 |
> |
{ |
242 |
> |
newMap(pages[index].getChildren(), pages[index].getPath(), |
243 |
> |
newPages.find(pages[index].getAddress())->second); |
244 |
> |
} |
245 |
> |
|
246 |
> |
fout << pages[index](3) << '\n'; |
247 |
|
} |
248 |
+ |
|
249 |
+ |
fout << "\t\t</list>\n" |
250 |
+ |
<< "\t</section>\n" |
251 |
+ |
<< "</page>\n"; |
252 |
+ |
|
253 |
+ |
fout.close(); |
254 |
+ |
} |
255 |
+ |
|
256 |
+ |
void SiteMapper::newMap(vector<Page>& pages, const string& childOf, |
257 |
+ |
multimap<string, Page>& newPages) |
258 |
+ |
{ |
259 |
+ |
for (unsigned index = 0; index < pages.size(); index++) |
260 |
+ |
{ |
261 |
+ |
newMap(pages[index].getChildren(), pages[index].getPath(), newPages); |
262 |
+ |
} |
263 |
+ |
|
264 |
+ |
for (multimap<string, Page>::iterator itor = newPages.lower_bound(childOf); |
265 |
+ |
itor != newPages.upper_bound(childOf); itor++) |
266 |
+ |
{ |
267 |
+ |
pages.push_back(itor->second); |
268 |
+ |
} |
269 |
+ |
|
270 |
+ |
newPages.erase(childOf); |
271 |
|
} |