optaros surf code camp dispatcher

30
Alfresco Surf Code Camp Dispatcher and Site Construction

Upload: jeff-potts

Post on 28-Nov-2014

3.697 views

Category:

Technology


0 download

DESCRIPTION

Learn how to assemble a Surf-based web site. Talks about page dispatching and page assembly.

TRANSCRIPT

Page 1: Optaros Surf Code Camp Dispatcher

Alfresco Surf Code Camp

Dispatcher and Site Construction

Page 2: Optaros Surf Code Camp Dispatcher

12/12/08 Optaros and Client confidential. All rights reserved. 2

Objectives

By the end of this module you should know• How pages are dispatched• How pages are assembled by invoking component renderers• How Page Types & Themes work together

Page 3: Optaros Surf Code Camp Dispatcher

12/12/08 3

You've used web script-based components as Share

Dashlets

Now let's learn about how Surf sites and Surf pages

are built

Site Dispatcher

Page 4: Optaros Surf Code Camp Dispatcher

12/12/08 4

The site dispatcher is responsible for figuring out

which page should be assembled for a given request,

and then assembling the page by invoking renderersPage

Renderer

Renderer Renderer

Renderer

Site Dispatcher

Page 5: Optaros Surf Code Camp Dispatcher

12/12/08 5

Model Objects contain information about site

construction

A web site looks to these objects during render

They define pages and page layout

They define where components appear on pages

Model Objects

Page 6: Optaros Surf Code Camp Dispatcher

12/12/08 6

Model Objects are XML files

Here is an example of a component XML file

<?xml version='1.0' encoding='UTF-8'?><component> <scope>global</scope> <region-id>footer</region-id> <source-id>global</source-id> <url>/age/footer</url> <properties> <custom1>My custom property value</custom1> </properties></component>

Model Objects

Page 7: Optaros Surf Code Camp Dispatcher

12/12/08 7

Types

Component Type

Template Type

Page Type

List of Model Objects

Instances

• Component

• Template Instance

• Page

Associations

• Page Association

• Content Association

Site

• Configuration

• Theme

• Chrome

Page 8: Optaros Surf Code Camp Dispatcher

12/12/08 Optaros and Client confidential. All rights reserved. 8

Key Surf Page Construction Concepts

SomeTemplate.ftl

Header

Gutter Body

Footer

Home

Blog About

Pages

Template Instances &Renderers

Regions

Component (Web Script)

Page 9: Optaros Surf Code Camp Dispatcher

12/12/08 9

Component Type

TemplateType

PageType

Component

TemplateInstance

Page PageAssociation

ContentAssociation

Configuration Theme

Chrome

Model Objects Graph

Page 10: Optaros Surf Code Camp Dispatcher

12/12/08 10

Regardless of the path, it always comes down to a Page

• An Object is requested -> What page should display it?• A Page Type is requested -> Which page is appropriate for this

Theme?• A specific Page is requested

URIServlet

DispatcherServlet

Page Type

Page

Object

Resolves to a page

Resolves to a page

To Rendering

Requests

Dispatching

Page 11: Optaros Surf Code Camp Dispatcher

12/12/08 11

1.Example: Hitting the home page http://labs3c:8580/alfwf/page?p=home

2.Look up Page (in /site-data/pages) ‏

Page has a template instance.

3.Look up Template Instance (in /site-data/template-

instances) ‏

4.Look up Renderer for Template In this case the Renderer is a FreeMarker Template Process regions on page by id

5.Find Component Bindings for those region ids

6.Look up Components (in /site-data/components) ‏

Page Dispatching Logic

Page 12: Optaros Surf Code Camp Dispatcher

12/12/08 12

Look up the page object by page id: home• /WEB-INF/classes/alfresco/site-data/pages

Look up the template by template id: home• /WEB-INF/classes/alfresco/site-data/template-instances

<?xml version='1.0' encoding='UTF-8'?><page> <title>Home Page</title> <template-instance>home</template-instance> <authentication>none</authentication></page>

<?xml version='1.0' encoding='UTF-8'?><template-instance> <template-type>freemarker</template-type> <url>/sample/home</url></template-instance>

Page Dispatching Logic

Potentially confusing

shortcut here!

<?xml version='1.0' encoding='UTF-8'?><template-instance> <template-type>/sample/home</template-type></template-instance>

OR

Page 13: Optaros Surf Code Camp Dispatcher

12/12/08 13

Execute the Template Renderer for path: /sample/home

• FreeMarker renderer• /WEB-INF/classes/alfresco/templates/sample/home.ftl

Execute the region tag and find matching components• /WEB-INF/classes/alfresco/site-data/components• Search for components in page scope, bound to home page for

the region ‘SomeImage’• page.test.home.xml

<html> <body> <@region id=“SomeImage” scope=“page” /> </body></html>

Page Dispatching Logic

Components have a naming convention which is duplicative of the XML it contains. Currently, the XML page, scope, and region XML are ignored, but in the future, the naming convention will be dropped.

Page 14: Optaros Surf Code Camp Dispatcher

12/12/08 14

Analyze the Component and prepare to render it• /WEB-INF/classes/alfresco/site-data/components

The url maps to a web script• URL = /blocks/image

The properties of the component are fed into the Web Script

<?xml version='1.0' encoding='UTF-8'?><component> <scope>page</scope> <region-id>SomeImage</region-id> <source-id>home</source-id> <url>/blocks/image</url> <properties> <src>${url.context}/images/masay.jpg</src> </properties></component>

