提交 6a72584d 编写于 作者: A aefimov

8150704: XALAN: ERROR: 'No more DTM IDs are available' when transforming with...

8150704: XALAN: ERROR: 'No more DTM IDs are available' when transforming with lots of temporary result trees
Reviewed-by: joehw
上级 3649df1c
此差异已折叠。
<?xml version="1.0" encoding="UTF-8"?>
<element>
<text>.</text>
</element>
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="text"/>
<xsl:template match="/">
<xsl:call-template name="recurse1">
<xsl:with-param name="num">
<xsl:value-of select="0"/>
</xsl:with-param>
</xsl:call-template>
<xsl:text>&#xa;</xsl:text>
</xsl:template>
<xsl:template name="recurse1">
<xsl:param name="num"/>
<xsl:call-template name="recurse2">
<xsl:with-param name="num" select="0"/>
</xsl:call-template>
<xsl:if test="not($num = 19)">
<xsl:variable name="tmpnumber"><xsl:value-of select="$num + 1"/></xsl:variable>
<xsl:call-template name="recurse1">
<xsl:with-param name="num">
<xsl:value-of select="$tmpnumber"/>
</xsl:with-param>
</xsl:call-template>
</xsl:if>
</xsl:template>
<xsl:template name="recurse2">
<xsl:param name="num"/>
<xsl:call-template name="recursefinal">
<xsl:with-param name="num" select="0"/>
</xsl:call-template>
<xsl:if test="not($num = 19)">
<xsl:variable name="tmpnumber"><xsl:value-of select="$num + 1"/></xsl:variable>
<xsl:call-template name="recurse2">
<xsl:with-param name="num" select="$tmpnumber"/>
</xsl:call-template>
</xsl:if>
</xsl:template>
<xsl:template name="recursefinal">
<xsl:param name="num"/>
<xsl:call-template name="dodot"/>
<xsl:call-template name="dodot"/>
<xsl:call-template name="dodot"/>
<xsl:call-template name="dodot"/>
<xsl:call-template name="dodot"/>
<xsl:call-template name="dodot"/>
<xsl:call-template name="dodot"/>
<xsl:call-template name="dodot"/>
<xsl:call-template name="dodot"/>
<xsl:call-template name="dodot"/>
<xsl:call-template name="dodot"/>
<xsl:call-template name="dodot"/>
<xsl:call-template name="dodot"/>
<xsl:call-template name="dodot"/>
<xsl:call-template name="dodot"/>
<xsl:if test="not($num = 10)">
<xsl:variable name="tmpnumber"><xsl:value-of select="$num + 1"/></xsl:variable>
<xsl:call-template name="recursefinal">
<xsl:with-param name="num" select="$tmpnumber"/>
</xsl:call-template>
</xsl:if>
</xsl:template>
<xsl:template name="dodot">
<xsl:variable name="ElementTexts">
<xsl:for-each select="element">
<xsl:value-of select="text"/>
</xsl:for-each>
</xsl:variable>
<xsl:value-of select="$ElementTexts"/>
</xsl:template>
</xsl:stylesheet>
此差异已折叠。
此差异已折叠。
此差异已折叠。
/*
* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/* @test
* @bug 8150704
* @summary Test that XSL transformation with lots of temporary result trees will not run out of DTM IDs.
* @run testng/othervm TransformerTest
*/
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.io.StringWriter;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerException;
import javax.xml.transform.TransformerFactory;
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.Test;
public class TransformerTest {
@Test(dataProvider = "bug8150704")
public final void testBug8150704(String xsl, String xml, String ref) throws Exception {
System.out.println("Testing transformation of "+xml);
Transformer transformer = createTransformerFromResource(xsl);
StringWriter result = transformResourceToStringWriter(transformer, xml);
String resultstring = result.toString().replaceAll("\\r\\n", "\n").replaceAll("\\r", "\n");
String reference = getFileContentAsString(new File(getClass().getResource(ref).getPath()));
Assert.assertEquals(resultstring, reference, "Output of transformation of "+xml+" does not match reference");
}
@DataProvider(name = "bug8150704")
private Object[][] dataBug8150704() {
return new Object[][] {
//xsl file, xml file, reference file
{"Bug8150704-1.xsl", "Bug8150704-1.xml", "Bug8150704-1.ref"},
{"Bug8150704-2.xsl", "Bug8150704-2.xml", "Bug8150704-2.ref"},
};
}
private Transformer createTransformerFromResource(String xslResource) throws TransformerException {
return TransformerFactory.newInstance().newTransformer(new StreamSource(getClass().getResource(xslResource).toString()));
}
private StringWriter transformResourceToStringWriter(Transformer transformer, String xmlResource) throws TransformerException {
StringWriter sw = new StringWriter();
transformer.transform(new StreamSource(getClass().getResource(xmlResource).toString()), new StreamResult(sw));
return sw;
}
/**
* Reads the contents of the given file into a string.
* WARNING: this method adds a final line feed even if the last line of the file doesn't contain one.
*
* @param f
* The file to read
* @return The content of the file as a string, with line terminators as \"n"
* for all platforms
* @throws IOException
* If there was an error reading
*/
private String getFileContentAsString(File f) throws IOException {
try (BufferedReader reader = new BufferedReader(new FileReader(f))) {
String line;
StringBuilder sb = new StringBuilder();
while ((line = reader.readLine()) != null) {
sb.append(line).append("\n");
}
return sb.toString();
}
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册