Rapid JCR applications development with Sling

10,259
-1

Published on

Slides of my "Rapid JCR applications development with Sling" at ApacheCon EU 2009. Starts like the US 2008 version but uses a different example for the second part.

Published in: Technology
2 Comments
8 Likes
Statistics
Notes
No Downloads
Views
Total Views
10,259
On Slideshare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
341
Comments
2
Likes
8
Embeds 0
No embeds

No notes for slide


















































































































  • Rapid JCR applications development with Sling

    1. Rapid JCR applications development with Apache Sling Bertrand Delacrétaz Senior R&D Developer, Day Software, www.day.com Member and Director, ASF bdelacretaz@apache.org blog at http:/ /grep.codeconsult.ch twitter: @bdelacretaz Slides revision: 2009-03- 20 Slides theme design: David Nuescheler Wednesday, March 25, 2009
    2. Rapid JCR applications development with Apache Sling Bertrand Delacrétaz Senior R&D Developer, Day Software, www.day.com Member and Director, ASF bdelacretaz@apache.org blog at http:/ /grep.codeconsult.ch twitter: @bdelacretaz Slides revision: 2009-03- 20 Slides theme design: David Nuescheler is thi busy s slide enou gh? Wednesday, March 25, 2009
    3. Intro to JCR JCR = Java Content Repository API JSR-170 / JSR283 - Everything Is Content - and JCR manages it as trees of Nodes and Properties, using rich data types. Wednesday, March 25, 2009
    4. Intro to JCR JCR = Java Content Repository API JSR-170 / JSR283 - silve r Everything Is Content - and JCR manages it as trees of Nodes and Properties, using rich data types. Wednesday, March 25, 2009
    5. What’s JCR? JSR-170 Content Repository for JavaTM technology API Spec-Lead: Day Software Status: Final Release 17-jun-2005 Expert Group: Wednesday, March 25, 2009
    6. What’s JCR? JSR-170 JSR-283 Content Repository for JavaTM technology API v2.0 Spec-Lead: Day Software Status: Public Review Closed sep-2007 Expert Group: Wednesday, March 25, 2009
    7. Wednesday, March 25, 2009
    8. What’s JCR? Wednesday, March 25, 2009
    9. What’s JCR? “The API should be a standard, implementation independent, way to access content bi-directionally on a granular level to a content repository.” Wednesday, March 25, 2009
    10. What’s JCR? “The API should be a standard, implementation independent, way to access content bi-directionally on a granular level to a content repository.” ? Wednesday, March 25, 2009
    11. What’s JCR? “The API should be a standard, implementation independent, way to access content bi-directionally on a granular level to a content repository.” ? Wednesday, March 25, 2009
    12. Best of both worlds. data base file s ys t e m hier- archi integ rity re es structu read streams tx write access query locking control multi- value ning obser- versio un-structured “full-text” sort vation order content repo sit or y Wednesday, March 25, 2009
    13. Best of both worlds. data base file s ys t e m hier- archi integ rity re es structu read streams tx write access query locking control multi- value ning obser- versio un-structured “full-text” sort vation order content repo sit or y Wednesday, March 25, 2009
    14. Known compliant Repositories Wednesday, March 25, 2009
    15. Known compliant Repositories * using third party connector * * Apache Exo Microsoft OpenText Jackrabbit Oracle XML DB ECMS Platform Sharepoint Livelink * Xythos Day CRX IBM FileNet P8 Repository Alfresco ECM Vignette V7 * * any ors ow mvendd? H S e +hun dre DBMou ne R do y Interwoven EMC TCKsds of regis Repository IBM CM Documentum tered Wednesday, March 25, 2009
    16. Some known JCR Applications Wednesday, March 25, 2009
    17. Some known JCR Applications Fast Enterprise BEA Portal Sun Oracle Portal Interface 21Search OpenPortal JBoss Portal Day Spring Communique Framework DAM Day magnolia WCMS Apache Sling Communique Alfresco ECMS Mindquarry ApacheCollab Collaboration Tapestry QSLabs Day Apache Compliance Communiqué IBM FileNet Cocoon WCMS Artifactory medic-2-medic WebSiteManage r Apache James Maven Proxy mapofmedicine Exo GX ECMS Platform TYPO3 WebManager v5.0 WCM InfoQ Liferay Online Hippo Enterprise Nuxeo ECM Community CMS Portal Jahia Sakai Percussion Framework E-learning Rhythmix QuickWCM Sourcemix WCMS Lutece Sourcemix Portal Wednesday, March 25, 2009
    18. Some known JCR Applications Fast Enterprise BEA Portal Sun Oracle Portal Interface 21Search OpenPortal JBoss Portal Day Spring Communique Framework DAM Day magnolia WCMS Apache Sling Communique Alfresco ECMS Mindquarry ApacheCollab Collaboration Tapestry QSLabs Day Apache Compliance Communiqué IBM FileNet Cocoon WCMS Artifactory medic-2-medic WebSiteManage r Apache James Maven Proxy mapofmedicine Exo GX ECMS Platform TYPO3 WebManager v5.0 WCM InfoQ Liferay Online Hippo Enterprise Nuxeo ECM Community CMS Portal Jahia Sakai Percussion Framework E-learning Rhythmix QuickWCM Sourcemix WCMS Lutece Sourcemix Portal Wednesday, March 25, 2009
    19. JCR code excerpt Repository repository = new TransientRepository(); Session session = repository.login(...); / Create content / Node root = session.getRootNode(); Node hello = root.addNode(quot;helloquot;); Node world = hello.addNode(quot;worldquot;); world.setProperty(quot;messagequot;, quot;Hello, World!quot;); session.save(); / Retrieve content / Node node = root.getNode(quot;hello/worldquot;); print(node.getPath()); print(node.getProperty(quot;messagequot;).getString()); Wednesday, March 25, 2009
    20. On to Sling Wednesday, March 25, 2009
    21. Sling builds on top of JCR Scriptable applications layer on top of JCR OSGi-based industrial-strength framework Simple, powerful, JCR inside Runs on Apache Jackrabbit by default http:/ /incubator.apache.org/sling Wednesday, March 25, 2009
    22. Sling builds on top of JCR Scriptable applications layer on top of JCR OSGi-based industrial-strength framework Simple, powerful, JCR inside Runs on Apache Jackrabbit by default http:/ /incubator.apache.org/sling join t he fun! Wednesday, March 25, 2009
    23. Sling == REST over JCR Wednesday, March 25, 2009
    24. Sling == REST over JCR REST -> Roy T. Fielding scheler JCR: David Nue 2005 rele a 1.0 r v ele ased sed y 162 p 2k +300 pages ages Wednesday, March 25, 2009
    25. Reclaiming the web. Sling URL decomposition. /cars/audi/s4.details.html Wednesday, March 25, 2009
    26. Reclaiming the web. Sling URL decomposition. /cars/audi/s4.details.html Repository Wednesday, March 25, 2009
    27. Reclaiming the web. Sling URL decomposition. /cars/audi/s4.details.html Content Repository epository Path R Wednesday, March 25, 2009
    28. Reclaiming the web. Sling URL decomposition. /cars/audi/s4.details.html Content Repository epository Path R Wednesday, March 25, 2009
    29. Reclaiming the web. Sling URL decomposition. /cars/audi/s4.details.html Content ...selects a Repository epository Path R particular scrip t Wednesday, March 25, 2009
    30. Sling architecture HTTP debugger filesystem browser standard custom servlets WebDAV Sling OSGi servlets and components server console javascript resource servlet/script OSGi bundles JSR 223 JSP Ruby resolution resolution scripting OSGi framework Velocity etc.. (Apache Felix) OSGi webapp JSR-170 API JCR repository Wednesday, March 25, 2009
    31. Sling architecture HTTP sling.js debugger filesystem browser utilit y POST, V json GE T WebDA access standard custom servlets WebDAV Sling OSGi servlets and components server console javascript resource servlet/script OSGi bundles JSR 223 JSP Ruby resolution resolution scripting OSGi framework Velocity etc.. (Apache Felix) OSGi webapp ESP de se r ver-si t ip JSR-170 API javascr JCR repository Wednesday, March 25, 2009
    32. A minimalone .esp script blog Consisting of Sling cat /Volumes/localhost/apps/blog/blog.esp | wc -l 54 Wednesday, March 25, 2009
    33. from e code : ge t th ay.com dev.d url.com/ /tiny 6 ht tp:/ gblog4 slin A minimalone .esp script blog Consisting of Sling cat /Volumes/localhost/apps/blog/blog.esp | wc -l 54 Wednesday, March 25, 2009
    34. 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 { quot;jcr:primaryTypequot;: quot;nt:unstructuredquot;, quot;titlequot;: quot;helloquot; } Wednesday, March 25, 2009
    35. Sling POST servlet # POST to Sling curl -F title=hello http://localhost:8888/foo -> 200 OK POST se t e ters s # GET created node in json format param opertie curl http:/ /localhost:8888/foo.tidy.json node pr { quot;jcr:primaryTypequot;: quot;nt:unstructuredquot;, quot;titlequot;: quot;helloquot; } Wednesday, March 25, 2009
    36. blog step 1: create content ! <form method=quot;POSTquot;> ! Title: ! <input type=quot;textquot; name=quot;titlequot; style=quot;width:100%quot;/> ! ! Text: ! <textarea style=quot;width:100%quot; name=quot;textquot;></textarea> ! ! <input type=quot;submitquot; value=quot;savequot;/> ! ! <input type=quot;hiddenquot; name=quot;:redirectquot; value=quot;*quot;/> ! </form> Wednesday, March 25, 2009
    37. blog step 1: create content ! <form method=quot;POSTquot;> ! Title: ! <input type=quot;textquot; name=quot;titlequot; style=quot;width:100%quot;/> ! ! Text: ! <textarea style=quot;width:100%quot; name=quot;textquot;></textarea> ! ! <input type=quot;submitquot; value=quot;savequot;/> ! ! <input type=quot;hiddenquot; name=quot;:redirectquot; value=quot;*quot;/> ! </form> dri ve fields t Form onten the c el mod Wednesday, March 25, 2009
    38. blog step 2: retrieve content <script src=quot;/system/sling.jsquot;></script>! <form method=quot;POSTquot;> ... </form> <!-- initialize form fields from current node values --> <script>Sling.wizard();</script> Wednesday, March 25, 2009
    39. blog step 2: retrieve content <script src=quot;/system/sling.jsquot;></script>! <form method=quot;POSTquot;> ... </form> <!-- initialize form fields from current node values --> <script>Sling.wizard();</script> U(D) Inst ant CR Wednesday, March 25, 2009
    40. blog step 3: navigation <ul> <li> <a href=quot;/content/blog/*quot;> [Create new post]</a> </li> ! <script> ! var posts = Sling.getContent(quot;/content/blogquot;, 2); ! for(var post in posts) { ! ! document.write( quot;<li><a href=’” + post + quot;'>quot; + posts[post].title + quot;</a></li>quot;); ! } ! </script> </ul> Wednesday, March 25, 2009
    41. we got a blog! html form + Sling.wizard() + Sling.getContent() Wednesday, March 25, 2009
    42. The ESP blog sample ESP scripting + java + javascript OSGi bundle, initial content, WebDAV, observation, RAD Wednesday, March 25, 2009
    43. The ESP blog sample ESP scripting + java + javascript OSGi bundle, initial content, WebDAV, observation, RAD mples ng/sa / der sli rl.com de un inyu Co ht tp:/ t logesp / slingb Wednesday, March 25, 2009
    44. ESP blog in action create retrieve thumbnails update Wednesday, March 25, 2009
    45. ESPblog demo Wednesday, March 25, 2009
    46. ESP blog source files admin.esp pom.xml edit.esp ThumbnailGeneratorService.java html.esp ThumbnailGeneratorServiceImpl.java list.esp espblog.css menu.esp sling-logo.png xml.esp (RSS feed) constants.esp header.esp Wednesday, March 25, 2009
    47. ESP blog source files admin.esp pom.xml edit.esp ThumbnailGeneratorService.java html.esp ThumbnailGeneratorServiceImpl.java list.esp espblog.css menu.esp sling-logo.png xml.esp (RSS feed) constants.esp source log re s to espb oint header.esp t ype p ripts those sc Wednesday, March 25, 2009
    48. ESP blog content structure JSON dump WebDAV view Wednesday, March 25, 2009
    49. <% ESP blog edit script pageTitle = currentNode.title; load(quot;header.espquot;); %> <body> <form method=quot;POSTquot; action=quot;<%= currentNode %>quot;> <p><label>Title</label> <input name=quot;titlequot; type=quot;textquot; value=quot;<%= currentNode.title %>quot;></p> ... <input type=quot;hiddenquot; name=quot;createdquot;/> <input name=quot;:redirectquot; type=quot;hiddenquot; value=quot;/content/espblog/posts.admin.htmlquot;/> <input type=quot;submitquot; value=quot;Postquot; class=quot;buttonquot;> </form> ... Wednesday, March 25, 2009
    50. ESP blog thumbnails: OSGi service /** * 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.service * @scr.component immediate=quot;truequot; * */ public class ThumbnailGeneratorServiceImpl implements ThumbnailGeneratorService, EventListener { Wednesday, March 25, 2009
    51. ESP blog thumbnails: 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:filequot; }; ! m.addEventListener( this, Event.NODE_ADDED, contentPath, ...); Wednesday, March 25, 2009
    52. 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;thumbnailsquot;))) { String p = event.getPath(); Node n = session.getRootNode().getNode(p); createThumbnails(addedNode); } } ... Wednesday, March 25, 2009
    53. 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. Wednesday, March 25, 2009
    54. We got a typical Sling application! JCR features: WebDAV, observation, nt:unstructured. Sling goodies: simple script mappings (BYOL), POST servlet, RESTful interface. ource blog s under ESP found es ode is ampl OSGi bundle, code + initial c sling/s content, Maven plugins. Wednesday, March 25, 2009
    55. Where is Sling going? Wednesday, March 25, 2009
    56. Where is Sling going? (aka conclusion) First web framework designed for JCR. Embrace the web, act like a very clever web server! Intelligent HTTP/JSON storage? OSGi, organic app growth. Growing community, graduate in 2009? http://incubator.apache.org/sling http://dev.day.com http://contentcentric.org/ Wednesday, March 25, 2009
    57. Where is Sling going? (aka conclusion) First web framework designed for JCR. Embrace the web, act like a very clever web server! Intelligent HTTP/JSON storage? not a web OSGi, organic app growth. “Sling is s ation a applic k, it’s fram e wor Growing community, graduate ame work” in 2009? w eb f r http://incubator.apache.org/sling http://dev.day.com join t hehttp://contentcentric.org/ fun! Wednesday, March 25, 2009

    ×