Write
Default Writing
Writing remotely to the repository generally follows the rules described in JCR_Webdav_Protocol.zip.
Batch Write
A set of transient modifications can in addition be sent by using the extended batch write: A single POST request that contains a custom :diff parameter describing the changes to be applied. The expected format is described in the JavaDoc.
Some cases however can be easily demonstrated. The following examples can be tested with the form provided at Example: Batch Write.Examples
The following examples illustrate the basics of the diff format. It does not cover the special treatment of properties with type Date, Name, Path, Reference and Binary (see below).
Set properties
^prop1 : "stringvalue" ^prop1 : "changedvalue" ^prop2 : true ^prop3 : 100.010 ^prop4 : 1234567890 ^prop5 : ["multi","valued","string prop"] ^. : "change existing property at path." ^/abs/path/to/the/new/prop : "some value."
Add new nodes (optionally including child items)
+node : {"title" : "title property of the new node"} +node2 : {"childN" : {}, "childN2" : {}} +/abs/path/to/the/new/node : {"text" : "some text"}
Move or rename nodes
>node : rename >rename : /moved/to/another/destination
Reorder nodes
>childN : childN2#after >childN : #first >childN : #last >childN : childN2#before
Remove items
-prop4 : -node2 : -/moved/to/another/destination :
Dealing with Special Property Types
Property types that can not be covered unambigously, need some special handling (see JavaDoc). This affects JCR properties being of type
- Date,
- Name,
- Path,
- Reference,
- Binary.
Set a Date property
POST /jackrabbit/server/default/jcr%3aroot/testNode HTTP/1.1 Content-Type: multipart/form-data; boundary=kTmAb2lkjCtxbMVFzHEplAJjHCUo5aQndaUu --kTmAb2lkjCtxbMVFzHEplAJjHCUo5aQndaUu Content-Disposition: form-data; name="dateProp" Content-Type: jcr-value/date 2009-02-12T10:19:40.778+01:00 --kTmAb2lkjCtxbMVFzHEplAJjHCUo5aQndaUu Content-Disposition: form-data; name=":diff" Content-Type: text/plain ^dateProp : --kTmAb2lkjCtxbMVFzHEplAJjHCUo5aQndaUu--
Setting Binary, Name, Path or Reference properties works accordingly.
Direct Content Editing
The functionality present with batch reading also enables very simplified content editing using common HTML forms.
The :diff parameter is omitted altogether and each request parameter is treated as property
- param name : property name
- param value : property value
If no node exists at the specified path an attempt is made to create the missing intermediate nodes. The primary node type of the new node is either retrieved from the corresponding jcr:primaryType param or automatically determined by the implementation.
Setting a property can be tested at Example: Simplified Writing
Examples
The following examples illustrate the simplified writing.
Set string property
- Existing or non-existing node at /testnode
- Set property 'propName' with value "any string value"
<form method="POST" action="<%= href %>/testnode"> <input type="text" name="propName" value="any string value"/> </form>
Add node with a defined node type and set a property
- Non-existing node at /testnode/nonexisting
- Define its primary type to be "nt:unstructured"
- Set property 'propName' with value "any string value"
<form method="POST" action="<%= href %>/nonexisting"> <input type="text" name="jcr:primaryType" value="nt:unstructured"/> <input type="text" name="propName" value="any string value"/> </form>