mirror of
				https://github.com/fooflington/wordsearch.git
				synced 2025-10-31 04:38:33 +00:00 
			
		
		
		
	api created
This commit is contained in:
		
							
								
								
									
										
											BIN
										
									
								
								war/WEB-INF/lib/json-simple-1.1.1.jar
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								war/WEB-INF/lib/json-simple-1.1.1.jar
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										4
									
								
								war/api-error.jsp
									
									
									
									
									
										Executable file
									
								
							
							
						
						
									
										4
									
								
								war/api-error.jsp
									
									
									
									
									
										Executable file
									
								
							| @@ -0,0 +1,4 @@ | ||||
| <%@ page language="java" contentType="application/json; charset=UTF-8" | ||||
|     pageEncoding="UTF-8"%> | ||||
| <%@ page isErrorPage="true" %> | ||||
| <%= exception %> | ||||
							
								
								
									
										46
									
								
								war/api.jsp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										46
									
								
								war/api.jsp
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,46 @@ | ||||
| <%@ page language="java" contentType="application/json; charset=UTF-8" | ||||
|     pageEncoding="UTF-8"%> | ||||
| <%@ page trimDirectiveWhitespaces="true" %> | ||||
| <%@ page import="uk.org.mafoo.wordsearch.*" %> | ||||
| <%@ page import="java.util.*" %> | ||||
| <%@ page import="org.apache.commons.lang.StringUtils" %> | ||||
| <%@ page import="org.apache.commons.lang.StringEscapeUtils" %> | ||||
| <%@ page import="org.json.simple.JSONObject" %> | ||||
| <%@ page errorPage="api-error.jsp" %> | ||||
| <% | ||||
|  | ||||
|         int height = Integer.parseInt(request.getParameter("height")); | ||||
|         int width  = Integer.parseInt(request.getParameter("width")); | ||||
|         boolean simple = request.getParameter("simple") != null; | ||||
|         String name = StringEscapeUtils.escapeHtml(request.getParameter("name")); | ||||
|  | ||||
|         if (request.getParameter("words").length() > 2048) { throw new Exception("Input too large"); } | ||||
|         if (height > 100 || width > 100) { throw new Exception("Dimentions too large"); } | ||||
|  | ||||
|         List<String> words = new ArrayList<String>(); | ||||
|         for ( String line : request.getParameter("words").split(",")) { | ||||
|                 words.add(line.trim()); | ||||
|         } | ||||
|         Collections.sort(words); | ||||
|  | ||||
|         char[][] grid = GridFactory.makeGrid(words, height, width, simple); | ||||
|  | ||||
| 	List<List<String>> grid_ar = new ArrayList<List<String>>();  | ||||
| 	for ( char[] row : grid ) { | ||||
| 		ArrayList<String> row_ar = new ArrayList<String>(); | ||||
| 		for ( char cell : row ) { | ||||
| 			row_ar.add("" + cell); | ||||
| 		} | ||||
| 		grid_ar.add(row_ar); | ||||
| 	} | ||||
|  | ||||
| 	JSONObject resp = new JSONObject(); | ||||
| 	 | ||||
| 	resp.put("grid", grid_ar); | ||||
| 	resp.put("words", words); | ||||
| 	resp.put("height", height); | ||||
| 	resp.put("width", width); | ||||
| 	resp.put("isSimple", simple); | ||||
|  | ||||
| %> | ||||
| <%= resp %> | ||||
		Reference in New Issue
	
	Block a user