use of org.apache.solr.handler.loader.XMLLoader in project lucene-solr by apache.
the class MetricsCollectorHandler method init.
@Override
public void init(NamedList initArgs) {
super.init(initArgs);
if (initArgs != null) {
params = SolrParams.toSolrParams(initArgs);
} else {
params = new ModifiableSolrParams();
}
loaders.put("application/xml", new XMLLoader().init(params));
loaders.put("application/json", new JsonLoader().init(params));
loaders.put("application/csv", new CSVLoader().init(params));
loaders.put("application/javabin", new JavabinLoader().init(params));
loaders.put("text/csv", loaders.get("application/csv"));
loaders.put("text/xml", loaders.get("application/xml"));
loaders.put("text/json", loaders.get("application/json"));
}
use of org.apache.solr.handler.loader.XMLLoader in project lucene-solr by apache.
the class XmlUpdateRequestHandlerTest method testReadDoc.
@Test
public void testReadDoc() throws Exception {
String xml = "<doc boost=\"5.5\">" + " <field name=\"id\" boost=\"2.2\">12345</field>" + " <field name=\"name\">kitten</field>" + " <field name=\"cat\" boost=\"3\">aaa</field>" + " <field name=\"cat\" boost=\"4\">bbb</field>" + " <field name=\"cat\" boost=\"5\">bbb</field>" + " <field name=\"ab\">a&b</field>" + "</doc>";
XMLStreamReader parser = inputFactory.createXMLStreamReader(new StringReader(xml));
// read the START document...
parser.next();
//null for the processor is all right here
XMLLoader loader = new XMLLoader();
SolrInputDocument doc = loader.readDoc(parser);
// Read values
assertEquals("12345", doc.getField("id").getValue());
assertEquals("kitten", doc.getField("name").getValue());
// read something with escaped characters
assertEquals("a&b", doc.getField("ab").getValue());
Collection<Object> out = doc.getField("cat").getValues();
assertEquals(3, out.size());
assertEquals("[aaa, bbb, bbb]", out.toString());
}
use of org.apache.solr.handler.loader.XMLLoader in project lucene-solr by apache.
the class XsltUpdateRequestHandlerTest method testEntities.
@Test
public void testEntities() throws Exception {
// use a binary file, so when it's loaded fail with XML eror:
String file = getFile("mailing_lists.pdf").toURI().toASCIIString();
String xml = "<?xml version=\"1.0\"?>" + "<!DOCTYPE foo [" + // check that external entities are not resolved!
"<!ENTITY bar SYSTEM \"" + file + "\">" + // but named entities should be
"<!ENTITY wacky \"zzz\">" + "]>" + "<random>" + " &bar;" + " <document>" + " <node name=\"id\" value=\"12345\"/>" + " <node name=\"foo_s\" value=\"&wacky;\"/>" + " </document>" + "</random>";
SolrQueryRequest req = req(CommonParams.TR, "xsl-update-handler-test.xsl");
SolrQueryResponse rsp = new SolrQueryResponse();
BufferingRequestProcessor p = new BufferingRequestProcessor(null);
XMLLoader loader = new XMLLoader().init(null);
loader.load(req, rsp, new ContentStreamBase.StringStream(xml), p);
AddUpdateCommand add = p.addCommands.get(0);
assertEquals("12345", add.solrDoc.getField("id").getFirstValue());
assertEquals("zzz", add.solrDoc.getField("foo_s").getFirstValue());
req.close();
}
Aggregations