Top Banner
Spring Surf & Web Scripts Dave Draper – UI Engineer - @_DaveDraper
34

PLAT-7 Spring Web Scripts and Spring Surf

Jan 15, 2015

Download

Technology

This session introduces the Spring Web Scripts and the Spring Surf framework describing how they are used to underpin the Alfresco Share user interface. As well as covering the basic concepts, this session will cover the history and future roadmap for the frameworks.
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: PLAT-7 Spring Web Scripts and Spring Surf

Spring Surf & Web Scripts!

Dave Draper – UI Engineer - @_DaveDraper!

Page 2: PLAT-7 Spring Web Scripts and Spring Surf

2007 • Alfresco 2.0 introduces first REST API (early WebScripts concepts)!• Alfresco 2.1 introduces WebScripts!

• REST framework, JSR-311 (Jax-RS) URI Index!• Scriptable controllers (or backed by Spring Java Beans)!• FreeMarker template output (or Java output stream)!

2008 • Alfresco Web Framework demo-ware (model objects, JSP, FTL)!• Alfresco Page Render (WebScripts as components on a page)!• Combined, productised and renamed to Surf!• Alfresco Share 3.0, 3.1 – Alfresco collaboration and DM – modern XHTML and Ajax based interface!

History lesson...

Page 3: PLAT-7 Spring Web Scripts and Spring Surf

Early 2009 • Alfresco Share 3.2!• First contact between Alfresco and Spring Source!

Late 2009 • Alfresco Surf and WebScripts integrated with Spring MVC!• Alfresco Surf and WebScripts contributed as Spring Extension – Spring WebScripts and Spring Surf!

• Alfresco Share 3.3 – refactored onto Spring WebScripts and Spring Surf!!

2010 • 3 Milestones and RC1 release!• Alfresco Share 3.4 – using SpringSurf RC1!

History lesson (cont)...

Page 4: PLAT-7 Spring Web Scripts and Spring Surf

2011 • Alfresco Team!• New extensibility capabilities added!• Version 1.0.0 releases!• Alfresco Share 4.0!

History lesson (cont)...

Page 5: PLAT-7 Spring Web Scripts and Spring Surf

What Are WebScripts? • Services bound to a URIs which respond to HTTP methods such as GET, POST, PUT and DELETE!

• Support multiple formats (HTML, JSON & XML)!• A framework for creating a REST API!• Made up of descriptor, controller, properties, configuration and presentation files!

Page 6: PLAT-7 Spring Web Scripts and Spring Surf

WebScripts!• Descriptor (XML) • Controller (JavaScript/Java Spring Bean) • Response Formats (FreeMarker) • I18N properties (Text) • Configuration (XML)

Page 7: PLAT-7 Spring Web Scripts and Spring Surf

Response Formats!•  Available formats

• HTML!• Text!• XML!• ATOM!• RSS!• JSON!

•  Set default in Descriptor (if more than one available) •  Request by:

• Extension (e.g. /script1.html, /script1.json, etc)!• Format request parameter (e.g. /script1?format=xml)!

Page 8: PLAT-7 Spring Web Scripts and Spring Surf

Why Use Web Scripts? •  Rapid development (no server restarts) •  Separation of concerns (MVC) •  Localization •  Extensibility •  FreeMarker and JavaScript

Page 9: PLAT-7 Spring Web Scripts and Spring Surf

But What Is Spring Surf ? •  An extension to Spring MVC •  A set of controllers, resolvers and views •  A way of breaking an HTML page into re-

usable composite parts •  An interface to the Alfresco Repository •  The framework that underpins Alfresco

Share

Page 10: PLAT-7 Spring Web Scripts and Spring Surf

Example Spring Surf Objects •  Pages •  Template Instances •  Regions •  Chrome •  Components •  Sub-Components

Page 11: PLAT-7 Spring Web Scripts and Spring Surf

Page  Template-­‐Instance  

Region-­‐Chrome  Region  Component  Chrome  

Component  Sub-­‐

Components  

Page 12: PLAT-7 Spring Web Scripts and Spring Surf

Mistakes were made… •  Chrome •  Scopes •  No Component nesting •  1-1 Region/Component binding •  Spring Roo •  Tools •  Difficult to match output to source

Page 13: PLAT-7 Spring Web Scripts and Spring Surf

…but there is lots of good stuff ! •  Themes •  Model Object stores (file system, classpath, remote,

etc) •  Presets / object creation •  URI templates •  Remote connections •  Authentication •  Extensibility •  Endlessly configurable

Page 14: PLAT-7 Spring Web Scripts and Spring Surf

What can you do with it? • Rapid web-tier view composition – Spring MVC View Resolver!

• FreeMarker, JSP, Groovy, PHP pages!• WebScript, FTL, JSP, Groovy, PHP components!• Simple JavaScript, Groovy controllers!• Remote API – REST request/response processing!

• WebScripts – standalone REST API tier!• Portlets!

Page 15: PLAT-7 Spring Web Scripts and Spring Surf

What you SHOULD do with it?!

• Customize Alfresco Share!• Use WebScripts and FreeMarker!• Use JavaScript controllers!• Use Endpoints to contact an Alfresco Repository in standalone applications!

Page 16: PLAT-7 Spring Web Scripts and Spring Surf

SOME USEFUL INFORMATION!

Page 17: PLAT-7 Spring Web Scripts and Spring Surf

