8138721: ElementTraversal: javadoc warning; also, hasFeature shall return true

Reviewed-by: lancea, dfuchs
This commit is contained in:
Joe Wang 2015-10-06 10:59:52 -07:00
parent df9e1bc8f7
commit 6b8fd86fa1
4 changed files with 41 additions and 16 deletions

View file

@ -101,7 +101,7 @@ public class CoreDOMImplementationImpl
* This is interpreted as "Version of the DOM API supported for the * This is interpreted as "Version of the DOM API supported for the
* specified Feature", and in Level 1 should be "1.0" * specified Feature", and in Level 1 should be "1.0"
* *
* @return true iff this implementation is compatable with the specified * @return true if this implementation is compatible with the specified
* feature and version. * feature and version.
*/ */
public boolean hasFeature(String feature, String version) { public boolean hasFeature(String feature, String version) {
@ -111,8 +111,7 @@ public class CoreDOMImplementationImpl
if (feature.startsWith("+")) { if (feature.startsWith("+")) {
feature = feature.substring(1); feature = feature.substring(1);
} }
return ( return (feature.equalsIgnoreCase("Core")
feature.equalsIgnoreCase("Core")
&& (anyVersion && (anyVersion
|| version.equals("1.0") || version.equals("1.0")
|| version.equals("2.0") || version.equals("2.0")
@ -123,7 +122,11 @@ public class CoreDOMImplementationImpl
|| version.equals("2.0") || version.equals("2.0")
|| version.equals("3.0"))) || version.equals("3.0")))
|| (feature.equalsIgnoreCase("LS") || (feature.equalsIgnoreCase("LS")
&& (anyVersion || version.equals("3.0"))); && (anyVersion
|| version.equals("3.0")))
|| (feature.equalsIgnoreCase("ElementTraversal")
&& (anyVersion
|| version.equals("1.0")));
} // hasFeature(String,String):boolean } // hasFeature(String,String):boolean

View file

@ -83,6 +83,9 @@ public class DOMImplementationImpl extends CoreDOMImplementationImpl
* specified feature and version. * specified feature and version.
*/ */
public boolean hasFeature(String feature, String version) { public boolean hasFeature(String feature, String version) {
if (feature == null || feature.length() == 0) {
return false;
}
boolean result = super.hasFeature(feature, version); boolean result = super.hasFeature(feature, version);
if (!result) { if (!result) {

View file

@ -50,7 +50,7 @@ package org.w3c.dom;
* elements of an element, for preprocessing before navigation. * elements of an element, for preprocessing before navigation.
* *
* @see * @see
* <a href='http://www.w3.org/TR/ElementTraversal/'><cite>Element Traversal Specification</cite></a>. * <a href='http://www.w3.org/TR/ElementTraversal/'><cite>Element Traversal Specification</cite></a>
* *
* @since 9 * @since 9
*/ */

View file

@ -31,15 +31,34 @@ import org.testng.Assert;
import org.testng.annotations.DataProvider; import org.testng.annotations.DataProvider;
import org.testng.annotations.Test; import org.testng.annotations.Test;
import org.w3c.dom.Document; import org.w3c.dom.Document;
import org.w3c.dom.DOMImplementation;
import org.w3c.dom.Element; import org.w3c.dom.Element;
import org.xml.sax.SAXException; import org.xml.sax.SAXException;
/* /*
* @bug 8135283 * @bug 8135283 8138721
* @summary Tests for the Element Traversal interface. * @summary Tests for the Element Traversal interface.
*/ */
public class ElementTraversal { public class ElementTraversal {
/*
Verifies that ElementTraversal is supported.
*/
@Test(dataProvider = "doc")
public void testHasFeature(Document doc) {
DOMImplementation di = doc.getImplementation();
//return false if feasure == null
Assert.assertFalse(di.hasFeature(null, null));
//A feature is supported without specifying version
Assert.assertTrue(di.hasFeature("ElementTraversal", null));
Assert.assertTrue(di.hasFeature("ElementTraversal", ""));
//ElementTraversal Version 1.0 is supported
Assert.assertTrue(di.hasFeature("ElementTraversal", "1.0"));
}
/* /*
Verifies the ElementTraversal interface by exercising all of its five Verifies the ElementTraversal interface by exercising all of its five
methods while reading through the xml document. methods while reading through the xml document.