htmlpage.cpp 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  1. /*##############################################################################
  2. HPCC SYSTEMS software Copyright (C) 2012 HPCC Systems®.
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. ############################################################################## */
  13. #pragma warning (disable : 4786)
  14. #include "esphttp.hpp"
  15. //Jlib
  16. #include "jliball.hpp"
  17. //SCM Interface definition includes:
  18. #include "esp.hpp"
  19. #include "espthread.hpp"
  20. //ESP Bindings
  21. #include "http/platform/httpprot.hpp"
  22. #include "http/platform/httptransport.ipp"
  23. #include "http/platform/httpservice.hpp"
  24. #include "SOAP/Platform/soapservice.hpp"
  25. //openssl
  26. #include <openssl/rsa.h>
  27. #include <openssl/crypto.h>
  28. #ifdef WIN32
  29. #define HTMLPAGE_EXPORT _declspec(dllexport)
  30. #else
  31. #define HTMLPAGE_EXPORT
  32. #endif
  33. #include "htmlpage.hpp"
  34. // ===========================================================================
  35. CHtmlEntity & CHtmlContainer::appendContent(CHtmlEntity & content)
  36. {
  37. content.Link();
  38. m_content.append(content);
  39. return content;
  40. }
  41. CHtmlEntity * CHtmlContainer::appendContent(CHtmlEntity * content)
  42. {
  43. m_content.append(*content);
  44. return content;
  45. }
  46. StringBuffer & CHtmlContainer::getContentHtml(StringBuffer & result)
  47. {
  48. ForEachItemIn(i, m_content)
  49. {
  50. CHtmlEntity &entity = m_content.item(i);
  51. StringBuffer entityHtml;
  52. result.append(entity.getHtml(entityHtml).str());
  53. }
  54. return result;
  55. }
  56. StringBuffer & CHtmlContainer::getContentHtml(StringBuffer & result, const char * tag)
  57. {
  58. ForEachItemIn(i, m_content)
  59. {
  60. CHtmlEntity &entity = m_content.item(i);
  61. StringBuffer entityHtml;
  62. result.appendf("<%s>%s</%s>", tag, entity.getHtml(entityHtml).str(), tag);
  63. }
  64. return result;
  65. }
  66. StringBuffer & CHtmlContainer::getContentHtml(StringBuffer & result, const char * prefix, const char * postfix)
  67. {
  68. ForEachItemIn(i, m_content)
  69. {
  70. CHtmlEntity &entity = m_content.item(i);
  71. StringBuffer entityHtml;
  72. result.appendf("%s%s%s", prefix, entity.getHtml(entityHtml).str(), postfix);
  73. }
  74. return result;
  75. }
  76. // ===========================================================================
  77. HtmlPage::HtmlPage(const char * title)
  78. {
  79. m_title.append(title);
  80. }
  81. const char * const HTML_PAGE = "\
  82. <html>\
  83. \
  84. <head>\
  85. <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">\
  86. <title>%s</title>\
  87. </head>\
  88. \
  89. <body>\
  90. %s\
  91. </body>\
  92. \
  93. </html>\
  94. ";
  95. StringBuffer & HtmlPage::getHtml(StringBuffer & result)
  96. {
  97. StringBuffer body;
  98. result.appendf(HTML_PAGE, m_title.str(), getContentHtml(body).str());
  99. return result;
  100. }
  101. // ===========================================================================
  102. CHtmlText::CHtmlText(const char * txt)
  103. {
  104. m_text.append(txt);
  105. }
  106. void CHtmlText::setText(const char * txt)
  107. {
  108. m_text.clear();
  109. m_text.append(txt);
  110. }
  111. StringBuffer & CHtmlText::getHtml(StringBuffer & result)
  112. {
  113. result.append(m_text.str());
  114. return result;
  115. }
  116. // ===========================================================================
  117. CHtmlHeader::CHtmlHeader(HTML_HEADER_SIZE size)
  118. {
  119. setSize(size);
  120. }
  121. CHtmlHeader::CHtmlHeader(HTML_HEADER_SIZE size, const char * text)
  122. {
  123. setSize(size);
  124. setText(text);
  125. }
  126. void CHtmlHeader::setSize(HTML_HEADER_SIZE size)
  127. {
  128. m_size.clear();
  129. switch(size)
  130. {
  131. case H1:
  132. m_size.append("h1");
  133. break;
  134. case H2:
  135. m_size.append("h2");
  136. break;
  137. case H3:
  138. m_size.append("h3");
  139. break;
  140. case H4:
  141. m_size.append("h4");
  142. break;
  143. case H5:
  144. m_size.append("h5");
  145. break;
  146. case H6:
  147. m_size.append("h6");
  148. break;
  149. }
  150. }
  151. const char * const HTML_HEADER = "<%s>%s</%s>";
  152. StringBuffer & CHtmlHeader::getHtml(StringBuffer & result)
  153. {
  154. StringBuffer body;
  155. result.appendf(HTML_HEADER, m_size.str(), m_text.str(), m_size.str());
  156. return result;
  157. }
  158. // ===========================================================================
  159. CHtmlParagraph::CHtmlParagraph(const char * txt)
  160. {
  161. appendContent(new CHtmlText(txt));
  162. }
  163. const char * const HTML_PARAGRAPH = "<p>%s</p>";
  164. StringBuffer & CHtmlParagraph::getHtml(StringBuffer & result)
  165. {
  166. StringBuffer body;
  167. result.appendf(HTML_PARAGRAPH, getContentHtml(body).str());
  168. return result;
  169. }
  170. // ===========================================================================
  171. CHtmlLink::CHtmlLink(const char * text, const char * link)
  172. {
  173. setText(text);
  174. setLink(link);
  175. }
  176. void CHtmlLink::setLink(const char * txt)
  177. {
  178. m_link.clear();
  179. m_link.append(txt);
  180. }
  181. const char * const HTML_LINK = "<a href=\"%s\">%s</a>";
  182. StringBuffer & CHtmlLink::getHtml(StringBuffer & result)
  183. {
  184. result.appendf(HTML_LINK, m_link.str(), m_text.str());
  185. return result;
  186. }
  187. // ===========================================================================
  188. const char * const HTML_LIST = "<ul>%s</ul>";
  189. StringBuffer & CHtmlList::getHtml(StringBuffer & result)
  190. {
  191. StringBuffer body;
  192. result.appendf(HTML_LIST, getContentHtml(body, "li").str());
  193. return result;
  194. }
  195. // ===========================================================================