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 5dfd5fb25..fb5068ca1 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 @@ -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); } 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 d1ad40091..3e8c7f184 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 @@ -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"); diff --git a/core/src/test/resources/XSLTResultTest.bad.character.xsl b/core/src/test/resources/XSLTResultTest.bad.character.xsl new file mode 100644 index 000000000..194b43030 --- /dev/null +++ b/core/src/test/resources/XSLTResultTest.bad.character.xsl @@ -0,0 +1,30 @@ + + + + +



+ +
+ +
\ No newline at end of file