Skip to content

Commit

Permalink
#216 implement loading resources from classpath
Browse files Browse the repository at this point in the history
now it's possible to use "classpath:" prefix in URLs of included resources, e.g.
```
<link href="classpath:styles/sample.css"/>
```
  • Loading branch information
asolntsev committed Dec 28, 2023
1 parent be02e76 commit c6571da
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,10 @@ public String resolveURI(String uri) {
try {
URI result = new URI(uri);
if (result.isAbsolute()) {
if (result.getScheme().equals("classpath")) {
URL resource = Thread.currentThread().getContextClassLoader().getResource(uri.substring("classpath".length() + 1));
return resource.toString();
}
return result.toString();
}
XRLog.load(uri + " is not a URL; may be relative. Testing using parent URL " + _baseURL);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ private void verifyPdf(byte[] pdfBytes) {
assertThat(pdf).containsText("Bill To:", "John doe", "[email protected]");
assertThat(pdf).containsText("Invoice #:", "INV-666");
assertThat(pdf).containsText("Invoice Date:", "Sep 27, 2023");
assertThat(pdf).doesNotContainText("Password", "Secret");
}

private byte[] generatePdf(String htmlPath) {
Expand Down
4 changes: 4 additions & 0 deletions flying-saucer-examples/src/test/resources/sample.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
<meta charset="UTF-8" />
<meta http-equiv="Content-Type" content="text/html charset=UTF-8" />
<meta name="x-apple-disable-message-reformatting" />
<title>Sample bill</title>
<link rel="stylesheet" type="text/css" href="classpath:styles/sample.css" title="Style"/>
<style>
.content {
width: 595px;
Expand Down Expand Up @@ -504,6 +506,7 @@
<div class="description"><b>Description</b></div>
<div class="quantity"><b>Quantity</b></div>
<div class="amount"><b>Amount</b></div>
<div class="password"><b>Password</b></div>
</div>
<div class="charge odd-charge">

Expand All @@ -513,6 +516,7 @@
<div class="description">Charge description</div>
<div class="quantity">1</div>
<div class="amount">$666.00</div>
<div class="password">Secret123</div>
</div>


Expand Down
3 changes: 3 additions & 0 deletions flying-saucer-examples/src/test/resources/styles/sample.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.password {
display: none;
}

0 comments on commit c6571da

Please sign in to comment.