/* html-ooa/html-ooa-incl.h, HTML Object-Oriented Authoring
Copyright (C) 2008 CONNOTECH Experts-conseils inc.
Written by Thierry Moreau (e-mail:thierry.moreau@connotech.com)
This library is free software; you can redistribute it and/or modify it
under the terms of the GNU Lesser General Public License as published by the
Free Software Foundation; either version 2.1 of the License, or (at your
option) any later version.
This library is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
details.
You should have received a copy of the GNU Lesser General Public License
along with this library; if not, write to the Free Software Foundation, Inc.,
59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
HOW TO CONTACT THE COPYRIGHT HOLDER:
CONNOTECH Experts-conseils inc.
home page: http://www.connotech.com
e-mail to: info@connotech.com
mailing address: 9130 Place de Montgolfier, Montreal, Quebec, Canada, H2M 2A1.
--------------------------------------------------------------------------------
Send bug reports to the above address.
*/
class html_block_element_cl;
class html_doc_node_cl {
protected:
public:
class html_block_element_cl *parent;
public:
html_doc_node_cl()
: parent(NULL)
{};
html_block_element_cl * find_enclosing(bool (*found)(html_doc_node_cl *));
html_doc_node_cl * find_reverse(bool (*found)(html_doc_node_cl *));
html_doc_node_cl * find_forward(bool (*found)(html_doc_node_cl *));
virtual void create_doc()=0;
virtual html_doc_node_cl * duplicate()=0;
};
typedef class html_doc_node_cl * html_doc_node_pt;
typedef std::list html_doc_node_li;
class html_doc_text_frag_cl : public html_doc_node_cl {
protected:
std::string str;
bool escaped;
public:
html_doc_text_frag_cl(std::string s)
: escaped(1), str(s)
{};
html_doc_text_frag_cl(int esc,std::string s)
: escaped(esc), str(s)
{};
virtual void create_doc();
virtual html_doc_node_cl * duplicate()
{
return new html_doc_text_frag_cl(*this);
};
};
class html_att_val_cl
{
protected:
public:
std::string name;
std::string value;
public:
html_att_val_cl(std::string nam, std::string val)
: name(nam), value(val)
{}
html_att_val_cl(std::string nam)
: name(nam)
{}
html_att_val_cl * duplicate()
{
return new html_att_val_cl(*this);
}
void create_doc();
};
typedef class html_att_val_cl * html_att_val_pt;
typedef std::vector html_att_val_li;
enum html_el_names_en
{ html_el_name_html
, html_el_name_head
, html_el_name_body
, html_el_name_title
, html_el_name_p
, html_el_name_pre
, html_el_name_span
, html_el_name_code
, html_el_name_em
, html_el_name_strong
, html_el_name_div
, html_el_name_table
, html_el_name_caption
, html_el_name_colgroup
, html_el_name_col
, html_el_name_thead
, html_el_name_tfoot
, html_el_name_tbody
, html_el_name_tr
, html_el_name_th
, html_el_name_td
, html_el_name_meta
, html_el_name_link
, html_el_name_style
, html_el_name_dl
, html_el_name_dt
, html_el_name_dd
, html_el_name_ul
, html_el_name_li
, html_el_name_h1
, html_el_name_h2
, html_el_name_h3
, html_el_name_h4
, html_el_name_h5
, html_el_name_h6
, html_el_name_a
};
class html_element_cl : public html_doc_node_cl {
protected:
public:
int start_tag_req, end_tag_req;
enum html_el_names_en el_name;
std::string el_name_str;
std::vector categories;
// std::string id;
html_att_val_li attributes;
public:
html_element_cl(int start_tag,
int end_tag,
enum html_el_names_en el_nam,
std::string el_name)
: start_tag_req(start_tag), end_tag_req(end_tag)
, el_name(el_nam), el_name_str(el_name)
{};
~html_element_cl();
void duplicate_attributes();
void add_category(std::string s);
// void set_id(std::string s);
void add_attribute(html_att_val_pt att);
void add_attribute(std::string nam, std::string val);
void add_attribute(std::string nam);
void create_doc_start_tag();
void create_doc_end_tag();
virtual void create_doc();
};
class html_block_element_cl: public html_element_cl {
protected:
public:
html_doc_node_li nodes;
public:
html_block_element_cl(int start_tag,
int end_tag,
enum html_el_names_en el_nam,
std::string el_name)
: html_element_cl(start_tag,end_tag,el_nam,el_name)
{};
~html_block_element_cl();
void duplicate_nodes();
html_doc_node_cl * find_last_within(bool (*found)(html_doc_node_cl *));
html_doc_node_cl * find_first_within(bool (*found)(html_doc_node_cl *));
virtual void create_doc();
void add_node(html_doc_node_pt pt);
void add_text(std::string s);
};
// *************************************
// Specific elements from the HTML 4.01 specification document
class html_el_html : public html_block_element_cl {
protected:
public:
html_el_html()
: html_block_element_cl(1,1,html_el_name_html,"HTML")
{};
virtual html_doc_node_cl * duplicate()
{ html_el_html *n = new html_el_html(*this);
n->duplicate_attributes(); n->duplicate_nodes();
return n; };
};
class html_el_head : public html_block_element_cl {
protected:
public:
html_el_head()
: html_block_element_cl(1,1,html_el_name_head,"HEAD")
{};
virtual html_doc_node_cl * duplicate()
{ html_el_head *n = new html_el_head(*this);
n->duplicate_attributes(); n->duplicate_nodes();
return n; };
};
class html_el_title : public html_block_element_cl {
protected:
public:
html_el_title(std::string s)
: html_block_element_cl(2,2,html_el_name_title,"TITLE")
{ add_text(s); }
virtual html_doc_node_cl * duplicate()
{ html_el_title *n = new html_el_title(*this);
n->duplicate_attributes(); n->duplicate_nodes();
return n; };
};
class html_el_body : public html_block_element_cl {
protected:
public:
html_el_body()
: html_block_element_cl(1,1,html_el_name_body,"BODY")
{};
virtual html_doc_node_cl * duplicate()
{ html_el_body *n = new html_el_body(*this);
n->duplicate_attributes(); n->duplicate_nodes();
return n; };
};
class html_el_p : public html_block_element_cl {
protected:
public:
html_el_p()
: html_block_element_cl(2,1,html_el_name_p,"P")
{};
html_el_p(std::string s)
: html_block_element_cl(2,1,html_el_name_p,"P")
{ add_text(s); };
html_el_p(std::string c, std::string s)
: html_block_element_cl(2,1,html_el_name_p,"P")
{ add_text(s); add_category(c); };
virtual html_doc_node_cl * duplicate()
{ html_el_p *n = new html_el_p(*this);
n->duplicate_attributes(); n->duplicate_nodes();
return n; };
};
class html_el_pre : public html_block_element_cl {
protected:
public:
html_el_pre()
: html_block_element_cl(2,2,html_el_name_p,"PRE")
{};
html_el_pre(std::string s)
: html_block_element_cl(2,2,html_el_name_p,"PRE")
{ add_text(s); };
virtual html_doc_node_cl * duplicate()
{ html_el_pre *n = new html_el_pre(*this);
n->duplicate_attributes(); n->duplicate_nodes();
return n; };
};
class html_el_span : public html_block_element_cl {
protected:
public:
html_el_span()
: html_block_element_cl(2,2,html_el_name_span,"SPAN")
{};
html_el_span(std::string s)
: html_block_element_cl(2,2,html_el_name_span,"SPAN")
{ add_text(s); };
virtual html_doc_node_cl * duplicate()
{ html_el_span *n = new html_el_span(*this);
n->duplicate_attributes(); n->duplicate_nodes();
return n; };
};
class html_el_code : public html_block_element_cl {
protected:
public:
html_el_code()
: html_block_element_cl(2,2,html_el_name_span,"CODE")
{};
html_el_code(std::string s)
: html_block_element_cl(2,2,html_el_name_span,"CODE")
{ add_text(s); };
virtual html_doc_node_cl * duplicate()
{ html_el_code *n = new html_el_code(*this);
n->duplicate_attributes(); n->duplicate_nodes();
return n; };
};
class html_el_em : public html_block_element_cl {
protected:
public:
html_el_em()
: html_block_element_cl(2,2,html_el_name_em,"EM")
{};
html_el_em(std::string s)
: html_block_element_cl(2,2,html_el_name_em,"EM")
{ add_text(s); };
virtual html_doc_node_cl * duplicate()
{ html_el_em *n = new html_el_em(*this);
n->duplicate_attributes(); n->duplicate_nodes();
return n; };
};
class html_el_strong : public html_block_element_cl {
protected:
public:
html_el_strong()
: html_block_element_cl(2,2,html_el_name_strong,"STRONG")
{};
html_el_strong(std::string s)
: html_block_element_cl(2,2,html_el_name_strong,"STRONG")
{ add_text(s); };
virtual html_doc_node_cl * duplicate()
{ html_el_strong *n = new html_el_strong(*this);
n->duplicate_attributes(); n->duplicate_nodes();
return n; };
};
class html_el_div : public html_block_element_cl {
protected:
public:
html_el_div()
: html_block_element_cl(2,2,html_el_name_div,"DIV")
{};
virtual html_doc_node_cl * duplicate()
{ html_el_div *n = new html_el_div(*this);
n->duplicate_attributes(); n->duplicate_nodes();
return n; };
};
class html_el_table : public html_block_element_cl {
protected:
public:
html_el_table()
: html_block_element_cl(2,2,html_el_name_table,"TABLE")
{};
virtual html_doc_node_cl * duplicate()
{ html_el_table *n = new html_el_table(*this);
n->duplicate_attributes(); n->duplicate_nodes();
return n; };
};
class html_el_caption : public html_block_element_cl {
protected:
public:
html_el_caption()
: html_block_element_cl(2,2,html_el_name_caption,"CAPTION")
{};
html_el_caption(std::string s)
: html_block_element_cl(2,2,html_el_name_caption,"CAPTION")
{ add_text(s); };
virtual html_doc_node_cl * duplicate()
{ html_el_caption *n = new html_el_caption(*this);
n->duplicate_attributes(); n->duplicate_nodes();
return n; };
};
class html_el_colgroup : public html_block_element_cl {
protected:
public:
html_el_colgroup()
: html_block_element_cl(2,1,html_el_name_colgroup,"COLGROUP")
{};
virtual html_doc_node_cl * duplicate()
{ html_el_colgroup *n = new html_el_colgroup(*this);
n->duplicate_attributes(); n->duplicate_nodes();
return n; };
};
class html_el_col : public html_element_cl {
protected:
public:
html_el_col()
: html_element_cl(2,0,html_el_name_col,"COL")
{};
virtual html_doc_node_cl * duplicate()
{ html_el_col *n = new html_el_col(*this);
n->duplicate_attributes();
return n; };
};
class html_el_thead : public html_block_element_cl {
protected:
public:
html_el_thead()
: html_block_element_cl(2,1,html_el_name_thead,"THEAD")
{};
virtual html_doc_node_cl * duplicate()
{ html_el_thead *n = new html_el_thead(*this);
n->duplicate_attributes(); n->duplicate_nodes();
return n; };
};
class html_el_tfoot : public html_block_element_cl {
protected:
public:
html_el_tfoot()
: html_block_element_cl(2,1,html_el_name_tfoot,"TFOOT")
{};
virtual html_doc_node_cl * duplicate()
{ html_el_tfoot *n = new html_el_tfoot(*this);
n->duplicate_attributes(); n->duplicate_nodes();
return n; };
};
class html_el_tbody : public html_block_element_cl {
protected:
public:
html_el_tbody()
: html_block_element_cl(2,1,html_el_name_tbody,"TBODY")
{};
virtual html_doc_node_cl * duplicate()
{ html_el_tbody *n = new html_el_tbody(*this);
n->duplicate_attributes(); n->duplicate_nodes();
return n; };
};
class html_el_tr : public html_block_element_cl {
protected:
public:
html_el_tr()
: html_block_element_cl(2,1,html_el_name_tr,"TR")
{};
virtual html_doc_node_cl * duplicate()
{ html_el_tr *n = new html_el_tr(*this);
n->duplicate_attributes(); n->duplicate_nodes();
return n; };
};
class html_el_th : public html_block_element_cl {
protected:
public:
html_el_th()
: html_block_element_cl(2,1,html_el_name_th,"TH")
{};
virtual html_doc_node_cl * duplicate()
{ html_el_th *n = new html_el_th(*this);
n->duplicate_attributes(); n->duplicate_nodes();
return n; };
};
class html_el_td : public html_block_element_cl {
protected:
public:
html_el_td()
: html_block_element_cl(2,1,html_el_name_td,"TD")
{};
virtual html_doc_node_cl * duplicate()
{ html_el_td *n = new html_el_td(*this);
n->duplicate_attributes(); n->duplicate_nodes();
return n; };
};
class html_el_meta : public html_element_cl {
protected:
public:
html_el_meta()
: html_element_cl(2,0,html_el_name_meta,"META")
{};
virtual html_doc_node_cl * duplicate()
{ html_el_meta *n = new html_el_meta(*this);
n->duplicate_attributes();
return n; };
};
class html_el_link : public html_element_cl {
protected:
public:
html_el_link()
: html_element_cl(2,0,html_el_name_link,"LINK")
{};
virtual html_doc_node_cl * duplicate()
{ html_el_link *n = new html_el_link(*this);
n->duplicate_attributes();
return n; };
};
class html_el_style : public html_block_element_cl {
protected:
public:
html_el_style()
: html_block_element_cl(2,2,html_el_name_style,"STYLE")
{};
virtual html_doc_node_cl * duplicate()
{ html_el_style *n = new html_el_style(*this);
n->duplicate_attributes(); n->duplicate_nodes();
return n; };
};
class html_el_dl : public html_block_element_cl {
protected:
public:
html_el_dl()
: html_block_element_cl(2,2,html_el_name_dl,"DL")
{};
virtual html_doc_node_cl * duplicate()
{ html_el_dl *n = new html_el_dl(*this);
n->duplicate_attributes(); n->duplicate_nodes();
return n; };
};
class html_el_dt : public html_block_element_cl {
protected:
public:
html_el_dt()
: html_block_element_cl(2,1,html_el_name_dt,"DT")
{};
html_el_dt(std::string s)
: html_block_element_cl(2,1,html_el_name_dt,"DT")
{ add_text(s); };
virtual html_doc_node_cl * duplicate()
{ html_el_dt *n = new html_el_dt(*this);
n->duplicate_attributes(); n->duplicate_nodes();
return n; };
};
class html_el_dd : public html_block_element_cl {
protected:
public:
html_el_dd()
: html_block_element_cl(2,1,html_el_name_dd,"DD")
{};
html_el_dd(std::string s)
: html_block_element_cl(2,1,html_el_name_dd,"DD")
{ add_text(s); };
virtual html_doc_node_cl * duplicate()
{ html_el_dd *n = new html_el_dd(*this);
n->duplicate_attributes(); n->duplicate_nodes();
return n; };
};
class html_el_ul : public html_block_element_cl {
protected:
public:
html_el_ul()
: html_block_element_cl(2,2,html_el_name_ul,"UL")
{};
virtual html_doc_node_cl * duplicate()
{ html_el_ul *n = new html_el_ul(*this);
n->duplicate_attributes(); n->duplicate_nodes();
return n; };
};
class html_el_li : public html_block_element_cl {
protected:
public:
html_el_li()
: html_block_element_cl(2,1,html_el_name_li,"LI")
{};
html_el_li(std::string s)
: html_block_element_cl(2,1,html_el_name_li,"LI")
{ add_text(s); };
virtual html_doc_node_cl * duplicate()
{ html_el_li *n = new html_el_li(*this);
n->duplicate_attributes(); n->duplicate_nodes();
return n; };
};
class html_el_h1 : public html_block_element_cl {
protected:
public:
html_el_h1()
: html_block_element_cl(2,2,html_el_name_h1,"H1")
{};
html_el_h1(std::string s)
: html_block_element_cl(2,2,html_el_name_h1,"H1")
{ add_text(s); };
virtual html_doc_node_cl * duplicate()
{ html_el_h1 *n = new html_el_h1(*this);
n->duplicate_attributes(); n->duplicate_nodes();
return n; };
};
class html_el_h2 : public html_block_element_cl {
protected:
public:
html_el_h2()
: html_block_element_cl(2,2,html_el_name_h2,"H2")
{};
html_el_h2(std::string s)
: html_block_element_cl(2,2,html_el_name_h2,"H2")
{ add_text(s); };
virtual html_doc_node_cl * duplicate()
{ html_el_h2 *n = new html_el_h2(*this);
n->duplicate_attributes(); n->duplicate_nodes();
return n; };
};
class html_el_h3 : public html_block_element_cl {
protected:
public:
html_el_h3()
: html_block_element_cl(2,2,html_el_name_h3,"H3")
{};
html_el_h3(std::string s)
: html_block_element_cl(2,2,html_el_name_h3,"H3")
{ add_text(s); };
virtual html_doc_node_cl * duplicate()
{ html_el_h3 *n = new html_el_h3(*this);
n->duplicate_attributes(); n->duplicate_nodes();
return n; };
};
class html_el_h4 : public html_block_element_cl {
protected:
public:
html_el_h4()
: html_block_element_cl(2,2,html_el_name_h4,"H4")
{};
html_el_h4(std::string s)
: html_block_element_cl(2,2,html_el_name_h4,"H4")
{ add_text(s); };
virtual html_doc_node_cl * duplicate()
{ html_el_h4 *n = new html_el_h4(*this);
n->duplicate_attributes(); n->duplicate_nodes();
return n; };
};
class html_el_h5 : public html_block_element_cl {
protected:
public:
html_el_h5()
: html_block_element_cl(2,2,html_el_name_h5,"H5")
{};
html_el_h5(std::string s)
: html_block_element_cl(2,2,html_el_name_h5,"H5")
{ add_text(s); };
virtual html_doc_node_cl * duplicate()
{ html_el_h5 *n = new html_el_h5(*this);
n->duplicate_attributes(); n->duplicate_nodes();
return n; };
};
class html_el_h6 : public html_block_element_cl {
protected:
public:
html_el_h6()
: html_block_element_cl(2,2,html_el_name_h6,"H6")
{};
html_el_h6(std::string s)
: html_block_element_cl(2,2,html_el_name_h6,"H6")
{ add_text(s); };
virtual html_doc_node_cl * duplicate()
{ html_el_h6 *n = new html_el_h6(*this);
n->duplicate_attributes(); n->duplicate_nodes();
return n; };
};
class html_el_a : public html_block_element_cl {
protected:
public:
html_el_a()
: html_block_element_cl(2,2,html_el_name_a,"A")
{};
html_el_a(std::string s)
: html_block_element_cl(2,2,html_el_name_a,"A")
{ add_text(s); };
html_el_a(std::string s,std::string href)
: html_block_element_cl(2,2,html_el_name_a,"A")
{ add_text(s); add_attribute("href",href); };
virtual html_doc_node_cl * duplicate()
{ html_el_a *n = new html_el_a(*this);
n->duplicate_attributes(); n->duplicate_nodes();
return n; };
virtual void create_doc();
};
// *************************************
class html_document_cl
{
protected:
class html_el_html top_node;
public:
html_el_head *node_head;
html_el_body *node_body;
public:
html_document_cl();
static std::string html_escape(std::string s);
static std::string map_to_id_chars(std::string s);
void set_title(std::string s); /**/ // must not be called twice
void create_doc();
};
// *************************************
#define CL "\n" // end of line for reduced PHP code compactness
//#define CL
// *************************************