From e1a8f5e8b28ca5aaace771464867d06dd3cdf358 Mon Sep 17 00:00:00 2001 From: Noble Paul Date: Mon, 22 Jun 2009 04:39:58 +0000 Subject: [PATCH] SOLR-1235 disallow period (.) in entity names git-svn-id: https://svn.apache.org/repos/asf/lucene/solr/trunk@787139 13f79535-47bb-0310-9956-ffa450edef68 --- contrib/dataimporthandler/CHANGES.txt | 2 ++ .../solr/handler/dataimport/DataConfig.java | 20 +++++++++++-------- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/contrib/dataimporthandler/CHANGES.txt b/contrib/dataimporthandler/CHANGES.txt index 3a396fac39c..2bff8977918 100644 --- a/contrib/dataimporthandler/CHANGES.txt +++ b/contrib/dataimporthandler/CHANGES.txt @@ -147,6 +147,8 @@ New Features 34.SOLR-1230: Enhanced dataimport.jsp to work with all DataImportHandler request handler configurations, rather than just a hardcoded /dataimport handler. (ehatcher) + +35.SOLR-1235: disallow period (.) in entity names (noble) Optimizations ---------------------- diff --git a/contrib/dataimporthandler/src/main/java/org/apache/solr/handler/dataimport/DataConfig.java b/contrib/dataimporthandler/src/main/java/org/apache/solr/handler/dataimport/DataConfig.java index 7e0bbb0ec1a..102b9725474 100644 --- a/contrib/dataimporthandler/src/main/java/org/apache/solr/handler/dataimport/DataConfig.java +++ b/contrib/dataimporthandler/src/main/java/org/apache/solr/handler/dataimport/DataConfig.java @@ -21,6 +21,7 @@ import org.w3c.dom.NamedNodeMap; import org.w3c.dom.Node; import org.w3c.dom.NodeList; import org.apache.solr.schema.SchemaField; +import static org.apache.solr.handler.dataimport.DataImportHandlerException.SEVERE; import java.util.*; @@ -111,8 +112,14 @@ public class DataConfig { public Entity(Element element) { name = getStringAttribute(element, NAME, null); + if(name == null){ + throw new DataImportHandlerException(SEVERE, "Entity must have name '" ); + } + if(name.indexOf(".") != -1){ + throw new DataImportHandlerException(SEVERE, "Entity name must not have period (.): '" + name); + } if (RESERVED_WORDS.contains(name)) { - throw new DataImportHandlerException(DataImportHandlerException.SEVERE, "Entity name : '" + name + throw new DataImportHandlerException(SEVERE, "Entity name : '" + name + "' is a reserved keyword. Reserved words are: " + RESERVED_WORDS); } pk = getStringAttribute(element, "pk", null); @@ -208,7 +215,7 @@ public class DataConfig { this.name = getStringAttribute(e, DataImporter.NAME, null); this.column = getStringAttribute(e, DataImporter.COLUMN, null); if (column == null) { - throw new DataImportHandlerException(DataImportHandlerException.SEVERE, "Field must have a column attribute"); + throw new DataImportHandlerException(SEVERE, "Field must have a column attribute"); } this.boost = Float.parseFloat(getStringAttribute(e, "boost", "1.0f")); allAttributes.putAll(getAllAttributes(e)); @@ -225,7 +232,7 @@ public class DataConfig { public void readFromXml(Element e) { List n = getChildNodes(e, "document"); if (n.isEmpty()) { - throw new DataImportHandlerException(DataImportHandlerException.SEVERE, "DataImportHandler " + + throw new DataImportHandlerException(SEVERE, "DataImportHandler " + "configuration file must have one node."); } document = new Document(n.get(0)); @@ -243,7 +250,7 @@ public class DataConfig { String clz = getStringAttribute(element, CLASS, null); if (func == null || clz == null){ throw new DataImportHandlerException( - DataImportHandlerException.SEVERE, + SEVERE, " must have a 'name' and 'class' attributes"); } else { functions.add(getAllAttributes(element)); @@ -317,10 +324,6 @@ public class DataConfig { public static final String NAME = "name"; - public static final String SCRIPT_LANG = "scriptlanguage"; - - public static final String SCRIPT_NAME = "scriptname"; - public static final String PROCESSOR = "processor"; /** @@ -347,6 +350,7 @@ public class DataConfig { RESERVED_WORDS.add("delta"); RESERVED_WORDS.add("functions"); RESERVED_WORDS.add("session"); + RESERVED_WORDS.add(SolrWriter.LAST_INDEX_KEY); } }