searchdoc.jsp

来自「Java的框架」· JSP 代码 · 共 260 行

JSP
260
字号
<%@ include file="/common/taglibs.jsp"%>
<%@ taglib uri="/WEB-INF/tld/doc-man.tld" prefix="docman" %>
<%@ page import="mcap.core.search.model.*" %>

<mcaps:userPreference key="pageSize" name="pageSize" scope="page"/>

<c:choose>
	<c:when test="${empty param.searchPub}">
	<c:url var="cancelURL" value="/docMan.action">
		<c:param name="path" value="${param.path}"/>
	</c:url>   
	</c:when>
	<c:otherwise>
	<c:url var="cancelURL" value="/docManPub.action">
	</c:url>   
	</c:otherwise>
</c:choose>

<html>
	<head>
		<c:choose>
			<c:when test="${empty param.searchPub}">
		<title><fmt:message key="search.title"/></title>
			</c:when>
			<c:otherwise>
		<title><fmt:message key="searchPub.title"/></title>
			</c:otherwise>
		</c:choose>
		<link rel="stylesheet" type="text/css" media="all" href="<c:url value='/styles/search.css'/>" />
		<content tag="heading">
			<c:choose>
				<c:when test="${empty param.searchPub}">
			<fmt:message key="search.heading"/>
				</c:when>
				<c:otherwise>
			<fmt:message key="searchPub.heading"/>
				</c:otherwise>
			</c:choose>
		</content>
    </head>

	<body>
		<span id="message"><c:out value="${message}"/></span>
		<div class="separator"></div>
		<c:set var="pageButtons">
			<tr>
				<td width="15%">
				</td>
				<td class="buttonBar" width="85%">
					<input type="submit" class="button" name="search" onclick="bCancel=false" value="<fmt:message key="button.search"/>" />		
					<input type="button" class="button" name="cancel" onclick="cancelSearch ('<c:out value="${cancelURL}"/>')" value="<fmt:message key="button.cancel"/>" />
				</td>
			</tr>
		</c:set>
		<form method="post" action="<c:url value="/searchDoc.action"/>" id="searchDocForm" onsubmit="return onFormSubmit(this)">
    		<c:choose>
   				<c:when test="${empty param.searchPub}">
		 	<p><h3><fmt:message key="search.search"/></h3></p>
   				</c:when>
   				<c:otherwise>
		 	<p><h3><fmt:message key="searchPub.search"/></h3></p>
   				</c:otherwise>
   			</c:choose>
			<input type="hidden" 
			  		id="path" 
			  		name="path" 
			  		value="<c:out value="${param.path}"/>">
			<input type="hidden" 
			  		id="pageSize" 
			  		name="pageSize" 
			  		value="<c:out value="${pageSize}"/>">
			<input type="hidden" 
			  		id="searchPub" 
			  		name="searchPub" 
			  		value="<c:out value="${param.searchPub}"/>">
			<table class="detail">
			<tr>
		       	<th width="15%">
		        	<mcaps:label key="search.search"/>
		        </th>
				<td width="85%">
					  <input type="text" maxlength="100" width="100%" size="100"
				  		id="query" 
				  		name="query" 
				  		value="<c:out value="${param.query}"/>">
				</td>
			</tr>
			<tr>
				<td colspan="2">
				<table class="detail">
					<c:out value="${pageButtons}" escapeXml="false" />
				</table>
				</td>
			</tr>
			<c:if test="${!empty docSearchResult}">
			<tr>
				<td colspan="2">
					<hr>
				</td>
			</tr>
			<tr>
				<td colspan="2">
				<c:url var="searchUrl" value="/searchDoc.action">
					<c:param name="query" value="${param.query}"/>
					<c:param name="pageSize" value="${pageSize}"/>
				</c:url>
				<c:url var="docUrl" value="/${searchUrlPrefix}" />
				<c:set var="pageNavi">
					<c:if test="${docSearchResult.numOfPage > 1}">
					<tr>
						<td>
						<c:if test="${docSearchResult.pageIndex > 0}">
							<a href="<c:out value="${searchUrl}"/>&pageIndex=${(docSearchResult.pageIndex) - 1}">Previous</a>
						</c:if>
							&nbsp;
						<c:forEach begin="0" end="${docSearchResult.numOfPage}" var="current">
							<c:out value="${current}"/>
						</c:forEach>
							&nbsp;
						<c:if test="${docSearchResult.pageIndex != (docSearchResult.numOfPage - 1)}">
							<a href="<c:out value="${searchUrl}"/>&pageIndex=${(docSearchResult.pageIndex) + 1}">Next</a>
						</c:if>
						</td>
					</tr>
					</c:if>
				</c:set>
				<table class="detail">
					<c:out value="${pageNavi}" escapeXml="false" />
