Apache Lucene open-source search software
SOLR-3087: Fixed DOMUtil so that code doing attribute validation will automaticly ignore nodes in the resserved "xml" prefix
Chris M. Hostetterf5b5835dee74
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txtindex 3be9142dffe..43a1fde3208 100644--- a/solr/CHANGES.txt+++ b/solr/CHANGES.txt@@ -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----------------------diff --git a/solr/core/src/java/org/apache/solr/util/DOMUtil.java b/solr/core/src/java/org/apache/solr/util/DOMUtil.javaindex 969d01eac74..e09500af10d 100644--- a/solr/core/src/java/org/apache/solr/util/DOMUtil.java+++ b/solr/core/src/java/org/apache/solr/util/DOMUtil.java@@ -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;diff --git a/solr/core/src/test-files/solr/collection1/conf/schema-snippet-field.xml b/solr/core/src/test-files/solr/collection1/conf/schema-snippet-field.xmlnew file mode 100644index 00000000000..9e0d29f3e20--- /dev/null+++ b/solr/core/src/test-files/solr/collection1/conf/schema-snippet-field.xml@@ -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" />diff --git a/solr/core/src/test-files/solr/collection1/conf/schema-snippet-type.xml b/solr/core/src/test-files/solr/collection1/conf/schema-snippet-type.xmlnew file mode 100644index 00000000000..bfbd3334204--- /dev/null+++ b/solr/core/src/test-files/solr/collection1/conf/schema-snippet-type.xml@@ -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"/>diff --git a/solr/core/src/test-files/solr/collection1/conf/schema-xinclude.xml b/solr/core/src/test-files/solr/collection1/conf/schema-xinclude.xmlnew file mode 100644index 00000000000..17a7b9fb4ec--- /dev/null+++ b/solr/core/src/test-files/solr/collection1/conf/schema-xinclude.xml@@ -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>diff --git a/solr/core/src/test-files/solr/collection1/conf/solrconfig-snippet-processor.xml b/solr/core/src/test-files/solr/collection1/conf/solrconfig-snippet-processor.xmlnew file mode 100644index 00000000000..8c76857f32b--- /dev/null+++ b/solr/core/src/test-files/solr/collection1/conf/solrconfig-snippet-processor.xml@@ -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>diff --git a/solr/core/src/test-files/solr/collection1/conf/solrconfig-xinclude.xml b/solr/core/src/test-files/solr/collection1/conf/solrconfig-xinclude.xmlindex 5135a7e1821..4162e4fefb3 100644--- a/solr/core/src/test-files/solr/collection1/conf/solrconfig-xinclude.xml+++ b/solr/core/src/test-files/solr/collection1/conf/solrconfig-xinclude.xml@@ -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>diff --git a/solr/core/src/test/org/apache/solr/core/TestXIncludeConfig.java b/solr/core/src/test/org/apache/solr/core/TestXIncludeConfig.javaindex aaf659c3cc3..ed4b4990f3a 100644--- a/solr/core/src/test/org/apache/solr/core/TestXIncludeConfig.java+++ b/solr/core/src/test/org/apache/solr/core/TestXIncludeConfig.java@@ -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;@Overridepublic String getSchemaFile() {- return "schema.xml";+ return "schema-xinclude.xml";}//public String getSolrConfigFile() { return "solrconfig.xml"; }@@ -43,28 +41,35 @@ public class TestXIncludeConfig extends AbstractSolrTestCase {@Overridepublic void setUp() throws Exception {- supports = true;javax.xml.parsers.DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();try {//see whether it even makes sense to run this testdbf.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"));}}