Build Your Own CMS with Apache Sling

14,482 views
14,158 views

Published on

Published in: Technology
0 Comments
17 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
14,482
On SlideShare
0
From Embeds
0
Number of Embeds
97
Actions
Shares
0
Downloads
205
Comments
0
Likes
17
Embeds 0
No embeds

No notes for slide
  • Sell yourself I write code I do design/architecture I lead teams I make development teams better.
  • And that's a good thing because these are often things that we want to define.
  • I want to build a website that people can go to and enter content. Without training, intuitive
  • Lots of product options. Each has it's benefits Many can be stood up quickly out of the box. But what if I want to customize?
  • Wait you just said the C word Customizing a product can be death by 1000 cuts depending on what you're doing.
  • Frameworks offer a middle ground. They solve a problem but still grant you the flexibility to customize.
  • So lets talk about sling
  • Combination of open source projects to make content driven sites easier.
  • Kind of a chicken or egg thing here. David Neuschler of Day Software created the JSR for JCR. They build Day CQ. Then donated the Sling framework to Apache. A number of Day (now Adobe) employees still run the community for it.
  • Very different mind set than your typical Web App. Content not MVC runs the show.
  • So Sling is RESTful by design HTTP request to get data in and out GET - retrieve POST – Create/Modify
  • Run simple curl commands Note we're creating a multi value field Display the urls through curl
  • The most sophisticated part of the system. And the hardest to learn. But once you get it. Some incredibly hard problems become easy.
  • Resource Path – just like your typical web app. Where to retrieve information from. Selectors – Identifies specific content and acts as a parameter passer. Great for SEO. Extention – helps identify the script we're running. Suffix – a second path that is useful to identify additional content.
  • Note that the multi field is missing. A Bug? Maybe I should submit a jira :).
  • JCR is the persistence for sling. Underlying it is a file system or a Database. Can run on several Dbs. OOTB it's HSQL.
  • Eclipse provides a plugin to view and do some simple JCR modifications. One way to administer. Also could use WebDav to move files. Or maven or json/xml with sling.
  • Lets trace what a homepage request will look like in our soon to be live CMS.
  • Here is the structure Bot extend the JCR root Apps directory contains scripts: JSP, GSP, ESP.. could be more. Content directory contains content nodes.
  • Request comes into sling and resolves to a node. That node looks at it's type then tries to resolve a script
  • That type searches the apps directory (also could go to the libs directory) Once it gets to the folder it wants then it tries to resolve to a script using selectors and extentions. Script executes but wait theirs a sling include tag
  • Ok we're looking for a node content that's a child of the node we asked for. Child also then resolves it's type
  • Back to the script directory Selectors and extensions are once again used. If none are provided they are inherited from the parent. Page returns.
  • It's a polygot programmers playground
  • Build Your Own CMS with Apache Sling

    1. 1. “Build your own CMS with Apache Sling” By Bob Paulin Paulin Solutions LLC
    2. 2. Independent Developer/Architect/Lead Focused on:Web Centric Application Development Mobile Development Support
    3. 3. Stuff Sling doesnt give youBYO...Robust Login SecurityXSS ProtectionWYSIWYG Editors
    4. 4. The Problem:I want to create a content driven website.
    5. 5. Lots of Options
    6. 6. STOP!Do one of these meet all of my needs or are they just part of the solution?
    7. 7. Why not use a framework instead! SLING
    8. 8. What is Sling?
    9. 9. Best of BreedApache Felix (OSGi)Apache Jackrabbit (JCR)REST
    10. 10. Whos already using Sling? Adobe CQ 5
    11. 11. How does Sling Work?
    12. 12. Sling Post Servlet One stop shop for Content CRUDhttp://sling.apache.org/site/manipulating-content-the-slingpostservlet-servletspost.html
    13. 13. Create/Modify curl -u admin:admin -Fmulti=one -Fmulti=two http://localhost:8080/content/sample Copy/Move curl -u admin:admin -F":operation=copy" -F":dest=/content/target" http://localhost:8080/content/sample Deletecurl -u admin:admin -F":operation=delete" http://localhost:8080/content/target
    14. 14. Resource ResolutionHow do I get what I want how I want it http://sling.apache.org/site/dispatching-requests.html http://sling.apache.org/site/url-decomposition.html
    15. 15. Method Resource Path Selectors Extension SuffixPOST /content/project/test.page.html/cool
    16. 16. HTML/content/sample.html
    17. 17. JSON/content/sample.json
    18. 18. XML/content/sample.xml
    19. 19. JCRWhat no tables?
    20. 20. Putting it all together
    21. 21. Everything is content. Configuration Scripts Assets Everything.
    22. 22. Other fun OOTB StuffAuthentication (form based, openid)Scheduling (Quartz)Version Control (JCR)Other JVM Languages (EcmaScript,Groovy, Scala.....)
    23. 23. Lets do some CODING!!
    24. 24. Recipe JDK 1.6 Eclipse MavenApache Sling Git Bootstrap jQuery ckeditor
    25. 25. Installing Sling 1) Place JAR in Directory 2) java -jar -Xmx1024m -XX:MaxPermSize=256m-agentlib:jdwp=transport=dt_socket,address=30 303,server=y,suspend=n org.apache.sling.launchpad-6-standalone.jar
    26. 26. Generate Project Archetypes1) Create Parent POM2) Create module sling-initial-content-archetype
    27. 27. Install a few bundles from extrashttp://localhost:8080/system/console/bundles 1) Sling Engine 2.2.4 (Bug Fix) 2) JSTL libs 3) Groovy
    28. 28. Create a Base Script1) HTML boilerplate2) Styles (bootstrap)3) Any JavaScript4) Test Content
    29. 29. Create a WYSIWYG Page1) Import ckeditor JavaScript libs2) Add JavaScript Include to head.jsp3) Create new Script for content page4) Add sling include to base script5) Add content node to Home Page
    30. 30. Create a Build a New Page...Page1) Create new Script2) Add content node3) Add to menu
    31. 31. Build an Image Upload Page1) Create image upload script2) Add content node3) Add to menu
    32. 32. Making it Groovy!(or Scala or Ruby or whateveryoure willing to implement with JSR 233)
    33. 33. Build a Menu that builds itself <% def resourceResolver = request.getResourceResolver();def rootContent = resourceResolver.getResource("/content/slingdemo/home"); %> <% rootContent.listChildren().each{ curRes -> if(curRes.isResourceType("slingdemo:base")) { def curPageNode = curRes.adaptTo(javax.jcr.Node); %> <li><a href="<%=curRes.getPath()%>.html"><%= curPageNode.getProperty("title").getString()%></a></li> <% } } %>
    34. 34. Make the Image Page Groovy<% def resourceResolver = request.getResourceResolver(); def rootContent =resourceResolver.getResource("/content/slingdemo/assets/img");%><% rootContent.listChildren().each{ curRes ->%> <img src="<%= curRes.getPath()%>"/></br><% }%>
    35. 35. References https://github.com/bobpaulin/sling-cms-demo http://sling.apache.org/site/index.htmlhttp://dev.day.com/content/docs/en/cq/current/developing/sling_cheatsheet.html
    36. 36. Questions ??????
    37. 37. Thank You. Go forth and enjoy SlingEmail: bob@bobpaulin.comTwitter: @bobpaulinLinkedin: http://www.linkedin.com/in/bobpaulinBlog: http://bobpaulin.com

    ×