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; |
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 |
|
{ |
61 |
– |
XMLPlatformUtils::Initialize(); |
62 |
– |
XPathEvaluator::initialize(); |
63 |
– |
|
41 |
|
SiteMapper mapper(siteIndex, siteMap); |
65 |
– |
|
66 |
– |
XPathEvaluator::terminate(); |
67 |
– |
XMLPlatformUtils::Terminate(); |
42 |
|
} |
43 |
|
else |
44 |
|
{ |
50 |
|
|
51 |
|
SiteMapper::SiteMapper(const string& siteIndex, const string& siteMap) |
52 |
|
{ |
79 |
– |
XalanSourceTreeInit init; |
80 |
– |
|
53 |
|
oldMap(siteMap); |
54 |
< |
// index(siteIndex); |
55 |
< |
// newMap(siteMap); |
54 |
> |
newIndex(siteIndex); |
55 |
> |
newMap(siteMap); |
56 |
|
} |
57 |
|
|
58 |
|
void SiteMapper::oldMap(const string& siteMap) |
59 |
|
{ |
60 |
< |
XalanSourceTreeDOMSupport support; |
61 |
< |
XalanSourceTreeParserLiaison liaison(support); |
60 |
> |
ext::Handle<xml::Document> document(xml::Parse(siteMap)); |
61 |
> |
ext::Handle<xml::Node> list(*document/"page"/"section"/"list"); |
62 |
> |
|
63 |
> |
comment = *document/"comment()"; |
64 |
> |
|
65 |
> |
oldMap(pages, list); |
66 |
> |
} |
67 |
> |
|
68 |
> |
void SiteMapper::oldMap(vector<Page>& pages, xml::Node* list) |
69 |
> |
{ |
70 |
> |
xml::NodeSet nodes(*list/"item"); |
71 |
> |
|
72 |
> |
for (xml::NodeSet::Iterator node(nodes.Begin()); node != nodes.End(); |
73 |
> |
++node) |
74 |
> |
{ |
75 |
> |
string url(**node/"link"/"@address"), title(**node/"link"); |
76 |
> |
Page page(url, title); |
77 |
> |
ext::Handle<xml::Node> list(**node/"list"); |
78 |
> |
|
79 |
> |
if (!list.IsEmpty()) oldMap(page.getChildren(), list); |
80 |
> |
|
81 |
> |
pages.push_back(page); |
82 |
> |
} |
83 |
> |
} |
84 |
> |
|
85 |
> |
void SiteMapper::newIndex(const string& siteIndex) |
86 |
> |
{ |
87 |
> |
ext::Handle<xml::Document> document(xml::Parse(siteIndex)); |
88 |
> |
xml::NodeSet nodes(*document/"index"/"page"); |
89 |
|
|
90 |
< |
support.setParserLiaison(&liaison); |
90 |
> |
for (xml::NodeSet::Iterator node(nodes.Begin()); node != nodes.End(); |
91 |
> |
++node) |
92 |
> |
{ |
93 |
> |
string address(**node/"address"); |
94 |
> |
string port(**node/"port"); |
95 |
|
|
96 |
< |
cerr << "Here!\n"; |
96 |
> |
if (!port.empty()) |
97 |
> |
{ |
98 |
> |
address += ':' + port; |
99 |
> |
} |
100 |
|
|
101 |
< |
const XalanDOMString file(siteMap.c_str()); |
102 |
< |
const LocalFileInputSource source(file.c_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") |
106 |
> |
+ "glas\\sThrift's\\sBlog:\\s(.+)$")) |
107 |
> |
{ |
108 |
> |
if (Matcher("^\\w+\\s\\d\\d\\d\\d\\sArchives$") == matcher[1]) |
109 |
> |
{ |
110 |
> |
page.setTitle(matcher[1]); |
111 |
> |
|
112 |
> |
if (newIndex(pages, page)) continue; |
113 |
> |
} |
114 |
> |
else continue; |
115 |
> |
} |
116 |
> |
else if (page == matcher("^Douglas\\sThrift's.+Website\\s\\|\\s(.+)$")) |
117 |
> |
{ |
118 |
> |
page.setTitle(matcher[1]); |
119 |
|
|
120 |
+ |
if (newIndex(pages, page)) continue; |
121 |
+ |
} |
122 |
+ |
else continue; |
123 |
|
|
124 |
< |
cerr << "There!\n"; |
124 |
> |
multimap<string, Page> items; |
125 |
|
|
126 |
< |
const XalanDocument* document = liaison.parseXMLStream(source); |
126 |
> |
newPages.insert(pair<string, multimap<string, Page> |
127 |
> |
>(page.getAddress(), items)).first->second.insert(pair<string, |
128 |
> |
Page>(page.getChildOf(), page)); |
129 |
> |
} |
130 |
|
} |
131 |
|
|
132 |
< |
void SiteMapper::index(const string& siteIndex) |
132 |
> |
bool SiteMapper::newIndex(vector<Page>& pages, Page& page) |
133 |
|
{ |
134 |
< |
// |
134 |
> |
for (unsigned index(0); index < pages.size(); ++index) |
135 |
> |
{ |
136 |
> |
if (pages[index] == page.getAddress()) |
137 |
> |
{ |
138 |
> |
Matcher matcher; |
139 |
> |
|
140 |
> |
if (pages[index] == page) |
141 |
> |
{ |
142 |
> |
page.setChildren(pages[index].getChildren()); |
143 |
> |
|
144 |
> |
pages[index] = page; |
145 |
> |
|
146 |
> |
return true; |
147 |
> |
} |
148 |
> |
else if (matcher('^' + pages[index].getPath()) == page) |
149 |
> |
{ |
150 |
> |
page.setChildOf(matcher[0]); |
151 |
> |
|
152 |
> |
if (matcher('^' + pages[index].getTitle() + "\\s\\|\\s(.+)$") |
153 |
> |
== page) |
154 |
> |
{ |
155 |
> |
page.setTitle(matcher[1]); |
156 |
> |
} |
157 |
> |
|
158 |
> |
return newIndex(pages[index].getChildren(), page); |
159 |
> |
} |
160 |
> |
} |
161 |
> |
} |
162 |
> |
|
163 |
> |
return false; |
164 |
|
} |
165 |
|
|
166 |
|
void SiteMapper::newMap(const string& siteMap) |
167 |
|
{ |
168 |
< |
// |
168 |
> |
ofstream fout(siteMap.c_str()); |
169 |
> |
|
170 |
> |
fout << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" |
171 |
> |
<< "<?xml-stylesheet type=\"text/xsl\" href=\"stylesheets/sitemap.xsl" |
172 |
> |
<< "\"?>\n" |
173 |
> |
<< "<!DOCTYPE page SYSTEM \"stylesheets/page.dtd\">\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) |
181 |
> |
{ |
182 |
> |
if (newPages.find(pages[index].getAddress()) != newPages.end()) |
183 |
> |
{ |
184 |
> |
newMap(pages[index].getChildren(), pages[index].getPath(), |
185 |
> |
newPages.find(pages[index].getAddress())->second); |
186 |
> |
} |
187 |
> |
|
188 |
> |
fout << pages[index](3) << '\n'; |
189 |
> |
} |
190 |
> |
|
191 |
> |
fout << "\t\t</list>\n" |
192 |
> |
<< "\t</section>\n" |
193 |
> |
<< "</page>\n"; |
194 |
> |
|
195 |
> |
fout.close(); |
196 |
> |
} |
197 |
> |
|
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) |
202 |
> |
{ |
203 |
> |
newMap(pages[index].getChildren(), pages[index].getPath(), newPages); |
204 |
> |
} |
205 |
> |
|
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); |
210 |
> |
} |
211 |
> |
|
212 |
> |
newPages.erase(childOf); |
213 |
|
} |