1//
2// PageReader.h
3//
4// Copyright (c) 2008, Applied Informatics Software Engineering GmbH.
5// and Contributors.
6//
7// SPDX-License-Identifier: BSL-1.0
8//
9
10
11#ifndef PageReader_INCLUDED
12#define PageReader_INCLUDED
13
14
15#include "Poco/Poco.h"
16#include <istream>
17#include <ostream>
18#include <sstream>
19
20
21class Page;
22
23
24class PageReader
25 /// This class implements the parser for reading page files
26 /// containing JSP-style tags.
27{
28public:
29 PageReader(Page& page, const std::string& path);
30 /// Creates the PageReader, using the given Page.
31
32 PageReader(const PageReader& parent, const std::string& path);
33 /// Creates the PageReader, using the given PageReader as parent.
34
35 ~PageReader();
36 /// Destroys the PageReader.
37
38 void parse(std::istream& pageStream);
39 /// Parses a HTML file containing server page directives,
40 /// converts the file into C++ code and adds the code
41 /// to the reader's Page object. Also parses page
42 /// attributes and include directives.
43
44 void emitLineDirectives(bool flag = true);
45 /// Enables writing of #line directives to generated code.
46
47protected:
48 enum ParsingState
49 {
50 STATE_MARKUP,
51 STATE_IMPLDECL,
52 STATE_HDRDECL,
53 STATE_PREHANDLER,
54 STATE_BLOCK,
55 STATE_EXPR,
56 STATE_COMMENT,
57 STATE_ATTR
58 };
59
60 static const std::string MARKUP_BEGIN;
61 static const std::string MARKUP_END;
62 static const std::string EXPR_BEGIN;
63 static const std::string EXPR_END;
64
65 void include(const std::string& path);
66 void parseAttributes();
67 void nextToken(std::istream& istr, std::string& token);
68 void handleAttribute(const std::string& name, const std::string& value);
69 std::string where() const;
70
71protected:
72 void generateLineDirective(std::ostream& ostr);
73
74private:
75 PageReader();
76 PageReader(const PageReader&);
77 PageReader& operator = (const PageReader&);
78
79 Page& _page;
80 const PageReader* _pParent;
81 std::string _path;
82 std::string _attrs;
83 int _line;
84 bool _emitLineDirectives;
85};
86
87
88#endif // PageReader_INCLUDED
89