JCR and Sling Quick Dive

Post on 08-May-2015

5,505 views 0 download

description

When getting in first touch with CQ5 and CRX, shipped by Day Software, now part of Adobe, the stakeholders need to understand the basic concept of the Open Architecture embraced by those systems.This is an easy to understand introduction to JCR and Sling architecture.

transcript

©2010 Adobe Systems Incorporated. All Rights Reserved. Adobe Con!dential.

JCR & Sling quick divePaolo Mo"adelli | Senior Sales Engineer

©2010 Adobe Systems Incorporated. All Rights Reserved. Adobe Con!dential.

Background

■ !e 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

2

©2010 Adobe Systems Incorporated. All Rights Reserved. Adobe Con!dential.

Content-centric vs Control-centric interfaces

■ Content-centric interfaces principles:■ Uniform identi!ers■ Standard methods■ Extensible representation types■ Simpli!ed application integration (much less interfaces)

■ Content Repository API = Uniform interface

3

©2010 Adobe Systems Incorporated. All Rights Reserved. Adobe Con!dential.

Content Repository

■ A Content Repository supports:■ Diverse data:

■ small & large, structured & unstructured, binary, metadata & relationships■ Services:

■ access control, locking, versioning, transactions, observation

■ "e 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 Con!dential.

JCR

■ !e JCR speci"cation de"nes 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.

5

©2010 Adobe Systems Incorporated. All Rights Reserved. Adobe Con!dential.

JCR: !e Repository Model

■ Workspaces■ Hierarchy of nodes■ Properties associated to a node■ Node types de"ne constraints(properties and child nodes)

6

Repository

Workspace Workspace Workspace

[root] [root] [root]

jcr:title = ‘Hello World’jcr:lastModifiedBy = ‘admin’

©2010 Adobe Systems Incorporated. All Rights Reserved. Adobe Con!dential.

JSON representation of a node

7

http://localhost:7402/content/firststeps.infinity.json

©2010 Adobe Systems Incorporated. All Rights Reserved. Adobe Con!dential.

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();

8

©2010 Adobe Systems Incorporated. All Rights Reserved. Adobe Con!dential.

JCR: Repository Functionalities

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

9

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

■ Optional■ Locking■ Transactions■ Versioning

■ SQL search■ Observation

©2010 Adobe Systems Incorporated. All Rights Reserved. Adobe Con!dential.

JCR: Observation

■ Observation enables an application to receive noti"cation 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 Con!dential.

JCR: Content Modelling

■ 2 use cases:

■ Structured content (e.g. !le storage)■ Needs de"nition of content models;■ Needs a stable structure;■ nt:resource

■ Unstructured content■ Any properties and child nodes allowed■ nt:unstructured

11

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

©2010 Adobe Systems Incorporated. All Rights Reserved. Adobe Con!dential.

JCR: node types & mixin types

■ prede"ned node types:■ nt:unstructured■ nt:"le■ nt:folder■ nt:resource represents the actual content of a "le.■ 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 Con!dential.

JCR Ecosystem

■ Open Standard■ Java Community Process (h"p://jcp.org)

■ Sustainability■ Reference Implementation & TCK

■ Apache infrastructure■ license, workspace, information

■ Community■ open review, testing & collaboration

■ Open adoption

13

©2010 Adobe Systems Incorporated. All Rights Reserved. Adobe Con!dential.

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

14

©2010 Adobe Systems Incorporated. All Rights Reserved. Adobe Con!dential.

!e Sling style

■ If you happen to hear this sentence:■ “Sling is not a web applications framework, it’s 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.

15

©2010 Adobe Systems Incorporated. All Rights Reserved. Adobe Con!dential.

CRX Architecture

16

OSGI framework (felix)

JCR repository (jackrabbit)

JCR api

Application framework (sling)

HTTP

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

‣ stores the content

‣ processes HTTP requests in a RESTful way

specification implementation

architectural style

©2010 Adobe Systems Incorporated. All Rights Reserved. Adobe Con!dential.

Sling Architecture

17

felix

jackrabbitJCR api

HTTP

standardservlets

custom servletsand components

resourceresolution

servlet/scriptresolution

JSR 223scripting

javascript

Ruby

WedDAVserver

sling OSGIconsole

sling

JSP

Scala

...

©2010 Adobe Systems Incorporated. All Rights Reserved. Adobe Con!dential.

Sling examples using cURL

■ Create a node■ curl -F"sling:resourceType=foo/bar" -F"title=some title" h"p://admin:admin@localhost:7402/content/mynode

■ Create a node (auto-named)■ curl -X POST "h"p://admin:admin@localhost:7402/content/blog"■ curl -D - -F"title=Adventures with Sling" "h"p://admin:admin@localhost:7402/content/blog/*"

18

©2010 Adobe Systems Incorporated. All Rights Reserved. Adobe Con!dential.

Sling URL decomposition

19

/geometrixx/en/products/triangle.html

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

de#nes the resource de#nes the rendition

©2010 Adobe Systems Incorporated. All Rights Reserved. Adobe Con!dential.

Sling URL decomposition

20

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

sling:resourceTypegeometrixx/components/contentpage