1 
2 /* Web Polygraph       http://www.web-polygraph.org/
3  * Copyright 2003-2011 The Measurement Factory
4  * Licensed under the Apache License, Version 2.0 */
5 
6 #include "base/polygraph.h"
7 
8 #include "xstd/h/iostream.h"
9 #include "xml/XmlAttr.h"
10 #include "loganalyzers/Formatter.h"
11 
attr(const String & value)12 inline const String &attr(const String &value) { return value; }
text(const String & value)13 inline const String &text(const String &value) { return value; }
14 
WebPageFormatter(ostream * aPage)15 WebPageFormatter::WebPageFormatter(ostream *aPage): thePage(aPage) {
16 }
17 
openSection(const String & id,const String & title)18 void WebPageFormatter::openSection(const String &id, const String &title) {
19 	*thePage << "<div class=\"section\" id=\"" << attr(id) << "\">" << endl;
20 	*thePage << "<h2>" << text(title) << "</h2>" << endl;
21 }
22 
closeSection()23 void WebPageFormatter::closeSection() {
24 	*thePage << "</div>" << endl;
25 }
26 
openTable(const String & id,const String & title)27 void WebPageFormatter::openTable(const String &id, const String &title) {
28 	*thePage << "<table id=\"" << attr(id) << "\" " <<
29 		"border=\"1\" cellspacing=\"0\" cellpadding=\"3\">" << endl;
30 	*thePage << "<tr class=\"title\"><th colspan=\"2\">" << text(title) <<
31 		"</th></tr>" << endl;
32 }
33 
openTableAnonym()34 void WebPageFormatter::openTableAnonym() {
35 	*thePage << "<table " <<
36 		"border=\"0\" cellspacing=\"0\" cellpadding=\"3\">" << endl;
37 }
38 
closeTable()39 void WebPageFormatter::closeTable() {
40 	*thePage << "</table>" << endl;
41 }
42 
openTableRecord()43 void WebPageFormatter::openTableRecord() {
44 	*thePage << "<tr>" << endl;
45 }
46 
closeTableRecord()47 void WebPageFormatter::closeTableRecord() {
48 	*thePage << "</tr>" << endl;
49 }
50 
openTableCell(const String & classId)51 void WebPageFormatter::openTableCell(const String &classId) {
52 	*thePage << "<td";
53 	if (classId.len() > 0)
54 		XmlAttr("class", classId).print(*thePage, " ");
55 	*thePage << ">";
56 }
57 
closeTableCell()58 void WebPageFormatter::closeTableCell() {
59 	*thePage << "</td>";
60 }
61 
addTableCell(const String & cell)62 void WebPageFormatter::addTableCell(const String &cell) {
63 	openTableCell("");
64 	addText(cell);
65 	closeTableCell();
66 }
67 
addLink(const String & addr,const String & text)68 void WebPageFormatter::addLink(const String &addr, const String &text) {
69 	*thePage << "<a";
70 	XmlAttr("href", addr).print(*thePage, " ");
71 	*thePage << ">";
72 	addText(text);
73 	*thePage << "</a>";
74 }
75 
addText(const String & text)76 void WebPageFormatter::addText(const String &text) {
77 	*thePage << text;
78 }
79 
addInteger(int v,const String & unit,bool addSign)80 void WebPageFormatter::addInteger(int v, const String &unit, bool addSign) {
81 	if (addSign && v >= 0)
82 		addText(v > 0 ? "+" : " ");
83 
84 	*thePage << v << unit;
85 }
86 
addNothing()87 void WebPageFormatter::addNothing() {
88 	*thePage << " ";
89 }
90 
make()91 void WebPageFormatter::make() {
92 	Assert(thePage);
93 }
94