implemented UI for find posts, debugged and tweaked the engine implementation
This commit is contained in:
113
src/com/silverwrist/venice/servlets/FindPost.java
Normal file
113
src/com/silverwrist/venice/servlets/FindPost.java
Normal file
@@ -0,0 +1,113 @@
|
||||
/*
|
||||
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
||||
* (the "License"); you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at <http://www.mozilla.org/MPL/>.
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis, WITHOUT
|
||||
* WARRANTY OF ANY KIND, either express or implied. See the License for the specific
|
||||
* language governing rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is the Venice Web Communities System.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Eric J. Bowersox <erbo@silcom.com>,
|
||||
* for Silverwrist Design Studios. Portions created by Eric J. Bowersox are
|
||||
* Copyright (C) 2001 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*/
|
||||
package com.silverwrist.venice.servlets;
|
||||
|
||||
import java.io.*;
|
||||
import javax.servlet.*;
|
||||
import javax.servlet.http.*;
|
||||
import com.silverwrist.venice.core.*;
|
||||
import com.silverwrist.venice.except.*;
|
||||
import com.silverwrist.venice.servlets.format.*;
|
||||
|
||||
public class FindPost extends VeniceServlet
|
||||
{
|
||||
/*--------------------------------------------------------------------------------
|
||||
* Overrides from class HttpServlet
|
||||
*--------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
public String getServletInfo()
|
||||
{
|
||||
String rc = "FindPost servlet - Searches for posts in communities, conferences, and/or topics\n"
|
||||
+ "Part of the Venice Web Communities System\n";
|
||||
return rc;
|
||||
|
||||
} // end getServletInfo
|
||||
|
||||
/*--------------------------------------------------------------------------------
|
||||
* Overrides from class VeniceServlet
|
||||
*--------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
protected VeniceContent doVeniceGet(HttpServletRequest request, VeniceEngine engine,
|
||||
UserContext user, RenderData rdat)
|
||||
throws ServletException, IOException, VeniceServletResult
|
||||
{
|
||||
CommunityContext comm = getCommunityParameter(request,user,true,"top");
|
||||
changeMenuCommunity(request,comm);
|
||||
String locator = "sig=" + comm.getCommunityID();
|
||||
|
||||
ConferenceContext conf = getConferenceParameter(request,comm,false,"confops?" + locator);
|
||||
TopicContext topic = null;
|
||||
if (conf!=null)
|
||||
{ // find the topic parameter
|
||||
locator += ("&conf=" + conf.getConfID());
|
||||
topic = getTopicParameter(request,conf,false,"confdisp?" + locator);
|
||||
if (topic!=null)
|
||||
locator += ("&top=" + topic.getTopicNumber());
|
||||
|
||||
} // end if
|
||||
|
||||
setMyLocation(request,"findpost?" + locator);
|
||||
return new FindPostData(comm,conf,topic);
|
||||
|
||||
} // end doVeniceGet
|
||||
|
||||
protected VeniceContent doVenicePost(HttpServletRequest request, VeniceEngine engine,
|
||||
UserContext user, RenderData rdat)
|
||||
throws ServletException, IOException, VeniceServletResult
|
||||
{
|
||||
CommunityContext comm = getCommunityParameter(request,user,true,"top");
|
||||
changeMenuCommunity(request,comm);
|
||||
String locator = "sig=" + comm.getCommunityID();
|
||||
|
||||
ConferenceContext conf = getConferenceParameter(request,comm,false,"confops?" + locator);
|
||||
TopicContext topic = null;
|
||||
if (conf!=null)
|
||||
{ // find the topic parameter
|
||||
locator += ("&conf=" + conf.getConfID());
|
||||
topic = getTopicParameter(request,conf,false,"confdisp?" + locator);
|
||||
if (topic!=null)
|
||||
locator += ("&top=" + topic.getTopicNumber());
|
||||
|
||||
} // end if
|
||||
|
||||
setMyLocation(request,"findpost?" + locator);
|
||||
FindPostData data = new FindPostData(comm,conf,topic);
|
||||
|
||||
try
|
||||
{ // attempt to configure the display
|
||||
data.doSearch(request,engine);
|
||||
|
||||
} // end try
|
||||
catch (AccessError ae)
|
||||
{ // error in find parameters
|
||||
return new ErrorBox("Find Error",ae.getMessage(),"top");
|
||||
|
||||
} // end catch
|
||||
catch (DataException de)
|
||||
{ // database error, man
|
||||
return new ErrorBox("Database Error","Database error on find: " + de.getMessage(),"top");
|
||||
|
||||
} // end catch
|
||||
|
||||
return data;
|
||||
|
||||
} // end doVenicePost
|
||||
|
||||
} // end class FindPost
|
||||
@@ -39,6 +39,7 @@ public class FindData implements JSPRender, SearchMode
|
||||
public static final int FD_COMMUNITIES = 0;
|
||||
public static final int FD_USERS = 1;
|
||||
public static final int FD_CATEGORIES = 2;
|
||||
public static final int FD_POSTS = 3;
|
||||
|
||||
// The titles and URLs of the header data
|
||||
private static Vector header_titles = null;
|
||||
@@ -78,12 +79,14 @@ public class FindData implements JSPRender, SearchMode
|
||||
header_titles.add("Communities");
|
||||
header_titles.add("Users");
|
||||
header_titles.add("Categories");
|
||||
header_titles.add("Posts");
|
||||
header_titles.trimToSize();
|
||||
|
||||
header_urls = new Vector();
|
||||
header_urls.add("find?disp=" + String.valueOf(FD_COMMUNITIES));
|
||||
header_urls.add("find?disp=" + String.valueOf(FD_USERS));
|
||||
header_urls.add("find?disp=" + String.valueOf(FD_CATEGORIES));
|
||||
header_urls.add("find?disp=" + String.valueOf(FD_POSTS));
|
||||
header_urls.trimToSize();
|
||||
|
||||
} // end if
|
||||
@@ -128,7 +131,7 @@ public class FindData implements JSPRender, SearchMode
|
||||
|
||||
public static int getNumChoices()
|
||||
{
|
||||
return FD_CATEGORIES + 1;
|
||||
return FD_POSTS + 1;
|
||||
|
||||
} // end getNumChoices
|
||||
|
||||
@@ -303,7 +306,8 @@ public class FindData implements JSPRender, SearchMode
|
||||
break;
|
||||
|
||||
case FD_CATEGORIES:
|
||||
// no parameters to set here - there's no "field" for category search
|
||||
case FD_POSTS:
|
||||
// no parameters to set here - there's no "field" for category/post search
|
||||
break;
|
||||
|
||||
default:
|
||||
@@ -311,10 +315,13 @@ public class FindData implements JSPRender, SearchMode
|
||||
|
||||
} // end switch
|
||||
|
||||
// Validate the search mode parameter.
|
||||
mode = getParamInt(request,"mode",SEARCH_PREFIX);
|
||||
if ((mode!=SEARCH_PREFIX) && (mode!=SEARCH_SUBSTRING) && (mode!=SEARCH_REGEXP))
|
||||
throw new ValidationException("The search mode parameter is not valid.");
|
||||
if (disp!=FD_POSTS)
|
||||
{ // Validate the search mode parameter.
|
||||
mode = getParamInt(request,"mode",SEARCH_PREFIX);
|
||||
if ((mode!=SEARCH_PREFIX) && (mode!=SEARCH_SUBSTRING) && (mode!=SEARCH_REGEXP))
|
||||
throw new ValidationException("The search mode parameter is not valid.");
|
||||
|
||||
} // end if
|
||||
|
||||
// Retrieve the search term parameter.
|
||||
term = request.getParameter("term");
|
||||
@@ -379,6 +386,12 @@ public class FindData implements JSPRender, SearchMode
|
||||
find_count = user.getSearchCategoryCount(mode,term);
|
||||
break;
|
||||
|
||||
case FD_POSTS:
|
||||
results = user.searchPosts(term,offset,count);
|
||||
if (find_count<0)
|
||||
find_count = user.getSearchPostCount(term);
|
||||
break;
|
||||
|
||||
} // end switch
|
||||
|
||||
} // end loadPost
|
||||
|
||||
275
src/com/silverwrist/venice/servlets/format/FindPostData.java
Normal file
275
src/com/silverwrist/venice/servlets/format/FindPostData.java
Normal file
@@ -0,0 +1,275 @@
|
||||
/*
|
||||
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
||||
* (the "License"); you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at <http://www.mozilla.org/MPL/>.
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis, WITHOUT
|
||||
* WARRANTY OF ANY KIND, either express or implied. See the License for the specific
|
||||
* language governing rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is the Venice Web Communities System.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Eric J. Bowersox <erbo@silcom.com>,
|
||||
* for Silverwrist Design Studios. Portions created by Eric J. Bowersox are
|
||||
* Copyright (C) 2001 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*/
|
||||
package com.silverwrist.venice.servlets.format;
|
||||
|
||||
import java.io.Writer;
|
||||
import java.io.IOException;
|
||||
import java.util.*;
|
||||
import javax.servlet.*;
|
||||
import com.silverwrist.util.StringUtil;
|
||||
import com.silverwrist.venice.core.*;
|
||||
import com.silverwrist.venice.except.*;
|
||||
|
||||
public class FindPostData implements JSPRender
|
||||
{
|
||||
/*--------------------------------------------------------------------------------
|
||||
* Static data members
|
||||
*--------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
// Attribute name for request attribute
|
||||
protected static final String ATTR_NAME = "com.silverwrist.venice.content.FindPostData";
|
||||
|
||||
/*--------------------------------------------------------------------------------
|
||||
* Attributes
|
||||
*--------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
private CommunityContext comm;
|
||||
private ConferenceContext conf;
|
||||
private TopicContext topic;
|
||||
private String term = "";
|
||||
private int offset = 0;
|
||||
private int find_count = 0;
|
||||
private List results = null;
|
||||
private int max_results = 0;
|
||||
|
||||
/*--------------------------------------------------------------------------------
|
||||
* Constructor
|
||||
*--------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
public FindPostData(CommunityContext comm, ConferenceContext conf, TopicContext topic)
|
||||
{
|
||||
this.comm = comm;
|
||||
this.conf = conf;
|
||||
this.topic = topic;
|
||||
|
||||
} // end constructor
|
||||
|
||||
/*--------------------------------------------------------------------------------
|
||||
* Internal static functions
|
||||
*--------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
private static int getParamInt(ServletRequest request, String name, int default_val)
|
||||
{
|
||||
String str = request.getParameter(name);
|
||||
if (str==null)
|
||||
return -1;
|
||||
|
||||
try
|
||||
{ // parse the integer value
|
||||
return Integer.parseInt(str);
|
||||
|
||||
} // end try
|
||||
catch (NumberFormatException nfe)
|
||||
{ // in case of conversion error, fall through
|
||||
} // end catch
|
||||
|
||||
return default_val;
|
||||
|
||||
} // end getParamInt
|
||||
|
||||
private static boolean isImageButtonClicked(ServletRequest request, String name)
|
||||
{
|
||||
String val = request.getParameter(name + ".x");
|
||||
return (val!=null);
|
||||
|
||||
} // end isImageButtonClicked
|
||||
|
||||
/*--------------------------------------------------------------------------------
|
||||
* External static functions
|
||||
*--------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
public static FindPostData retrieve(ServletRequest request)
|
||||
{
|
||||
return (FindPostData)(request.getAttribute(ATTR_NAME));
|
||||
|
||||
} // end retrieve
|
||||
|
||||
/*--------------------------------------------------------------------------------
|
||||
* Implementations from interface VeniceContent
|
||||
*--------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
public String getPageTitle(RenderData rdat)
|
||||
{
|
||||
return "Find Posts";
|
||||
|
||||
} // end getPageTitle
|
||||
|
||||
public String getPageQID()
|
||||
{
|
||||
return null;
|
||||
|
||||
} // end getPageQID
|
||||
|
||||
/*--------------------------------------------------------------------------------
|
||||
* Implementations from interface JSPRender
|
||||
*--------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
public void store(ServletRequest request)
|
||||
{
|
||||
request.setAttribute(ATTR_NAME,this);
|
||||
|
||||
} // end store
|
||||
|
||||
public String getTargetJSPName()
|
||||
{
|
||||
return "findpost.jsp";
|
||||
|
||||
} // end getTargetJSPName
|
||||
|
||||
/*--------------------------------------------------------------------------------
|
||||
* External operations
|
||||
*--------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
public final void doSearch(ServletRequest request, VeniceEngine engine) throws AccessError, DataException
|
||||
{
|
||||
max_results = engine.getStdNumSearchResults();
|
||||
|
||||
// Retrieve the search term parameter.
|
||||
term = request.getParameter("term");
|
||||
if (term==null)
|
||||
term = "";
|
||||
|
||||
// Retrieve the offset and find count parameters.
|
||||
offset = getParamInt(request,"ofs",0);
|
||||
find_count = getParamInt(request,"fcount",-1);
|
||||
|
||||
// Adjust the search return offset based on the command button click.
|
||||
if (isImageButtonClicked(request,"search"))
|
||||
offset = 0;
|
||||
else if (isImageButtonClicked(request,"previous"))
|
||||
{ // adjust the offset in the reverse direction
|
||||
offset -= max_results;
|
||||
if (offset<0)
|
||||
offset = 0;
|
||||
|
||||
} // end else if
|
||||
else if (isImageButtonClicked(request,"next"))
|
||||
offset += max_results; // go forwards instead
|
||||
else
|
||||
throw new InternalStateError("Unable to determine what action triggered the form.");
|
||||
|
||||
if (topic!=null)
|
||||
{ // search the topic
|
||||
results = topic.searchPosts(term,offset,max_results);
|
||||
if (find_count<0)
|
||||
find_count = topic.getSearchPostCount(term);
|
||||
|
||||
} // end if
|
||||
else if (conf!=null)
|
||||
{ // search the conference
|
||||
results = conf.searchPosts(term,offset,max_results);
|
||||
if (find_count<0)
|
||||
find_count = conf.getSearchPostCount(term);
|
||||
|
||||
} // end else if
|
||||
else
|
||||
{ // search the community
|
||||
results = comm.searchPosts(term,offset,max_results);
|
||||
if (find_count<0)
|
||||
find_count = comm.getSearchPostCount(term);
|
||||
|
||||
} // end else
|
||||
|
||||
} // end doSearch
|
||||
|
||||
public final String getExtraParameters()
|
||||
{
|
||||
StringBuffer buf = new StringBuffer("<INPUT TYPE=\"HIDDEN\" NAME=\"sig\" VALUE=\"");
|
||||
buf.append(comm.getCommunityID()).append("\">");
|
||||
if (conf!=null)
|
||||
{ // append the conference number parameter
|
||||
buf.append("\n<INPUT TYPE=\"HIDDEN\" NAME=\"conf\" VALUE=\"").append(conf.getConfID()).append("\">");
|
||||
if (topic!=null)
|
||||
{ // append the topic number parameter
|
||||
buf.append("\n<INPUT TYPE=\"HIDDEN\" NAME=\"top\" VALUE=\"").append(topic.getTopicNumber());
|
||||
buf.append("\">");
|
||||
|
||||
} // end if
|
||||
|
||||
} // end if
|
||||
|
||||
return buf.toString();
|
||||
|
||||
} // end getExtraParameters
|
||||
|
||||
public final String getReturnLink(RenderData rdat)
|
||||
{
|
||||
if (topic!=null)
|
||||
return "<A HREF=\"" + rdat.getEncodedServletPath("confdisp?sig=" + comm.getCommunityID()
|
||||
+ "&conf=" + conf.getConfID() + "&top="
|
||||
+ topic.getTopicNumber()) + "\">Return to Topic</A>";
|
||||
else if (conf!=null)
|
||||
return "<A HREF=\"" + rdat.getEncodedServletPath("confdisp?sig=" + comm.getCommunityID()
|
||||
+ "&conf=" + conf.getConfID())
|
||||
+ "\">Return to Topic List</A>";
|
||||
else
|
||||
return "<A HREF=\"" + rdat.getEncodedServletPath("confops?sig=" + comm.getCommunityID())
|
||||
+ "\">Return to Topic List</A>";
|
||||
|
||||
} // end getReturnLink
|
||||
|
||||
public final String getSubtitle()
|
||||
{
|
||||
if (topic!=null)
|
||||
return "Topic: " + topic.getName();
|
||||
else if (conf!=null)
|
||||
return "Conference: " + conf.getName();
|
||||
else
|
||||
return "Community: " + comm.getName();
|
||||
|
||||
} // end getSubtitle
|
||||
|
||||
public final String getTerm()
|
||||
{
|
||||
return term;
|
||||
|
||||
} // end getTerm
|
||||
|
||||
public final int getOffset()
|
||||
{
|
||||
return offset;
|
||||
|
||||
} // end getOffset
|
||||
|
||||
public final int getFindCount()
|
||||
{
|
||||
return find_count;
|
||||
|
||||
} // end getFindCount
|
||||
|
||||
public final List getResults()
|
||||
{
|
||||
return results;
|
||||
|
||||
} // end getResults
|
||||
|
||||
public final int getMaxResults()
|
||||
{
|
||||
return max_results;
|
||||
|
||||
} // end getMaxResults
|
||||
|
||||
} // end class FindPostData
|
||||
Reference in New Issue
Block a user