<commit_before>/* QueryRenderer
 *
 * $Id$
 *
 * Created on 2:47:42 PM Nov 7, 2005.
 *
 * Copyright (C) 2005 Internet Archive.
 *
 * This file is part of wayback.
 *
 * wayback is free software; you can redistribute it and/or modify
 * it under the terms of the GNU Lesser Public License as published by
 * the Free Software Foundation; either version 2.1 of the License, or
 * any later version.
 *
 * wayback is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser Public License for more details.
 *
 * You should have received a copy of the GNU Lesser Public License
 * along with wayback; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */
package org.archive.wayback.query;

import java.io.IOException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.archive.wayback.QueryRenderer;
import org.archive.wayback.ResultURIConverter;
import org.archive.wayback.WaybackConstants;
import org.archive.wayback.core.SearchResults;
import org.archive.wayback.core.WaybackRequest;

/**
 * Brain-dead simple QueryRenderer implementation, which shunts all the work off
 * to a .jsp file as defined by administrators. Also has basic logic to switch
 * to a different .jsp to format request asking for XML data. 
 *
 * @author brad
 * @version $Date$, $Revision$
 */
public class Renderer implements QueryRenderer {

	private String captureJsp = "/jsp/HTMLResults.jsp";
	private String urlJsp = "/jsp/HTMLResults.jsp";
	private String xmlJsp = "/jsp/XMLResults.jsp";
	
	/**
	 * @param request
	 * @param response
	 * @param jspName
	 * @throws ServletException
	 * @throws IOException
	 */
	private void proxyRequest(HttpServletRequest request,
			HttpServletResponse response, final String jspPath)
			throws ServletException, IOException {

		RequestDispatcher dispatcher = request.getRequestDispatcher(jspPath);
		dispatcher.forward(request, response);
	}

	public void renderUrlResults(HttpServletRequest httpRequest,
			HttpServletResponse httpResponse, WaybackRequest wbRequest,
			SearchResults results, ResultURIConverter uriConverter)
			throws ServletException, IOException {

		UIQueryResults uiResults = new UIQueryResults(httpRequest, wbRequest,
				results, uriConverter);
		String jsp = captureJsp;
		if(wbRequest.containsKey(WaybackConstants.REQUEST_XML_DATA)) {
			jsp = xmlJsp;
		}

		uiResults.storeInRequest(httpRequest,jsp);
		proxyRequest(httpRequest, httpResponse, jsp);

	}

	/* (non-Javadoc)
	 * @see org.archive.wayback.QueryRenderer#renderUrlPrefixResults(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse, org.archive.wayback.core.WaybackRequest, org.archive.wayback.core.SearchResults, org.archive.wayback.ResultURIConverter)
	 */
	public void renderUrlPrefixResults(HttpServletRequest httpRequest,
			HttpServletResponse httpResponse, WaybackRequest wbRequest,
			SearchResults results, ResultURIConverter uriConverter)
			throws ServletException, IOException {

		UIQueryResults uiResults = new UIQueryResults(httpRequest, wbRequest, 
				results, uriConverter);
		String jsp = urlJsp;
		if(wbRequest.containsKey(WaybackConstants.REQUEST_XML_DATA)) {
			jsp = xmlJsp;
		}

		uiResults.storeInRequest(httpRequest,jsp);
		proxyRequest(httpRequest, httpResponse, jsp);

	}

	/**
	 * @return the captureJsp
	 */
	public String getCaptureJsp() {
		return captureJsp;
	}

	/**
	 * @param captureJsp the captureJsp to set
	 */
	public void setCaptureJsp(String captureJsp) {
		this.captureJsp = captureJsp;
	}

	/**
	 * @return the urlJsp
	 */
	public String getUrlJsp() {
		return urlJsp;
	}

	/**
	 * @param urlJsp the urlJsp to set
	 */
	public void setUrlJsp(String urlJsp) {
		this.urlJsp = urlJsp;
	}

	/**
	 * @return the xmlJsp
	 */
	public String getXmlJsp() {
		return xmlJsp;
	}

	/**
	 * @param xmlJsp the xmlJsp to set
	 */
	public void setXmlJsp(String xmlJsp) {
		this.xmlJsp = xmlJsp;
	}
}<commit_msg>REFACTOR: SearchResult => (Url|Capture)SearchResult INTERFACE: changed names of two render* methods to match Capture/Url scheme. TWEAK: Moved query specific .jsps to /query/ directory in webapp TWEAK: allow separate XML renderers for Url/Capture results.<commit_after>/* QueryRenderer
 *
 * $Id$
 *
 * Created on 2:47:42 PM Nov 7, 2005.
 *
 * Copyright (C) 2005 Internet Archive.
 *
 * This file is part of wayback.
 *
 * wayback is free software; you can redistribute it and/or modify
 * it under the terms of the GNU Lesser Public License as published by
 * the Free Software Foundation; either version 2.1 of the License, or
 * any later version.
 *
 * wayback is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser Public License for more details.
 *
 * You should have received a copy of the GNU Lesser Public License
 * along with wayback; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */
