File: html-doc.c

package info (click to toggle)
libgda5 5.2.8-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 75,580 kB
  • sloc: ansic: 495,416; xml: 10,470; yacc: 5,165; sh: 4,442; makefile: 4,093; php: 1,416; java: 1,300; python: 896; sql: 879; perl: 116
file content (116 lines) | stat: -rw-r--r-- 3,985 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
/*
 * Copyright (C) 2008 - 2011 Vivien Malerba <malerba@gnome-db.org>
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program 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 General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 */
#include "html-doc.h"
#include <glib/gi18n-lib.h>

HtmlDoc *
html_doc_new (const gchar *title)
{
	HtmlDoc *hdoc;
	xmlNodePtr topnode, head, node, div1, div2, div3;

	hdoc = g_new0 (HtmlDoc, 1);
	hdoc->doc = xmlNewDoc (BAD_CAST "1.0");
	topnode = xmlNewDocNode (hdoc->doc, NULL, BAD_CAST "html", NULL);
	xmlDocSetRootElement (hdoc->doc, topnode);

	/* head */
	head = xmlNewChild (topnode, NULL, BAD_CAST "head", NULL);
	hdoc->head = head;

	node = xmlNewChild (head, NULL, BAD_CAST "meta", BAD_CAST "");
	xmlSetProp(node, BAD_CAST "http-equiv", BAD_CAST "Content-Type");
	xmlSetProp(node, BAD_CAST "content", BAD_CAST "text/html; charset=UTF-8");

	/*
	node = xmlNewChild (head, NULL, BAD_CAST "meta", NULL);
	xmlSetProp(node, BAD_CAST "http-equiv", BAD_CAST "refresh");
	xmlSetProp(node, BAD_CAST "content", BAD_CAST "30");*/ /* refresh the page every 30 seconds */

	node = xmlNewChild (head, NULL, BAD_CAST "title", BAD_CAST title);

	node = xmlNewChild (head, NULL, BAD_CAST "link", BAD_CAST "");
	xmlSetProp(node, BAD_CAST "href", BAD_CAST "/gda.css");
	xmlSetProp(node, BAD_CAST "rel", BAD_CAST "stylesheet");
	xmlSetProp(node, BAD_CAST "type", BAD_CAST "text/css");
	xmlSetProp(node, BAD_CAST "media", BAD_CAST "screen");

	node = xmlNewChild (head, NULL, BAD_CAST "link", BAD_CAST "");
	xmlSetProp(node, BAD_CAST "href", BAD_CAST "/gda-print.css");
	xmlSetProp(node, BAD_CAST "rel", BAD_CAST "stylesheet");
	xmlSetProp(node, BAD_CAST "type", BAD_CAST "text/css");
	xmlSetProp(node, BAD_CAST "media", BAD_CAST "print");

	/* body */
	node = xmlNewChild (topnode, NULL, BAD_CAST "body", NULL);
	hdoc->body = node;

	/* top */
	div1 = xmlNewChild (hdoc->body, NULL, BAD_CAST "div", NULL);
	xmlSetProp (div1, BAD_CAST "id", BAD_CAST "header");
	xmlNewChild (div1, NULL, BAD_CAST "h1", BAD_CAST title);

	/* main part */
	div1 = xmlNewChild (hdoc->body, NULL, BAD_CAST "div", NULL);
	xmlSetProp (div1, BAD_CAST "class", BAD_CAST "colmask leftmenu");

	div2 = xmlNewChild (div1, NULL, BAD_CAST "div", NULL);
	xmlSetProp (div2, BAD_CAST "class", BAD_CAST "colleft");

	div3 = xmlNewChild (div2, NULL, BAD_CAST "div", BAD_CAST "");
	xmlSetProp (div3, BAD_CAST "class", BAD_CAST "col1");
	hdoc->content = div3;

	div3 = xmlNewChild (div2, NULL, BAD_CAST "div", BAD_CAST "");
	xmlSetProp (div3, BAD_CAST "class", BAD_CAST "col2");
	hdoc->sidebar = div3;

	/* footer */
	div1 = xmlNewChild (hdoc->body, NULL, BAD_CAST "div", NULL);
	xmlSetProp (div1, BAD_CAST "id", BAD_CAST "footer");
	xmlNewChild (div1, NULL, BAD_CAST "p", BAD_CAST _("Generated by the GDA SQL console"));
	hdoc->footer = div1;

	return hdoc;
}

void
html_doc_free  (HtmlDoc *hdoc)
{
	xmlFreeDoc (hdoc->doc);
	g_free (hdoc);
}

xmlChar *
html_doc_to_string (HtmlDoc *hdoc, gsize *out_size)
{
	xmlChar *retval = NULL;
	int size;
	xmlNodePtr li, a, node;

	node = xmlNewChild (hdoc->sidebar, NULL, BAD_CAST "ul", BAD_CAST "Misc");
	li = xmlNewChild (node, NULL, BAD_CAST "li", NULL);
	a = xmlNewChild (li, NULL, BAD_CAST "a", BAD_CAST _("Console"));
	xmlSetProp (a, BAD_CAST "href", BAD_CAST "/~console");

	xmlDocDumpFormatMemory (hdoc->doc, &retval, &size, 1);
	if (out_size)
		*out_size = (gsize) size;

	return retval;
}