<%@ page import="java.net.URI" %> <%@ page import="org.apache.jackrabbit.j2ee.JcrRemotingServlet" %> <%@ page import="org.apache.jackrabbit.util.Text" %> <%-- Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. --%><% URI uri = new URI(request.getRequestURL().toString()); String href = uri.getScheme() + "://" + uri.getHost() + ":" + uri.getPort() + request.getContextPath() + JcrRemotingServlet.getPathPrefix(pageContext.getServletContext()); href = Text.encodeIllegalXMLCharacters(href); href += "/default/jcr:root"; %>

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

In order to set properties of any of the types listed, the value part in the :diff param must be left empty and a separate request parameter must be included. Its name equals the corresponding key in the :diff, its value represents the property value. In addition the desired property type must be specified using the conversion defined with JcrValueType#contentTypeFromType(int).

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

whereas the form action indicates the path of the parent node.

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

<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

<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>