Code:
setInfos(9, "html-format-test", "test", "RustyHammer", "v0.0", 0xFFFFFF, "en", [])
setImage(null)
def lorumIpsum = "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."
def shortLorumIpsum = "Lorem ipsum dolor sit amet"
def tryEscapeHtmlChar = { char c ->
switch (c)
{
case '<':
return "<"
case '>':
return ">"
case '&':
return "&"
case '"':
return """
case "'":
return "'"
}
return null
}
def escapeHtmlCharacters = { String text ->
String escapedText = ""
for (char c in text)
{
final String replacementCharText = tryEscapeHtmlChar(c)
if (replacementCharText != null)
escapedText = escapedText + replacementCharText
else
escapedText = escapedText + c
}
return escapedText
}
def injectLorumIpsum = { String text ->
return text.replaceAll("@LI", lorumIpsum).replaceAll("@SLI", shortLorumIpsum)
}
def showHtmlPage = { String htmlText ->
final String injectedText = injectLorumIpsum(htmlText)
final String pageText = escapeHtmlCharacters(injectedText) + "\n\n" + injectedText
show(pageText)
}
final String[] testHtmlPageText =
[
"<font color=\"red\">Red Text</font>\n<font color=\"green\">Green Text</font>\n<font color=\"blue\">Blue Text</font>\n<font color=\"#a000a0\">Magenta Text</font>",
"<strong>Strong</strong>\n<b>Bold</b>\n<em>Emphasis</em>\n<cite>Citation</cite>\n<dfn>Definition Element</dfn>\n<i>Italic</i>",
"<big>Big Text</big>\n<small>Small Text</small>",
"<tt>Monospace</tt>\n<u>Underline</u>\n<del>Strikethrough</del>\n<s>Strikethrough</s>\n<strike>Strikethrough</strike>\nNormal<sup>Superscript</sup><sub>Subscript</sub>",
"<h1>Heading 1</h1>\n<h2>Heading 2</h2>\n<h3>Heading 3</h3>\n<h4>Heading 4</h4>\n<h5>Heading 5</h5>\n<h6>Heading 6</h6>",
"<h1 style=\"text-align: start;\">Heading Align 'start'</h1>\n<h1 style=\"text-align: center;\">Heading Align 'center'</h1>\n<h1 style=\"text-align: end;\">Heading Align 'end'</h1>",
"<span style=\"color: red;\">Red Text</span>\n<span style=\"color: green;\">Green Text</span>\n<span style=\"color: blue;\">Blue Text</span>\n<span style=\"color: #a000a0;\">Magenta Text</span>",
"<span style=\"background: red;\">Red Background</span>\n<span style=\"background: green;\">Green Background</span>\n<span style=\"background: blue;\">Blue Background</span>\n<span style=\"background: #a000a0;\">Magenta Background</span>",
"<span style=\"text-decoration: line-through;\">Strikethrough Text</span>",
"<p style=\"color: red;\">Red Text</p>\n<p style=\"color: green;\">Green Text</p>\n<p style=\"color: blue;\">Blue Text</p>\n<p style=\"color: #a000a0;\">Magenta Text</p>",
"<p style=\"background: red;\">Red Background</p>\n<p style=\"background: green;\">Green Background</p>\n<p style=\"background: blue;\">Blue Background</p>\n<p style=\"background: #a000a0;\">Magenta Background</p>",
"<p style=\"text-decoration: line-through;\">Strikethrough Text</p>",
"<p style=\"text-align: start;\">Align 'start': @LI</p>\n<p style=\"text-align: center;\">Align 'center': @LI</p>\n<p style=\"text-align: end;\">Align 'end': @LI</p>",
"<font face=\"Arial\">Arial Font: @SLI</font>\n<font face=\"Roboto\">Roboto Font: @SLI</font>\n<font face=\"Times New Roman\">Times New Roman Font: @SLI</font>\n<font face=\"Times\">Times Font: @SLI</font>\n<font face=\"Courier New\">Courier New Font: @SLI</font>",
"<font face=\"Courier\">Courier Font: @SLI</font>\n<font face=\"Verdana\">Verdana Font: @SLI</font>\n<font face=\"Georgia\">Georgia Font: @SLI</font>\n<font face=\"Palatino\">Palatino Font: @SLI</font>\n<font face=\"Garamond\">Garamond Font: @SLI</font>",
"<font face=\"Bookman\">Bookman Font: @SLI</font>\n<font face=\"Comic Sans MS\">Comic Sans MS Font: @SLI</font>\n<font face=\"Candara\">Candara Font: @SLI</font>\n<font face=\"Arial Black\">Arial Black Font: @SLI</font>\n<font face=\"Impact\">Impact Font: @SLI</font>",
"<div style=\"text-align: start;\">Align 'start': @LI</div>\n<div style=\"text-align: center;\">Align 'center': @LI</div>\n<div style=\"text-align: end;\">Align 'end': @LI</div>",
"<ul><li style=\"color: red;\">Red Item</li><li style=\"color: green;\">Green Item</li><li style=\"color: blue;\">Blue Item</li><li style=\"color: #a000a0;\">Magenta Item</li></ul>",
"<ul><li style=\"background: red;\">Red Background</li><li style=\"background: green;\">Green Background</li><li style=\"background: blue;\">Blue Background</li><li style=\"background: #a000a0;\">Magenta Background</li></ul>",
"<ul><li style=\"text-align: start;\">Align 'start'</li><li style=\"text-align: center;\">Align 'center'</li><li style=\"text-align: end;\">Align 'end'</li></ul>",
"<ul><li>Item 1</li><li style=\"text-decoration: line-through;\">Strikethrough Text</li><li>Item 3</li></ul>",
"<ul style=\"text-align: start\"><li>Item 1</li><li>Item 2</li><li>Item 3</li></ul>\n<ul style=\"text-align: center\"><li>Item 1</li><li>Item 2</li><li>Item 3</li></ul>\n<ul style=\"text-align: end\"><li>Item 1</li><li>Item 2</li><li>Item 3</li></ul>",
"<blockquote style=\"text-align: start;\">Align 'start': @LI</blockquote>\n<blockquote style=\"text-align: center;\">Align 'center': @LI</blockquote>\n<blockquote style=\"text-align: end;\">Align 'end': @LI</blockquote>"
]
int pageIndex = 0
for (;;)
{
showHtmlPage(testHtmlPageText[pageIndex])
final int selection = getSelectedValue(null, ["Prev", "Next"])
if (selection == 0)
--pageIndex
else
++pageIndex
if (pageIndex < 0)
pageIndex = testHtmlPageText.size() - 1
else
if (pageIndex >= testHtmlPageText.size())
pageIndex = 0
}