ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/repos/SiteMapper/SiteMapper.cpp
(Generate patch)

Comparing SiteMapper/SiteMapper.cpp (file contents):
Revision 136 by Douglas Thrift, 2004-03-25T01:21:21-08:00 vs.
Revision 237 by Douglas Thrift, 2004-09-10T16:22:07-07:00

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines