Search in sources :

Example 6 with XMLLoader

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"));
}
Also used : CSVLoader(org.apache.solr.handler.loader.CSVLoader) JsonLoader(org.apache.solr.handler.loader.JsonLoader) JavabinLoader(org.apache.solr.handler.loader.JavabinLoader) ModifiableSolrParams(org.apache.solr.common.params.ModifiableSolrParams) XMLLoader(org.apache.solr.handler.loader.XMLLoader)

Example 7 with XMLLoader

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&amp;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());
}
Also used : SolrInputDocument(org.apache.solr.common.SolrInputDocument) XMLStreamReader(javax.xml.stream.XMLStreamReader) StringReader(java.io.StringReader) XMLLoader(org.apache.solr.handler.loader.XMLLoader) Test(org.junit.Test)

Example 8 with XMLLoader

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();
}
Also used : LocalSolrQueryRequest(org.apache.solr.request.LocalSolrQueryRequest) SolrQueryRequest(org.apache.solr.request.SolrQueryRequest) SolrQueryResponse(org.apache.solr.response.SolrQueryResponse) BufferingRequestProcessor(org.apache.solr.update.processor.BufferingRequestProcessor) AddUpdateCommand(org.apache.solr.update.AddUpdateCommand) XMLLoader(org.apache.solr.handler.loader.XMLLoader) ContentStreamBase(org.apache.solr.common.util.ContentStreamBase) Test(org.junit.Test)

Aggregations

XMLLoader (org.apache.solr.handler.loader.XMLLoader)8 Test (org.junit.Test)6 ContentStreamBase (org.apache.solr.common.util.ContentStreamBase)4 SolrQueryResponse (org.apache.solr.response.SolrQueryResponse)4 SolrQueryRequest (org.apache.solr.request.SolrQueryRequest)3 AddUpdateCommand (org.apache.solr.update.AddUpdateCommand)3 BufferingRequestProcessor (org.apache.solr.update.processor.BufferingRequestProcessor)3 StringReader (java.io.StringReader)2 XMLStreamReader (javax.xml.stream.XMLStreamReader)2 SolrInputDocument (org.apache.solr.common.SolrInputDocument)2 ModifiableSolrParams (org.apache.solr.common.params.ModifiableSolrParams)2 CSVLoader (org.apache.solr.handler.loader.CSVLoader)2 JavabinLoader (org.apache.solr.handler.loader.JavabinLoader)2 JsonLoader (org.apache.solr.handler.loader.JsonLoader)2 OutputStream (java.io.OutputStream)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 ByteArrayOutputStream (org.apache.commons.io.output.ByteArrayOutputStream)1 RequestWriter (org.apache.solr.client.solrj.request.RequestWriter)1 UpdateRequest (org.apache.solr.client.solrj.request.UpdateRequest)1