Source:
<code>protected Blob replaceURLsByAbsolutePaths(Blob blob, Path tempDirectory) throws IOException { String initialBlobContent = blob.getString(); String blobContentWithAbsolutePaths = initialBlobContent; <START> String regex = "src=\"((.*?)/nuxeo/nxfile/(.*?)/([0-9a-z-]+)/files:files/([0-9])+/file/(.*?))\""; <END> Pattern pattern = Pattern.compile(regex); Matcher matcher = pattern.matcher(initialBlobContent); while (matcher.find()) { String url = matcher.group(1); String docId = matcher.group(4); int fileIndex = Integer.parseInt(matcher.group(5)); IdRef docIdRef = new IdRef(docId); DocumentModel doc = session.getDocument(docIdRef); List<Map<String, Object>> docFiles = (List<Map<String, Object>>) doc.getProperty("files", "files"); Map<String, Object> imageDoc = docFiles.get(fileIndex); Blob imageBlob = (Blob) imageDoc.get("file"); File imageFile = new File(tempDirectory + "/" + imageDoc.get("filename")); imageBlob.transferTo(imageFile); blobContentWithAbsolutePaths = blobContentWithAbsolutePaths.replaceAll(url, imageFile.toPath().toString()); } if (blobContentWithAbsolutePaths.equals(initialBlobContent)) { return blob; } Blob newBlob = new StringBlob(blobContentWithAbsolutePaths, blob.getMimeType(), blob.getEncoding()); newBlob.setFilename(blob.getFilename()); newBlob.setDigest(blob.getDigest()); return newBlob; }</code><technical_language>this is dependent URL format move this logic DownloadService is responsible for computing download URL. /nuxeo part (servlet context) configured differently match it</technical_language>

Target:
protected Blob replaceURLsByAbsolutePaths(Blob blob, Path tempDirectory) throws IOException { String initialBlobContent = blob.getString(); String blobContentWithAbsolutePaths = initialBlobContent; DownloadService downloadService = Framework.getService(DownloadService.class); List<Map<String, String>> parsedUrls = downloadService.parseDownloadUrlsInHtmlLinks(initialBlobContent); for (Map<String, String> parsedUrl : parsedUrls) { try { CoreSession session = CoreInstance.openCoreSession(parsedUrl.get("repository")); IdRef docIdRef = new IdRef(parsedUrl.get("id")); DocumentModel doc = session.getDocument(docIdRef); List<Map<String, Object>> docFiles = (List<Map<String, Object>>) doc.getPropertyValue("files:files"); int fileIndex = Integer.parseInt(parsedUrl.get("index")); if (docFiles == null || docFiles.size() <= fileIndex) { break; } Map<String, Object> imageDoc = docFiles.get(fileIndex); if (imageDoc == null) { break; } Blob imageBlob = (Blob) imageDoc.get("file"); if (imageBlob == null) { break; } String sanitizedFilename = FileUtils.sanitizeFilename((String) imageDoc.get("filename")); File imageFile = tempDirectory.resolve(sanitizedFilename).toFile(); imageBlob.transferTo(imageFile); session.close(); blobContentWithAbsolutePaths = blobContentWithAbsolutePaths.replaceAll(parsedUrl.get("url"), imageFile.toPath().toString()); } catch (DocumentNotFoundException | DocumentSecurityException | NumberFormatException e) { break; } } if (blobContentWithAbsolutePaths.equals(initialBlobContent)) { return blob; } Blob newBlob = new StringBlob(blobContentWithAbsolutePaths, blob.getMimeType(), blob.getEncoding()); newBlob.setFilename(blob.getFilename()); return newBlob; }