01: /**
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */package org.apache.solr.request;
17:
18: import java.io.Writer;
19: import java.io.IOException;
20:
21: import org.apache.solr.util.NamedList;
22:
23: /**
24: * Implementations of <code>QueryResponseWriter</code> are used to format responses to query requests.
25: *
26: * Different <code>QueryResponseWriter</code>s are registered with the <code>SolrCore</code>.
27: * One way to register a QueryResponseWriter with the core is thorugh the <code>solrconfig.xml</code> file.
28: * <p>
29: * Example <code>solrconfig.xml</code> entry to register a <code>QueryResponseWRiter</code> implementation to
30: * handle all queries with a writer type of "simple":
31: * <p>
32: * <code>
33: * <queryResponseWriter name="simple" class="foo.SimpleResponseWriter" />
34: * </code>
35: * <p>
36: * A single instance of any registered QueryResponseWriter is created
37: * via the default constructor and is reused for all relevant queries.
38: *
39: * @author yonik
40: * @version $Id: QueryResponseWriter.java 472574 2006-11-08 18:25:52Z yonik $
41: */
42: public interface QueryResponseWriter {
43: public static String CONTENT_TYPE_XML_UTF8 = "text/xml; charset=UTF-8";
44: public static String CONTENT_TYPE_TEXT_UTF8 = "text/plain; charset=UTF-8";
45: public static String CONTENT_TYPE_TEXT_ASCII = "text/plain; charset=US-ASCII";
46:
47: /**
48: * Write a SolrQueryResponse, this method must be thread save.
49: *
50: * <p>
51: * Information about the request (in particular: formating options) may be
52: * obtained from <code>req</code> but the dominant source of information
53: * should be <code>rsp</code>.
54: * <p>
55: * There are no mandatory actions that write must perform.
56: * An empty write implementation would fulfill
57: * all interface obligations.
58: * </p>
59: */
60: public void write(Writer writer, SolrQueryRequest request,
61: SolrQueryResponse response) throws IOException;
62:
63: /**
64: * Return the applicable Content Type for a request, this method
65: * must be thread safe.
66: *
67: * <p>
68: * QueryResponseWriter's must implement this method to return a valid
69: * HTTP Content-Type header for the request, that will logically
70: * corrispond with the output produced by the write method.
71: * </p>
72: * @return a Content-Type string, which may not be null.
73: */
74: public String getContentType(SolrQueryRequest request,
75: SolrQueryResponse response);
76:
77: /** <code>init</code> will be called just once, immediately after creation.
78: * <p>The args are user-level initialization parameters that
79: * may be specified when declaring a response writer in
80: * solrconfig.xml
81: */
82: public void init(NamedList args);
83: }
|