rapid jcr applications development with sling

Download Rapid JCR Applications Development with Sling

If you can't read please download the document

Upload: felix-meschberger

Post on 16-Apr-2017

7.344 views

Category:

Technology


4 download

TRANSCRIPT

Slide 1

Rapid JCR Applications Development with Sling

Felix MeschbergerApacheCon US 09

About

Senior Developer at Day

[email protected]

http://blog.meschberger.ch

Apache Projects:Sling

Felix

Jackrabbit

Contents

Introduction to JCR

Sling Overview

Single Script Blog

ESP Blog

Questions

Intro to JCR

JCR = Java Content Repository

SpecificationsJSR-170 / JCR 1.0

JSR-283 / JCR 2.0

Everything is ContentJCR manages it in trees of Nodes & Properties

Rich Data Types

JSR-170

Content Repository for JavaTM technology API

Spec Lead: David Nscheler, Day Software

Final Release: 17 June 2005

Expert Group:

JSR-283

Content Repository for JavaTM Technology API Version 2.0

Spec Lead: David Nscheler, Day Software

Final Release: 25 September 2009

Expert Group:

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.

JCRJCR = 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

DBFS

Implementations

ImplementationsApache 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

Some known Applications

JCR code excerpt

Repository repository = new TransientRepository();Session session = repository.login(...);

// Create contentNode root = session.getRootNode();Node hello = root.addNode("hello");Node world = hello.addNode("world");world.setProperty("message", "Hello, World!");session.save();

// Retrieve contentNode node = root.getNode("hello/world");print(node.getPath());print(node.getProperty("message").getString());

Contents

Introduction to JCR

Sling Overview

Single Script Blog

ESP Blog

Questions

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

Sling URL decomposition

/content/cars/audi/s4.details.html

Sling Architecture

OSGi FrameworkFelixWeb ConsoleWebDAVServerbrowserfilesystemdebuggerHTTPJSR-170/283 APIJCRrepositoryresourceresolutionservletresolutionstandardservletscustomservletsJSR223ScriptingJSPjavascriptetc.

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)

Contents

Introduction to JCR

Sling Overview

Single Script Blog

ESP Blog

Questions

Minimal Sling blog

One Script (blog.esp)

JavaScript

46 Lines of Code (!)

http://sling.apache.org/site/46-line-blog.html

Sling POST servlet

# POST to Slingcurl -F title=hello http://localhost:8888/foo-> 200 OK # GET created node in json formatcurl http:/ /localhost:8888/foo.tidy.json{ "jcr:primaryType": "nt:unstructured", "title": "hello"}

Blog Step 1: Create Content


Title:


Text:




Blog Step 2: Retrieve Content



...



Sling.wizard();

Blog Step 3: Navigation




  • [Create new post]


    var posts = Sling.getContent(/content/blog, 2);
    for (var post in posts) {
    document.write(

  • + posts[post].title);
    }

We Got a Blog !

html form+Sling.wizard()+Sling.getContent()

Contents

Introduction to JCR

Sling Overview

Single Script Blog

ESP Blog

Questions

The ESP Blog Sample

ESP (Server side JavaScript) scripting

Java

JavaScript

OSGi Bundle

Initial Content

WebDAV

Observation

http://tinyurl.com/slingblogesp2

ESP Blog Demo

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

ESP Blog Content Structure

ESP Blog Edit Script




Title

...




...

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="true"
*
*/
public class ThumbnailGenerator implements EventListener {

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 = { "nt:file" };
m.addEventListener(
this,
Event.NODE_ADDED,
contentPath,
true,
null,
types,
false);

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("thumbnails")))
{
String p = event.getPath();
Node n = session.getRootNode().getNode(p);
createThumbnails(addedNode);
}
}
...

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

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

Links

http://sling.apache.org/

http://dev.day.com/

http://contentcentric.org/

Questions ?

Thank You !