Repository: struts Updated Branches: refs/heads/master fc6ffba9c -> f48c9620f
WW-4731 Adds additional test case to confirm that everything is ok Project: http://git-wip-us.apache.org/repos/asf/struts/repo Commit: http://git-wip-us.apache.org/repos/asf/struts/commit/f48c9620 Tree: http://git-wip-us.apache.org/repos/asf/struts/tree/f48c9620 Diff: http://git-wip-us.apache.org/repos/asf/struts/diff/f48c9620 Branch: refs/heads/master Commit: f48c9620fcb877d23492c6fdd3cc7f7be5cc10e7 Parents: fc6ffba Author: Lukasz Lenart <[email protected]> Authored: Tue Jan 10 10:28:54 2017 +0100 Committer: Lukasz Lenart <[email protected]> Committed: Tue Jan 10 10:28:54 2017 +0100 ---------------------------------------------------------------------- .../apache/struts2/views/xslt/XSLTResult.java | 6 +-- .../struts2/views/xslt/XSLTResultTest.java | 29 ++++++++++++-- core/src/test/resources/XSLTResultTest6.xsl | 40 ++++++++++++++++++++ core/src/test/resources/log4j2.xml | 1 + 4 files changed, 70 insertions(+), 6 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/struts/blob/f48c9620/core/src/main/java/org/apache/struts2/views/xslt/XSLTResult.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/struts2/views/xslt/XSLTResult.java b/core/src/main/java/org/apache/struts2/views/xslt/XSLTResult.java index c264a59..2e2746e 100644 --- a/core/src/main/java/org/apache/struts2/views/xslt/XSLTResult.java +++ b/core/src/main/java/org/apache/struts2/views/xslt/XSLTResult.java @@ -171,8 +171,9 @@ public class XSLTResult implements Result { if (location != null) { templates = getTemplates(location); transformer = templates.newTransformer(); - } else + } else { transformer = TransformerFactory.newInstance().newTransformer(); + } transformer.setURIResolver(getURIResolver()); transformer.setErrorListener(buildErrorListener()); @@ -247,8 +248,7 @@ public class XSLTResult implements Result { * function. The default is an instance of ServletURIResolver, which operates relative to the servlet context. */ protected URIResolver getURIResolver() { - return new ServletURIResolver( - ServletActionContext.getServletContext()); + return new ServletURIResolver(ServletActionContext.getServletContext()); } protected Templates getTemplates(final String path) throws TransformerException, IOException { http://git-wip-us.apache.org/repos/asf/struts/blob/f48c9620/core/src/test/java/org/apache/struts2/views/xslt/XSLTResultTest.java ---------------------------------------------------------------------- diff --git a/core/src/test/java/org/apache/struts2/views/xslt/XSLTResultTest.java b/core/src/test/java/org/apache/struts2/views/xslt/XSLTResultTest.java index 3e8c7f1..47e7345 100644 --- a/core/src/test/java/org/apache/struts2/views/xslt/XSLTResultTest.java +++ b/core/src/test/java/org/apache/struts2/views/xslt/XSLTResultTest.java @@ -35,6 +35,7 @@ import javax.xml.transform.TransformerException; import javax.xml.transform.URIResolver; import javax.xml.transform.stream.StreamSource; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; /** @@ -82,6 +83,22 @@ public class XSLTResultTest extends StrutsInternalTestCase { assertTrue(out.indexOf("<result xmlns=\"http://www.w3.org/TR/xhtml1/strict\"") > -1); } + public void testSimpleTransform5() throws Exception { + result.setParse(false); + result.setStylesheetLocation("XSLTResultTest6.xsl"); + result.execute(mai); + + String out = response.getContentAsString(); + assertTrue(out.startsWith("<?xml version=\"1.0\" encoding=\"UTF-8\"?>")); + assertTrue(out.contains("<title>WebWork in Action</title>")); + assertTrue(out.contains("<author>Patrick and Jason</author>")); + assertTrue(out.contains("<editions><edition value=\"I\">I</edition><edition value=\"IV\">IV</edition></editions>")); + assertTrue(out.contains("<book><title/><author/><editions/></book>")); + assertTrue(out.contains("<title>XWork not in Action</title>")); + assertTrue(out.contains("<author>Superman</author>")); + assertTrue(out.contains("<editions><edition value=\"1234\">1234</edition><edition value=\"345\">345</edition><edition value=\"6667\">6667</edition></editions>")); + } + public void testSimpleTransformParse() throws Exception { result.setParse(true); result.setStylesheetLocation("${top.myLocation}"); @@ -277,9 +294,9 @@ public class XSLTResultTest extends StrutsInternalTestCase { public List getBooks() { List list = new ArrayList(); - list.add(new Book("WebWork in Action", "Patrick and Jason")); + list.add(new Book("WebWork in Action", "Patrick and Jason", Arrays.asList("I", "IV"))); list.add(null); - list.add(new Book("XWork not in Action", "Superman")); + list.add(new Book("XWork not in Action", "Superman", Arrays.asList("1234", "345", "6667"))); return list; } @@ -289,10 +306,12 @@ public class XSLTResultTest extends StrutsInternalTestCase { private String title; private String author; + private List<String> editions; - public Book(String title, String author) { + public Book(String title, String author, List<String> editions) { this.title = title; this.author = author; + this.editions = editions; } public String getTitle() { @@ -302,5 +321,9 @@ public class XSLTResultTest extends StrutsInternalTestCase { public String getAuthor() { return author; } + + public List<String> getEditions() { + return editions; + } } } http://git-wip-us.apache.org/repos/asf/struts/blob/f48c9620/core/src/test/resources/XSLTResultTest6.xsl ---------------------------------------------------------------------- diff --git a/core/src/test/resources/XSLTResultTest6.xsl b/core/src/test/resources/XSLTResultTest6.xsl new file mode 100644 index 0000000..606466d --- /dev/null +++ b/core/src/test/resources/XSLTResultTest6.xsl @@ -0,0 +1,40 @@ +<?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. + */ +--> + +<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> + <xsl:output method="xml" encoding="UTF-8" /> + <xsl:template match="result"> + <books> + <xsl:for-each select="books/item"> + <book> + <title><xsl:value-of select="title"/></title> + <author><xsl:value-of select="author"/></author> + <editions> + <xsl:for-each select="editions/item"> + <edition><xsl:attribute name="value"><xsl:value-of select="."/></xsl:attribute><xsl:value-of select="."/></edition> + </xsl:for-each> + </editions> + </book> + </xsl:for-each> + </books> + </xsl:template> +</xsl:stylesheet> http://git-wip-us.apache.org/repos/asf/struts/blob/f48c9620/core/src/test/resources/log4j2.xml ---------------------------------------------------------------------- diff --git a/core/src/test/resources/log4j2.xml b/core/src/test/resources/log4j2.xml index 263585e..c93452b 100644 --- a/core/src/test/resources/log4j2.xml +++ b/core/src/test/resources/log4j2.xml @@ -9,5 +9,6 @@ <Root level="info"> <AppenderRef ref="STDOUT"/> </Root> + <Logger name="org.apache.struts2.views.xslt" level="debug"/> </Loggers> </Configuration> \ No newline at end of file
