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 |
> |
XalanNode* list = evaluator.selectSingleNode(support, document, |
76 |
> |
XalanDOMString("/page/section/list").c_str()); |
77 |
> |
|
78 |
> |
if (list == 0) return; |
79 |
> |
|
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 |
> |
this->list = evaluator.createXPath(XalanDOMString("list").c_str()); |
84 |
> |
|
85 |
> |
oldMap(pages, list); |
86 |
> |
} |
87 |
> |
|
88 |
> |
void SiteMapper::oldMap(vector<Page>& pages, XalanNode* list) |
89 |
> |
{ |
90 |
> |
NodeRefList nodes = evaluator.selectNodeList(support, list, *item); |
91 |
> |
|
92 |
> |
for (int index = 0; index < nodes.getLength(); index++) |
93 |
> |
{ |
94 |
> |
XalanNode* node = nodes.item(index); |
95 |
> |
XObjectPtr address = evaluator.evaluate(support, node, |
96 |
> |
*(this->address)); |
97 |
> |
ostringstream url; |
98 |
> |
|
99 |
> |
if (!address.null()) |
100 |
> |
{ |
101 |
> |
url << address->str(); |
102 |
> |
} |
103 |
> |
|
104 |
> |
XObjectPtr link = evaluator.evaluate(support, node, *(this->link)); |
105 |
> |
ostringstream title; |
106 |
|
|
107 |
< |
const XalanDOMString file(siteMap.c_str()); |
108 |
< |
const LocalFileInputSource source(file.c_str()); |
107 |
> |
if (!link.null()) |
108 |
> |
{ |
109 |
> |
title << link->str(); |
110 |
> |
} |
111 |
|
|
112 |
+ |
Page page(url.str(), title.str()); |
113 |
+ |
XalanNode* list = evaluator.selectSingleNode(support, node, |
114 |
+ |
*(this->list)); |
115 |
|
|
116 |
< |
cerr << "There!\n"; |
116 |
> |
if (list != 0) oldMap(page.getChildren(), list); |
117 |
|
|
118 |
< |
const XalanDocument* document = liaison.parseXMLStream(source); |
118 |
> |
pages.push_back(page); |
119 |
> |
} |
120 |
|
} |
121 |
|
|
122 |
|
void SiteMapper::index(const string& siteIndex) |
127 |
|
void SiteMapper::newMap(const string& siteMap) |
128 |
|
{ |
129 |
|
// |
130 |
+ |
|
131 |
+ |
for (int index = 0; index < pages.size(); index++) |
132 |
+ |
{ |
133 |
+ |
cout << pages[index] << '\n'; |
134 |
+ |
} |
135 |
|
} |