一个关于商业的网站

源代码在线查看: search.jsp

软件大小: 1416 K
上传用户: zwaheron
关键词: 网站
下载地址: 免注册下载 普通下载 VIP

相关代码

				
								/**
				 *	$RCSfile: search.jsp,v $
				 *	$Revision: 1.4 $
				 *	$Date: 2000/12/27 22:39:45 $
				 */
				%>
				
									import="java.util.*,
							java.text.*,
							java.net.*,
				            com.coolservlets.forum.*,
				            com.coolservlets.forum.util.*"
					errorPage="error.jsp"
				%>
				
									final static SimpleDateFormat formatter = new SimpleDateFormat( "EE, MMM d yyyy 'at' h:mm:ss 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 = "Somebody";
								}
							}
							if (username == null)
							    username = "Anonymous";
							int threadID = message.getForumThread().getID();
							
							if( subject == null || subject.equals("") ) {
								subject = "[no subject]";
							}
							String dateText = "";
							
							dateText = formatter.format(messageDate);
							
							// subject cell
							buf.append("");
							buf.append("							buf.append(threadID).append("&forum=").append(forumID);
							buf.append("&parent=-1").append("'>");
							buf.append("").append(subject).append("");
							buf.append("");
							buf.append("").append("\n");
							
							// username cell
							buf.append("");
							buf.append("");
							buf.append(username);
							buf.append("");
							
							// date cell
							if( messageDateMS >= (now-ONE_DAY) ) {
								buf.append("");
							} else { 
								buf.append("");
							}
							buf.append("");
							buf.append( dateText );
							buf.append("");
							buf.append("").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 = "Search";
				%>
				
				
				
				Home
				 0) { %>
				>
				
				
				>
				
					Search results
				
					Search
				
				
				
				
				
				
				
				
				
				
				
				
				
					
					
				
				
				
				
				
				
									document.searchForm.q.focus();
				//-->
				
				
				
				
					
					
					
					
					
					
						No results. Try again.
					
					
				
						
						
						
						
							subject
							posted by
							date
						
				
													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";
						%>  
								
								
								
													}
						%>
				
						
						
						
				
					
				
					
						
							
							
															if( (start-range) >= 0 ) { %>
								<< previous results
							
							
						
						
						
						
						
							
							
							
								next results >>
							
							
						
					
				
				
				
				
				
							

相关资源