Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.solr.response;
import static org.apache.solr.common.params.CommonParams.NAME;
import java.io.IOException;
import java.io.Writer;
import java.lang.invoke.MethodHandles;
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import org.apache.solr.common.SolrDocument;
import org.apache.solr.common.util.NamedList;
import org.apache.solr.common.util.SimpleOrderedMap;
import org.apache.solr.common.util.XML;
import org.apache.solr.request.SolrQueryRequest;
import org.apache.solr.schema.FieldType;
import org.apache.solr.schema.IndexSchema;
import org.apache.solr.schema.SimilarityFactory;
import org.apache.solr.search.ReturnFields;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* @lucene.internal
*/
public class SchemaXmlWriter extends TextResponseWriter {
private static final Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
private static final char[] XML_DECLARATION =
"".toCharArray();
private static final char[] MANAGED_SCHEMA_DO_NOT_EDIT_WARNING =
"".toCharArray();
private boolean emitManagedSchemaDoNotEditWarning = false;
public void setEmitManagedSchemaDoNotEditWarning(boolean emitManagedSchemaDoNotEditWarning) {
this.emitManagedSchemaDoNotEditWarning = emitManagedSchemaDoNotEditWarning;
}
public static void writeResponse(Writer writer, SolrQueryRequest req, SolrQueryResponse rsp)
throws IOException {
SchemaXmlWriter schemaXmlWriter = null;
try {
schemaXmlWriter = new SchemaXmlWriter(writer, req, rsp);
schemaXmlWriter.writeResponse();
} finally {
if (null != schemaXmlWriter) {
schemaXmlWriter.close();
}
}
}
public SchemaXmlWriter(Writer writer, SolrQueryRequest req, SolrQueryResponse rsp) {
super(writer, req, rsp);
}
@SuppressWarnings({"unchecked"})
public void writeResponse() throws IOException {
writer.write(XML_DECLARATION);
if (emitManagedSchemaDoNotEditWarning) {
if (doIndent) {
writer.write('\n');
}
writer.write(MANAGED_SCHEMA_DO_NOT_EDIT_WARNING);
}
Map schemaProperties =
(Map) rsp.getValues().get(IndexSchema.SCHEMA);
openStartTag(IndexSchema.SCHEMA);
writeAttr(IndexSchema.NAME, schemaProperties.get(IndexSchema.NAME).toString());
writeAttr(IndexSchema.VERSION, schemaProperties.get(IndexSchema.VERSION).toString());
closeStartTag(false);
incLevel();
for (Map.Entry entry : schemaProperties.entrySet()) {
String schemaPropName = entry.getKey();
Object val = entry.getValue();
if (schemaPropName.equals(IndexSchema.NAME) || schemaPropName.equals(IndexSchema.VERSION)) {
continue;
}
if (schemaPropName.equals(IndexSchema.UNIQUE_KEY)) {
openStartTag(IndexSchema.UNIQUE_KEY);
closeStartTag(false);
writer.write(val.toString());
endTag(IndexSchema.UNIQUE_KEY, false);
} else if (schemaPropName.equals(IndexSchema.SIMILARITY)) {
writeSimilarity((SimpleOrderedMap