Line data Source code
1 : /*************************************************************************
2 : *
3 : * Copyright (c) 2010-2012 Kohei Yoshida
4 : *
5 : * Permission is hereby granted, free of charge, to any person
6 : * obtaining a copy of this software and associated documentation
7 : * files (the "Software"), to deal in the Software without
8 : * restriction, including without limitation the rights to use,
9 : * copy, modify, merge, publish, distribute, sublicense, and/or sell
10 : * copies of the Software, and to permit persons to whom the
11 : * Software is furnished to do so, subject to the following
12 : * conditions:
13 : *
14 : * The above copyright notice and this permission notice shall be
15 : * included in all copies or substantial portions of the Software.
16 : *
17 : * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18 : * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
19 : * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20 : * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
21 : * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
22 : * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
23 : * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
24 : * OTHER DEALINGS IN THE SOFTWARE.
25 : *
26 : ************************************************************************/
27 :
28 : #include "orcus/xml_parser.hpp"
29 : #include "orcus/xml_handler.hpp"
30 : #include "orcus/tokens.hpp"
31 : #include "orcus/sax_token_parser.hpp"
32 :
33 : #include <iostream>
34 : #include <vector>
35 : #include <sstream>
36 :
37 : using namespace std;
38 :
39 : namespace orcus {
40 :
41 : // ============================================================================
42 :
43 0 : xml_stream_parser::parse_error::parse_error(const string& msg) :
44 0 : m_msg(msg) {}
45 :
46 0 : xml_stream_parser::parse_error::~parse_error() throw() {}
47 :
48 0 : const char* xml_stream_parser::parse_error::what() const throw()
49 : {
50 0 : return m_msg.c_str();
51 : }
52 :
53 0 : xml_stream_parser::xml_stream_parser(const tokens& tokens, const char* content, size_t size, const string& name) :
54 0 : m_tokens(tokens), mp_handler(NULL), m_content(content), m_size(size), m_name(name)
55 : {
56 0 : }
57 :
58 0 : xml_stream_parser::~xml_stream_parser()
59 : {
60 0 : }
61 :
62 0 : void xml_stream_parser::parse()
63 : {
64 0 : if (!mp_handler)
65 0 : return;
66 :
67 0 : sax_token_parser<xml_stream_handler, tokens> sax(m_content, m_size, m_tokens, *mp_handler);
68 0 : sax.parse();
69 : }
70 :
71 0 : void xml_stream_parser::set_handler(xml_stream_handler* handler)
72 : {
73 0 : mp_handler = handler;
74 0 : }
75 :
76 0 : xml_stream_handler* xml_stream_parser::get_handler() const
77 : {
78 0 : return mp_handler;
79 : }
80 :
81 24 : }
|