build your own cms with apache sling
TRANSCRIPT
“Build your own CMS with Apache Sling”By Bob Paulin
Paulin Solutions LLC
Independent Developer/Architect/Lead
Focused on:Web Centric Application Development
MobileDevelopment Support
Stuff Sling doesn't give you BYO...
Robust Login SecurityXSS ProtectionWYSIWYG Editors
The Problem:I want to create a content driven website.
Lots of Options
STOP!
Do one of these meet all of my needs or are they just part of the solution?
Why not use a framework instead!
SLING
What is Sling?
Best of Breed
Apache Felix (OSGi)Apache Jackrabbit (JCR)REST
Who's already using Sling?
Adobe CQ 5
How does Sling Work?
Sling Post ServletOne stop shop for Content CRUD
http://sling.apache.org/site/manipulating-content-the-slingpostservlet-servletspost.html
Create/Modifycurl -u admin:admin -Fmulti=one -Fmulti=two
http://localhost:8080/content/sample
Copy/Movecurl -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
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
Method
Resource Path Selectors Extension Suffix
POST /content/project/test.page.html/cool
HTML/content/sample.html
JSON/content/sample.json
XML/content/sample.xml
JCRWhat no tables?
Putting it all together
Everything is content.Configuration
ScriptsAssets
Everything.
Other fun OOTB Stuff
Authentication (form based, openid)Scheduling (Quartz)Version Control (JCR)Other JVM Languages (EcmaScript, Groovy, Scala.....)
Lets do some CODING!!
RecipeJDK 1.6EclipseMaven
Apache SlingGit
BootstrapjQuery
ckeditor
Installing Sling
1) Place JAR in Directory
2) java -jar -Xmx1024m -XX:MaxPermSize=256m -
agentlib:jdwp=transport=dt_socket,address=30303,server=y,suspend=n
org.apache.sling.launchpad-6-standalone.jar
Generate Project Archetypes
1) Create Parent POM2) Create module sling-initial-content-archetype
Install a few bundles from extras
http://localhost:8080/system/console/bundles
1) Sling Engine 2.2.4 (Bug Fix)2) JSTL libs3) Groovy
Create a Base Script
1) HTML boilerplate2) Styles (bootstrap)3) Any JavaScript4) Test Content
Create a WYSIWYG Page
1) 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
Create a Build a New Page...Page
1) Create new Script2) Add content node3) Add to menu
Build an Image Upload Page
1) Create image upload script2) Add content node3) Add to menu
Making it Groovy!(or Scala or Ruby or whatever you're willing to implement with
JSR 233)
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> <% }}%>
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>
<%}
%>
References
https://github.com/bobpaulin/sling-cms-demohttp://sling.apache.org/site/index.html
http://dev.day.com/content/docs/en/cq/current/developing/sling_cheatsheet.html
Questions
??????
Thank You.
Go forth and enjoy Sling
Email: [email protected]: @bobpaulinLinkedin: http://www.linkedin.com/in/bobpaulinBlog: http://bobpaulin.com