2
* Licensed to the Apache Software Foundation (ASF) under one or more
3
* contributor license agreements. See the NOTICE file distributed with
4
* this work for additional information regarding copyright ownership.
5
* The ASF licenses this file to You under the Apache License, Version 2.0
6
* (the "License"); you may not use this file except in compliance with
7
* the License. You may obtain a copy of the License at
9
* http://www.apache.org/licenses/LICENSE-2.0
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.
18
package org.apache.solr.response;
20
import java.io.Writer;
21
import java.io.IOException;
23
import org.apache.solr.common.util.NamedList;
24
import org.apache.solr.request.SolrQueryRequest;
26
public class PHPResponseWriter implements QueryResponseWriter {
27
static String CONTENT_TYPE_PHP_UTF8="text/x-php;charset=UTF-8";
29
public void init(NamedList n) {
33
public void write(Writer writer, SolrQueryRequest req, SolrQueryResponse rsp) throws IOException {
34
PHPWriter w = new PHPWriter(writer, req, rsp);
42
public String getContentType(SolrQueryRequest request, SolrQueryResponse response) {
43
return CONTENT_TYPE_TEXT_UTF8;
47
class PHPWriter extends JSONWriter {
48
public PHPWriter(Writer writer, SolrQueryRequest req, SolrQueryResponse rsp) {
49
super(writer, req, rsp);
53
public void writeNamedList(String name, NamedList val) throws IOException {
54
writeNamedListAsMapMangled(name,val);
58
public void writeMapOpener(int size) throws IOException {
59
writer.write("array(");
63
public void writeMapCloser() throws IOException {
68
public void writeArrayOpener(int size) throws IOException {
69
writer.write("array(");
73
public void writeArrayCloser() throws IOException {
78
public void writeNull(String name) throws IOException {
83
protected void writeKey(String fname, boolean needsEscaping) throws IOException {
84
writeStr(null, fname, needsEscaping);
90
public void writeStr(String name, String val, boolean needsEscaping) throws IOException {
93
for (int i=0; i<val.length(); i++) {
94
char ch = val.charAt(i);
97
case '\\': writer.write('\\'); writer.write(ch); break;