Rapid JCR Applications Development with Sling

Loading...

Flash Player 9 (or above) is needed to view presentations.
We have detected that you do not have it on your computer. To install it, go here.

0 comments

Post a comment

    Post a comment
    Embed Video
    Edit your comment Cancel

    Favorites, Groups & Events

    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
      • fmeschbe@apache.org
      • http://blog.meschberger.ch
      • Apache Projects:
        • Sling
        • Felix
        • Jackrabbit
    3. Contents
      • Introduction to JCR
      • Sling Overview
      • Single Script Blog
      • ESP Blog
      • Questions
    4. Intro to JCR
      • JCR = Java Content Repository
      • Specifications
        • JSR-170 / JCR 1.0
        • JSR-283 / JCR 2.0
      • Everything is Content
        • JCR manages it in trees of Nodes & Properties
        • Rich Data Types
    5. JSR-170
      • Content Repository for Java TM technology API
      • Spec Lead: David Nüscheler, Day Software
      • Final Release: 17 June 2005
      • Expert Group:
    6. JSR-283
      • Content Repository for Java TM Technology API Version 2.0
      • Spec Lead: David Nüscheler, Day Software
      • Final Release: 25 September 2009
      • Expert Group:
    7. 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.
    8. 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
    9. Implementations
      • Implementations
        • Apache Jackrabbit
        • Day CRX
        • Oracle XML DB
        • IBM FileNet P8
        • IBM CM
        • Exo ECMS Platform
        • Xythos Repository
        • Alfresco ECM
      • Connectors:
        • Interwoven Repository
        • EMC Documentum
        • MS Sharepoint
        • OpenText Livelink
        • Vignette V7
      100s of TCKs registered
    10. Some known Applications
    11. 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());
    12. Contents
      • Introduction to JCR
      • Sling Overview
      • Single Script Blog
      • ESP Blog
      • Questions
    13. Sling builds on top of JCR
      • Scriptable applications layer
      • OSGi based industrial strength
      • Simple, powerful, JCR inside
      • Runs on Apache Jackrabbit by default
      • Sling == REST over JCR
    14. Sling URL decomposition /content/cars/audi/s4.details.html
    15. 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.
    16. Demo Preparation
      • Get Sling 5 Standalone from http://sling.apache.org/site/downloads.cgi
      • Upgrade to Web Console 2.0.2 from http://felix.apache.org/site/downloads.cgi
      • Compile and Install the Path based Resource Type Provider (from the samples/path-based-rtp folder)
    17. Contents
      • Introduction to JCR
      • Sling Overview
      • Single Script Blog
      • ESP Blog
      • Questions
    18. Minimal Sling blog
      • One Script (blog.esp)
      • JavaScript
      • 46 Lines of Code (!)
      • http://sling.apache.org/site/46-line-blog.html
    19. 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" }
    20. 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>
    21. 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>
    22. 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>
    23. We Got a Blog ! html form + Sling.wizard() + Sling.getContent()
    24. Contents
      • Introduction to JCR
      • Sling Overview
      • Single Script Blog
      • ESP Blog
      • Questions
    25. The ESP Blog Sample
      • ESP (Server side JavaScript) scripting
      • Java
      • JavaScript
      • OSGi Bundle
      • Initial Content
      • WebDAV
      • Observation
      • http://tinyurl.com/slingblogesp2
    26. ESP Blog Demo
    27. ESP Blog Source Files
      • admin.esp
      • edit.esp
      • html.esp
      • list.esp
      • menu.esp
      • xml.esp (RSS)
      • constants.esp
      • header.esp
      • pom.xml
      • ThumbnailGenerator.java
      • espblog.css
      • sling-logo.png
    28. ESP Blog Content Structure
    29. 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> ...
    30. 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 {
    31. 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);
    32. 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); } } ...
    33. We got a typical Sling Application!
      • JCR Features: WebDAV, Observation, nt:unstructured
      • Sling Goodies: Simple Script mappings (BYOL), POST Servlet, RESTful interface
      • OSGi Bundle, Code + Initial Content, Maven Plugins
    34. Where is Sling going ?
      • First Web Framework designed for JCR
      • Embrace the web, act like a very clever web server !
      • Intelligent HTTP/JSON storage
      • OSGi
      • Organic Application Growth
      • Sling graduated as a TLP in May 2009
    35. Links
      • http://sling.apache.org/
      • http://dev.day.com/
      • http://contentcentric.org/
    36. Questions ?
    37. Thank You !

    + Felix MeschbergerFelix Meschberger, 3 weeks ago

    custom

    168 views, 0 favs, 1 embeds more stats

    Apache Sling is an OSGi-based, scriptable applicati more

    More info about this document

    © All Rights Reserved

    Go to text version

    • Total Views 168
      • 152 on SlideShare
      • 16 from embeds
    • Comments 0
    • Favorites 0
    • Downloads 11
    Most viewed embeds
    • 16 views on http://dev.day.com

    more

    All embeds
    • 16 views on http://dev.day.com

    less

    Flagged as inappropriate Flag as inappropriate
    Flag as inappropriate

    Select your reason for flagging this presentation as inappropriate. If needed, use the feedback form to let us know more details.

    Cancel
    File a copyright complaint
    Having problems? Go to our helpdesk?

    Categories