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; |
61 |
|
SiteMapper::SiteMapper(const string& siteIndex, const string& siteMap) |
62 |
|
{ |
63 |
|
oldMap(siteMap); |
64 |
< |
index(siteIndex); |
64 |
> |
newIndex(siteIndex); |
65 |
|
newMap(siteMap); |
66 |
|
} |
67 |
|
|
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 |
< |
list_ = evaluator.createXPath(XalanDOMString("list").c_str()); |
90 |
> |
this->list = evaluator.createXPath(XalanDOMString("list").c_str()); |
91 |
|
|
92 |
|
oldMap(pages, list); |
93 |
|
|
94 |
|
evaluator.destroyXPath(item); |
95 |
|
evaluator.destroyXPath(address); |
96 |
|
evaluator.destroyXPath(link); |
97 |
< |
evaluator.destroyXPath(list_); |
97 |
> |
evaluator.destroyXPath(this->list); |
98 |
|
} |
99 |
|
|
100 |
< |
void SiteMapper::oldMap(list<Page>& pages, XalanNode* list) |
100 |
> |
void SiteMapper::oldMap(vector<Page>& pages, XalanNode* list) |
101 |
|
{ |
102 |
|
NodeRefList nodes = evaluator.selectNodeList(support, list, *item); |
103 |
|
|
104 |
< |
for (int index = 0; index < nodes.getLength(); index++) |
104 |
> |
for (int index(0); index < nodes.getLength(); ++index) |
105 |
|
{ |
106 |
|
XalanNode* node = nodes.item(index); |
107 |
|
ostringstream url, title; |
108 |
< |
|
108 |
> |
|
109 |
|
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, *list_); |
113 |
> |
XalanNode* list = evaluator.selectSingleNode(support, node, |
114 |
> |
*(this->list)); |
115 |
|
|
116 |
|
if (list != 0) oldMap(page.getChildren(), list); |
117 |
|
|
119 |
|
} |
120 |
|
} |
121 |
|
|
122 |
< |
void SiteMapper::index(const string& siteIndex) |
122 |
> |
void SiteMapper::newIndex(const string& siteIndex) |
123 |
|
{ |
124 |
|
XalanDOMString file(siteIndex.c_str()); |
125 |
|
LocalFileInputSource source(file.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 |
< |
|
135 |
> |
|
136 |
|
NodeRefList nodes = evaluator.selectNodeList(support, document, |
137 |
|
XalanDOMString("/index/page").c_str()); |
138 |
|
|
139 |
< |
for (int index = 0; index < nodes.getLength(); index++) |
139 |
> |
for (int index(0); index < nodes.getLength(); ++index) |
140 |
|
{ |
141 |
|
XalanNode* node = nodes.item(index); |
142 |
|
ostringstream address; |
156 |
|
title << evaluator.evaluate(support, node, *(this->title))->str(); |
157 |
|
|
158 |
|
Page page(address.str(), path.str(), title.str()); |
159 |
< |
Matcher matcher("^Douglas Thrift's.+Website \\| (.+)$"); |
159 |
> |
Matcher matcher; |
160 |
|
|
161 |
< |
if (page == matcher) |
161 |
> |
if (page == matcher(string("^Douglas\\sThrift's\\sWebsite\\s\\|\\sDou") |
162 |
> |
+ "glas\\sThrift's\\sBlog:\\s(.+)$")) |
163 |
> |
{ |
164 |
> |
if (Matcher("^\\w+\\s\\d\\d\\d\\d\\sArchives$") == matcher[1]) |
165 |
> |
{ |
166 |
> |
page.setTitle(matcher[1]); |
167 |
> |
|
168 |
> |
if (newIndex(pages, page)) continue; |
169 |
> |
} |
170 |
> |
else continue; |
171 |
> |
} |
172 |
> |
else if (page == matcher("^Douglas\\sThrift's.+Website\\s\\|\\s(.+)$")) |
173 |
|
{ |
174 |
|
page.setTitle(matcher[1]); |
175 |
|
|
176 |
< |
newPages.insert(page); |
176 |
> |
if (newIndex(pages, page)) continue; |
177 |
|
} |
178 |
+ |
else continue; |
179 |
+ |
|
180 |
+ |
multimap<string, Page> items; |
181 |
+ |
|
182 |
+ |
newPages.insert(pair<string, multimap<string, Page> |
183 |
+ |
>(page.getAddress(), items)).first->second.insert(pair<string, |
184 |
+ |
Page>(page.getChildOf(), page)); |
185 |
|
} |
186 |
|
|
187 |
|
evaluator.destroyXPath(address); |
190 |
|
evaluator.destroyXPath(title); |
191 |
|
} |
192 |
|
|
193 |
+ |
bool SiteMapper::newIndex(vector<Page>& pages, Page& page) |
194 |
+ |
{ |
195 |
+ |
for (unsigned index(0); index < pages.size(); ++index) |
196 |
+ |
{ |
197 |
+ |
if (pages[index] == page.getAddress()) |
198 |
+ |
{ |
199 |
+ |
Matcher matcher; |
200 |
+ |
|
201 |
+ |
if (pages[index] == page) |
202 |
+ |
{ |
203 |
+ |
page.setChildren(pages[index].getChildren()); |
204 |
+ |
|
205 |
+ |
pages[index] = page; |
206 |
+ |
|
207 |
+ |
return true; |
208 |
+ |
} |
209 |
+ |
else if (matcher('^' + pages[index].getPath()) == page) |
210 |
+ |
{ |
211 |
+ |
page.setChildOf(matcher[0]); |
212 |
+ |
|
213 |
+ |
if (matcher('^' + pages[index].getTitle() + "\\s\\|\\s(.+)$") |
214 |
+ |
== page) |
215 |
+ |
{ |
216 |
+ |
page.setTitle(matcher[1]); |
217 |
+ |
} |
218 |
+ |
|
219 |
+ |
return newIndex(pages[index].getChildren(), page); |
220 |
+ |
} |
221 |
+ |
} |
222 |
+ |
} |
223 |
+ |
|
224 |
+ |
return false; |
225 |
+ |
} |
226 |
+ |
|
227 |
|
void SiteMapper::newMap(const string& siteMap) |
228 |
|
{ |
229 |
< |
// |
229 |
> |
ofstream fout(siteMap.c_str()); |
230 |
> |
|
231 |
> |
fout << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" |
232 |
> |
<< "<?xml-stylesheet type=\"text/xsl\" href=\"stylesheets/sitemap.xsl" |
233 |
> |
<< "\"?>\n" |
234 |
> |
<< "<!DOCTYPE page SYSTEM \"stylesheets/page.dtd\">\n" |
235 |
> |
<< "<!--" << comment.str() << "-->\n" |
236 |
> |
<< "<page>\n" |
237 |
> |
<< "\t<title>Sitemap</title>\n" |
238 |
> |
<< "\t<section>\n" |
239 |
> |
<< "\t\t<list>\n"; |
240 |
|
|
241 |
< |
for (list<Page>::iterator itor = pages.begin(); itor != pages.end(); |
172 |
< |
itor++) |
241 |
> |
for (unsigned index(0); index < pages.size(); ++index) |
242 |
|
{ |
243 |
< |
cout << *itor << '\n'; |
243 |
> |
if (newPages.find(pages[index].getAddress()) != newPages.end()) |
244 |
> |
{ |
245 |
> |
newMap(pages[index].getChildren(), pages[index].getPath(), |
246 |
> |
newPages.find(pages[index].getAddress())->second); |
247 |
> |
} |
248 |
> |
|
249 |
> |
fout << pages[index](3) << '\n'; |
250 |
|
} |
251 |
+ |
|
252 |
+ |
fout << "\t\t</list>\n" |
253 |
+ |
<< "\t</section>\n" |
254 |
+ |
<< "</page>\n"; |
255 |
+ |
|
256 |
+ |
fout.close(); |
257 |
+ |
} |
258 |
+ |
|
259 |
+ |
void SiteMapper::newMap(vector<Page>& pages, const string& childOf, |
260 |
+ |
multimap<string, Page>& newPages) |
261 |
+ |
{ |
262 |
+ |
for (unsigned index(0); index < pages.size(); ++index) |
263 |
+ |
{ |
264 |
+ |
newMap(pages[index].getChildren(), pages[index].getPath(), newPages); |
265 |
+ |
} |
266 |
+ |
|
267 |
+ |
for (multimap<string, Page>::iterator itor(newPages.lower_bound(childOf)); |
268 |
+ |
itor != newPages.upper_bound(childOf); itor++) |
269 |
+ |
{ |
270 |
+ |
pages.push_back(itor->second); |
271 |
+ |
} |
272 |
+ |
|
273 |
+ |
newPages.erase(childOf); |
274 |
|
} |