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" />
|
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"));
|
2017-10-08 22:02:56 +01:00
|
|
|
Modes mode = Modes.NORMAL;
|
|
|
|
if(request.getParameter("mode") != null) {
|
|
|
|
if(request.getParameter("mode") == "SIMPLE") mode = Modes.SIMPLE;
|
|
|
|
if(request.getParameter("mode") == "CROSSWORD") mode = Modes.CROSSWORD;
|
|
|
|
}
|
2016-12-19 12:28:56 +00:00
|
|
|
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);
|
|
|
|
|
2017-10-08 22:02:56 +01:00
|
|
|
char[][] grid = GridFactory.makeGrid(words, height, width, mode);
|
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>
|