build your own cms with apache sling

43
“Build your own CMS with Apache Sling” By Bob Paulin Paulin Solutions LLC

Upload: bob-paulin

Post on 27-Jan-2017

15.393 views

Category:

Technology


4 download

TRANSCRIPT

Page 1: Build Your Own CMS with Apache Sling

“Build your own CMS with Apache Sling”By Bob Paulin

Paulin Solutions LLC

Page 2: Build Your Own CMS with Apache Sling

Independent Developer/Architect/Lead

Focused on:Web Centric Application Development

MobileDevelopment Support

Page 3: Build Your Own CMS with Apache Sling

Stuff Sling doesn't give you BYO...

Robust Login SecurityXSS ProtectionWYSIWYG Editors

Page 4: Build Your Own CMS with Apache Sling

The Problem:I want to create a content driven website.

Page 5: Build Your Own CMS with Apache Sling

Lots of Options

Page 6: Build Your Own CMS with Apache Sling

STOP!

Do one of these meet all of my needs or are they just part of the solution?

Page 7: Build Your Own CMS with Apache Sling

Why not use a framework instead!

SLING

Page 8: Build Your Own CMS with Apache Sling

What is Sling?

Page 9: Build Your Own CMS with Apache Sling

Best of Breed

Apache Felix (OSGi)Apache Jackrabbit (JCR)REST

Page 10: Build Your Own CMS with Apache Sling

Who's already using Sling?

Adobe CQ 5

Page 11: Build Your Own CMS with Apache Sling

How does Sling Work?

Page 12: Build Your Own CMS with Apache Sling

Sling Post ServletOne stop shop for Content CRUD

http://sling.apache.org/site/manipulating-content-the-slingpostservlet-servletspost.html

Page 13: Build Your Own CMS with Apache Sling

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

Page 14: Build Your Own CMS with Apache Sling

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

Page 15: Build Your Own CMS with Apache Sling

Method

Resource Path Selectors Extension Suffix

POST /content/project/test.page.html/cool

Page 16: Build Your Own CMS with Apache Sling

HTML/content/sample.html

Page 17: Build Your Own CMS with Apache Sling

JSON/content/sample.json

Page 18: Build Your Own CMS with Apache Sling

XML/content/sample.xml

Page 19: Build Your Own CMS with Apache Sling

JCRWhat no tables?

Page 20: Build Your Own CMS with Apache Sling
Page 21: Build Your Own CMS with Apache Sling

Putting it all together

Page 22: Build Your Own CMS with Apache Sling
Page 23: Build Your Own CMS with Apache Sling
Page 24: Build Your Own CMS with Apache Sling
Page 25: Build Your Own CMS with Apache Sling
Page 26: Build Your Own CMS with Apache Sling
Page 27: Build Your Own CMS with Apache Sling

Everything is content.Configuration

ScriptsAssets

Everything.

Page 28: Build Your Own CMS with Apache Sling

Other fun OOTB Stuff

Authentication (form based, openid)Scheduling (Quartz)Version Control (JCR)Other JVM Languages (EcmaScript, Groovy, Scala.....)

Page 29: Build Your Own CMS with Apache Sling

Lets do some CODING!!

Page 30: Build Your Own CMS with Apache Sling

RecipeJDK 1.6EclipseMaven

Apache SlingGit

BootstrapjQuery

ckeditor

Page 31: Build Your Own CMS with Apache Sling

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

Page 32: Build Your Own CMS with Apache Sling

Generate Project Archetypes

1) Create Parent POM2) Create module sling-initial-content-archetype

Page 33: Build Your Own CMS with Apache Sling

Install a few bundles from extras

http://localhost:8080/system/console/bundles

1) Sling Engine 2.2.4 (Bug Fix)2) JSTL libs3) Groovy

Page 34: Build Your Own CMS with Apache Sling

Create a Base Script

1) HTML boilerplate2) Styles (bootstrap)3) Any JavaScript4) Test Content

Page 35: Build Your Own CMS with Apache Sling

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

Page 36: Build Your Own CMS with Apache Sling

Create a Build a New Page...Page

1) Create new Script2) Add content node3) Add to menu

Page 37: Build Your Own CMS with Apache Sling

Build an Image Upload Page

1) Create image upload script2) Add content node3) Add to menu

Page 38: Build Your Own CMS with Apache Sling

Making it Groovy!(or Scala or Ruby or whatever you're willing to implement with

JSR 233)

Page 39: Build Your Own CMS with Apache Sling

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> <% }}%>

Page 40: Build Your Own CMS with Apache Sling

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>

<%}

%>

Page 41: Build Your Own CMS with Apache Sling

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

Page 42: Build Your Own CMS with Apache Sling

Questions

??????

Page 43: Build Your Own CMS with Apache Sling

Thank You.

Go forth and enjoy Sling

Email: [email protected]: @bobpaulinLinkedin: http://www.linkedin.com/in/bobpaulinBlog: http://bobpaulin.com