9 |
|
#endif |
10 |
|
|
11 |
|
#include "SiteMapper.hpp" |
12 |
< |
#include "Matcher.hpp" |
12 |
> |
#include "Matcher/Matcher.hpp" |
13 |
|
#include "Page.hpp" |
14 |
|
|
15 |
< |
string program; |
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=(.*)$")) |
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 |
|
|
84 |
|
comment << evaluator.evaluate(support, document, |
85 |
|
XalanDOMString("comment()").c_str())->str(); |
86 |
|
|
87 |
< |
if (debug) cerr << "comment = " << comment.str() << '\n'; |
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()); |
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) |
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, |
116 |
< |
*(this->list)); |
117 |
> |
XalanNode* list = evaluator.selectSingleNode(support, node, *(this->list)); |
118 |
|
|
119 |
|
if (list != 0) oldMap(page.getChildren(), list); |
120 |
|
|
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()); |
136 |
|
path = evaluator.createXPath(XalanDOMString("path").c_str()); |
137 |
|
title = evaluator.createXPath(XalanDOMString("title").c_str()); |
138 |
|
|
139 |
< |
NodeRefList nodes = evaluator.selectNodeList(support, document, |
140 |
< |
XalanDOMString("/index/page").c_str()); |
139 |
> |
NodeRefList nodes; |
140 |
> |
|
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 |
|
|
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(); |
162 |
|
Page page(address.str(), path.str(), title.str()); |
163 |
|
Matcher matcher; |
164 |
|
|
165 |
< |
if (page == matcher(string("^Douglas\\sThrift's\\sWebsite\\s\\|\\sDou") |
164 |
< |
+ "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{4}\\sArchives$") == matcher[1]) |
168 |
|
{ |
180 |
|
} |
181 |
|
else continue; |
182 |
|
|
183 |
< |
multimap<string, Page> items; |
183 |
> |
std::multimap<std::string, Page> items; |
184 |
|
|
185 |
< |
newPages.insert(pair<string, multimap<string, Page> |
185 |
< |
>(page.getAddress(), items)).first->second.insert(pair<string, |
186 |
< |
Page>(page.getChildOf(), page)); |
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); |
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) |
197 |
|
{ |
205 |
|
|
206 |
|
pages[index] = page; |
207 |
|
|
208 |
< |
cout << "Updated: " << page.getUrl() << '\n'; |
208 |
> |
std::cout << "Updated: " << page.getUrl() << '\n'; |
209 |
|
|
210 |
|
return true; |
211 |
|
} |
227 |
|
return false; |
228 |
|
} |
229 |
|
|
230 |
< |
void SiteMapper::newMap(const string& siteMap) |
230 |
> |
void SiteMapper::newMap(const std::string& siteMap) |
231 |
|
{ |
232 |
< |
ofstream fout(siteMap.c_str()); |
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" |
259 |
|
fout.close(); |
260 |
|
} |
261 |
|
|
262 |
< |
void SiteMapper::newMap(vector<Page>& pages, const string& childOf, |
264 |
< |
multimap<string, Page>& newPages) |
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 (multimap<string, Page>::iterator itor(newPages.lower_bound(childOf)); |
272 |
< |
itor != newPages.upper_bound(childOf); itor++) |
269 |
> |
for (std::multimap<std::string, Page>::iterator itor(newPages.lower_bound(childOf)); itor != newPages.upper_bound(childOf); itor++) |
270 |
|
{ |
271 |
< |
cout << "Added: " << itor->second.getUrl() << '\n'; |
271 |
> |
std::cout << "Added: " << itor->second.getUrl() << '\n'; |
272 |
|
|
273 |
|
pages.push_back(itor->second); |
274 |
|
} |