/* $ID: $
 * Created on 14.08.2003 by Burkhard Sell
 */
package de.skyrix.zsp.logic.httpserver;

import java.util.Properties;

/**Modul interface for HTTP/DAV methods.
 * <code>HttpServer</code> allows to register modules for processing
 * different method queries like GET, POST, PROPFIND, ...
 * 
 * Each of this moduls must extend this object.
 * 
 * @author Burkhard Sell
 */
public abstract class MethodModule {

  /**Creates a Response object and fills it with some default values.
   * 
   * @param status   - response status (eg "404 File not found")
   * @param mimeType - the mime type of the response
   * @param body     - the message body (if any)
   * 
   * @return         - the prepared <code>Response</code> object.      
   */
	protected Response prepareResponse(
		String status,
		String mimeType,
		String body) {
		Response response = new Response(status, mimeType, body);

		response.addHeader("server", "SOPE 4.2/WebDAV");
		response.addHeader("DAV", "1,2");
		response.addHeader("Ms-Author-Via", "DAV");
		response.addHeader("connection", "close");
		response.addHeader("X-Dav-Error", "200 No error");
		response.addHeader("content-type", "text/xml");
		response.addHeader("cache-control", "no-cache");
		response.addHeader("pragma", "no-cache");
		response.addHeader(
			"content-length",
			((body != null) ? "" + body.length() : "0"));
		return response;
	}

	/**Determine the name of the HTTP/DAV method this module is responsible for.
	 * 
	 * @return method name.
	 */
	public abstract String getMethodName();

	/**Handles the query.
	 * 
	 * @param uri     - the uri called by the client
	 * @param header  - the HTTP/DAV header
	 * @param parms   - request parameters (if given)
	 * @param body    - request body (if given)
	 * 
	 * @return        - the response to the query
	 */
	public abstract Response processQuery(
		String uri,
		Properties header,
		Properties parms,
		String body);

}
