TemplatedProcessor
: private void verifySelector(String selector, Element element, TemplateSelector templateSelector,
org.jsoup.nodes.Element root) {
// make sure to use the same logic for finding matching elements as in TemplateUtils!
Elements elements = root.getElementsByAttributeValue("data-element", selector);
/**
* Find elements that have an attribute with the specific value. Case insensitive.
...
*/
public Elements getElementsByAttributeValue(String key, String value) {
//Elements elements = root.getElementsByAttributeValue("data-element", selector);
Elements elements = root.getElementsByAttribute("data-element");
long matchCount = elements.stream().filter(elem -> elem.attributes().getIgnoreCase("data-element").equals(selector)).count();
I use to do this approach https://blog.jayway.com/2017/07/13/open-pdf-downloaded-api-javascript/
showFile(blob){
// It is necessary to create a new blob object with mime-type explicitly set
// otherwise only Chrome works like it should
var newBlob = new Blob([blob], {type: "application/pdf"})
// IE doesn't allow using a blob object directly as link href
// instead it is necessary to use msSaveOrOpenBlob
if (window.navigator && window.navigator.msSaveOrOpenBlob) {
window.navigator.msSaveOrOpenBlob(newBlob);
return;
}
// For other browsers:
// Create a link pointing to the ObjectURL containing the blob.
const data = window.URL.createObjectURL(newBlob);
var link = document.createElement('a');
link.href = data;
link.download="file.pdf";
link.click();
setTimeout(function(){
// For Firefox it is necessary to delay revoking the ObjectURL
window.URL.revokeObjectURL(data);
}, 100);
}
fetch([url to fetch], {[options setting custom http-headers]})
.then(r => r.blob())
.then(showFile)
but it is no longer possible
My current impl:
public class BlobDownload {
private BlobDownload() {
}
public static <T> void downloadBlob(T data, String contentType, String fileName) {
BlobPropertyBag blobPropertyBag = BlobPropertyBag.create();
blobPropertyBag.setType(contentType);
Blob blob = new Blob(new Blob.ConstructorBlobPartsArrayUnionType[]{Blob.ConstructorBlobPartsArrayUnionType.of(data)}, blobPropertyBag);
downloadBlob(blob, fileName);
}
public static void downloadBlob(Blob blob, String fileName) {
String url = URL.createObjectURL(blob);
HTMLAnchorElement anchor = a()
.attr("href", url)
.attr("download", fileName)
.style("display: none;")
.element();
DomGlobal.document.body.appendChild(anchor);
anchor.focus();
anchor.remove();
DomGlobal.setTimeout(p0 -> URL.revokeObjectURL(url), 5000);
}
}