4 |
|
// |
5 |
|
// $Id$ |
6 |
|
|
7 |
– |
#ifdef _WIN32 |
8 |
– |
#pragma warning(disable:4503) |
9 |
– |
#endif |
10 |
– |
|
7 |
|
#include "SiteMapper.hpp" |
8 |
|
#include "Matcher.hpp" |
9 |
|
#include "Page.hpp" |
10 |
|
|
11 |
|
string program; |
12 |
< |
bool debug = false; |
12 |
> |
bool debug(false); |
13 |
|
|
14 |
|
int main(int argc, char* argv[]) |
15 |
|
{ |
17 |
|
|
18 |
|
string siteIndex, siteMap; |
19 |
|
|
20 |
< |
for (int index = 1; index < argc; index++) |
20 |
> |
for (int index(1); index < argc; index++) |
21 |
|
{ |
22 |
|
string arg(argv[index]); |
23 |
|
Matcher matcher; |
38 |
|
|
39 |
|
if (siteIndex != "" && siteMap != "") |
40 |
|
{ |
45 |
– |
XMLPlatformUtils::Initialize(); |
46 |
– |
XPathEvaluator::initialize(); |
47 |
– |
|
41 |
|
SiteMapper mapper(siteIndex, siteMap); |
49 |
– |
|
50 |
– |
XPathEvaluator::terminate(); |
51 |
– |
XMLPlatformUtils::Terminate(); |
42 |
|
} |
43 |
|
else |
44 |
|
{ |
57 |
|
|
58 |
|
void SiteMapper::oldMap(const string& siteMap) |
59 |
|
{ |
60 |
< |
support.setParserLiaison(&liaison); |
61 |
< |
|
72 |
< |
XalanDOMString file(siteMap.c_str()); |
73 |
< |
LocalFileInputSource source(file.c_str()); |
74 |
< |
|
75 |
< |
XalanDocument* document = liaison.parseXMLStream(source); |
60 |
> |
ext::Handle<xml::Document> document(xml::Parse(siteMap)); |
61 |
> |
ext::Handle<xml::Node> list(*document/"page"/"section"/"list"); |
62 |
|
|
63 |
< |
if (document == 0) return; |
78 |
< |
|
79 |
< |
XalanNode* list = evaluator.selectSingleNode(support, document, |
80 |
< |
XalanDOMString("/page/section/list").c_str()); |
81 |
< |
|
82 |
< |
if (list == 0) return; |
83 |
< |
|
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 |
< |
this->list = evaluator.createXPath(XalanDOMString("list").c_str()); |
63 |
> |
comment = *document/"comment()"; |
64 |
|
|
65 |
|
oldMap(pages, list); |
90 |
– |
|
91 |
– |
evaluator.destroyXPath(item); |
92 |
– |
evaluator.destroyXPath(address); |
93 |
– |
evaluator.destroyXPath(link); |
94 |
– |
evaluator.destroyXPath(this->list); |
66 |
|
} |
67 |
|
|
68 |
< |
void SiteMapper::oldMap(vector<Page>& pages, XalanNode* list) |
68 |
> |
void SiteMapper::oldMap(vector<Page>& pages, xml::Node* list) |
69 |
|
{ |
70 |
< |
NodeRefList nodes = evaluator.selectNodeList(support, list, *item); |
70 |
> |
xml::NodeSet nodes(*list/"item"); |
71 |
|
|
72 |
< |
for (int index = 0; index < nodes.getLength(); index++) |
72 |
> |
for (xml::NodeSet::Iterator node(nodes.Begin()); node != nodes.End(); |
73 |
> |
++node) |
74 |
|
{ |
75 |
< |
XalanNode* node = nodes.item(index); |
76 |
< |
ostringstream url, title; |
77 |
< |
|
106 |
< |
url << evaluator.evaluate(support, node, *address)->str(); |
107 |
< |
title << evaluator.evaluate(support, node, *link)->str(); |
75 |
> |
string url(**node/"link"/"@address"), title(**node/"link"); |
76 |
> |
Page page(url, title); |
77 |
> |
ext::Handle<xml::Node> list(**node/"list"); |
78 |
|
|
79 |
< |
Page page(url.str(), title.str()); |
110 |
< |
XalanNode* list = evaluator.selectSingleNode(support, node, |
111 |
< |
*(this->list)); |
112 |
< |
|
113 |
< |
if (list != 0) oldMap(page.getChildren(), list); |
79 |
> |
if (!list.IsEmpty()) oldMap(page.getChildren(), list); |
80 |
|
|
81 |
|
pages.push_back(page); |
82 |
|
} |
84 |
|
|
85 |
|
void SiteMapper::newIndex(const string& siteIndex) |
86 |
|
{ |
87 |
< |
XalanDOMString file(siteIndex.c_str()); |
88 |
< |
LocalFileInputSource source(file.c_str()); |
123 |
< |
|
124 |
< |
XalanDocument* document = liaison.parseXMLStream(source); |
125 |
< |
|
126 |
< |
if (document == 0) return; |
127 |
< |
|
128 |
< |
address = evaluator.createXPath(XalanDOMString("address").c_str()); |
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 |
< |
|
133 |
< |
NodeRefList nodes = evaluator.selectNodeList(support, document, |
134 |
< |
XalanDOMString("/index/page").c_str()); |
87 |
> |
ext::Handle<xml::Document> document(xml::Parse(siteIndex)); |
88 |
> |
xml::NodeSet nodes(*document/"index"/"page"); |
89 |
|
|
90 |
< |
for (int index = 0; index < nodes.getLength(); index++) |
90 |
> |
for (xml::NodeSet::Iterator node(nodes.Begin()); node != nodes.End(); |
91 |
> |
++node) |
92 |
|
{ |
93 |
< |
XalanNode* node = nodes.item(index); |
94 |
< |
ostringstream address; |
93 |
> |
string address(**node/"address"); |
94 |
> |
string port(**node/"port"); |
95 |
|
|
96 |
< |
address << evaluator.evaluate(support, node, *(this->address))->str(); |
142 |
< |
|
143 |
< |
double port = evaluator.evaluate(support, node, *(this->port))->num(); |
144 |
< |
|
145 |
< |
if (port >= 0 && port <= 65535) |
96 |
> |
if (!port.empty()) |
97 |
|
{ |
98 |
< |
address << ':' << int(port); |
98 |
> |
address += ':' + port; |
99 |
|
} |
100 |
|
|
101 |
< |
ostringstream path, title; |
102 |
< |
|
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()); |
101 |
> |
string path(**node/"path"), title(**node/"title"); |
102 |
> |
Page page(address, path, title); |
103 |
|
Matcher matcher; |
104 |
|
|
105 |
|
if (page == matcher(string("^Douglas\\sThrift's\\sWebsite\\s\\|\\sDou") |
127 |
|
>(page.getAddress(), items)).first->second.insert(pair<string, |
128 |
|
Page>(page.getChildOf(), page)); |
129 |
|
} |
183 |
– |
|
184 |
– |
evaluator.destroyXPath(address); |
185 |
– |
evaluator.destroyXPath(port); |
186 |
– |
evaluator.destroyXPath(path); |
187 |
– |
evaluator.destroyXPath(title); |
130 |
|
} |
131 |
|
|
132 |
|
bool SiteMapper::newIndex(vector<Page>& pages, Page& page) |
133 |
|
{ |
134 |
< |
for (unsigned index = 0; index < pages.size(); index++) |
134 |
> |
for (unsigned index(0); index < pages.size(); ++index) |
135 |
|
{ |
136 |
|
if (pages[index] == page.getAddress()) |
137 |
|
{ |
171 |
|
<< "<?xml-stylesheet type=\"text/xsl\" href=\"stylesheets/sitemap.xsl" |
172 |
|
<< "\"?>\n" |
173 |
|
<< "<!DOCTYPE page SYSTEM \"stylesheets/page.dtd\">\n" |
174 |
< |
<< "<!-- /sitemap.xml -->\n" |
174 |
> |
<< "<!--" << comment << "-->\n" |
175 |
|
<< "<page>\n" |
176 |
|
<< "\t<title>Sitemap</title>\n" |
177 |
|
<< "\t<section>\n" |
178 |
|
<< "\t\t<list>\n"; |
179 |
|
|
180 |
< |
for (unsigned index = 0; index < pages.size(); index++) |
180 |
> |
for (unsigned index(0); index < pages.size(); ++index) |
181 |
|
{ |
182 |
|
if (newPages.find(pages[index].getAddress()) != newPages.end()) |
183 |
|
{ |
198 |
|
void SiteMapper::newMap(vector<Page>& pages, const string& childOf, |
199 |
|
multimap<string, Page>& newPages) |
200 |
|
{ |
201 |
< |
for (unsigned index = 0; index < pages.size(); index++) |
201 |
> |
for (unsigned index(0); index < pages.size(); ++index) |
202 |
|
{ |
203 |
|
newMap(pages[index].getChildren(), pages[index].getPath(), newPages); |
204 |
|
} |
205 |
|
|
206 |
< |
for (multimap<string, Page>::iterator itor = newPages.lower_bound(childOf); |
206 |
> |
for (multimap<string, Page>::iterator itor(newPages.lower_bound(childOf)); |
207 |
|
itor != newPages.upper_bound(childOf); itor++) |
208 |
|
{ |
209 |
|
pages.push_back(itor->second); |