You are viewing a plain text version of this content. The canonical link for it is here.
Posted to solr-commits@lucene.apache.org by ho...@apache.org on 2009/12/09 00:06:24 UTC
svn commit: r888622 - in /lucene/solr/trunk: CHANGES.txt
src/common/org/apache/solr/common/util/DOMUtil.java
Author: hossman
Date: Tue Dec 8 23:06:23 2009
New Revision: 888622
URL: http://svn.apache.org/viewvc?rev=888622&view=rev
Log:
SOLR-1635: Fixed error message when numeric values can't be parsed by DOMUtils
Modified:
lucene/solr/trunk/CHANGES.txt
lucene/solr/trunk/src/common/org/apache/solr/common/util/DOMUtil.java
Modified: lucene/solr/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/lucene/solr/trunk/CHANGES.txt?rev=888622&r1=888621&r2=888622&view=diff
==============================================================================
--- lucene/solr/trunk/CHANGES.txt (original)
+++ lucene/solr/trunk/CHANGES.txt Tue Dec 8 23:06:23 2009
@@ -117,6 +117,9 @@
in a multivalued field when term positions (term vectors) are stored.
(Chris Harris via yonik)
+* SOLR-1635: Fixed error message when numeric values can't be parsed by
+ DOMUtils - notably for plugin init params in solrconfig.xml.
+ (hossman)
Other Changes
----------------------
Modified: lucene/solr/trunk/src/common/org/apache/solr/common/util/DOMUtil.java
URL: http://svn.apache.org/viewvc/lucene/solr/trunk/src/common/org/apache/solr/common/util/DOMUtil.java?rev=888622&r1=888621&r2=888622&view=diff
==============================================================================
--- lucene/solr/trunk/src/common/org/apache/solr/common/util/DOMUtil.java (original)
+++ lucene/solr/trunk/src/common/org/apache/solr/common/util/DOMUtil.java Tue Dec 8 23:06:23 2009
@@ -108,40 +108,60 @@
return lst;
}
-
+ /**
+ * Examines a Node from the DOM representation of a NamedList and adds the
+ * contents of that node to both the specified NamedList and List passed
+ * as arguments.
+ *
+ * @param nd The Node whose type will be used to determine how to parse the
+ * text content. If there is a 'name' attribute it will be used
+ * when adding to the NamedList
+ * @param nlst A NamedList to add the item to with name if application.
+ * If this param is null it will be ignored.
+ * @param arr A List to add the item to.
+ * If this param is null it will be ignored.
+ */
@SuppressWarnings("unchecked")
public static void addToNamedList(Node nd, NamedList nlst, List arr) {
// Nodes often include whitespace, etc... so just return if this
// is not an Element.
if (nd.getNodeType() != Node.ELEMENT_NODE) return;
- String type = nd.getNodeName();
+ final String type = nd.getNodeName();
- String name = null;
- if (nd.hasAttributes()) {
- NamedNodeMap attrs = nd.getAttributes();
- Node nameNd = attrs.getNamedItem("name");
- if (nameNd != null) name=nameNd.getNodeValue();
- }
+ final String name = getAttr(nd, "name");
Object val=null;
- if ("str".equals(type)) {
- val = getText(nd);
- } else if ("int".equals(type)) {
- val = Integer.valueOf(getText(nd));
- } else if ("long".equals(type)) {
- val = Long.valueOf(getText(nd));
- } else if ("float".equals(type)) {
- val = Float.valueOf(getText(nd));
- } else if ("double".equals(type)) {
- val = Double.valueOf(getText(nd));
- } else if ("bool".equals(type)) {
- val = StrUtils.parseBool(getText(nd));
- } else if ("lst".equals(type)) {
+ if ("lst".equals(type)) {
val = childNodesToNamedList(nd);
} else if ("arr".equals(type)) {
val = childNodesToList(nd);
+ } else {
+ final String textValue = getText(nd);
+ try {
+ if ("str".equals(type)) {
+ val = textValue;
+ } else if ("int".equals(type)) {
+ val = Integer.valueOf(textValue);
+ } else if ("long".equals(type)) {
+ val = Long.valueOf(textValue);
+ } else if ("float".equals(type)) {
+ val = Float.valueOf(textValue);
+ } else if ("double".equals(type)) {
+ val = Double.valueOf(textValue);
+ } else if ("bool".equals(type)) {
+ val = StrUtils.parseBool(textValue);
+ }
+ // :NOTE: Unexpected Node names are ignored
+ // :TODO: should we generate an error here?
+ } catch (NumberFormatException nfe) {
+ throw new SolrException
+ (SolrException.ErrorCode.SERVER_ERROR,
+ "Value " + (null != name ? ("of '" +name+ "' ") : "") +
+ "can not be parsed as '" +type+ "': \"" + textValue + "\"",
+ nfe);
+ }
}
if (nlst != null) nlst.add(name,val);