MODE-1767 Added logic to simplify MIME Type handling #657
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
When a session is saved, it now looks for nodes that are of type 'nt:resource' (including when the node's primary type is a subtype) and checks whether the 'jcr:mimeType' property is set. If it is not and there is a 'jcr:data' property with a single BINARY value, then the session attempts to obtain the MIME type from the Binary value and set the 'jcr:mimeType' property. (Note that name of the 'nt:resource' node's parent, if there is one, is supplied to the 'getMimeType(...)' method to hopefully get the most accurate MIME type for the node.)
This is useful because applications should be able to access the MIME type for 'nt:resource' nodes (e.g., the 'jcr:content' child of 'nt:file' nodes is often of type 'nt:resource') without having to cast to a ModeShape-specific interface.
Because the MIME types are computed asynchronously as soon as the Binary value is created (and thus before it is set on a specific value), the determination of the MIME type will hopefully have completed before 'Session.save()' even tries to get the value.
Also, the 'jcr:mimeType' property is an optional property on 'nt:resource'. So whenever possible, client applications should set this property where possible. In such situations, there is no additional overhead to the 'Session.save()' call.