ModeShape/modeshape — pull request #657 by rhauch (2013-01-22 20:05:28+00:00)
Title: MODE-1767 Added logic to simplify MIME Type handling

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.