Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MODE-1767 Added logic to simplify MIME Type handling #657

Merged
merged 2 commits into from Jan 24, 2013

Conversation

rhauch
Copy link
Contributor

@rhauch rhauch commented Jan 22, 2013

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.

@hchiorean
Copy link
Member

Changes look good, but shouldn't we have at least a test which validates this behavior ?

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.
Added four unit tests that verify the behavior of the automatic setting of the
'jcr:mimeType' property only on nodes of type 'nt:resource'.
@rhauch
Copy link
Contributor Author

rhauch commented Jan 23, 2013

Rebased and then added four unit tests that validate the behavior.

@hchiorean
Copy link
Member

Do we want this both in 3.1.1 and master or just master ?

@rhauch
Copy link
Contributor Author

rhauch commented Jan 23, 2013

Damn. I should have created a commit just with the tests. I'll do that now and create a separate pull-request for 'master'. So this should only be merged onto '3.1.x'.

@hchiorean
Copy link
Member

@rhauch: looking at the commits from this branch, it seems that they have been rebased on "master" not on "3.1.x".
So I'm confused as to the previous comment: imo this should be merged into "master" and for "3.1.x" there should be a separate full request, not the other way around.

@hchiorean hchiorean merged commit 16df9c0 into ModeShape:master Jan 24, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants