SOLR-2391: Replace remaining occurences of text/xml mime types to application/xml & further cleanups in XSLTResponseWriter

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1075190 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Uwe Schindler 2011-02-28 00:41:32 +00:00
parent 09b9091711
commit aaad623e64
14 changed files with 29 additions and 20 deletions

View File

@ -24,7 +24,7 @@
xmlns:xsl='http://www.w3.org/1999/XSL/Transform'
>
<xsl:output media-type="text/html; charset=UTF-8" encoding="UTF-8"/>
<xsl:output media-type="text/html" encoding="UTF-8"/>
<xsl:variable name="title" select="concat('Solr search results (',response/result/@numFound,' documents)')"/>

View File

@ -27,7 +27,7 @@
<xsl:output
method="xml"
encoding="utf-8"
media-type="text/xml; charset=UTF-8"
media-type="application/xml"
/>
<xsl:template match='/'>

View File

@ -27,7 +27,7 @@
<xsl:output
method="xml"
encoding="utf-8"
media-type="text/xml; charset=UTF-8"
media-type="text/xml"
/>
<xsl:template match='/'>
<rss version="2.0">

View File

@ -28,7 +28,7 @@
<xsl:output
method="html"
encoding="UTF-8"
media-type="text/html; charset=UTF-8"
media-type="text/html"
doctype-public="-//W3C//DTD XHTML 1.0 Strict//EN"
doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"
/>

View File

@ -43,7 +43,7 @@ import org.apache.solr.util.plugin.NamedListInitializedPlugin;
* @version $Id$
*/
public interface QueryResponseWriter extends NamedListInitializedPlugin {
public static String CONTENT_TYPE_XML_UTF8="text/xml; charset=UTF-8";
public static String CONTENT_TYPE_XML_UTF8="application/xml; charset=UTF-8";
public static String CONTENT_TYPE_TEXT_UTF8="text/plain; charset=UTF-8";
public static String CONTENT_TYPE_TEXT_ASCII="text/plain; charset=US-ASCII";

View File

@ -44,8 +44,8 @@ public final class XMLWriter extends TextResponseWriter {
private static final char[] XML_START1="<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n".toCharArray();
private static final char[] XML_STYLESHEET="<?xml-stylesheet type=\"text/xsl\" href=\"/admin/".toCharArray();
private static final char[] XML_STYLESHEET_END=".xsl\"?>\n".toCharArray();
private static final char[] XML_STYLESHEET="<?xml-stylesheet type=\"text/xsl\" href=\"".toCharArray();
private static final char[] XML_STYLESHEET_END="\"?>\n".toCharArray();
/***
private static final char[] XML_START2_SCHEMA=(
@ -89,7 +89,7 @@ public final class XMLWriter extends TextResponseWriter {
String stylesheet = req.getParams().get("stylesheet");
if (stylesheet != null && stylesheet.length() > 0) {
writer.write(XML_STYLESHEET);
writer.write(stylesheet);
XML.escapeAttributeValue(stylesheet, writer);
writer.write(XML_STYLESHEET_END);
}

View File

@ -44,7 +44,7 @@ import org.apache.solr.util.xslt.TransformerProvider;
*/
public class XSLTResponseWriter implements QueryResponseWriter {
public static final String DEFAULT_CONTENT_TYPE = "text/xml";
public static final String DEFAULT_CONTENT_TYPE = "application/xml";
public static final String TRANSFORM_PARAM = "tr";
public static final String CONTEXT_TRANSFORMER_KEY = "xsltwriter.transformer";
@ -70,14 +70,23 @@ public class XSLTResponseWriter implements QueryResponseWriter {
throw new RuntimeException("getTransformer fails in getContentType",e);
}
final String mediaTypeFromXslt = t.getOutputProperty("media-type");
if(mediaTypeFromXslt == null || mediaTypeFromXslt.length()==0) {
String mediaType = t.getOutputProperty("media-type");
if (mediaType == null || mediaType.length()==0) {
// This did not happen in my tests, mediaTypeFromXslt is set to "text/xml"
// if the XSLT transform does not contain an xsl:output element. Not sure
// if this is standard behavior or if it's just my JVM/libraries
return DEFAULT_CONTENT_TYPE;
mediaType = DEFAULT_CONTENT_TYPE;
}
return mediaTypeFromXslt;
if (!mediaType.contains("charset")) {
String encoding = t.getOutputProperty("encoding");
if (encoding == null || encoding.length()==0) {
encoding = "UTF-8";
}
mediaType = mediaType + "; charset=" + encoding;
}
return mediaType;
}
public void write(Writer writer, SolrQueryRequest request, SolrQueryResponse response) throws IOException {

View File

@ -48,7 +48,7 @@ import org.apache.solr.common.util.*;
public class ClientUtils
{
// Standard Content types
public static final String TEXT_XML = "text/xml; charset=utf-8";
public static final String TEXT_XML = "application/xml; charset=UTF-8";
/**
* Take a string and make it an iterable ContentStream

View File

@ -26,7 +26,7 @@
method="html"
indent="yes"
encoding="utf-8"
media-type="text/html; charset=UTF-8"
media-type="text/html"
doctype-public="-//W3C//DTD HTML 4.01//EN"
doctype-system="http://www.w3.org/TR/html4/strict.dtd" />

View File

@ -21,7 +21,7 @@
<xsl:output
method="html"
encoding="utf-8"
media-type="text/html; charset=UTF-8"
media-type="text/html"
indent="yes"
doctype-public="-//W3C//DTD HTML 4.01//EN"
doctype-system="http://www.w3.org/TR/html4/strict.dtd" />

View File

@ -26,7 +26,7 @@
<xsl:output
method="html"
encoding="utf-8"
media-type="text/html; charset=UTF-8"
media-type="text/html"
indent="yes"
doctype-public="-//W3C//DTD HTML 4.01//EN"
doctype-system="http://www.w3.org/TR/html4/strict.dtd" />

View File

@ -26,7 +26,7 @@
<xsl:output
method="html"
encoding="utf-8"
media-type="text/html; charset=UTF-8"
media-type="text/html"
indent="yes"
doctype-public="-//W3C//DTD HTML 4.01//EN"
doctype-system="http://www.w3.org/TR/html4/strict.dtd" />

View File

@ -27,7 +27,7 @@
<xsl:output
method="html"
encoding="utf-8"
media-type="text/html; charset=UTF-8"
media-type="text/html"
indent="yes"
doctype-public="-//W3C//DTD HTML 4.01//EN"
doctype-system="http://www.w3.org/TR/html4/strict.dtd" />

View File

@ -26,7 +26,7 @@
method="html"
indent="yes"
encoding="utf-8"
media-type="text/html; charset=UTF-8"
media-type="text/html"
doctype-public="-//W3C//DTD HTML 4.01//EN"
doctype-system="http://www.w3.org/TR/html4/strict.dtd" />