Write access is a little less clear to me. I'd like to have a servlet
which handles json, xml or form POSTs for anything submitted to the
path
of my ResourceProvider. I think I need to do this:
1. MyResourceTypeProvider implements JcrResourceTypeProvider
- provider.roots = /my/resources
- any node below the root is returned as resourceType my/Model,
otherwise return null
2. MyPostServlet extends SlingAllMethodsServlet
- registered to handle nodes of type my/Model
- override doPost() to handle data based on content-type
- creates new database entries using MyService
That would allow the creation of a new database row by posting an
appropriate json or xml file to /my/resource/*.html . For the form
data,
I'd conform to the SlingPostServlet interface to remain compatible
with
generic node editing.
Am I thinking about this correctly, or is their a more appropriate
Sling-Way?
Hmm not sure :) I guess your idea should work. Now, for updating db
data
it should already work if your resource is adaptable to
PersistableValueMap.
For adding/deleting resources something like the above might work. We
are thinking of extending the resource provider interface to get
better support for these use cases. This is one of the topics for the
near future, so maybe we should start thinking about this (again)
now :)
The PersistableValueMap seems like a good way to go. If I extend
MyResourceProvider to allow creation of MyResources from a node, I
should then consider adding a SlingPostProcessor instead, which would
use MyResourceProvider.createResourceForNode(n) for any nodes created
under /my/resource. I guess I'd have to undo any nodes actually
created in the jcr since they'd be masked by MyResourceProvider. But,
that would then get me round-trip node semantics.
For xml or json posts, I've noticed the OptingServlet interface, which
is probably a better approach than trying to use the
JcrResourceTypeProvider to assert a default resource type in an
attempt to resolve the request to a POST servlet mapped to that type.
I could then register my POST servlets as default resource type
handlers, which only opt-in for post requests to the appropriate path
and http content-type. Better, right?
Thanks for your advice,
Andreas