package org.archive.wayback.query;

import java.io.IOException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.archive.wayback.QueryRenderer;
import org.archive.wayback.ResultURIConverter;
import org.archive.wayback.WaybackConstants;
import org.archive.wayback.core.CaptureSearchResults;
import org.archive.wayback.core.UrlSearchResults;
import org.archive.wayback.core.WaybackRequest;

/**
 * Brain-dead simple QueryRenderer implementation, which shunts all the work off
 * to a .jsp file as defined by administrators. Also has basic logic to switch
 * to a different .jsp to format request asking for XML data. 
 *
 * @author brad
 * @version $Date$, $Revision$
 */
public class Renderer implements QueryRenderer {

	private String captureJsp = "/query/HTMLCaptureResults.jsp";
	private String urlJsp = "/query/HTMLUrlResults.jsp";
	private String xmlCaptureJsp = "/query/XMLCaptureResults.jsp";
	private String xmlUrlJsp = "/query/XMLUrlResults.jsp";
	
	/**
	 * @param request
	 * @param response
	 * @param jspName
	 * @throws ServletException
	 * @throws IOException
	 */
	private void proxyRequest(HttpServletRequest request,
			HttpServletResponse response, final String jspPath)
			throws ServletException, IOException {

		RequestDispatcher dispatcher = request.getRequestDispatcher(jspPath);
		dispatcher.forward(request, response);
	}

	public void renderCaptureResults(HttpServletRequest httpRequest,
			HttpServletResponse httpResponse, WaybackRequest wbRequest,
			CaptureSearchResults results, ResultURIConverter uriConverter)
			throws ServletException, IOException {

		UICaptureQueryResults uiResults = new UICaptureQueryResults(httpRequest, wbRequest,
				results, uriConverter);
		String jsp = captureJsp;
		if(wbRequest.containsKey(WaybackConstants.REQUEST_XML_DATA)) {
			jsp = xmlCaptureJsp;
		}

		uiResults.storeInRequest(httpRequest,jsp);
		proxyRequest(httpRequest, httpResponse, jsp);

	}

	/* (non-Javadoc)
	 * @see org.archive.wayback.QueryRenderer#renderUrlPrefixResults(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse, org.archive.wayback.core.WaybackRequest, org.archive.wayback.core.SearchResults, org.archive.wayback.ResultURIConverter)
	 */
	public void renderUrlResults(HttpServletRequest httpRequest,
			HttpServletResponse httpResponse, WaybackRequest wbRequest,
			UrlSearchResults results, ResultURIConverter uriConverter)
			throws ServletException, IOException {

		UIUrlQueryResults uiResults = new UIUrlQueryResults(httpRequest, wbRequest, 
				results, uriConverter);
		String jsp = urlJsp;
		if(wbRequest.containsKey(WaybackConstants.REQUEST_XML_DATA)) {
			jsp = xmlUrlJsp;
		}

		uiResults.storeInRequest(httpRequest,jsp);
		proxyRequest(httpRequest, httpResponse, jsp);

	}

	/**
	 * @return the captureJsp
	 */
	public String getCaptureJsp() {
		return captureJsp;
	}

	/**
	 * @param captureJsp the captureJsp to set
	 */
	public void setCaptureJsp(String captureJsp) {
		this.captureJsp = captureJsp;
	}

	/**
	 * @return the urlJsp
	 */
	public String getUrlJsp() {
		return urlJsp;
	}

	/**
	 * @param urlJsp the urlJsp to set
	 */
	public void setUrlJsp(String urlJsp) {
		this.urlJsp = urlJsp;
	}

	/**
	 * @return the xmlCaptureJsp
	 */
	public String getXmlCaptureJsp() {
		return xmlCaptureJsp;
	}

	/**
	 * @param xmlCaptureJsp the xmlCaptureJsp to set
	 */
	public void setXmlCaptureJsp(String xmlCaptureJsp) {
		this.xmlCaptureJsp = xmlCaptureJsp;
	}
	/**
	 * @return the xmlUrlJsp
	 */
	public String getXmlUrlJsp() {
		return xmlUrlJsp;
	}

	/**
	 * @param xmlUrlJsp the xmlUrlJsp to set
	 */
	public void setXmlUrlJsp(String xmlUrlJsp) {
		this.xmlUrlJsp = xmlUrlJsp;
	}
}
{'fraction_non_alphanumeric': 0.08726673984632272, 'fraction_numerical': 0.006586169045005488, 'mean_word_length': 4.508464328899637, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 28}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4940302', 'n_tokens_mistral': 2878, 'n_tokens_neox': 2650, 'n_words': 787}