Skip to content

Commit

Permalink
remove nulls from RsXslt
Browse files Browse the repository at this point in the history
  • Loading branch information
Kartofanych committed Dec 28, 2024
1 parent 2f7bc6c commit 7f75d7e
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/main/java/org/takes/rs/RsXslt.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
import org.cactoos.io.WriterTo;
import org.cactoos.scalar.Unchecked;
import org.takes.Response;
import org.takes.misc.Opt;

/**
* Response that converts XML into HTML using attached XSL stylesheet.
Expand Down Expand Up @@ -236,15 +237,17 @@ private static byte[] consume(final InputStream input) throws IOException {
*/
private static Source stylesheet(final TransformerFactory factory,
final Source xml) throws TransformerConfigurationException {
final Source stylesheet = factory.getAssociatedStylesheet(
xml, null, null, null
final Opt<Source> stylesheet = new Opt.Single<>(
factory.getAssociatedStylesheet(
xml, null, null, null
)
);
if (stylesheet == null) {
if (!stylesheet.has()) {
throw new IllegalArgumentException(
"No associated stylesheet found in XML"
);
}
return stylesheet;
return stylesheet.get();
}

/**
Expand Down

0 comments on commit 7f75d7e

Please sign in to comment.