mirror of
https://github.com/apache/struts.git
synced 2026-08-06 15:17:00 +00:00
WW-2561 Throws a Struts exception when there is a bad character in template
This commit is contained in:
@@ -1,6 +1,4 @@
|
||||
/*
|
||||
* $Id$
|
||||
*
|
||||
* 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
|
||||
@@ -330,26 +328,7 @@ public class XSLTResult implements Result {
|
||||
transformer = TransformerFactory.newInstance().newTransformer();
|
||||
|
||||
transformer.setURIResolver(getURIResolver());
|
||||
transformer.setErrorListener(new ErrorListener() {
|
||||
|
||||
public void error(TransformerException exception)
|
||||
throws TransformerException {
|
||||
throw new StrutsException("Error transforming result", exception);
|
||||
}
|
||||
|
||||
public void fatalError(TransformerException exception)
|
||||
throws TransformerException {
|
||||
throw new StrutsException("Fatal error transforming result", exception);
|
||||
}
|
||||
|
||||
public void warning(TransformerException exception)
|
||||
throws TransformerException {
|
||||
if (LOG.isWarnEnabled()) {
|
||||
LOG.warn(exception.getMessage(), exception);
|
||||
}
|
||||
}
|
||||
|
||||
});
|
||||
transformer.setErrorListener(buildErrorListener());
|
||||
|
||||
String mimeType;
|
||||
if (templates == null)
|
||||
@@ -385,6 +364,24 @@ public class XSLTResult implements Result {
|
||||
}
|
||||
}
|
||||
|
||||
protected ErrorListener buildErrorListener() {
|
||||
return new ErrorListener() {
|
||||
|
||||
public void error(TransformerException exception) throws TransformerException {
|
||||
throw new StrutsException("Error transforming result", exception);
|
||||
}
|
||||
|
||||
public void fatalError(TransformerException exception) throws TransformerException {
|
||||
throw new StrutsException("Fatal error transforming result", exception);
|
||||
}
|
||||
|
||||
public void warning(TransformerException exception) throws TransformerException {
|
||||
LOG.warn(exception.getMessage(), exception);
|
||||
}
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
protected AdapterFactory getAdapterFactory() {
|
||||
if (adapterFactory == null)
|
||||
adapterFactory = new AdapterFactory();
|
||||
@@ -422,6 +419,7 @@ public class XSLTResult implements Result {
|
||||
|
||||
TransformerFactory factory = TransformerFactory.newInstance();
|
||||
factory.setURIResolver(getURIResolver());
|
||||
factory.setErrorListener(buildErrorListener());
|
||||
templates = factory.newTemplates(new StreamSource(resource.openStream()));
|
||||
templatesCache.put(path, templates);
|
||||
}
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
/*
|
||||
* $Id$
|
||||
*
|
||||
* 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
|
||||
@@ -192,6 +190,17 @@ public class XSLTResultTest extends StrutsInternalTestCase {
|
||||
}
|
||||
}
|
||||
|
||||
public void testTransformWithBadCharacter() throws Exception {
|
||||
result = new XSLTResult();
|
||||
result.setStylesheetLocation("XSLTResultTest.bad.character.xsl");
|
||||
try {
|
||||
result.execute(mai);
|
||||
fail("Should have thrown an exception");
|
||||
} catch (Exception ex) {
|
||||
assertEquals("Error transforming result", ex.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public void testStatusCode() throws Exception {
|
||||
result.setParse(false);
|
||||
result.setStylesheetLocation("XSLTResultTest.xsl");
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
<!--
|
||||
/*
|
||||
* 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"
|
||||
xmlns="http://www.w3.org/TR/xhtml1/strict">
|
||||
|
||||
<xsl:template match="result">
|
||||
<p></p>
|
||||
<xsl:copy-of select="document('XSLTResultTest-val.xml')"/>
|
||||
</xsl:template>
|
||||
|
||||
</xsl:stylesheet>
|
||||
Reference in New Issue
Block a user