search.jsp
资源名称:NetOffice.rar [点击查看]
上传用户:guhaomin
上传日期:2007-06-10
资源大小:23203k
文件大小:8k
源码类别:
电子政务应用
开发平台:
Java
- <%
- /**
- * $RCSfile: search.jsp,v $
- * $Revision: 1.4 $
- * $Date: 2000/12/27 22:39:45 $
- */
- %>
- <%@ page
- import="java.util.*,
- java.text.*,
- java.net.*,
- com.coolservlets.forum.*,
- com.coolservlets.forum.util.*"
- errorPage="/mainctrl/bbs/error"
- %>
- <%! // Global variables
- final static SimpleDateFormat formatter = new SimpleDateFormat( "yyyy.MM.dd h:mm a" );
- final static long ONE_DAY = 1000 * 60 * 60 * 24;
- final static long ONE_WEEK = ONE_DAY * 7;
- final static int DEFAULT_RANGE = 15;
- // method to print one table line for a message.
- private String displayMessage(int forumID, ForumMessage message, long now) {
- StringBuffer buf = new StringBuffer();
- if (message != null) {
- java.util.Date messageDate = message.getCreationDate();
- long messageDateMS = messageDate.getTime();
- String subject = message.getSubject();
- int messageID = message.getID();
- String username = null;
- if (!message.isAnonymous()) {
- try {
- User user = message.getUser();
- username = user.getName();
- if (username == null)
- username = user.getUsername();
- } catch (Exception ignore) {
- username = "<i>某人</i>";
- }
- }
- if (username == null)
- username = "<i>匿名者</i>";
- int threadID = message.getForumThread().getID();
- if( subject == null || subject.equals("") ) {
- subject = "[没有主题]";
- }
- String dateText = "";
- dateText = formatter.format(messageDate);
- // subject cell
- buf.append("<td width='97%'><font face='verdana' >");
- buf.append("<a href='/mainctrl/bbs/viewMessage?message=").append(messageID).append("&thread=");
- buf.append(threadID).append("&forum=").append(forumID);
- buf.append("&parent=-1").append("'>");
- buf.append("<font class=strong>").append(subject).append("</font>");
- buf.append("</a>");
- buf.append("</font></td>").append("n");
- // username cell
- buf.append("<td width='1%' nowrap align='center'>");
- buf.append("<font color='#666666' face='verdana' >");
- buf.append(username);
- buf.append("</font></td>");
- // date cell
- if( messageDateMS >= (now-ONE_DAY) ) {
- buf.append("<td width='1%' nowrap class='dateTimeListToday'>");
- } else {
- buf.append("<td width='1%' nowrap class='dateTimeList'>");
- }
- buf.append("<font face='verdana' >");
- buf.append( dateText );
- buf.append("</font></font>");
- buf.append("</td>").append("n");
- }
- return buf.toString();
- }
- %>
- <% ////////////////////////
- // Authorization check
- // check for the existence of an authorization token
- Authorization authToken = SkinUtils.getUserAuthorization(request,response);
- // if the token was null, they're not authorized. Since this skin will
- // allow guests to view forums, we'll set a "guest" authentication
- // token
- if( authToken == null ) {
- authToken = AuthorizationFactory.getAnonymousAuthorization();
- }
- /////////////////
- // Get parameters
- int forumID = ParamUtils.getIntParameter(request,"forum",-1);
- boolean doSearch = ParamUtils.getBooleanParameter(request,"doSearch");
- String queryText = ParamUtils.getParameter(request,"q");
- int range = ParamUtils.getIntParameter(request,"range",DEFAULT_RANGE);
- int start = ParamUtils.getIntParameter(request,"start",0);
- ///////////////////
- // perform a search
- ForumFactory forumFactory = ForumFactory.getInstance(authToken);
- Forum forum = forumFactory.getForum(forumID);
- int nextStart = start;
- Query query = null;
- Iterator searchResults = null;
- if (doSearch && queryText != null) {
- if( forum != null ) {
- query = forum.createQuery();
- }
- query.setQueryString(queryText);
- // use the +1 to see if there are more results...
- searchResults = query.results(start, range +1);
- }
- %>
- <% /////////////////
- // header include
- String title = "查找";
- %>
- <%@ include file="/skins/bay/header.jsp" %>
- <%-- begin breadcrumbs --%>
- <table bgcolor="#666666" cellpadding=0 cellspacing=0 border=0 width="100%">
- <tr>
- <td colspan="3">
- <font class="strongw"><a href="/mainctrl/home/index"><font color="#FFFFFF">首页</font></a>>><a href="/mainctrl/communication/main"><font color="#FFFFFF">通信</font></a>>><a href="/mainctrl/bbs/index" ><font color="#FFFFFF">论坛主页</font></a>
- <% if (forumID > 0) { %>
- >>
- <a href="/mainctrl/bbs/viewForum?forum=<%= forumID %>"><font color="#FFFFFF"><%= forum.getName() %></font></a>
- <% } %>
- >>
- <% if (doSearch) { %>
- 查找结果
- <% } else { %>
- 查找
- <% } %>
- </font>
- </td>
- </tr>
- </table>
- <%-- end breadcrubms --%>
- <center>
- <table bgcolor="#fafafa" class=title cellspacing=1 cellpadding=2 border=0 width="600">
- <tr bgcolor="#fafafa">
- <td align=left> 由于论坛的自动检索功能是定时进行的,所以当你在发新贴之后,在系统的查找功能中可能并不能立即查找到此贴,需要在一段时间之后,也就是系统对新贴进行检索后,才能查找到此贴。
- </td>
- </tr>
- <tr bgcolor="#fafafa">
- <td align=center>
- <form action="/mainctrl/bbs/search" name="searchForm">
- <input type="hidden" name="doSearch" value="true">
- <input type="hidden" name="forum" value="<%= forumID %>">
- <input type="text" name="q" value="<%= doSearch && queryText != null ? queryText : "" %>" size="40" maxlength="100" class="text">
- <input type="submit" value="查找" class="text">
- </form>
- </td>
- </tr>
- </table>
- </center>
- <script language="JavaScript" type="text/javascript">
- <!--
- document.searchForm.q.focus();
- //-->
- </script>
- <% if (doSearch) { %>
- <p>
- <br>
- <p>
- <% if( query == null || searchResults == null || !searchResults.hasNext() ) { %>
- <center>没有结果,请再试一遍!</center>
- <% } else { %>
- <table bgcolor="#999999" cellpadding=0 cellspacing=0 border=0 width="600">
- <td>
- <table bgcolor="#999999" cellpadding=3 cellspacing=1 border=0 width="600">
- <tr bgcolor="#dddddd">
- <td align="center" width="98%"><font face="tahoma,arial,helvetica">主题</font></td>
- <td align="center" width="1%" nowrap><font face="tahoma,arial,helvetica">作者</font></td>
- <td align="center" width="1%" nowrap><font face="tahoma,arial,helvetica">日期</font></td>
- </tr>
- <%
- ForumFactory fact = ForumFactory.getInstance(authToken);
- long now = (new java.util.Date()).getTime();
- String bgColor = null;
- int nrRows = 0;
- int nrResults = 0;
- while (nrResults++ < range && searchResults.hasNext()) {
- ForumMessage message = (ForumMessage)searchResults.next();
- int msgForumID = message.getForumThread().getForum().getID();
- bgColor = (++nrRows % 2 == 0 ) ? "#ffffff": "#eeeeee";
- %>
- <tr bgcolor="<%= bgColor %>">
- <%= displayMessage(msgForumID, message, now) %>
- </tr>
- <%
- }
- %>
- </table>
- </td>
- </table>
- <% } %>
- <table cellpadding=0 cellspacing=0 border=0 width="600">
- <td width="1%" nowrap>
- <font face="verdana,arial">
- <br>
- <% String url = "/mainctrl/bbs/search?doSearch=true&forum="+forumID+"&q="+(queryText == null ? "" : URLEncoder.encode(queryText))+"&range="+range;
- if( (start-range) >= 0 ) { %>
- <a href="<%= url %>&start=<%= (start-range) %>"><font class="strong"><<</font>向前</a>
- <% } %>
- </font>
- </td>
- <td width="98%" nowrap>
- </td>
- <td width="1%" nowrap>
- <font face="verdana,arial">
- <br>
- <% if (searchResults != null && searchResults.hasNext()) { %>
- <a href="<%= url %>&start=<%= (nextStart+range) %>">向后<font class="strong">>></font></a>
- <% } %>
- </font>
- </td>
- </table>
- <% } %>
- <%@ include file="/skins/bay/footer.jsp" %>