Page Dispatching Logic

Page 15: Optaros Surf Code Camp Dispatcher

12/12/08 15

blocks/image is an Image Display component

The Presentation Web Script fetches data from component instance

The FreeMarker based view then renders the output

var src = instance.properties[“src”];if(src != null)‏{

// proceed}

<img src=“${src}” />

Page Dispatching Logic

Page 16: Optaros Surf Code Camp Dispatcher

12/12/08 16

http://labs3c:8580/alfwf/page?p=home

The template would execute

SomeImage

Page Dispatching Logic

home.ftl

Page 17: Optaros Surf Code Camp Dispatcher

12/12/08 17

http://labs3c:8580/alfwf/page?p=home

Generated output

Page Dispatching Logic

Page 18: Optaros Surf Code Camp Dispatcher

12/12/08 18

Page Types are used to define a general “class” or type of pages

Examples:• Login• Profile• Others?

Example: Hitting the login page• http://labs3c:8580/alfwf/page?pt=login

Page Type Dispatching Logic

Page 19: Optaros Surf Code Camp Dispatcher

12/12/08 19

First, see if there is a configured theme● Themes can specify overrides for page types● Default themes are specified by site configuration objects

<?xml version='1.0' encoding='UTF-8'?><theme> <title>Extranet - Enterprise Theme</title> <page-types> <page-type> <id>login</id> <page-instance-id>sample-login</page-instance-id> </page-type> </page-types></theme>

Page Type Dispatching Logic

Page 20: Optaros Surf Code Camp Dispatcher

12/12/08 20

If nothing specifed in a theme, see if the framework has a default

• The web-framework-config*.xml files can specify defaults

<alfresco-config> <config evaluator="string-compare" condition="WebFramework"> <web-framework> <application-defaults> <theme>newtheme</theme> <page-type> <id>login</id> <page-instance-id>sample-login</page-instance-id> </page-type> </application-defaults> </web-framework> </config></alfresco-config>

Page Type Dispatching Logic

Page 21: Optaros Surf Code Camp Dispatcher

12/12/08 21

Last resort, try to use a generic page• Looks for a page with id = generic

Page Type Dispatching Logic

Page 22: Optaros Surf Code Camp Dispatcher

12/12/08 22

At this point, we have a page object

Dispatch to page as before

Page Type Dispatching Logic

Page 23: Optaros Surf Code Camp Dispatcher

12/12/08 23

Example: Displaying a content object

http://labs3c:8580/alfwf/page?o=workspace://SpacesStore/56923743-7436-482e-b1cf-eda326d11dc2

• Assumes the default endpoint

• “Load content object with this id from the default endpoint”

http://labs3c:8580/alfwf/page?

o=workspace://SpacesStore/56923743-7436-482e-b1cf-

eda326d11dc2&endpointId=alfresco

• Uses a specific endpoint

• “Load content object with this id from the alfresco endpoint”

Object Dispatching Logic

Page 24: Optaros Surf Code Camp Dispatcher

12/12/08 24

Look up the ContentLoader implementation• A content loader that knows how to load content from this

endpoint<alfresco-config> <config evaluator="string-compare" condition="WebFramework"> <web-framework> <content-loader> <id>alfresco</id> <name>Alfresco Content Loader</name> <class>org.alfresco.web.site.AlfrescoContentLoader</class> <endpoint>alfresco</endpoint> </content-loader> </web-framework> </config></alfresco-config>

Object Dispatching Logic

Page 25: Optaros Surf Code Camp Dispatcher

12/12/08 25

If a ContentLoader is found, then load the object

Then, look for Content Association instances which describe a match for this content object

• /WEB-INF/classes/alfresco/site-data/content-associations

Describes a page that can be used to display content of type: {http://www.alfresco.org/model/content/1.0}content

<?xml version="1.0" encoding="UTF-8"?>

<content-association> <source-id>{http://www.alfresco.org/model/content/1.0}content</source-id> <dest-id>content-details</dest-id> <assoc-type>page</assoc-type></content-association>

Object Dispatching Logic

Page 26: Optaros Surf Code Camp Dispatcher

12/12/08 26

At this point, we have a page object

Dispatch to page as before

Object Dispatching Logic

Page 27: Optaros Surf Code Camp Dispatcher

12/12/08 27

/WEB-INF/classes/alfresco

/site-data

/chrome

/components

/component-types

/configurations

/content-associations

/page-associations

/pages

/page-types

/template-instances

/template-types

/themes

Site Data

Page 28: Optaros Surf Code Camp Dispatcher

12/12/08 28

/WEB-INF/classes/alfresco

/site-webscripts

/example

/component.get.desc.xml

/component.get.js

/component.get.html.ftl

/component.get.head.ftl

/component.get.properties

/component.get.config

Components

Page 29: Optaros Surf Code Camp Dispatcher

12/12/08 29

/WEB-INF/classes/alfresco

/templates

/example

/template.js

/template.ftl

/template.head.ftl

Templates

Page 30: Optaros Surf Code Camp Dispatcher

12/12/08 Optaros and Client confidential. All rights reserved. 30

Wrap-up

In this module, you learned...• How Surf model objects inter-relate• Three ways pages are dispatched

– Specific page– Page type– Object

• Pages are assembled by invoking component renderers