SOLR-427: Allow IndexSchema to be loadable from an InputStream.

git-svn-id: https://svn.apache.org/repos/asf/lucene/solr/trunk@602443 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Erik Hatcher 2007-12-08 10:42:31 +00:00
parent 9b79f1af3a
commit bd0e6827f2
1 changed files with 14 additions and 5 deletions

View File

@ -55,6 +55,8 @@ import java.util.logging.Logger;
* @version $Id$
*/
public final class IndexSchema {
public static final String DEFAULT_SCHEMA_FILE = "schema.xml";
final static Logger log = Logger.getLogger(IndexSchema.class.getName());
private final SolrConfig solrConfig;
private final String schemaFile;
@ -67,10 +69,16 @@ public final class IndexSchema {
*
* @see Config#openResource
*/
@Deprecated
public IndexSchema(SolrConfig solrConfig, String schemaFile) {
this(solrConfig, solrConfig.getResourceLoader().openResource(schemaFile));
}
public IndexSchema(SolrConfig solrConfig, InputStream is) {
this.solrConfig = solrConfig;
this.schemaFile=schemaFile;
readSchema(solrConfig);
this.schemaFile = DEFAULT_SCHEMA_FILE;
readSchema(is);
SolrResourceLoader loader = solrConfig.getResourceLoader();
loader.inform( loader );
@ -79,11 +87,13 @@ public final class IndexSchema {
public SolrConfig getSolrConfig() {
return solrConfig;
}
/**
* Direct access to the InputStream for the schemaFile used by this instance.
*
* @see Config#openResource
*/
@Deprecated
public InputStream getInputStream() {
return solrConfig.getResourceLoader().openResource(schemaFile);
}
@ -295,8 +305,7 @@ public final class IndexSchema {
}
}
private void readSchema(final SolrConfig solrConfig) {
private void readSchema(InputStream is) {
log.info("Reading Solr Schema");
try {
@ -305,7 +314,7 @@ public final class IndexSchema {
Document document = builder.parse(getInputStream());
***/
Config schemaConf = new Config("schema", getInputStream(), "/schema/");
Config schemaConf = new Config("schema", is, "/schema/");
Document document = schemaConf.getDocument();
final XPath xpath = schemaConf.getXPath();