Alfresco WebScripts

download Alfresco WebScripts

of 17

Transcript of Alfresco WebScripts

  • 7/31/2019 Alfresco WebScripts

    1/17

    Alfresco Web Scripts

    Scriptable MVC for REST, AJAX,

    Widgets and Portlets

  • 7/31/2019 Alfresco WebScripts

    2/17

    What are Web Scripts?

    Web Scripting!Agile Script-Driven MVC

    !Multiple uses

    !Roll your own API

    !Create new UI components

    !Create portlets/widgets

    !Expose WCM/AVM features

    !Script-based implementation

    !Server-side JavaScript

    !Freemarker

    !Limited only by your imagination

    ! Integration: Create a mashup

    !Search: Exposed to other systems.

    !

    Rich Internet Applications!Cross-language

    !Cross-platformJavaScript (Controller)

    Freemarker (View)

    Alfresco Repository (Model)

    Consumer / Client

  • 7/31/2019 Alfresco WebScripts

    3/17

    Two types of Web Scripts

    Data Web Script RESTstyle / RESTful URL

    Returns structured data:

    XML

    JSON CSV

    UI Web Script

    Renders self-contained UI.

    Can leverage Data Web Scripts.

  • 7/31/2019 Alfresco WebScripts

    4/17

    Examples

    Web Scripting

    Examples

    !JavaScript that generates

    JSON output.

    !AJAX & DHTML Portlet

    !E.g. OpenSearch is hosted

    as Web Script

  • 7/31/2019 Alfresco WebScripts

    5/17

    Lightweight Portlet Model

    Single Portlet Approach One portlet can render many scripts.

    Service-oriented interfaces

    Transformation

    Templating

    Workflow

    JavaScript extensions

    Access to full Alfresco data model.

    Templating

    FreeMarker for mark-up.

    Access to compound structures.

    REST-style of interface

    URL-addressability of all functions.

  • 7/31/2019 Alfresco WebScripts

    6/17

    Richer, Mashable User Experience

    Content authored

    and categorized Content metadata

    drives mashup

    RSS content feeds for both

    Web Content and Documents from

    same Alfresco repository

  • 7/31/2019 Alfresco WebScripts

    7/17

    Developing Web Scripts

    Where do they live? Under Data Dictionary

    In Classpath Under

    **/alfresco/extension/templates/webscripts

    What are the required components?

    Descriptor

    JavaScript

    FreeMarker Template

    How do I (re)deploy them?

    Theyre auto-deployed and auto-refreshed

  • 7/31/2019 Alfresco WebScripts

    8/17

    Sample Descriptor

    Sample Alfresco Repository

    Services

    Repository services and

    utilities

    /repo//repo/node/{nodeid}

    /repo/node/path/{path}

    guest

  • 7/31/2019 Alfresco WebScripts

    9/17

    reposervices.get.js (part 1)

    var curNode = companyhome;

    // Check for presence of arguments and locate the referenced node or path.

    if (url.extension != "") {

    if (url.match == "/alfresco/service/repo/node/path/") {

    var expr = "Company Home/";

    var str = url.extension.replace(expr,"");

    // If the path was just "Company Home/" then don"t bother setting curNodeto anything.

    if (str != "") {

    curNode = companyhome.childByNamePath(str);

    }

    } else if (url.match == "/alfresco/service/repo/node/") {

    curNode = search.findNode("workspace://SpacesStore/" + url.extension);

    }

    } // end if

  • 7/31/2019 Alfresco WebScripts

    10/17

    reposervices.get.js (part 2)

    // Initialize the variables and arrays

    var children = curNode.children;

    var results = {};

    var numDocs = 0;

    var numSpaces = 0;

    results.node = curNode;

    results.spaces = new Array();

    results.documents = new Array();

    // Iterate through children and populate returnobjects

    for (var i=0; i < children.length; i++) {

    var index = 0;

    if (children[i].isContainer) {

    results.spaces[numSpaces] = children[i];

    index = numSpaces++;

    } else if (children[i].isDocument) {results.documents[numDocs] = children[i];

    index = numDocs++;

    } // end if

    } // end for

    model.results = results;

  • 7/31/2019 Alfresco WebScripts

    11/17

    reposervices.get.html.ftl

    Spaces:

    ${space.name}

    Documents:

    ${doc.name}

  • 7/31/2019 Alfresco WebScripts

    12/17

    How does this apply to portlets?

    Portlets can leverage Web Scripts as aData API.

    Portlets can incorporate UI Web Scripts

    as Widgets.

  • 7/31/2019 Alfresco WebScripts

    13/17

    JSR 168 Portlet

    Standard JSR 168 portlet invokesa Web Script via HTTP.

    Web Script returns JSON text.

    Parsers for Java at JSON.org

    JavaScript (Controller)

    Freemarker (View)

    Alfresco Repository (Model)

    Portal

    JSR

    168

    JSON

    over

    HTTP

  • 7/31/2019 Alfresco WebScripts

    14/17

    Alfresco Portlet

    Single portlet can render anyUI Web Script.

    Currently requires Alfresco to

    be deployed on the same

    application server.

    IFRAME portlet can be a

    viable alternative for remoteAlfresco servers.

  • 7/31/2019 Alfresco WebScripts

    15/17

    Demo

    Examine the Services Registry

    Invoke our Service Use JavaScript Debugger

    Tour other Web Scripts & Portlets

  • 7/31/2019 Alfresco WebScripts

    16/17

    The End

    For more information, visit: http://wiki.alfresco.com/wiki/Web_Scripts

    http://wiki.alfresco.com/wiki/JavaScript_API

    http://wiki.alfresco.com/wiki/Template_Guide Contact Info:

    Luis Sala, Sr. Director of Solutions Engineering

    [email protected]

    http://blogs.alfresco.com/luissala

  • 7/31/2019 Alfresco WebScripts

    17/17

    Alfresco Web Scripts

    Scriptable MVC for REST, AJAX,

    Widgets and Portlets