Rolling back commit on SOLR-614 pending discussion and consensus.

git-svn-id: https://svn.apache.org/repos/asf/lucene/solr/trunk@683315 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Shalin Shekhar Mangar 2008-08-06 16:10:40 +00:00
parent d816b977b4
commit 0e1915b38a
4 changed files with 4 additions and 145 deletions

View File

@ -345,9 +345,6 @@ New Features
69. SOLR-506: Emitting HTTP Cache headers can be enabled or disabled through configuration 69. SOLR-506: Emitting HTTP Cache headers can be enabled or disabled through configuration
on a per-handler basis (shalin) on a per-handler basis (shalin)
70. SOLR-614: Allow components to be configured with NamedListInitializedPlugin using arbitary XML in solrconfig
without using XPath (Noble Paul, shalin)
Changes in runtime behavior Changes in runtime behavior
1. SOLR-559: use Lucene updateDocument, deleteDocuments methods. This 1. SOLR-559: use Lucene updateDocument, deleteDocuments methods. This

View File

@ -89,8 +89,7 @@ public class DOMUtil {
// Should these be moved to Config? Should all of these things? // Should these be moved to Config? Should all of these things?
////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////
public static NamedList<Object> childNodesToNamedList(Node nd) { public static NamedList<Object> childNodesToNamedList(Node nd) {
NamedList<Object> nl = nodesToNamedList(nd.getChildNodes()); return nodesToNamedList(nd.getChildNodes());
return nl;
} }
public static List childNodesToList(Node nd) { public static List childNodesToList(Node nd) {
@ -147,51 +146,12 @@ public class DOMUtil {
val = childNodesToNamedList(nd); val = childNodesToNamedList(nd);
} else if ("arr".equals(type)) { } else if ("arr".equals(type)) {
val = childNodesToList(nd); val = childNodesToList(nd);
} else {
name = type;
val = readFlexibleNamedList(nd);
} }
if (nlst != null) nlst.add(name,val); if (nlst != null) nlst.add(name,val);
if (arr != null) arr.add(val); if (arr != null) arr.add(val);
} }
private static Object readFlexibleNamedList(Node nd) {
if (hasChildren(nd)) {
NamedList nl = new NamedList<Object>();
readAttributes(nd, nl);
NodeList nlist = nd.getChildNodes();
if (nlist != null) {
for (int i = 0; i < nlist.getLength(); i++) {
if (nlist.item(i).getNodeType() == Node.ELEMENT_NODE)
addToNamedList(nlist.item(i), nl, null);
}
}
return nl;
} else {
return getText(nd);
}
}
private static void readAttributes(Node nd, NamedList nl) {
NamedNodeMap attrs = nd.getAttributes();
if (attrs != null) {
for (int i = 0; i < attrs.getLength(); i++) {
Node nameNd = attrs.item(i);
nl.add("@"+nameNd.getNodeName(), nameNd.getNodeValue());
}
}
}
private static boolean hasChildren(Node nd){
if(nd.hasAttributes()) return true;
NodeList nlst = nd.getChildNodes();
for (int i=0; i<nlst.getLength(); i++) {
if(nlst.item(i).getNodeType() == Node.ELEMENT_NODE) return true;
}
return false;
}
/** /**
* Drop in replacement for Node.getTextContent(). * Drop in replacement for Node.getTextContent().
* *

View File

@ -18,7 +18,6 @@
package org.apache.solr.core; package org.apache.solr.core;
import org.apache.solr.common.util.NamedList; import org.apache.solr.common.util.NamedList;
import org.apache.solr.common.util.DOMUtil;
import org.apache.solr.handler.PingRequestHandler; import org.apache.solr.handler.PingRequestHandler;
import org.apache.solr.request.LocalSolrQueryRequest; import org.apache.solr.request.LocalSolrQueryRequest;
import org.apache.solr.request.SolrQueryRequest; import org.apache.solr.request.SolrQueryRequest;
@ -28,13 +27,13 @@ import org.apache.solr.update.SolrIndexConfig;
import org.apache.lucene.search.BooleanQuery; import org.apache.lucene.search.BooleanQuery;
import org.w3c.dom.Node; import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.xml.sax.SAXException; import org.xml.sax.SAXException;
import javax.xml.parsers.ParserConfigurationException; import javax.xml.parsers.ParserConfigurationException;
import javax.xml.xpath.XPathConstants;
import java.util.*; import java.util.Collection;
import java.util.HashSet;
import java.util.StringTokenizer;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.regex.Pattern; import java.util.regex.Pattern;
import java.util.regex.Matcher; import java.util.regex.Matcher;
@ -211,32 +210,6 @@ public class SolrConfig extends Config {
return new LocalSolrQueryRequest(core, pingQueryParams); return new LocalSolrQueryRequest(core, pingQueryParams);
} }
/**
* Get a list of NamedList, one for each node matched by the given XPath
*
* @param xpath the XPath to match
* @return a list of NamedList instances corresponding to each node matched by the given XPath
*/
public List<NamedList> getAllNodesAsNamedList(String xpath) {
NodeList nodes = (NodeList) evaluate(xpath, XPathConstants.NODESET);
List<NamedList> result = new ArrayList<NamedList>();
for (int i = 0; i < nodes.getLength(); i++) {
result.add(DOMUtil.childNodesToNamedList(nodes.item(i)));
}
return result;
}
/**
* Get the NamedList corresponding to the first node matched by the given XPath
*
* @param xpath the XPath to match
* @return the NamedList corresponding to the first node matched by the given XPath
*/
public NamedList getNodeAsNamedList(String xpath) {
List<NamedList> list = getAllNodesAsNamedList(xpath);
return list.isEmpty() ? null : list.get(0);
}
public static class JmxConfiguration { public static class JmxConfiguration {
public boolean enabled = false; public boolean enabled = false;

View File

@ -1,71 +0,0 @@
package org.apache.solr.common.util;
import org.junit.Test;
import org.junit.Assert;
import org.xml.sax.InputSource;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
import javax.xml.parsers.DocumentBuilderFactory;
import java.io.StringReader;
public class TestDOMUtil {
@Test
public void readFlexiSchemaNodes() throws Exception {
String xml ="<root>\n" +
" <a>val a</a>\n" +
" <b>val b</b>\n" +
" <c>\n" +
" <d>val d</d>\n" +
" <e>val e</e>\n" +
" </c>\n" +
"</root>";
NamedList nl = DOMUtil.childNodesToNamedList(getRootNode(xml));
Assert.assertEquals("val a",nl.get("a"));
Assert.assertEquals("val b",nl.get("b"));
NamedList c = (NamedList) nl.get("c");
Assert.assertEquals("val d",c.get("d"));
Assert.assertEquals("val e",c.get("e"));
}
@Test
public void readFlexiSchemaNodesWithAttributes() throws Exception {
String xml ="<root>\n" +
" <defaults a=\"A\" b=\"B\" c=\"C\">\n" +
" <x>X1</x>\n" +
" <x>X2</x>\n" +
" </defaults>\n" +
"</root>";
NamedList nl = DOMUtil.childNodesToNamedList(getRootNode(xml));
NamedList defaults = (NamedList) nl.get("defaults");
Assert.assertEquals("A",defaults.get("@a"));
Assert.assertEquals("B",defaults.get("@b"));
Assert.assertEquals("C",defaults.get("@c"));
Assert.assertEquals("X1",defaults.getVal(3));
Assert.assertEquals("X2",defaults.getVal(4));
}
@Test
public void readFlexiSchemaNodesWithAttributesWithOldFormat() throws Exception {
String xml ="<root>\n" +
" <defaults a=\"A\" b=\"B\" c=\"C\">\n" +
" <str name=\"x\">X1</str>\n" +
" <str name=\"x\">X2</str>\n" +
" <bool name=\"boo\">true</bool>\n" +
" </defaults>\n" +
"</root>";
NamedList nl = DOMUtil.childNodesToNamedList(getRootNode(xml));
NamedList defaults = (NamedList) nl.get("defaults");
Assert.assertEquals("A",defaults.get("@a"));
Assert.assertEquals("B",defaults.get("@b"));
Assert.assertEquals("C",defaults.get("@c"));
Assert.assertEquals("X1",defaults.getVal(3));
Assert.assertEquals("X2",defaults.getVal(4));
Assert.assertEquals(Boolean.TRUE,defaults.get("boo"));
}
private Node getRootNode(String xml) throws Exception {
javax.xml.parsers.DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
Document doc = builder.parse(new InputSource(new StringReader(xml)));
return doc.getDocumentElement();
}
}