SOLR-3087: Fixed DOMUtil so that code doing attribute validation will automaticly ignore nodes in the resserved "xml" prefix

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1387778 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Chris M. Hostetter 2012-09-19 21:34:10 +00:00
parent 9be371a198
commit f5b5835dee
8 changed files with 77 additions and 18 deletions

View File

@ -251,6 +251,11 @@ Bug Fixes
* SOLR-3850: DataImportHandler "cacheKey" parameter was incorrectly renamed "cachePk"
(James Dyer)
* SOLR-3087: Fixed DOMUtil so that code doing attribute validation will
automaticly ignore nodes in the resserved "xml" prefix - in particular this
fixes some bugs related to xinclude and fieldTypes.
(Amit Nithian, hossman)
Other Changes
----------------------

View File

@ -31,6 +31,8 @@ import org.w3c.dom.NodeList;
*/
public class DOMUtil {
public static final String XML_RESERVED_PREFIX = "xml";
public static Map<String,String> toMap(NamedNodeMap attrs) {
return toMapExcept(attrs);
}
@ -39,6 +41,10 @@ public class DOMUtil {
Map<String,String> args = new HashMap<String,String>();
outer: for (int j=0; j<attrs.getLength(); j++) {
Node attr = attrs.item(j);
// automaticly exclude things in the xml namespace, ie: xml:base
if (XML_RESERVED_PREFIX.equals(attr.getPrefix())) continue outer;
String attrName = attr.getNodeName();
for (String ex : exclusions)
if (ex.equals(attrName)) continue outer;

View File

@ -0,0 +1,3 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!-- example of a snippet of xml for use with xml includes -->
<field name="field-included" type="ft-included" />

View File

@ -0,0 +1,3 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!-- example of a snippet of xml for use with xml includes -->
<fieldType name="ft-included" class="solr.StrField" sortMissingLast="true" omitNorms="true"/>

View File

@ -0,0 +1,26 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!--
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<schema name="xinclude" version="1.5" xmlns:xi="http://www.w3.org/2001/XInclude">
<types>
<fieldType name="string" class="solr.StrField"/>
<xi:include href="schema-snippet-type.xml" />
</types>
<fields>
<xi:include href="schema-snippet-field.xml" />
</fields>
</schema>

View File

@ -0,0 +1,6 @@
<!-- snippet file used via xml xinclude -->
<processor class="solr.RegexReplaceProcessorFactory">
<str name="fieldName">field-included</str>
<str name="pattern">x</str>
<str name="replacement">x_x</str>
</processor>

View File

@ -25,4 +25,9 @@
<xi:include href="solrconfig-reqHandler.incl" xmlns:xi="http://www.w3.org/2001/XInclude"/>
</xi:fallback>
</xi:include>
<updateRequestProcessorChain name="special-include" xmlns:xi="http://www.w3.org/2001/XInclude">
<xi:include href="solrconfig-snippet-processor.xml" />
</updateRequestProcessorChain>
</config>

View File

@ -17,22 +17,20 @@ package org.apache.solr.core;
* limitations under the License.
*/
import org.apache.solr.request.SolrRequestHandler;
import org.apache.solr.update.processor.UpdateRequestProcessorChain;
import org.apache.solr.update.processor.RegexReplaceProcessorFactory;
import org.apache.solr.util.AbstractSolrTestCase;
import javax.xml.parsers.DocumentBuilderFactory;
import org.junit.Assume;
/**
*
*
**/
public class TestXIncludeConfig extends AbstractSolrTestCase {
protected boolean supports;
@Override
public String getSchemaFile() {
return "schema.xml";
return "schema-xinclude.xml";
}
//public String getSolrConfigFile() { return "solrconfig.xml"; }
@ -43,28 +41,35 @@ public class TestXIncludeConfig extends AbstractSolrTestCase {
@Override
public void setUp() throws Exception {
supports = true;
javax.xml.parsers.DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
try {
//see whether it even makes sense to run this test
dbf.setXIncludeAware(true);
dbf.setNamespaceAware(true);
} catch (UnsupportedOperationException e) {
supports = false;
Assume.assumeTrue(false);
}
super.setUp();
}
public void testXInclude() throws Exception {
//Figure out whether this JVM supports XInclude anyway, if it doesn't then don't run this test????
// TODO: figure out a better way to handle this.
if (supports == true){
SolrCore core = h.getCore();
SolrRequestHandler solrRequestHandler = core.getRequestHandler("includedHandler");
assertNotNull("Solr Req Handler is null", solrRequestHandler);
} else {
log.info("Didn't run testXInclude, because this XML DocumentBuilderFactory doesn't support it");
}
SolrCore core = h.getCore();
assertNotNull("includedHandler is null",
core.getRequestHandler("includedHandler"));
UpdateRequestProcessorChain chain
= core.getUpdateProcessingChain("special-include");
assertNotNull("chain is missing included processor", chain);
assertEquals("chain with inclued processor is wrong size",
1, chain.getFactories().length);
assertEquals("chain has wrong included processor",
RegexReplaceProcessorFactory.class,
chain.getFactories()[0].getClass());
assertNotNull("ft-included is null",
core.getSchema().getFieldTypeByName("ft-included"));
assertNotNull("field-included is null",
core.getSchema().getFieldOrNull("field-included"));
}
}