Rapid JCR Applications Development with Sling
Upcoming SlideShare
Loading in...5
×
 

Like this? Share it with your network

Share

Rapid JCR Applications Development with Sling

on

  • 7,616 views

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.

Statistics

Views

Total Views
7,616
Views on SlideShare
7,549
Embed Views
67

Actions

Likes
4
Downloads
203
Comments
0

5 Embeds 67

http://dev.day.com 48
http://www.slideshare.net 15
http://www.linkedin.com 2
https://www.eclipsecon.org 1
https://dev.day.com 1

Accessibility

Categories

Upload Details

Uploaded via as OpenOffice

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

Rapid JCR Applications Development with Sling Presentation 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:
      • Sling
      • 6. Felix
      • 7. Jackrabbit
  • 8. Contents
    • Introduction to JCR
    • 9. Sling Overview
    • 10. Single Script Blog
    • 11. ESP Blog
    • 12. Questions
  • 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
    • Implementations
      • Apache Jackrabbit
      • 28. Day CRX
      • 29. Oracle XML DB
      • 30. IBM FileNet P8
      • 31. IBM CM
      • 32. Exo ECMS Platform
      • 33. Xythos Repository
      • 34. Alfresco ECM
    • Connectors:
      • Interwoven Repository
      • 35. EMC Documentum
      • 36. MS Sharepoint
      • 37. OpenText Livelink
      • 38. Vignette V7
    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
    • Introduction to JCR
    • 42. Sling Overview
    • 43. Single Script Blog
    • 44. ESP Blog
    • 45. Questions
  • 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
    • Introduction to JCR
    • 57. Sling Overview
    • 58. Single Script Blog
    • 59. ESP Blog
    • 60. Questions
  • 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
    • Introduction to JCR
    • 71. Sling Overview
    • 72. Single Script Blog
    • 73. ESP Blog
    • 74. Questions
  • 75. The ESP Blog Sample
    • ESP (Server side JavaScript) scripting
    • 76. Java
    • 77. JavaScript
    • 78. OSGi Bundle
    • 79. Initial Content
    • 80. WebDAV
    • 81. Observation
    • 82. http://tinyurl.com/slingblogesp2
  • 83. ESP Blog Demo
  • 84. ESP Blog Source Files
    • admin.esp
    • 85. edit.esp
    • 86. html.esp
    • 87. list.esp
    • 88. menu.esp
    • 89. xml.esp (RSS)
    • 90. constants.esp
    • 91. header.esp
    • pom.xml
    • 92. ThumbnailGenerator.java
    • 93. espblog.css
    • 94. sling-logo.png
  • 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 !