0
|
1
|
|
2 package nabble.view.web.help;
|
|
3
|
|
4 import fschmidt.util.java.HtmlUtils;
|
|
5 import nabble.model.Lucene;
|
|
6 import nabble.view.lib.Jtp;
|
|
7 import nabble.view.lib.Shared;
|
|
8 import nabble.view.lib.help.Help;
|
|
9 import org.apache.lucene.queryParser.ParseException;
|
|
10
|
|
11 import javax.servlet.ServletException;
|
|
12 import javax.servlet.http.HttpServlet;
|
|
13 import javax.servlet.http.HttpServletRequest;
|
|
14 import javax.servlet.http.HttpServletResponse;
|
|
15 import java.io.IOException;
|
|
16 import java.io.PrintWriter;
|
|
17
|
|
18
|
|
19 public class SearchHelp extends HttpServlet {
|
|
20
|
|
21 static {
|
|
22 Help.index();
|
|
23 }
|
|
24
|
|
25 protected void service(HttpServletRequest request,HttpServletResponse response)
|
|
26 throws ServletException, IOException
|
|
27 {
|
|
28 PrintWriter out = response.getWriter();
|
|
29 String errorMessage = null;
|
|
30 String query = request.getParameter("query");
|
|
31 if (query != null) {
|
|
32 query = query.trim().replaceAll("\\band\\b","AND").replaceAll("\\bor\\b","OR").replaceAll("\\bnot\\b","NOT");
|
|
33 }
|
|
34 if (query == null || "".equals(query)) {
|
|
35 response.sendRedirect("Index.jtp");
|
|
36 return;
|
|
37 }
|
|
38
|
|
39 Help[] help = null;
|
|
40 try {
|
|
41 help = Lucene.searchHelp(query);
|
|
42 } catch(ParseException e) {
|
|
43 errorMessage = "This query is invalid.\nFor more information, read [link]http://lucene.apache.org/java/2_4_1/queryparsersyntax.html[/link]";
|
|
44 }
|
|
45
|
|
46 out.print( "\n<html>\n <head>\n " );
|
|
47 Shared.title(request,response,"Help");
|
|
48 out.print( "\n </head>\n <body>\n " );
|
|
49 Shared.helpHeader(request,response);
|
|
50 out.print( "\n <div class=\"content-description\">\n <h1>Search Results</h1>\n <form action=\"" );
|
|
51 out.print( (response.encodeURL("SearchHelp.jtp")) );
|
|
52 out.print( "\" name=\"searchform\">\n <input name=\"query\" size=\"40\" value=\"" );
|
|
53 out.print( (HtmlUtils.htmlEncode(Jtp.hideNull(query))) );
|
|
54 out.print( "\" />\n <input type=\"submit\" value=\"Search\" />\n <span class=\"small\" style=\"margin-left:2em;\"><a href=\"" );
|
|
55 out.print( (response.encodeURL("Index.jtp")) );
|
|
56 out.print( "\">Return to Help Topics</a> »</span>\n </form>\n <p>\n " );
|
|
57 if (errorMessage != null) {
|
|
58 Shared.errorMessage(request, response, errorMessage, "Please check our <a href=\""+Help.search.url()+"\">search tips</a> page.");
|
|
59 } else if (help != null && help.length==0) {
|
|
60
|
|
61 out.print( "\nNo help topics found for <strong>" );
|
|
62 out.print( (HtmlUtils.htmlEncode(query)) );
|
|
63 out.print( "</strong>\n" );
|
|
64
|
|
65 } else {
|
|
66
|
|
67 out.print( "\n<strong>" );
|
|
68 out.print( (help.length) );
|
|
69 out.print( "</strong> help topics found for <strong>" );
|
|
70 out.print( (HtmlUtils.htmlEncode(query)) );
|
|
71 out.print( "</strong>\n</p>\n<ul>\n" );
|
|
72
|
|
73 for (int i=0; i<help.length; i++) {
|
|
74
|
|
75 out.print( "\n<li>" );
|
|
76 out.print( (help[i].link(request)) );
|
|
77 out.print( "</li>\n" );
|
|
78
|
|
79 }
|
|
80
|
|
81 out.print( "\n</ul>\n" );
|
|
82
|
|
83 }
|
|
84
|
|
85 out.print( "\n<p><br />If you still have questions, visit the " );
|
|
86 out.print( (Jtp.supportLink()) );
|
|
87 out.print( " forum.</p>\n</div>\n" );
|
|
88 Shared.footer(request,response);
|
|
89 out.print( "\n" );
|
|
90 Shared.analytics(request,response);
|
|
91 out.print( "\n</body>\n</html>\n" );
|
|
92
|
|
93 }
|
|
94 }
|
|
95
|