Skip to content

Conversation

@reckart
Copy link
Member

@reckart reckart commented Dec 9, 2025

What's in the PR

  • Ability to fetch image metadata via ImageIO
  • Also embed width/height on img tags we render from the backend

How to test manually

  • Import a MHTML archive which has images without dimensions declared in the HTML - those should now be added by INCEpTION
  • Manually try accessing the metadata endpoint

Automatic testing

  • PR includes unit tests

Documentation

  • PR updates documentation

- Ability to fetch image metadata via ImageIO
- Also embed width/height on img tags we render from the backend
@reckart reckart added this to the 40.0 milestone Dec 9, 2025
@reckart reckart self-assigned this Dec 9, 2025
@reckart reckart added this to Kanban Dec 9, 2025
@github-project-automation github-project-automation bot moved this to 🔖 To do in Kanban Dec 9, 2025
@reckart reckart merged commit 6ad627c into main Dec 10, 2025
3 checks passed
@github-project-automation github-project-automation bot moved this from 🔖 To do to 🍹 Done in Kanban Dec 10, 2025
@reckart reckart deleted the feature/5777-Allow-fetching-resource-metadata-from-the-backend branch December 10, 2025 06:12
@reckart reckart requested a review from Copilot December 10, 2025 06:12
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds the ability to fetch image metadata (width and height) from the backend and automatically embed these dimensions on <img> tags during HTML rendering. This feature is particularly useful for MHTML archives that contain images without declared dimensions.

Key Changes:

  • Added a new REST endpoint (/meta) to fetch image metadata as JSON
  • Implemented automatic embedding of width/height attributes on img tags during document rendering
  • Fixed a typo in NamespaceDecodingContentHandlerAdapter class name

Reviewed changes

Copilot reviewed 10 out of 12 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
pom.xml Added imageio-tiff version property (3.10.0) for enhanced image format support
inception-dependencies/pom.xml Added imageio-tiff dependency declaration for TIFF image support
inception-external-editor/pom.xml Added imageio-tiff dependency and configured maven-dependency-plugin to ignore it (SPI-based)
NamespaceDecodingContentHandlerAdapter.java Fixed class name typo from 'Namspace' to 'Namespace'
ImageMetaData.java New record class to represent image dimensions (width/height) with builder pattern
XHtmlXmlDocumentViewController.java Added getResourceMetadata method signature to interface
XHtmlXmlDocumentViewControllerImpl.java Core implementation: added metadata endpoint, image dimension extraction via ImageIO, and automatic dimension embedding handler
XmlDocumentViewControllerImplBase.java Removed applyHtmlResourceUrlFilter method (moved to subclass)
MatrixWorkloadManagementPage.java Reformatted method call for better readability
WicketApplicationBase.java Reformatted CSP value initialization for consistency
InceptionSecurityWebUIApiAutoConfiguration.java Reformatted CSP value initialization for consistency
PdfJsViewerPage.java Reformatted comments and method calls for better readability
Comments suppressed due to low confidence (2)

inception/inception-support/src/main/java/de/tudarmstadt/ukp/inception/support/xml/NamespaceDecodingContentHandlerAdapter.java:35

  • Fixed typo in class name: 'Namspace' corrected to 'Namespace'.
    inception/inception-support/src/main/java/de/tudarmstadt/ukp/inception/support/xml/NamespaceDecodingContentHandlerAdapter.java:45
  • Fixed typo in constructor name: 'Namspace' corrected to 'Namespace'.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +481 to +529
@PreAuthorize("@documentAccess.canViewAnnotationDocument(#aProjectId, #aDocumentId, #principal.name)")
@Override
@GetMapping(path = GET_METADATA_PATH)
public ResponseEntity<String> getResourceMetadata( //
@PathVariable("projectId") long aProjectId, //
@PathVariable("documentId") long aDocumentId, //
@RequestParam("resId") String aResourceId, //
Principal principal)
throws Exception
{
var srcDoc = documentService.getSourceDocument(aProjectId, aDocumentId);

var maybeFormatSupport = formatRegistry.getFormatById(srcDoc.getFormat());
if (maybeFormatSupport.isEmpty()) {
return ResponseEntity.notFound().build();
}

var srcDocFile = documentStorageService.getSourceDocumentFile(srcDoc);

var formatSupport = maybeFormatSupport.get();

if (!formatSupport.hasResources()
|| !formatSupport.isAccessibleResource(srcDocFile, aResourceId)) {
LOG.debug("Resource [{}] for document {} not found", aResourceId, srcDoc);
return ResponseEntity.notFound().build();
}

try {
var inputStream = formatSupport.openResourceStream(srcDocFile, aResourceId);

var httpHeaders = new HttpHeaders();
httpHeaders.setContentType(APPLICATION_JSON);

var imageMetaData = getImageDimensions(inputStream);
if (imageMetaData.isPresent()) {
return new ResponseEntity<>(toJsonString(imageMetaData.get()), httpHeaders, OK);
}

return new ResponseEntity<>("{}", httpHeaders, NOT_FOUND);
}
catch (FileNotFoundException e) {
LOG.debug("Resource [{}] for document {} not found", aResourceId, srcDoc);
return ResponseEntity.notFound().build();
}
catch (Exception e) {
LOG.debug("Unable to load resource [{}] for document {}", aResourceId, srcDoc, e);
return ResponseEntity.notFound().build();
}
}
Copy link

Copilot AI Dec 10, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new getResourceMetadata endpoint lacks test coverage. Consider adding tests to verify:

  • Successful metadata retrieval for valid image resources
  • Proper 404 responses for non-existent resources
  • Proper 404 responses for non-image resources
  • Access control enforcement
  • JSON response format correctness

This is a new public API endpoint that should have comprehensive test coverage.

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

Status: 🍹 Done

Development

Successfully merging this pull request may close these issues.

2 participants