<%
PagedResultSet docSearchResult = (PagedResultSet) request.getAttribute ("docSearchResult");
if (docSearchResult != null) {
	Highlighter highlighter = docSearchResult.getHighlighter ();
	int totalDoc = docSearchResult.total();
	if (totalDoc > 0) {
%>
					<tr>
						<td>&nbsp;
						</td>
					</tr>
<%
		for (int i = 0; i < totalDoc; i++) {
			mcap.core.search.model.ResultDocument rdoc = docSearchResult.getDocument (i);
			String name = rdoc.getName();
			String nameH = null;
			try {
				nameH = highlighter.getBestFragment (SearchField.NAME, name);
			}
			catch (Exception e) {
			}
	
			if (nameH != null && !nameH.equals("")) {
				name = nameH;
			}
			
			String content = rdoc.getBody();
			String contentH = null;
			try {
				contentH = highlighter.getBestFragments (SearchField.BODY, content, 3, "...<br>");
			}
			catch (Exception e) {
			}
	
			if (contentH != null && !contentH.equals("")) {
				content = contentH;
			}
			else if (content != null && !content.equals("") && content.length () > 100) {
				content = content.substring (0, 100) + "...";
			}
%>
					<tr>
						<td>
							<a href="<c:out value="${docUrl}"/>/<docman:convertUUIDToPath uuid="<%=rdoc.getUrl()%>" />" class="aSearch" id="<c:out value="${docUrl}"/>/<docman:convertUUIDToPath uuid="<%=rdoc.getUrl()%>" />">
								(<%=rdoc.getType().getDisplayName()%>) <%=name%>
							</a>
						</td>
					</tr>
					<tr>
						<td>
<%
			if (content != null) {
%>
							<%=content%><br>
<%
			}
%>
							<c:out value="${docUrl}"/>/<docman:convertUUIDToPath uuid="<%=rdoc.getUrl()%>" />
						</td>
					</tr>
					<tr>
						<td>&nbsp;
						</td>
					</tr>
<%
		}
	}
	else {
%>
					<tr>
						<td>No Result Found.
						</td>
					</tr>
<%
	}
}
%>
					<c:out value="${pageNavi}" escapeXml="false" />
				</table>
				</td>
			</tr>
			</c:if>
			<!-- cater for if no search is being indexed before -->
			<c:if test="${empty docSearchResult}">
				<c:if test="${!empty param.query}">
			<tr>
				<td colspan="2">
					<hr>
				</td>
			</tr>
			<tr>
				<td colspan="2">
				<table class="detail">
					<tr>
						<td>No Result Found.
						</td>
					</tr>
				</table>
				</td>
			</tr>
				</c:if>
			</c:if>
			</table>
		</form>
	
<script type="text/javascript">
<c:set var="focus" value="query"/>

var focusControl = document.forms["searchDocForm"].elements["<c:out value="${focus}"/>"];

<!-- This is here so we can exclude the selectAll call when roles is hidden -->
function onFormSubmit(theForm) {
    if (theForm.query.value == "") {
	    alert ("Please enter the search field.");
	    return false;
    }
    
    if (theForm.query.value.indexOf("*") == 0 || theForm.query.value.indexOf("?") == 0) {
	    alert ("Cannot use \"*\" or \"?\" as the first character of a search.");
	    return false;
    }
    return true;
}

function cancelSearch (actionUrl) {
	document.forms["searchDocForm"].action = actionUrl;
	document.forms["searchDocForm"].submit ();
}
</script>

	</body>
</html>

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?