EBOOKHTMLParser.h
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /*
3 * This file is part of the libe-book project.
4 *
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 */
9
10 #ifndef EBOOKHTMLPARSER_H_INCLUDED
11 #define EBOOKHTMLPARSER_H_INCLUDED
12
13 #include <boost/shared_ptr.hpp>
14
15 #include <librevenge/librevenge.h>
16 #include <librevenge-stream/librevenge-stream.h>
17
18 #include "XMLTreeNode.h"
19
20 namespace libebook
21 {
22
23 class XMLCollector;
24 struct EBOOKHTMLMetadata;
25 class EBOOKHTMLParagraphAttributes;
26 class EBOOKHTMLSpanAttributes;
27 class EBOOKHTMLTableCellAttributes;
28 class EBOOKOutputElements;
29 class XMLTreeWalker;
30
31 class EBOOKHTMLParser
32 {
33 struct State;
34
35 public:
36 enum Dialect
37 {
38 DIALECT_UNKNOWN,
39 DIALECT_HTML,
40 DIALECT_XHTML
41 };
42
43 public:
44 EBOOKHTMLParser(librevenge::RVNGInputStream *input, Dialect dialect, librevenge::RVNGTextInterface *document);
45 virtual ~EBOOKHTMLParser();
46
47 void parse();
48 const XMLTreeNodePtr_t readTree();
49
50 virtual librevenge::RVNGInputStream *getImage(const char *path) = 0;
51 virtual librevenge::RVNGInputStream *getObject(const char *path) = 0;
52 virtual librevenge::RVNGInputStream *getStylesheet(const char *path) = 0;
53
54 private:
55 const XMLTreeNodePtr_t readTreeImpl(std::string &encoding, bool &encodingChange);
56 void processNode(const XMLTreeWalker &node);
57
58 void startElement(const XMLTreeWalker &node);
59 void endElement(const XMLTreeWalker &node);
60 void text(const XMLTreeWalker &node);
61
62 void startExternalElement(const XMLTreeWalker &node);
63 void endExternalElement(const XMLTreeWalker &node);
64
65 void sendParagraph(const XMLTreeWalker &node);
66 void sendSpan(const XMLTreeWalker &node);
67 void sendTableCell(const XMLTreeWalker &node);
68 void sendPreformattedText(const char *ch, int len);
69 void sendHeading(const XMLTreeWalker &node, int level);
70
71 private:
72 boost::shared_ptr<XMLCollector> m_collector;
73 boost::shared_ptr<State> m_state;
74 boost::shared_ptr<librevenge::RVNGInputStream> m_input;
75 // const Dialect m_dialect;
76 boost::shared_ptr<librevenge::RVNGInputStream> m_workingInput;
77 };
78
79 }
80
81 #endif // EBOOKHTMLPARSER_H_INCLUDED
82
83 /* vim:set shiftwidth=2 softtabstop=2 expandtab: */
libebook::XMLTreeNodePtr_t
boost::intrusive_ptr< XMLTreeNode > XMLTreeNodePtr_t
Definition: XMLTreeNode.h:24
libebook::EBOOKHTMLParser::~EBOOKHTMLParser
virtual ~EBOOKHTMLParser()
Definition: EBOOKHTMLParser.cpp:935
libebook::EBOOKHTMLParser::getStylesheet
virtual librevenge::RVNGInputStream * getStylesheet(const char *path)=0
libebook::EBOOKHTMLParser
Definition: EBOOKHTMLParser.h:31
libebook::EBOOKHTMLParser::m_state
boost::shared_ptr< State > m_state
Definition: EBOOKHTMLParser.h:73
libebook::EBOOKHTMLParser::text
void text(const XMLTreeWalker &node)
Definition: EBOOKHTMLParser.cpp:1434
libebook::EBOOKHTMLParser::endElement
void endElement(const XMLTreeWalker &node)
Definition: EBOOKHTMLParser.cpp:1266
libebook::EBOOKHTMLParser::parse
void parse()
Definition: EBOOKHTMLParser.cpp:939
libebook::EBOOKHTMLParser::m_input
boost::shared_ptr< librevenge::RVNGInputStream > m_input
Definition: EBOOKHTMLParser.h:74
XMLTreeNode.h
libebook::EBOOKHTMLParser::EBOOKHTMLParser
EBOOKHTMLParser(librevenge::RVNGInputStream *input, Dialect dialect, librevenge::RVNGTextInterface *document)
Definition: EBOOKHTMLParser.cpp:926
libebook::EBOOKHTMLParser::sendTableCell
void sendTableCell(const XMLTreeWalker &node)
Definition: EBOOKHTMLParser.cpp:1489
libebook::EBOOKHTMLParser::sendSpan
void sendSpan(const XMLTreeWalker &node)
Definition: EBOOKHTMLParser.cpp:1483
libebook::EBOOKHTMLParser::DIALECT_XHTML
Definition: EBOOKHTMLParser.h:40
libebook::EBOOKHTMLParser::m_collector
boost::shared_ptr< XMLCollector > m_collector
Definition: EBOOKHTMLParser.h:72
libebook::EBOOKHTMLParser::endExternalElement
void endExternalElement(const XMLTreeWalker &node)
Definition: EBOOKHTMLParser.cpp:1471
libebook::EBOOKHTMLParser::processNode
void processNode(const XMLTreeWalker &node)
Definition: EBOOKHTMLParser.cpp:1002
path
string path
Definition: EBOOKOPFParser.cpp:49
libebook::EBOOKHTMLParser::sendPreformattedText
void sendPreformattedText(const char *ch, int len)
Definition: EBOOKHTMLParser.cpp:1495
libebook::EBOOKHTMLParser::sendParagraph
void sendParagraph(const XMLTreeWalker &node)
Definition: EBOOKHTMLParser.cpp:1477
libebook::EBOOKHTMLParser::readTree
const XMLTreeNodePtr_t readTree()
Definition: EBOOKHTMLParser.cpp:952
document
XMLTreeNodePtr_t document
Definition: EBOOKHTMLParser.cpp:169
libebook::EBOOKHTMLParser::getObject
virtual librevenge::RVNGInputStream * getObject(const char *path)=0
libebook::EBOOKHTMLToken::input
Definition: EBOOKHTMLToken.h:91
libebook::EBOOKHTMLParser::DIALECT_UNKNOWN
Definition: EBOOKHTMLParser.h:38
libebook::EBOOKHTMLParser::startExternalElement
void startExternalElement(const XMLTreeWalker &node)
Definition: EBOOKHTMLParser.cpp:1465
len
size_t len
Definition: EBOOKHTMLParser.cpp:53
libebook::EBOOKHTMLParser::Dialect
Dialect
Definition: EBOOKHTMLParser.h:36
libebook
Definition: CHMParser.cpp:20
libebook::EBOOKHTMLParser::State
Definition: EBOOKHTMLParser.cpp:908
libebook::EBOOKHTMLParser::startElement
void startElement(const XMLTreeWalker &node)
Definition: EBOOKHTMLParser.cpp:1016
libebook::EBOOKHTMLParser::m_workingInput
boost::shared_ptr< librevenge::RVNGInputStream > m_workingInput
Definition: EBOOKHTMLParser.h:76
libebook::EBOOKHTMLParser::sendHeading
void sendHeading(const XMLTreeWalker &node, int level)
Definition: EBOOKHTMLParser.cpp:1539
libebook::EBOOKHTMLParser::DIALECT_HTML
Definition: EBOOKHTMLParser.h:39
libebook::EBOOKHTMLParser::getImage
virtual librevenge::RVNGInputStream * getImage(const char *path)=0
libebook::EBOOKHTMLParser::readTreeImpl
const XMLTreeNodePtr_t readTreeImpl(std::string &encoding, bool &encodingChange)
Definition: EBOOKHTMLParser.cpp:970
encoding
const char * encoding
Definition: EBOOKHTMLParser.cpp:172
libebook::XMLTreeWalker
Definition: XMLTreeWalker.h:27