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
12/12/08 Optaros and Client confidential. All rights reserved. 2
3. Site Dispatcher
You've used web script-based components as Share
Dashlets
Now let's learn about how Surf sites and Surf pages
are built
12/12/08 3
4. Site Dispatcher
The site dispatcher is responsible for figuring out
which page should be assembled for a given request,
and then assembling the page by invoking renderers
Page
Renderer
Renderer Renderer
Renderer
12/12/08 4
5. Model Objects
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
12/12/08 5
6. Model Objects
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>
12/12/08 6
7. List of Model Objects
Types Associations
Component Type Page
•
Association
Template Type
Content
•
Page Type Association
Instances Site
Component Configuration
• •
Template Theme
• •
Instance
Chrome
•
Page
•
12/12/08 7
8. Key Surf Page Construction Concepts
SomeTemplate.ftl
Pages Home Header
Blog About
Gutter Body
Template
Instances & Regions
Renderers
Footer
Component
(Web Script)
12/12/08 Optaros and Client confidential. All rights reserved. 8
9. Model Objects Graph
Page Page
Page
Type Association
Template Template Content
Type Instance Association
Component
Component Chrome
Type
Configuration Theme
12/12/08 9
10. Dispatching
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
URI Resolves to a page
Servlet
Page Type
Requests
To Rendering
Dispatcher
Page
Servlet
Object
Resolves to a page
12/12/08 10
11. Page Dispatching Logic
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)
12/12/08 11
12. Page Dispatching Logic
Look up the page object by page id: home
• /WEB-INF/classes/alfresco/site-data/pages
<?xml version='1.0' encoding='UTF-8'?>
<page>
<title>Home Page</title>
<template-instance>home</template-instance>
<authentication>none</authentication>
</page>
Look up the template by template id: home
• /WEB-INF/classes/alfresco/site-data/template-instances
<?xml version='1.0' encoding='UTF-8'?>
<template-instance>
<template-type>freemarker</template-type>
<url>/sample/home</url>
</template-instance>
OR
Potentially
<?xml version='1.0' encoding='UTF-8'?>
confusing
<template-instance>
shortcut here!
<template-type>/sample/home</template-type>
</template-instance>
12/12/08 12
13. Page Dispatching Logic
Execute the Template Renderer for path:
/sample/home
• FreeMarker renderer
• /WEB-INF/classes/alfresco/templates/sample/home.ftl
<html>
<body>
<@region id=“SomeImage” scope=“page” />
</body>
</html>
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’
Components have a naming
• page.test.home.xml
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.
12/12/08 13
14. Page Dispatching Logic
Analyze the Component and prepare to render it
• /WEB-INF/classes/alfresco/site-data/components
<?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>
The url maps to a web script
• URL = /blocks/image
The properties of the component are fed into the Web
Script
12/12/08 14
15. Page Dispatching Logic
blocks/image is an Image Display component
The Presentation Web Script fetches data from
component instance
var src = instance.properties[“src”];
if(src != null)
{
// proceed
}
The FreeMarker based view then renders the output
<img src=“${src}” />
12/12/08 15
16. Page Dispatching Logic
http://labs3c:8580/alfwf/page?p=home
The template would execute
home.ftl
SomeImage
12/12/08 16
18. Page Type Dispatching Logic
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
12/12/08 18
19. Page Type Dispatching Logic
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>
12/12/08 19
20. Page Type Dispatching Logic
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=quot;string-comparequot; condition=quot;WebFrameworkquot;>
<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>
12/12/08 20
21. Page Type Dispatching Logic
Last resort, try to use a generic page
• Looks for a page with id = generic
12/12/08 21
22. Page Type Dispatching Logic
At this point, we have a page object
Dispatch to page as before
12/12/08 22
23. Object Dispatching Logic
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”
12/12/08 23
24. Object Dispatching Logic
Look up the ContentLoader implementation
• A content loader that knows how to load content from this
endpoint
<alfresco-config>
<config evaluator=quot;string-comparequot; condition=quot;WebFrameworkquot;>
<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>
12/12/08 24
25. Object Dispatching Logic
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
<?xml version=quot;1.0quot; encoding=quot;UTF-8quot;?>
<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>
Describes a page that can be used to display content
of type: {http://www.alfresco.org/model/content/1.0}content
12/12/08 25
26. Object Dispatching Logic
At this point, we have a page object
Dispatch to page as before
12/12/08 26
27. Site Data
/WEB-INF/classes/alfresco
/site-data
/chrome
/components
/component-types
/configurations
/content-associations
/page-associations
/pages
/page-types
/template-instances
/template-types
/themes
12/12/08 27
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
12/12/08 Optaros and Client confidential. All rights reserved. 30