WebScript and Surf Object lookup!

Page 18: PLAT-7 Spring Web Scripts and Spring Surf

Authentication (WebScripts & Surf Pages)!

• Use <authentication> element • Available types:

• “none”!• “guest”!• “user”!• “admin”!

•  Authenticates against Alfresco Repository •  Can use “runas” property with WebScripts only

Page 19: PLAT-7 Spring Web Scripts and Spring Surf

URI Templates (WebScripts)!

•  Use tokens in URL • e.g. “/x/{token1}/y/{token2}/z”!

•  Can define multiple URLs in single descriptor •  Use “url.templateArgs” to access

• ${url.templateArgs.token1}!

Page 20: PLAT-7 Spring Web Scripts and Spring Surf

URI Templates (Surf Pages)!

•  Define “uri-template” in <alfresco-config> (e.g. “share-config-custom.xml) • Include {pageid} token for Page mapping!• Or ensure Page exists (e.g. Created through Preset)!

•  Use page.url.templateArgs to access tokens • e.g. ${page.url.templateArgs.token1}!

Page 21: PLAT-7 Spring Web Scripts and Spring Surf

Surf Configuration!

•  Configuration object • Site home page!• Site theme!

•  Surf.xml • Object type implementations (e.g. AdvancedComponent)!• User factories!• Site configuration!• Chrome!• Page type (e.g. Login)!• Module Deployment!

•  Spring Application Context • Services (configuration loading, user factories, persistence, remote access, etc)!• Controllers (login controllers, etc)!• Interceptors!

Page 22: PLAT-7 Spring Web Scripts and Spring Surf

Custom Home Page!

•  From: http://blogs.alfresco.com/wp/ddraper/2011/11/01/advanced-share-customization-part-1/

•  Optionally override <site-configuration> in “surf.xml” • Default is “slingshot.site.configuration”!

•  Set <root-page> property in Configuration object

Page 23: PLAT-7 Spring Web Scripts and Spring Surf

Custom Login Page!

•  From: http://blogs.alfresco.com/wp/ddraper/2011/11/03/advanced-share-customization-part-2/

•  Create Page and Template-Instance objects for custom login page

•  Define new default “login” Page-Type object

Page 24: PLAT-7 Spring Web Scripts and Spring Surf

Regions and Components •  Regions define location into which Components can

be bound •  Binding done through region-id, source-id and

scope o  Forced 1-1 bindings o  Flawed concept for Component switching

•  Sub-Components introduced as a workaround •  Components SHOULD use ComponentType or

Processor but are “optimized” to use WebScript URL

Page 25: PLAT-7 Spring Web Scripts and Spring Surf

• Connectors & Authenticators!• XML configure access to “endpoints” – obtained by id!

• Access HTTP methods through JavaScript controller or Ajax via proxy controller!

• Endpoints hide the URL stem from scripts – authentication encapsulated by connectors and authenticators!

• Connect to multiple REST sources; alfresco, wiki, search!

Remote API

Page 26: PLAT-7 Spring Web Scripts and Spring Surf

Remote API – Example!var conn = remote.connect("alfresco"); var json = conn.get("/api/products/" + args.filter); if (json.status == 200) { // Create JavaScript objects from the response var obj = eval('(' + json + ')'); if (obj) { // Perform processing on the js objects // set results into the model for the template model.results = somearray; } }

Page 27: PLAT-7 Spring Web Scripts and Spring Surf

• Persisters – read model object definitions from classpath, WEB-INF, JARs!

• Alfresco legacy locations and Spring “friendly” locations!o Migration of Alfresco Surf 3.2 apps!o New locations require less files, folders!

• Read and write to remote location and local file system!

• Example - Alfresco Share stores pages and components for dynamic dashboards in the repository!

Model Object Stores

Page 28: PLAT-7 Spring Web Scripts and Spring Surf

Component .head.ftl template!

<link rel="stylesheet" type="text/css" href="${page.url.context}/products/products.css" />

<script src="${page.url.context}/products/products.js"></script>

•  Allow WebScripts to add JavaScript and CSS dependencies into HTML <head>

•  Use ${head} in Template Instance to output dependencies into <head>

•  Use <@script> to automatically switch between .js and –min.js

Page 29: PLAT-7 Spring Web Scripts and Spring Surf

Useful Runtime Tools

•  /service/index o  Browse WebScripts

o  WebScript refresh

o  SurfBug toggle

Page 30: PLAT-7 Spring Web Scripts and Spring Surf

Roadmap!

•  Forking from Spring back into Alfresco • Continued development (more extensibility

features, performance improvements) • Continued use in Alfresco projects • More blogging, forums and documentation

Page 31: PLAT-7 Spring Web Scripts and Spring Surf

How do I use it?!

• You CAN SVN checkout, maven build: https://src.springframework.org/svn/se-surf/trunk!

• You SHOULD use Alfresco Community JARs when available!

Page 32: PLAT-7 Spring Web Scripts and Spring Surf

Learn More!

• Blog posts: • http://blogs.alfresco.com/wp/ewinlof/!• http://blogs.alfresco.com/wp/kevinr/!• http://blogs.alfresco.com/wp/ddraper/!• http://mindthegab.com/!

• Alfresco Forum: “Surf Development”

Page 33: PLAT-7 Spring Web Scripts and Spring Surf

Questions?!

Page 34: PLAT-7 Spring Web Scripts and Spring Surf