8 |
|
#include "Matcher.hpp" |
9 |
|
#include "Page.hpp" |
10 |
|
|
11 |
– |
#include <xalanc/Include/PlatformDefinitions.hpp> |
12 |
– |
#include <xercesc/util/PlatformUtils.hpp> |
13 |
– |
#include <xercesc/framework/LocalFileInputSource.hpp> |
14 |
– |
#include <xalanc/XPath/XPathEvaluator.hpp> |
15 |
– |
#include <xalanc/DOMSupport/XalanDocumentPrefixResolver.hpp> |
16 |
– |
#include <xalanc/XalanSourceTree/XalanSourceTreeDOMSupport.hpp> |
17 |
– |
#include <xalanc/XalanSourceTree/XalanSourceTreeInit.hpp> |
18 |
– |
#include <xalanc/XalanSourceTree/XalanSourceTreeParserLiaison.hpp> |
19 |
– |
|
20 |
– |
XALAN_USING_XERCES(XMLPlatformUtils) |
21 |
– |
XALAN_USING_XERCES(LocalFileInputSource) |
22 |
– |
XALAN_USING_XALAN(XPathEvaluator) |
23 |
– |
XALAN_USING_XALAN(XalanDocument) |
24 |
– |
XALAN_USING_XALAN(XalanDocumentPrefixResolver) |
25 |
– |
XALAN_USING_XALAN(XalanDOMString) |
26 |
– |
XALAN_USING_XALAN(XalanNode) |
27 |
– |
XALAN_USING_XALAN(XalanSourceTreeInit) |
28 |
– |
XALAN_USING_XALAN(XalanSourceTreeDOMSupport) |
29 |
– |
XALAN_USING_XALAN(XalanSourceTreeParserLiaison) |
30 |
– |
|
11 |
|
string program; |
12 |
|
bool debug = false; |
13 |
|
|
56 |
|
|
57 |
|
SiteMapper::SiteMapper(const string& siteIndex, const string& siteMap) |
58 |
|
{ |
79 |
– |
XalanSourceTreeInit init; |
80 |
– |
|
59 |
|
oldMap(siteMap); |
60 |
< |
// index(siteIndex); |
61 |
< |
// newMap(siteMap); |
60 |
> |
index(siteIndex); |
61 |
> |
newMap(siteMap); |
62 |
|
} |
63 |
|
|
64 |
|
void SiteMapper::oldMap(const string& siteMap) |
65 |
|
{ |
88 |
– |
XalanSourceTreeDOMSupport support; |
89 |
– |
XalanSourceTreeParserLiaison liaison(support); |
90 |
– |
|
66 |
|
support.setParserLiaison(&liaison); |
67 |
|
|
68 |
< |
cerr << "Here!\n"; |
68 |
> |
XalanDOMString file(siteMap.c_str()); |
69 |
> |
LocalFileInputSource source(file.c_str()); |
70 |
> |
|
71 |
> |
XalanDocument* document = liaison.parseXMLStream(source); |
72 |
> |
|
73 |
> |
if (document == 0) return; |
74 |
|
|
75 |
< |
const XalanDOMString file(siteMap.c_str()); |
76 |
< |
const LocalFileInputSource source(file.c_str()); |
75 |
> |
XalanNode* list = evaluator.selectSingleNode(support, document, |
76 |
> |
XalanDOMString("/page/section/list").c_str()); |
77 |
|
|
78 |
+ |
if (list == 0) return; |
79 |
|
|
80 |
< |
cerr << "There!\n"; |
80 |
> |
item = evaluator.createXPath(XalanDOMString("item").c_str()); |
81 |
> |
address = evaluator.createXPath(XalanDOMString("link/@address").c_str()); |
82 |
> |
link = evaluator.createXPath(XalanDOMString("link").c_str()); |
83 |
> |
list_ = evaluator.createXPath(XalanDOMString("list").c_str()); |
84 |
|
|
85 |
< |
const XalanDocument* document = liaison.parseXMLStream(source); |
85 |
> |
oldMap(pages, list); |
86 |
> |
|
87 |
> |
evaluator.destroyXPath(item); |
88 |
> |
evaluator.destroyXPath(address); |
89 |
> |
evaluator.destroyXPath(link); |
90 |
> |
evaluator.destroyXPath(list_); |
91 |
> |
} |
92 |
> |
|
93 |
> |
void SiteMapper::oldMap(list<Page>& pages, XalanNode* list) |
94 |
> |
{ |
95 |
> |
NodeRefList nodes = evaluator.selectNodeList(support, list, *item); |
96 |
> |
|
97 |
> |
for (int index = 0; index < nodes.getLength(); index++) |
98 |
> |
{ |
99 |
> |
XalanNode* node = nodes.item(index); |
100 |
> |
ostringstream url, title; |
101 |
> |
|
102 |
> |
url << evaluator.evaluate(support, node, *address)->str(); |
103 |
> |
title << evaluator.evaluate(support, node, *link)->str(); |
104 |
> |
|
105 |
> |
Page page(url.str(), title.str()); |
106 |
> |
XalanNode* list = evaluator.selectSingleNode(support, node, *list_); |
107 |
> |
|
108 |
> |
if (list != 0) oldMap(page.getChildren(), list); |
109 |
> |
|
110 |
> |
pages.push_back(page); |
111 |
> |
} |
112 |
|
} |
113 |
|
|
114 |
|
void SiteMapper::index(const string& siteIndex) |
115 |
|
{ |
116 |
< |
// |
116 |
> |
XalanDOMString file(siteIndex.c_str()); |
117 |
> |
LocalFileInputSource source(file.c_str()); |
118 |
> |
|
119 |
> |
XalanDocument* document = liaison.parseXMLStream(source); |
120 |
> |
|
121 |
> |
if (document == 0) return; |
122 |
> |
|
123 |
> |
address = evaluator.createXPath(XalanDOMString("address").c_str()); |
124 |
> |
port = evaluator.createXPath(XalanDOMString("port").c_str()); |
125 |
> |
path = evaluator.createXPath(XalanDOMString("path").c_str()); |
126 |
> |
title = evaluator.createXPath(XalanDOMString("title").c_str()); |
127 |
> |
|
128 |
> |
NodeRefList nodes = evaluator.selectNodeList(support, document, |
129 |
> |
XalanDOMString("/index/page").c_str()); |
130 |
> |
|
131 |
> |
for (int index = 0; index < nodes.getLength(); index++) |
132 |
> |
{ |
133 |
> |
XalanNode* node = nodes.item(index); |
134 |
> |
ostringstream address; |
135 |
> |
|
136 |
> |
address << evaluator.evaluate(support, node, *(this->address))->str(); |
137 |
> |
|
138 |
> |
double port = evaluator.evaluate(support, node, *(this->port))->num(); |
139 |
> |
|
140 |
> |
if (port >= 0 && port <= 65535) |
141 |
> |
{ |
142 |
> |
address << ':' << int(port); |
143 |
> |
} |
144 |
> |
|
145 |
> |
ostringstream path, title; |
146 |
> |
|
147 |
> |
path << evaluator.evaluate(support, node, *(this->path))->str(); |
148 |
> |
title << evaluator.evaluate(support, node, *(this->title))->str(); |
149 |
> |
|
150 |
> |
Page page(address.str(), path.str(), title.str()); |
151 |
> |
Matcher matcher("^Douglas Thrift's.+Website \\| (.+)$"); |
152 |
> |
|
153 |
> |
if (page == matcher) |
154 |
> |
{ |
155 |
> |
page.setTitle(matcher[1]); |
156 |
> |
|
157 |
> |
newPages.insert(page); |
158 |
> |
} |
159 |
> |
} |
160 |
> |
|
161 |
> |
evaluator.destroyXPath(address); |
162 |
> |
evaluator.destroyXPath(port); |
163 |
> |
evaluator.destroyXPath(path); |
164 |
> |
evaluator.destroyXPath(title); |
165 |
|
} |
166 |
|
|
167 |
|
void SiteMapper::newMap(const string& siteMap) |
168 |
|
{ |
169 |
|
// |
170 |
+ |
|
171 |
+ |
for (list<Page>::iterator itor = pages.begin(); itor != pages.end(); |
172 |
+ |
itor++) |
173 |
+ |
{ |
174 |
+ |
cout << *itor << '\n'; |
175 |
+ |
} |
176 |
|
} |