joergviola/play20-pdf — pull request #7 by gertv (2012-08-01 20:50:47+00:00)
Title: Fix NoSuchElementException when Scala API returns None

While playing around with the play20-pdf module, we bumped into this exception:

java.util.NoSuchElementException: None.get
at scala.None$.get(Option.scala:274) ~[scala-library.jar:0.11.3]
at scala.None$.get(Option.scala:272) ~[scala-library.jar:0.11.3]
at util.pdf.PDF$MyUserAgent.getImageResource(PDF.java:43) ~[pdf_2.9.1-0.3.jar:0.3]
at org.xhtmlrenderer.pdf.ITextReplacedElementFactory.createReplacedElement(ITextReplacedElementFactory.java:57) ~[core-renderer-R8.jar:na]
at org.xhtmlrenderer.render.BlockBox.calcDimensions(BlockBox.java:674) ~[core-renderer-R8.jar:na]
at org.xhtmlrenderer.render.BlockBox.calcDimensions(BlockBox.java:628) ~[core-renderer-R8.jar:na]

The `resourceAsStream(uri)` method in Play's Scala API will return `None` if no resource has been found and calling `.get()` on a `None` instance will throw the above exception.

This pull request fixes the issue by using the `isDefined()` method to check if `Some` or `None` is being returned.