Author: dklco
Date: Tue Dec 16 16:31:34 2014
New Revision: 1645999
URL: http://svn.apache.org/r1645999
Log:
Further refinement and naming the doc page for SLING-4248
Added:
sling/site/trunk/content/documentation/the-sling-engine/sling-api-crud-support.mdtext
Modified:
sling/site/trunk/content/documentation/the-sling-engine.mdtext
Modified: sling/site/trunk/content/documentation/the-sling-engine.mdtext
URL:
http://svn.apache.org/viewvc/sling/site/trunk/content/documentation/the-sling-engine.mdtext?rev=1645999&r1=1645998&r2=1645999&view=diff
==============================================================================
--- sling/site/trunk/content/documentation/the-sling-engine.mdtext (original)
+++ sling/site/trunk/content/documentation/the-sling-engine.mdtext Tue Dec 16
16:31:34 2014
@@ -20,7 +20,7 @@ Title: The Sling Engine
## Resources
* [Resources]({{ refs.resources.path }})
-* [CRUD API]({{ refs.crud-api.path }})
+* [Sling API CRUD Support]({{ refs.crud-api.path }})
* [Wrap or Decorate Resources]({{ refs.wrap-or-decorate-resources.path }})
* [Mappings for Resource Resolution]({{
refs.mappings-for-resource-resolution.path }})
Added:
sling/site/trunk/content/documentation/the-sling-engine/sling-api-crud-support.mdtext
URL:
http://svn.apache.org/viewvc/sling/site/trunk/content/documentation/the-sling-engine/sling-api-crud-support.mdtext?rev=1645999&view=auto
==============================================================================
---
sling/site/trunk/content/documentation/the-sling-engine/sling-api-crud-support.mdtext
(added)
+++
sling/site/trunk/content/documentation/the-sling-engine/sling-api-crud-support.mdtext
Tue Dec 16 16:31:34 2014
@@ -0,0 +1,164 @@
+Title: Sling API CRUD Support
+
+[TOC]
+
+## Apache Sling API Support
+
+As of version 2.3.0, the Sling API provides full Create Read Update Delete
(CRUD) features. CRUD support is provided by the addition of the following
methods to the ResourceResolver:
+
+ * [void delete(Resource resource) throws
PersistenceException](https://sling.apache.org/apidocs/sling7/org/apache/sling/api/resource/ResourceResolver.html#delete-org.apache.sling.api.resource.Resource-)
+ * [Resource create(Resource parent, String name, Map<String, Object>
properties) throws
PersistenceException](https://sling.apache.org/apidocs/sling7/org/apache/sling/api/resource/ResourceResolver.html#create-org.apache.sling.api.resource.Resource-java.lang.String-java.util.Map-)
+ * [void
revert()](https://sling.apache.org/apidocs/sling7/org/apache/sling/api/resource/ResourceResolver.html#revert--)
+ * [void commit() throws
PersistenceException](https://sling.apache.org/apidocs/sling7/org/apache/sling/api/resource/ResourceResolver.html#commit--)
+ * [boolean
hasChanges()](https://sling.apache.org/apidocs/sling7/org/apache/sling/api/resource/ResourceResolver.html#hasChanges--)
+ * [void
refresh()](https://sling.apache.org/apidocs/sling7/org/apache/sling/api/resource/ResourceResolver.html#refresh--)
+
+Which provide the ability to create and delete resources as well as the
addition of the ModifiableValueMap interface which is similar to the ValueMap
interface, but allows for updating properties on a resource.
+
+## Comparing Sling API CRUD to Sling Post Servlet
+
+Here are some examples of common operations performed using the Sling Post
Servlet and Sling API CRUD support. Note, the examples are derived from the
[SlingPostServlet
Cheatsheet](http://dev.day.com/content/ddc/blog/2008/07/cheatsheet/_jcr_content/images/cheatsheet/back.png).
+
+### Updating a Property
+
+Update /myresource, setting the title and body:
+
+**Sling Post Servlet**
+
+ <form action="/myresource" method="POST">
+ <input type="text" name="title">
+ <textarea name="body">
+ </form>
+
+**Sling API CRUD**
+
+ Resource myResource = resourceResolver.getResource("/myresource");
+ ModifiableValueMap properties = myNode.adaptTo(ModifiableValueMap.class);
+ properties.put("title", {TITLE});
+ properties.put("body", {BODY});
+ resourceResolver.commit();
+
+### Create New Resource
+
+Create a new resource below /myresource
+
+**Sling Post Servlet**
+
+ <form action="/myresource/" method="POST">
+ <input type="text" name="dummy">
+ </form>
+
+**Sling API CRUD**
+
+ Map<String,Object> properties = new HashMap<String,Object>();
+ properties.put("jcr:primaryType", "nt:unstructured");
+ properties.put("sling:resourceType", "myapp/components/mytype");
+ Resource dummy = resourceResolver.create(myResource, "dummy", properties);
+ resourceResolver.commit();
+
+### Remove a Property
+
+Remove the property title
+
+**Sling Post Servlet**
+
+ <form action="/myresource" method="POST">
+ <input type="hidden" name="title@Delete">
+ </form>
+
+**Sling API CRUD**
+
+ ModifiableValueMap properties =
myResource.adaptTo(ModifiableValueMap.class);
+ properties.remove("title");
+ resourceResolver.commit();
+
+### Copy a Resource
+
+Copy the resource /myresource to /myresource2
+
+**Sling Post Servlet**
+
+ <form action="/myresource" method="POST">
+ <input type="hidden" name=":operation" value="copy">
+ <input type="hidden" name=":dest" value="/myresource2">
+ <input type="hidden" name=":replace" value="true">
+ </form>
+
+**Sling API CRUD**
+
+ Map<String,Object> properties = myResource.adaptTo(ValueMap.class);
+ Resource myResource2 = resourceResolver.create(null, "myresource2",
properties);
+ resourceResolver.commit();
+
+### Move a Resource
+
+Move the resource /myresource2 to /myresource3
+
+**Sling Post Servlet**
+
+ <form action="/myresource2" method="POST">
+ <input type="hidden" name=":operation" value="move">
+ <input type="hidden" name=":dest" value="/myresource3">
+ </form>
+
+**Sling API CRUD**
+
+ Map<String,Object> properties = myResource2.adaptTo(ValueMap.class);
+ Resource myResource3 = resourceResolver.create(null, "myresource3",
properties);
+ resourceResolver.delete(myResource2);
+ resourceResolver.commit();
+
+### Setting non-String Value
+
+Set the property date to a particular date
+
+**Sling Post Servlet**
+
+ <form action="/myresource3" method="POST">
+ <input type="text" name="date" value="2008-06-13T18:55:00">
+ <input type="hidden" name="date@TypeHint" value="Date">
+ </form>
+
+**Sling API CRUD**
+
+ Calendar calendar = [SOME_DATE];
+ ModifiableValueMap properties =
myResource3.adaptTo(ModifiableValueMap.class);
+ properties.put("date", calendar);
+ resourceResolver.commit();
+
+### Delete a Resource
+
+Delete the resource /myresource
+
+**Sling Post Servlet**
+
+ <form action="/myresource" method="POST">
+ <input type="hidden" name=":operation" value="delete">
+ </form>
+
+**Sling API CRUD**
+
+ resourceResolver.delete(myResource);
+ resourceResolver.commit();
+
+## Value Class Support
+
+
+<div class="info">
+ Please note, this information is specific to the Sling JCR Resource
implementation provided by the Apache Sling project. Other implementations may
have different value class support.
+</div>
+
+The Classes implementing the following types are supported directly when
setting properties:
+
+ * [Calendar](http://docs.oracle.com/javase/8/docs/api/java/util/Calendar.html)
+ *
[InputStream](http://docs.oracle.com/javase/8/docs/api/java/io/InputStream.html)
+ *
[Node](http://www.day.com/maven/javax.jcr/javadocs/jcr-2.0/javax/jcr/Node.html)
+ *
[BigDecimal](http://docs.oracle.com/javase/8/docs/api/java/math/BigDecimal.html)
+ * [Long](http://docs.oracle.com/javase/8/docs/api/java/lang/Long.html)
+ * [Short](http://docs.oracle.com/javase/8/docs/api/java/lang/Short.html)
+ * [Integer](http://docs.oracle.com/javase/8/docs/api/java/lang/Integer.html)
+ * [Number](http://docs.oracle.com/javase/8/docs/api/java/lang/Number.html)
+ * [Boolean](http://docs.oracle.com/javase/8/docs/api/java/lang/Boolean.html)
+ * [String](http://docs.oracle.com/javase/8/docs/api/java/lang/String.html)
+
+As well as the corresponding primitive types. Any object which implements the
Serializable interface will be serialized and the result of the serialization
will be saved as a binary value for the property.
\ No newline at end of file