Skip to content

Commit 6062c33

Browse files
committed
bug(#300): catch compile
1 parent 2810101 commit 6062c33

2 files changed

Lines changed: 12 additions & 3 deletions

File tree

src/main/java/com/jcabi/xml/XSLDocument.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -441,6 +441,8 @@ private void transformInto(final XML xml, final Result result) {
441441
*/
442442
private Transformer transformer() {
443443
final TransformerFactory factory = TransformerFactory.newInstance();
444+
final ConsoleErrorListener errors = new ConsoleErrorListener();
445+
factory.setErrorListener(errors);
444446
factory.setURIResolver(this.sources);
445447
final Transformer trans;
446448
try {
@@ -459,6 +461,15 @@ private Transformer transformer() {
459461
for (final Map.Entry<String, Object> ent : this.params.entrySet()) {
460462
trans.setParameter(ent.getKey(), ent.getValue());
461463
}
464+
if (!errors.summary().isEmpty()) {
465+
throw new IllegalArgumentException(
466+
String.format(
467+
"Failed to compile stylesheet by %s: %s",
468+
trans.getClass().getName(),
469+
errors.summary()
470+
)
471+
);
472+
}
462473
return trans;
463474
}
464475

src/test/java/com/jcabi/xml/XSLDocumentTest.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
import java.util.concurrent.ExecutorService;
1010
import java.util.concurrent.Executors;
1111
import java.util.concurrent.TimeUnit;
12-
import javax.xml.transform.TransformerException;
1312
import org.apache.commons.lang3.StringUtils;
1413
import org.hamcrest.MatcherAssert;
1514
import org.hamcrest.Matchers;
@@ -186,7 +185,7 @@ void catchesXslErrorMessages() {
186185
}
187186

188187
@Test
189-
void catchesXslWarnings() {
188+
void catchesXslWarningsDuringCompilation() {
190189
MatcherAssert.assertThat(
191190
Assertions.assertThrows(
192191
RuntimeException.class,
@@ -196,7 +195,6 @@ void catchesXslWarnings() {
196195
.transform(new XMLDocument("<f/>"))
197196
).getLocalizedMessage(),
198197
Matchers.allOf(
199-
Matchers.containsString("Warning at xsl:stylesheet on line 31 column 139"),
200198
Matchers.containsString(
201199
"Stylesheet module file:/second.xsl is included or imported more than once"
202200
)

0 commit comments

Comments
 (0)