SOLR-1084 -- Better error reporting when entity name is a reserved word and when data-config.xml is missing the root node

git-svn-id: https://svn.apache.org/repos/asf/lucene/solr/trunk@757691 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Shalin Shekhar Mangar 2009-03-24 09:07:47 +00:00
parent 5b885e1642
commit 96a3f027ce
3 changed files with 24 additions and 3 deletions

View File

@ -229,6 +229,10 @@ Other
5. SOLR-1027: Alias the 'dataimporter' namespace to a shorter name 'dih'.
(Noble Paul via shalin)
6. SOLR-1084: Better error reporting when entity name is a reserved word and data-config.xml root node
is not <dataConfig>.
(Noble Paul via shalin)
================== Release 1.3.0 20080915 ==================
Status

View File

@ -111,6 +111,10 @@ public class DataConfig {
public Entity(Element element) {
name = getStringAttribute(element, NAME, null);
if (RESERVED_WORDS.contains(name)) {
throw new DataImportHandlerException(DataImportHandlerException.SEVERE, "Entity name : '" + name
+ "' is a reserved keyword. Reserved words are: " + RESERVED_WORDS);
}
pk = getStringAttribute(element, "pk", null);
docRoot = getStringAttribute(element, ROOT_ENTITY, null);
proc = getStringAttribute(element, PROCESSOR, null);
@ -335,4 +339,14 @@ public class DataConfig {
public static final String DATA_SRC = "dataSource";
private static final Set<String> RESERVED_WORDS = new HashSet<String>();
static{
RESERVED_WORDS.add(IMPORTER_NS);
RESERVED_WORDS.add(IMPORTER_NS_SHORT);
RESERVED_WORDS.add("request");
RESERVED_WORDS.add("delta");
RESERVED_WORDS.add("functions");
RESERVED_WORDS.add("session");
}
}

View File

@ -26,6 +26,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;
import org.xml.sax.InputSource;
import javax.xml.parsers.DocumentBuilder;
@ -153,9 +154,11 @@ public class DataImporter {
configFile)));
config = new DataConfig();
config.readFromXml((Element) document.getElementsByTagName("dataConfig")
.item(0));
NodeList elems = document.getElementsByTagName("dataConfig");
if(elems == null || elems.getLength() == 0) {
throw new DataImportHandlerException(DataImportHandlerException.SEVERE, "the root node '<dataConfig>' is missing");
}
config.readFromXml((Element) elems.item(0));
LOG.info("Data Configuration loaded successfully");
} catch (Exception e) {
SolrConfig.severeErrors.add(e);