wordsearch/war/build.jsp

78 lines
2.0 KiB
Plaintext
Raw Normal View History

2016-12-20 06:42:23 +00:00
<!DOCTYPE html>
2016-12-18 07:43:01 +00:00
<html>
<head>
<title>Wordsearch builder</title>
2016-12-19 15:44:06 +00:00
<link rel="stylesheet" type="text/css" href="base.css" />
2020-04-05 12:25:43 +01:00
<link href="https://fonts.googleapis.com/css2?family=Fira+Mono:wght@400;500&family=Roboto:wght@500&display=swap" rel="stylesheet">
2016-12-18 07:43:01 +00:00
</head>
<%@ page import="uk.org.mafoo.wordsearch.*" %>
<%@ page import="java.util.*" %>
2016-12-18 20:55:35 +00:00
<%@ page import="org.apache.commons.lang.StringUtils" %>
2016-12-19 12:28:56 +00:00
<%@ page import="org.apache.commons.lang.StringEscapeUtils" %>
2016-12-19 14:26:25 +00:00
<%@ page errorPage="error.jsp" %>
2016-12-18 07:43:01 +00:00
<%
int height = Integer.parseInt(request.getParameter("height"));
int width = Integer.parseInt(request.getParameter("width"));
2016-12-19 12:28:56 +00:00
boolean simple = request.getParameter("simple") != null;
String name = StringEscapeUtils.escapeHtml(request.getParameter("name"));
2016-12-18 07:43:01 +00:00
if (request.getParameter("words").length() > 2048) { throw new Exception("Input too large"); }
2017-10-08 21:53:08 +01:00
if (height > 100 || width > 100) { throw new Exception("Dimensions too large"); }
2016-12-18 07:43:01 +00:00
List<String> words = new ArrayList<String>();
for ( String line : request.getParameter("words").split("\r\n")) {
words.add(line.trim());
}
2016-12-18 20:55:35 +00:00
Collections.sort(words);
2016-12-19 12:28:56 +00:00
char[][] grid = GridFactory.makeGrid(words, height, width, simple);
2016-12-18 20:55:35 +00:00
String csv = "";
2016-12-18 07:43:01 +00:00
%>
<body>
2016-12-19 12:28:56 +00:00
<h1><%= name %></h1>
2016-12-19 16:03:38 +00:00
<div class="noprint">
[ <a href="index.jsp">Start again</a> | <a id='csvdownload'>Download CSV</a> ]
</div>
2016-12-18 20:55:35 +00:00
<script>
var csv = '<%= csv %>';
var csvdownload = document.getElementById('csvdownload');
csvdownload.href='data:text/csv;base64,' + btoa(csv);
</script>
2016-12-18 07:54:41 +00:00
</div>
2016-12-18 07:43:01 +00:00
2016-12-18 20:55:35 +00:00
<div id="wrapper">
<div id="wordsearch">
<h2>Grid</h2>
<table id="grid">
<% for(char[] row : grid) { %>
<tr>
<% for(char c : row) {
csv += "" + c + ',';
%>
2016-12-19 16:03:38 +00:00
<td class="cell"><%= c %></td>
2016-12-18 20:55:35 +00:00
<% } %>
</tr>
<%
csv += "\\n";
}
%>
</table>
</div> <!-- end wordsearch -->
2016-12-18 07:54:41 +00:00
2016-12-18 20:55:35 +00:00
<div id="words">
<h2>Words</h2>
<ul>
<% for (String word : words) { %>
<li><%= word.trim() %></li>
<% } %>
</ul>
</div> <!-- end words -->
</div> <!-- end wrapper -->
2016-12-22 07:52:15 +00:00
<br />
<br />
<%@include file="/WEB-INF/jspf/footer.jspf" %>
2016-12-18 07:43:01 +00:00
</body>
</html>