2016-12-18 07:43:01 +00:00
|
|
|
<html>
|
|
|
|
<head>
|
|
|
|
<title>Wordsearch builder</title>
|
|
|
|
<style>
|
|
|
|
table, th, td {
|
|
|
|
border: 1px solid black;
|
|
|
|
border-collapse: collapse;
|
|
|
|
padding: 2px 4px;
|
|
|
|
}
|
2016-12-18 20:55:35 +00:00
|
|
|
|
|
|
|
#grid {
|
|
|
|
font-family: monospace; font-size: 16;
|
|
|
|
}
|
|
|
|
|
|
|
|
#wrapper {
|
|
|
|
width: 80%;
|
|
|
|
margin: 0 auto;
|
|
|
|
}
|
|
|
|
#wordsearch {
|
|
|
|
float: left;
|
|
|
|
}
|
|
|
|
|
|
|
|
#words {
|
|
|
|
float: right;
|
|
|
|
width: 200px;
|
|
|
|
}
|
2016-12-19 12:28:56 +00:00
|
|
|
|
|
|
|
@media only print {
|
|
|
|
.noprint {
|
|
|
|
display: none;
|
|
|
|
}
|
|
|
|
}
|
2016-12-18 07:43:01 +00:00
|
|
|
</style>
|
|
|
|
</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-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"); }
|
2016-12-18 07:54:41 +00:00
|
|
|
if (height > 100 || width > 100) { throw new Exception("Dimentions 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>
|
|
|
|
<a id='csvdownload' class="noprint">Download CSV</a>
|
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 + ',';
|
|
|
|
%>
|
|
|
|
<td><%= c %></td>
|
|
|
|
<% } %>
|
|
|
|
</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 -->
|
|
|
|
<br />
|
|
|
|
<div>
|
2016-12-18 07:43:01 +00:00
|
|
|
</body>
|
|
|
|
</html>
|