mirror of
https://github.com/apache/struts.git
synced 2026-08-11 01:27:14 +00:00
WW-4731 Adds additional test case to confirm that everything is ok
This commit is contained in:
@@ -171,8 +171,9 @@ public class XSLTResult implements Result {
|
|||||||
if (location != null) {
|
if (location != null) {
|
||||||
templates = getTemplates(location);
|
templates = getTemplates(location);
|
||||||
transformer = templates.newTransformer();
|
transformer = templates.newTransformer();
|
||||||
} else
|
} else {
|
||||||
transformer = TransformerFactory.newInstance().newTransformer();
|
transformer = TransformerFactory.newInstance().newTransformer();
|
||||||
|
}
|
||||||
|
|
||||||
transformer.setURIResolver(getURIResolver());
|
transformer.setURIResolver(getURIResolver());
|
||||||
transformer.setErrorListener(buildErrorListener());
|
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.
|
* function. The default is an instance of ServletURIResolver, which operates relative to the servlet context.
|
||||||
*/
|
*/
|
||||||
protected URIResolver getURIResolver() {
|
protected URIResolver getURIResolver() {
|
||||||
return new ServletURIResolver(
|
return new ServletURIResolver(ServletActionContext.getServletContext());
|
||||||
ServletActionContext.getServletContext());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected Templates getTemplates(final String path) throws TransformerException, IOException {
|
protected Templates getTemplates(final String path) throws TransformerException, IOException {
|
||||||
|
|||||||
@@ -35,6 +35,7 @@ import javax.xml.transform.TransformerException;
|
|||||||
import javax.xml.transform.URIResolver;
|
import javax.xml.transform.URIResolver;
|
||||||
import javax.xml.transform.stream.StreamSource;
|
import javax.xml.transform.stream.StreamSource;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
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);
|
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 {
|
public void testSimpleTransformParse() throws Exception {
|
||||||
result.setParse(true);
|
result.setParse(true);
|
||||||
result.setStylesheetLocation("${top.myLocation}");
|
result.setStylesheetLocation("${top.myLocation}");
|
||||||
@@ -277,9 +294,9 @@ public class XSLTResultTest extends StrutsInternalTestCase {
|
|||||||
|
|
||||||
public List getBooks() {
|
public List getBooks() {
|
||||||
List list = new ArrayList();
|
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(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;
|
return list;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -289,10 +306,12 @@ public class XSLTResultTest extends StrutsInternalTestCase {
|
|||||||
|
|
||||||
private String title;
|
private String title;
|
||||||
private String author;
|
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.title = title;
|
||||||
this.author = author;
|
this.author = author;
|
||||||
|
this.editions = editions;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getTitle() {
|
public String getTitle() {
|
||||||
@@ -302,5 +321,9 @@ public class XSLTResultTest extends StrutsInternalTestCase {
|
|||||||
public String getAuthor() {
|
public String getAuthor() {
|
||||||
return author;
|
return author;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<String> getEditions() {
|
||||||
|
return editions;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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>
|
||||||
@@ -9,5 +9,6 @@
|
|||||||
<Root level="info">
|
<Root level="info">
|
||||||
<AppenderRef ref="STDOUT"/>
|
<AppenderRef ref="STDOUT"/>
|
||||||
</Root>
|
</Root>
|
||||||
|
<Logger name="org.apache.struts2.views.xslt" level="debug"/>
|
||||||
</Loggers>
|
</Loggers>
|
||||||
</Configuration>
|
</Configuration>
|
||||||
Reference in New Issue
Block a user