< prev index next >

test/javax/xml/jaxp/unittest/transform/XSLTFunctionsTest.java

Print this page

        

*** 32,60 **** import javax.xml.transform.TransformerFactory; import javax.xml.transform.URIResolver; import javax.xml.transform.stream.StreamResult; import javax.xml.transform.stream.StreamSource; import org.testng.annotations.DataProvider; import org.testng.annotations.Listeners; import org.testng.annotations.Test; import static org.testng.Assert.assertEquals; /* * @test * @library /javax/xml/jaxp/libs /javax/xml/jaxp/unittest * @compile DocumentExtFunc.java * @run testng/othervm -DrunSecMngr=true transform.XSLTFunctionsTest * @run testng/othervm transform.XSLTFunctionsTest * @summary This class contains tests for XSLT functions. */ ! //@Listeners({jaxp.library.BasePolicy.class}) //uncomment this line after 8161454 is resolved public class XSLTFunctionsTest { /** * @bug 8062518 8153082 * Verifies that a reference to the DTM created by XSLT document function is * actually read from the DTM by an extension function. * @param xml Content of xml file to process * @param xsl stylesheet content that loads external document {@code externalDoc} --- 32,121 ---- import javax.xml.transform.TransformerFactory; import javax.xml.transform.URIResolver; import javax.xml.transform.stream.StreamResult; import javax.xml.transform.stream.StreamSource; + import org.testng.Assert; import org.testng.annotations.DataProvider; import org.testng.annotations.Listeners; import org.testng.annotations.Test; import static org.testng.Assert.assertEquals; + import static jaxp.library.JAXPTestUtilities.runWithAllPerm; + import static jaxp.library.JAXPTestUtilities.clearSystemProperty; + import static jaxp.library.JAXPTestUtilities.setSystemProperty; + import static jaxp.library.JAXPTestUtilities.getSystemProperty; /* * @test * @library /javax/xml/jaxp/libs /javax/xml/jaxp/unittest * @compile DocumentExtFunc.java * @run testng/othervm -DrunSecMngr=true transform.XSLTFunctionsTest * @run testng/othervm transform.XSLTFunctionsTest * @summary This class contains tests for XSLT functions. */ ! @Listeners({jaxp.library.BasePolicy.class}) public class XSLTFunctionsTest { /** + * @bug 8161454 + * Verifies that the new / correct name is supported, as is the old / incorrect + * one for compatibility + */ + @Test + public void testNameChange() { + + boolean feature; + TransformerFactory tf = TransformerFactory.newInstance(); + feature = tf.getFeature(ORACLE_ENABLE_EXTENSION_FUNCTION); + System.out.println("Default setting: " + feature); + // The default: true if no SecurityManager, false otherwise + Assert.assertTrue(feature == getDefault()); + + setSystemProperty(SP_ENABLE_EXTENSION_FUNCTION, getDefaultOpposite()); + tf = TransformerFactory.newInstance(); + feature = tf.getFeature(ORACLE_ENABLE_EXTENSION_FUNCTION); + System.out.println("After setting " + SP_ENABLE_EXTENSION_FUNCTION + ": " + feature); + clearSystemProperty(SP_ENABLE_EXTENSION_FUNCTION); + // old/incorrect name is still supported + Assert.assertTrue(feature != getDefault()); + + setSystemProperty(SP_ENABLE_EXTENSION_FUNCTION_SPEC, getDefaultOpposite()); + tf = TransformerFactory.newInstance(); + feature = tf.getFeature(ORACLE_ENABLE_EXTENSION_FUNCTION); + System.out.println("After setting " + SP_ENABLE_EXTENSION_FUNCTION_SPEC + ": " + feature); + clearSystemProperty(SP_ENABLE_EXTENSION_FUNCTION_SPEC); + // new/correct name is effective + Assert.assertTrue(feature != getDefault()); + } + + final boolean isSecure; + { + String runSecMngr = getSystemProperty("runSecMngr"); + isSecure = runSecMngr != null && runSecMngr.equals("true"); + } + + // The default: true if no SecurityManager, false otherwise + private boolean getDefault() { + if (isSecure) { + return false; + } else { + return true; + } + } + + // Gets a String value that is opposite to the default value + private String getDefaultOpposite() { + if (isSecure) { + return "true"; + } else { + return "false"; + } + } + + /** * @bug 8062518 8153082 * Verifies that a reference to the DTM created by XSLT document function is * actually read from the DTM by an extension function. * @param xml Content of xml file to process * @param xsl stylesheet content that loads external document {@code externalDoc}
*** 70,80 **** Source src = new StreamSource(new StringReader(xml)); Source xslsrc = new StreamSource(new StringReader(xsl)); // Create factory and transformer TransformerFactory tf = TransformerFactory.newInstance(); ! tf.setFeature("http://www.oracle.com/xml/jaxp/properties/enableExtensionFunctions", true); Transformer t = tf.newTransformer( xslsrc ); t.setErrorListener(tf.getErrorListener()); // Set URI Resolver to return the newly constructed xml // stream source object from xml test string --- 131,143 ---- Source src = new StreamSource(new StringReader(xml)); Source xslsrc = new StreamSource(new StringReader(xsl)); // Create factory and transformer TransformerFactory tf = TransformerFactory.newInstance(); ! tf.setFeature(ORACLE_ENABLE_EXTENSION_FUNCTION, true); ! tf.setAttribute(EXTENSION_CLASS_LOADER, ! runWithAllPerm(() -> Thread.currentThread().getContextClassLoader())); Transformer t = tf.newTransformer( xslsrc ); t.setErrorListener(tf.getErrorListener()); // Set URI Resolver to return the newly constructed xml // stream source object from xml test string
*** 131,137 **** --- 194,212 ---- + "<xsl:value-of select=\"cfunc:transform.DocumentExtFunc.test($other_doc/Test)\"/>" + "</xsl:element></xsl:template></xsl:transform>"; static final String documentTesteExpectedResult = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + "<root>[Test:Doc][Test:External Doc]</root>"; + + public static final String ORACLE_JAXP_PROPERTY_PREFIX = + "http://www.oracle.com/xml/jaxp/properties/"; + /** + * Feature enableExtensionFunctions + */ + public static final String ORACLE_ENABLE_EXTENSION_FUNCTION = + ORACLE_JAXP_PROPERTY_PREFIX + "enableExtensionFunctions"; + static final String SP_ENABLE_EXTENSION_FUNCTION = "javax.xml.enableExtensionFunctions"; + // This is the correct name by the spec + static final String SP_ENABLE_EXTENSION_FUNCTION_SPEC = "jdk.xml.enableExtensionFunctions"; + private static final String EXTENSION_CLASS_LOADER = "jdk.xml.transform.extensionClassLoader"; }
< prev index next >