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 134 by Douglas Thrift, 2004-03-24T22:23:19-08:00 vs.
Revision 139 by Douglas Thrift, 2004-03-25T16:10:22-08:00

# Line 8 | Line 8
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/XObject.hpp>
15 #include <xalanc/XPath/XPathEvaluator.hpp>
16 #include <xalanc/DOMSupport/XalanDocumentPrefixResolver.hpp>
17 #include <xalanc/XalanSourceTree/XalanSourceTreeDOMSupport.hpp>
18 #include <xalanc/XalanSourceTree/XalanSourceTreeInit.hpp>
19 #include <xalanc/XalanSourceTree/XalanSourceTreeParserLiaison.hpp>
20
21 XALAN_USING_XERCES(XMLPlatformUtils)
22 XALAN_USING_XERCES(LocalFileInputSource)
23 XALAN_USING_XALAN(XObjectPtr)
24 XALAN_USING_XALAN(XPathEvaluator)
25 XALAN_USING_XALAN(XalanDocument)
26 XALAN_USING_XALAN(XalanDocumentPrefixResolver)
27 XALAN_USING_XALAN(XalanDOMString)
28 XALAN_USING_XALAN(XalanNode)
29 XALAN_USING_XALAN(XalanSourceTreeInit)
30 XALAN_USING_XALAN(XalanSourceTreeDOMSupport)
31 XALAN_USING_XALAN(XalanSourceTreeParserLiaison)
32
11   string program;
12   bool debug = false;
13  
# Line 78 | Line 56 | int main(int argc, char* argv[])
56  
57   SiteMapper::SiteMapper(const string& siteIndex, const string& siteMap)
58   {
81        XalanSourceTreeInit init;
82
59          oldMap(siteMap);
60          index(siteIndex);
61          newMap(siteMap);
# Line 87 | Line 63 | SiteMapper::SiteMapper(const string& sit
63  
64   void SiteMapper::oldMap(const string& siteMap)
65   {
90        XalanSourceTreeDOMSupport support;
91        XalanSourceTreeParserLiaison liaison(support);
92
66          support.setParserLiaison(&liaison);
67  
68          XalanDOMString file(siteMap.c_str());
# Line 99 | Line 72 | void SiteMapper::oldMap(const string& si
72  
73          if (document == 0) return;
74  
102        XPathEvaluator evaluator;
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 +        evaluator.destroyXPath(item);
88 +        evaluator.destroyXPath(address);
89 +        evaluator.destroyXPath(link);
90 +        evaluator.destroyXPath(this->list);
91 + }
92 +
93 + void SiteMapper::oldMap(vector<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,
107 +                        *(this->list));
108 +
109 +                if (list != 0) oldMap(page.getChildren(), list);
110 +
111 +                pages.push_back(page);
112 +        }
113   }
114  
115   void SiteMapper::index(const string& siteIndex)
116   {
117 <        //
117 >        XalanDOMString file(siteIndex.c_str());
118 >        LocalFileInputSource source(file.c_str());
119 >
120 >        XalanDocument* document = liaison.parseXMLStream(source);
121 >
122 >        if (document == 0) return;
123 >
124 >        address = evaluator.createXPath(XalanDOMString("address").c_str());
125 >        port = evaluator.createXPath(XalanDOMString("port").c_str());
126 >        path = evaluator.createXPath(XalanDOMString("path").c_str());
127 >        title = evaluator.createXPath(XalanDOMString("title").c_str());
128 >        
129 >        NodeRefList nodes = evaluator.selectNodeList(support, document,
130 >                XalanDOMString("/index/page").c_str());
131 >
132 >        for (int index = 0; index < nodes.getLength(); index++)
133 >        {
134 >                XalanNode* node = nodes.item(index);
135 >                ostringstream address;
136 >
137 >                address << evaluator.evaluate(support, node, *(this->address))->str();
138 >
139 >                double port = evaluator.evaluate(support, node, *(this->port))->num();
140 >
141 >                if (port >= 0 && port <= 65535)
142 >                {
143 >                        address << ':' << int(port);
144 >                }
145 >
146 >                cerr << address.str() << '\n';
147 >        }
148 >
149 >        evaluator.destroyXPath(address);
150 >        evaluator.destroyXPath(port);
151 >        evaluator.destroyXPath(path);
152 >        evaluator.destroyXPath(title);
153   }
154  
155   void SiteMapper::newMap(const string& siteMap)
156   {
157          //
158 +
159 + //      for (int index = 0; index < pages.size(); index++)
160 + //      {
161 + //              cout << pages[index] << '\n';
162 + //      }
163   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines