Your SlideShare is downloading. ×
  • Like
Rapid JCR Applications Development with Sling
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×

Now you can save presentations on your phone or tablet

Available for both IPhone and Android

Text the download link to your phone

Standard text messaging rates apply

Rapid JCR Applications Development with Sling

  • 6,526 views
Published

Apache Sling is an OSGi-based, scriptable applications layer, using REST principles, that runs on top of a JCR content repository. In this talk, we'll see how Sling enables rapid development of …

Apache Sling is an OSGi-based, scriptable applications layer, using REST principles, that runs on top of a JCR content repository. In this talk, we'll see how Sling enables rapid development of JCR-based content applications, by leveraging the JSR 223 scripting framework. We'll also look at the rich set of OSGi components provided by Sling. We will create a simple application from scratch in a few minutes, and explain a more complex multimedia application that does a lot with just a few lines of code. This talk will help you get started with Sling and understand how the different components fit together.

Published in Technology , Education
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Be the first to comment
No Downloads

Views

Total Views
6,526
On SlideShare
0
From Embeds
0
Number of Embeds
2

Actions

Shares
Downloads
233
Comments
0
Likes
4

Embeds 0

No embeds

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
    No notes for slide

Transcript

  • 1. Rapid JCR Applications Development with Sling Felix Meschberger ApacheCon US 09
  • 2. About
    • Senior Developer at Day
    • 3. fmeschbe@apache.org
    • 4. http://blog.meschberger.ch
    • 5. Apache Projects:
  • 8. Contents
  • 13. Intro to JCR
    • JCR = Java Content Repository
    • 14. Specifications
      • JSR-170 / JCR 1.0
      • 15. JSR-283 / JCR 2.0
    • Everything is Content
      • JCR manages it in trees of Nodes & Properties
      • 16. Rich Data Types
  • 17. JSR-170
    • Content Repository for Java TM technology API
    • 18. Spec Lead: David Nüscheler, Day Software
    • 19. Final Release: 17 June 2005
    • 20. Expert Group:
  • 21. JSR-283
    • Content Repository for Java TM Technology API Version 2.0
    • 22. Spec Lead: David Nüscheler, Day Software
    • 23. Final Release: 25 September 2009
    • 24. Expert Group:
  • 25. JCR in 21 Words
      The API should be a standard, implementation independent way to access content bidirectionally on a granular level to a Content Repository.
  • 26. JCR = DB + FS + more access control streams locking hierar-chies write read query structure tx obser-vation full text versions item order unstruc-tured multi value integrity JCR DB FS
  • 27. Implementations
    • Connectors:
    100s of TCKs registered
  • 39. Some known Applications
  • 40. JCR code excerpt
      Repository repository = new TransientRepository(); Session session = repository. login (...); // Create content Node root = session. getRootNode (); Node hello = root. addNode ("hello"); Node world = hello.addNode("world"); world. setProperty ("message", "Hello, World!"); session. save (); // Retrieve content Node node = root. getNode ("hello/world"); print(node. getPath ()); print(node. getProperty ("message").getString());
  • 41. Contents
  • 46. Sling builds on top of JCR
    • Scriptable applications layer
    • 47. OSGi based industrial strength
    • 48. Simple, powerful, JCR inside
    • 49. Runs on Apache Jackrabbit by default
    • 50. Sling == REST over JCR
  • 51. Sling URL decomposition /content/cars/audi/s4.details.html
  • 52. Sling Architecture OSGi Framework Felix Web Console WebDAV Server browser filesystem debugger HTTP JSR-170/283 API JCR repository resource resolution servlet resolution standard servlets custom servlets JSR223 Scripting JSP javascript etc.
  • 53. Demo Preparation
    • Get Sling 5 Standalone from http://sling.apache.org/site/downloads.cgi
    • 54. Upgrade to Web Console 2.0.2 from http://felix.apache.org/site/downloads.cgi
    • 55. Compile and Install the Path based Resource Type Provider (from the samples/path-based-rtp folder)
  • 56. Contents
  • 61. Minimal Sling blog
    • One Script (blog.esp)
    • 62. JavaScript
    • 63. 46 Lines of Code (!)
    • 64. http://sling.apache.org/site/46-line-blog.html
  • 65. Sling POST servlet
      # POST to Sling curl -F title=hello http://localhost:8888/foo -> 200 OK # GET created node in json format curl http:/ /localhost:8888/foo.tidy.json { "jcr:primaryType": "nt:unstructured", "title": "hello" }
  • 66. Blog Step 1: Create Content
      <form method=“ POST “> Title: <input type=“text“ name=“ title “ /> Text: <textarea name=“ text ></textarea> <input type=“submit“ /> <input type=“hidden“ name=“:redirect“ value=“*.html“ /> </form>
  • 67. Blog Step 2: Retrieve Content
      <script src=“ /system/sling.js “></script> <form method=“POST“> ... </form> <!-- init form fields from current node --> <script> Sling.wizard(); </script>
  • 68. Blog Step 3: Navigation
      <ul> <li> <a href=“ /content/blog/*.html “> [Create new post]</a> </li> <script> var posts = Sling. getContent („/content/blog“, 2); for (var post in posts) { document.write(„<li><a href='“ + post + „.html'>“ + posts[post].title </a></li>“); } </script> </ul>
  • 69. We Got a Blog ! html form + Sling.wizard() + Sling.getContent()
  • 70. Contents
  • 75. The ESP Blog Sample
  • 83. ESP Blog Demo
  • 84. ESP Blog Source Files
  • 95. ESP Blog Content Structure
  • 96. ESP Blog Edit Script
      <% pageTitle = currentNode.title; load(&quot;header.esp&quot;); %> <body> <form method=&quot;POST&quot; action=&quot;<%= currentNode%>&quot;> <p><label>Title</label> <input name=&quot;title&quot; type=&quot;text&quot; value=&quot;<%= currentNode.title %>&quot;></p> ... <input type=&quot;hidden&quot; name=&quot;created&quot;/> <input name=&quot;:redirect&quot; type=&quot;hidden&quot; value=&quot;/content/espblog/posts.admin.html&quot;/> <input type=&quot;submit&quot; value=&quot;Post&quot; class=&quot;button&quot;> </form> ...
  • 97. ESP Blog Thumbnails: OSGi DS Component
      /** * Observe the espblog content for changes, and generate * thumbnails when images are added. * * maven-scr-plugin uses annotations to generate the OSGi * Declarative Services XML configuration files * @scr.component immediate=&quot;true&quot; * */ public class ThumbnailGenerator implements EventListener {
  • 98. ESP Blog Thumbnails: JCR Observation
      /** @scr.reference (framework injects it automatically) */ private SlingRepository repository; /** called by framework when service is activated */ protected void activate(ComponentContext context) { Session s = repository.loginAdministrative(null); // Listen for nt:file NODE_ADDED repository events ObservationManager m = s.getWorkspace().getObservationManager(); String[] types = { &quot;nt:file&quot; }; m.addEventListener( this, Event.NODE_ADDED, contentPath, true, null, types, false);
  • 99. ESP Blog Thumbnails: NODE_ADDED
      /** Called by JCR Observation manager for events that this * EventListener registered for */ public void onEvent(EventIterator it) { while (it.hasNext()) { Event event = it.nextEvent(); if (event.getType() == Event.NODE_ADDED && !(event.getPath().contains(&quot;thumbnails&quot;))) { String p = event.getPath(); Node n = session.getRootNode().getNode(p); createThumbnails(addedNode); } } ...
  • 100. We got a typical Sling Application!
    • JCR Features: WebDAV, Observation, nt:unstructured
    • 101. Sling Goodies: Simple Script mappings (BYOL), POST Servlet, RESTful interface
    • 102. OSGi Bundle, Code + Initial Content, Maven Plugins
  • 103. Where is Sling going ?
    • First Web Framework designed for JCR
    • 104. Embrace the web, act like a very clever web server !
    • 105. Intelligent HTTP/JSON storage
    • 106. OSGi
    • 107. Organic Application Growth
    • 108. Sling graduated as a TLP in May 2009
  • 109. Links
    • http://sling.apache.org/
    • 110. http://dev.day.com/
    • 111. http://contentcentric.org/
  • 112. Questions ?
  • 113. Thank You !