You are on page 1of 21

JCR & Sling quick dive

Paolo Mottadelli | Senior Sales Engineer

2010 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.

Background

The WWW design approach:


Single, simple standardize interface Independent from storage/creation Trascends the complexity

Same design principles for application development:


Commitment to standardization Simple, generic, Content-Centric interface

2010 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.

Content-centric vs Control-centric interfaces

Content-centric interfaces principles:


Uniform identifiers Standard methods Extensible representation types Simplified application integration (much less interfaces)

Content Repository API = Uniform interface

2010 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.

Content Repository

A Content Repository supports:

Diverse data:

small & large, structured & unstructured, binary, metadata & relationships access control, locking, versioning, transactions, observation

Services:

The Java Content Repository provides:


Abstraction of data storage Generalized content services Separation of real storage from application interactions Standard API
4

2010 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.

JCR

The JCR specification defines an abstract model and a Java API for data storage and related services commonly used by content-oriented applications.
!

Target: any application that must handle both unstructured digital assets and structured or semi-structured information.

2010 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.

JCR: The Repository Model

Workspaces Hierarchy of nodes Properties associated to a node Node types define constraints (properties and child nodes)

Repository

Workspace
[root]

Workspace
[root]

Workspace
[root]

jcr:title = Hello World jcr:lastModiedBy = admin

2010 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.

JSON representation of a node

http://localhost:7402/content/rststeps.innity.json

2010 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.

JCR code sample


Repository repository = new TransientRepository(); Session session = repository.login(new SimpleCredentials("username", "password".toCharArray())); // Store content Node hello = root.addNode("hello"); Node world = hello.addNode("world"); world.setProperty("message", "Hello, World!"); session.save(); // Retrieve content Node node = root.getNode("hello/world"); System.out.println(node.getPath()); System.out.println(node.getProperty("message").getString()); // Remove content root.getNode("hello").remove(); session.save();
2010 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.

JCR: Repository Functionalities

Level 1

Level 2
Write nodes & properties ! XML Import ! Assign a node types to nodes ! Change namespace registry
!

Login Read Nodes & properties XML export XPath queries Node types discovery Namespaces remapping

Optional
Locking ! Transactions ! Versioning
!

SQL search ! Observation


!

2010 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.

JCR: Observation
!

Observation enables an application to receive notification of persistence changes in the workspace. Base for BPM.
! ! ! ! ! !

NODE_ADDED NODE_MOVED NODE_REMOVED PROPERTY_ADDED PROPERTY_REMOVED PROPERTY_CHANGED

Can be asynchronous or journaled


10

2010 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.

JCR: Content Modelling

2 use cases:

[nt:resource] > mix:mimeType, mix:lastModied primaryitem jcr:data - jcr:data (BINARY) mandatory

Structured content (e.g. file storage)


Needs definition of content models; Needs a stable structure; nt:resource

Unstructured content
Any properties and child nodes allowed nt:unstructured

2010 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.

11

JCR: node types & mixin types


!

predefined node types:


! ! ! ! !

nt:unstructured nt:file nt:folder nt:resource represents the actual content of a file. nt:version

mixin types provide extra characteristics to the node:


! ! !

mix:versionable: allows a node to support versioning mix:lockable: enables locking capabilities mix:referenceable: provides an auto-created jcr:uuid property
12

2010 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.

JCR Ecosystem

Open Standard

Java Community Process (http://jcp.org) Reference Implementation & TCK license, workspace, information open review, testing & collaboration

Sustainability

Apache infrastructure

Community

Open adoption
13

2010 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.

Sling

OSGI-based scriptable application layer on top of JCR


! ! ! ! !

REST based web framework Content-driven, using a JCR content repository Powered by OSGi Scripting inside, multiple languages (JSP, server-side javascript, Scala, etc.) Apache Open Source project

2010 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.

14

The Sling style

If you happen to hear this sentence:

Sling is not a web applications framework, its a web framework.

It means:

Sling is built in a way that embraces the web. Sling design is based on the principles of the WWW. Sling processes HTTP requests in a RESTful way.

2010 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.

15

CRX Architecture HTTP


" processes HTTP requests in a RESTful way

Application framework (sling) OSGI framework (felix)


specification implementation

architectural style

" manages bundles as app components " provides system services to bundles

JCR api
" stores the content

JCR repository (jackrabbit)


2010 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.

16

Sling Architecture HTTP


standard servlets custom servlets and components javascript JSP Scala resource resolution servlet/script resolution JSR 223 scripting Ruby ... WedDAV server sling OSGI console

sling

felix
JCR api

jackrabbit
2010 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.

17

Sling examples using cURL


!

Create a node
!

curl -F"sling:resourceType=foo/bar" -F"title=some title" http://admin:admin@localhost:7402/content/mynode

Create a node (auto-named)


! !

curl -X POST "http://admin:admin@localhost:7402/content/blog" curl -D - -F"title=Adventures with Sling" "http://admin:admin@localhost:7402/content/blog/*"

2010 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.

18

Sling URL decomposition

/geometrixx/en/products/triangle.html
defines the resource defines the rendition

/geometrixx/en/products/triangle.teaser.html
2010 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.

19

Sling URL decomposition

/geometrixx/en/products/triangle.teaser.html

sling:resourceType geometrixx/components/contentpage

2010 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.

20

Where to go from here

JSR 283 spec: http://jcp.org/en/jsr/detail?id=283 ! Apache Jackrabbit: http://jackrabbit.apache.org/ ! Apache Sling: http://sling.apache.org/
! !

First steps with CRX:


!

http://dev.day.com/docs/en/crx/current/getting_started/first_steps_with_crx.html

2010 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.

21

You might also like