Photon 1.0.0
Loading...
Searching...
No Matches
IDOMObject.hpp
Go to the documentation of this file.
1/*
2 * =====================================================================
3 *
4 * Photon
5 * Copyright Amlal EL Mahrouss, all rights reserved.
6 *
7 * =====================================================================
8 */
9
10#pragma once
11
12#include <core/Core.hpp>
13#include <memory>
14#include <rapidxml/rapidxml.hpp>
16
17#define PHOTON_DOM_OBJECT (0U)
18
19#define PHOTON_HTML_START "<html>"
20#define PHOTON_HTML_MARKUP "<!doctype html>"
21#define PHOTON_HTML_END "</html>"
22
23namespace Photon
24{
25 class IDOMObject;
26
28 {
29 protected:
30 explicit IDOMObject(rapidxml::xml_node<char>* p_node) : m_node(p_node)
31 {
33 }
34
35 public:
36 virtual ~IDOMObject() = default;
37
39
40 public:
41 virtual Int32 node_type()
42 {
43 return PHOTON_DOM_OBJECT;
44 }
45
46 virtual bool is_element()
47 {
50 }
51
52 virtual bool is_data()
53 {
55 return rapidxml::node_data == m_node->type();
56 }
57
58 virtual bool is_comment()
59 {
62 }
63
64 virtual bool is_doc_type()
65 {
68 }
69
70 virtual String type()
71 {
72 if (auto type = this->get_attribute("type"); type)
73 return type->value();
74
75 return "";
76 }
77
78 virtual String src()
79 {
80 if (auto type = this->get_attribute("src"); type)
81 return type->value();
82
83 return "";
84 }
85
86 virtual String value()
87 {
88 return this->m_node->value();
89 }
90
91 virtual rapidxml::xml_attribute<char>* get_attribute(const char* attrib_name)
92 {
94 return m_node->first_attribute(attrib_name, strlen(attrib_name));
95 }
96
97 virtual rapidxml::xml_node<char>* get_node(const char* attrib_name)
98 {
100
101 if (!attrib_name)
102 return m_node->first_node();
103
104 return m_node->first_node(attrib_name);
105 }
106
107 public:
109
110 private:
112 };
113
115 Bool is_html_document(String the_xml_blob) noexcept;
116
118 String get_html_document(String the_xml_blob);
119} // namespace Photon
#define PHOTON_DOM_OBJECT
Definition IDOMObject.hpp:17
Definition IDOMObject.hpp:28
virtual rapidxml::xml_attribute< char > * get_attribute(const char *attrib_name)
Definition IDOMObject.hpp:91
virtual String type()
Definition IDOMObject.hpp:70
IDOMObject(rapidxml::xml_node< char > *p_node)
Definition IDOMObject.hpp:30
PHOTON_COPY_DEFAULT(IDOMObject)
rapidxml::xml_node< char > * m_node
Definition IDOMObject.hpp:111
virtual ~IDOMObject()=default
virtual String value()
Definition IDOMObject.hpp:86
virtual bool is_element()
Definition IDOMObject.hpp:46
virtual rapidxml::xml_node< char > * get_node(const char *attrib_name)
Definition IDOMObject.hpp:97
virtual bool is_doc_type()
Definition IDOMObject.hpp:64
virtual Int32 node_type()
Definition IDOMObject.hpp:41
virtual String src()
Definition IDOMObject.hpp:78
static IDOMObject * make_dom_object(String data)
Definition IDOMObject.mm:63
virtual bool is_comment()
Definition IDOMObject.hpp:58
virtual bool is_data()
Definition IDOMObject.hpp:52
Definition rapidxml.hpp:784
Ch * value() const
Definition rapidxml.hpp:679
Definition rapidxml.hpp:882
node_type type() const
Definition rapidxml.hpp:900
xml_attribute< Ch > * first_attribute(const Ch *name=0, std::size_t name_size=0, bool case_sensitive=true) const
Definition rapidxml.hpp:1017
xml_node< Ch > * first_node(const Ch *name=0, std::size_t name_size=0, bool case_sensitive=true) const
Definition rapidxml.hpp:924
type
Definition core.h:681
#define PHOTON_ASSERT(expression)
Definition Config.hpp:106
This file is also about defining core js concepts.
Definition BasePhotonWindow.hpp:22
String get_html_document(String the_xml_blob)
Get HTML document from xml blob.
Definition IDOMObject.mm:31
bool Bool
Definition Config.hpp:101
std::string String
Definition Core.hpp:37
std::int32_t Int32
Definition Config.hpp:95
Bool is_html_document(String the_xml_blob) noexcept
Check if xml is HTML.
Definition IDOMObject.mm:20
@ node_comment
A comment node. Name is empty. Value contains comment text.
Definition rapidxml.hpp:147
@ node_element
An element node. Name contains element name. Value contains text of first data node.
Definition rapidxml.hpp:144
@ node_data
A data node. Name is empty. Value contains data text.
Definition rapidxml.hpp:145
@ node_doctype
A DOCTYPE node. Name is empty. Value contains DOCTYPE text.
Definition rapidxml.hpp:150
This file contains rapidxml parser and DOM implementation.
This file contains rapidxml printer implementation.
Definition format.h:1901