ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/repos/SiteMapperOld/SiteMapper.cpp
Revision: 136
Committed: 2004-03-25T01:21:21-08:00 (21 years, 2 months ago) by Douglas Thrift
Original Path: SiteMapper/SiteMapper.cpp
File size: 2918 byte(s)
Log Message:
Slight error, no comment!

File Contents

# User Rev Content
1 Douglas Thrift 126 // Site Mapper
2     //
3     // Douglas Thrift
4     //
5     // $Id$
6    
7     #include "SiteMapper.hpp"
8     #include "Matcher.hpp"
9 Douglas Thrift 128 #include "Page.hpp"
10 Douglas Thrift 126
11 Douglas Thrift 128 string program;
12     bool debug = false;
13    
14 Douglas Thrift 126 int main(int argc, char* argv[])
15     {
16 Douglas Thrift 128 program = argv[0];
17 Douglas Thrift 132
18 Douglas Thrift 126 string siteIndex, siteMap;
19    
20 Douglas Thrift 132 for (int index = 1; index < argc; index++)
21 Douglas Thrift 126 {
22 Douglas Thrift 128 string arg(argv[index]);
23     Matcher matcher;
24 Douglas Thrift 126
25 Douglas Thrift 128 if (arg == matcher("^-index=(.*)$"))
26     {
27     siteIndex = matcher[1];
28     }
29     else if (arg == matcher("^-map=(.*)$"))
30     {
31     siteMap = matcher[1];
32     }
33 Douglas Thrift 133 else if (arg == "-D")
34     {
35     if (!debug) debug = true;
36     }
37 Douglas Thrift 126 }
38    
39 Douglas Thrift 128 if (siteIndex != "" && siteMap != "")
40 Douglas Thrift 132 {
41 Douglas Thrift 128 XMLPlatformUtils::Initialize();
42     XPathEvaluator::initialize();
43 Douglas Thrift 126
44 Douglas Thrift 128 SiteMapper mapper(siteIndex, siteMap);
45    
46     XPathEvaluator::terminate();
47     XMLPlatformUtils::Terminate();
48     }
49     else
50     {
51 Douglas Thrift 133 cout << "Usage: " << program << " -index=index -map=map [-D]\n";
52 Douglas Thrift 128 }
53 Douglas Thrift 129
54 Douglas Thrift 126 return 0;
55     }
56    
57     SiteMapper::SiteMapper(const string& siteIndex, const string& siteMap)
58     {
59 Douglas Thrift 133 oldMap(siteMap);
60 Douglas Thrift 134 index(siteIndex);
61     newMap(siteMap);
62 Douglas Thrift 133 }
63    
64     void SiteMapper::oldMap(const string& siteMap)
65     {
66 Douglas Thrift 135 XalanSourceTreeInit init;
67 Douglas Thrift 133 XalanSourceTreeDOMSupport support;
68     XalanSourceTreeParserLiaison liaison(support);
69    
70     support.setParserLiaison(&liaison);
71    
72 Douglas Thrift 134 XalanDOMString file(siteMap.c_str());
73     LocalFileInputSource source(file.c_str());
74 Douglas Thrift 133
75 Douglas Thrift 134 XalanDocument* document = liaison.parseXMLStream(source);
76 Douglas Thrift 133
77 Douglas Thrift 134 if (document == 0) return;
78 Douglas Thrift 133
79 Douglas Thrift 134 XPathEvaluator evaluator;
80     XalanNode* list = evaluator.selectSingleNode(support, document,
81     XalanDOMString("/page/section/list").c_str());
82 Douglas Thrift 133
83 Douglas Thrift 134 if (list == 0) return;
84 Douglas Thrift 135
85     oldMap(pages, evaluator, support, list);
86 Douglas Thrift 133 }
87    
88 Douglas Thrift 135 void SiteMapper::oldMap(vector<Page>& pages, XPathEvaluator& evaluator,
89     XalanSourceTreeDOMSupport& support, XalanNode* list)
90     {
91     NodeRefList nodes = evaluator.selectNodeList(support, list,
92     XalanDOMString("item").c_str());
93    
94    
95     for (int index = 0; index < nodes.getLength(); index++)
96     {
97     XalanNode* node = nodes.item(index);
98    
99     cerr << "node=" << node << '\n';
100    
101     ostringstream url, title;
102    
103     {
104     XObjectPtr address = evaluator.evaluate(support, node,
105     XalanDOMString("link/@address").c_str());
106    
107     if (!address.null())
108     {
109     url << address->str();
110     cerr << "url=" << url.str() << '\n';
111     }
112     }
113    
114     {
115     XObjectPtr link = evaluator.evaluate(support, node,
116     XalanDOMString("link").c_str());
117    
118     if (!link.null())
119     {
120     title << link->str();
121     cerr << "title=" << title.str() << '\n';
122     }
123     }
124    
125     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());
129    
130     cerr << "list=" << list << '\n';
131    
132     if (list != 0) oldMap(page.getChildren(), evaluator, support, list);
133    
134     pages.push_back(page);
135     }
136     }
137    
138 Douglas Thrift 133 void SiteMapper::index(const string& siteIndex)
139     {
140 Douglas Thrift 126 //
141     }
142 Douglas Thrift 133
143     void SiteMapper::newMap(const string& siteMap)
144     {
145     //
146 Douglas Thrift 136
147     for (int index = 0; index < pages.size(); index++)
148     {
149     cout << pages[index] << '\n';
150     }
151 Douglas Thrift 133 }

Properties

Name Value
svn:eol-style native
svn:keywords Id