星期二, 3月 22, 2011

[Alfresco] Create your first web script

if you want to create customize web script in Alfresco.
You will need to understand:
  • XML for expressing the Web Script description
    • <basename>.<httpmethod>.desc.xml
  • Optionally, JavaScript for writing Web Script behaviour
    • <basename>.<httpmethod>.js
  • Freemarker for rendering a Web Script response
    • <basename>.<httpmethod>.<format>.ftl


Those are some steps as the below:
Step1.create a descriptor file
You must create descriptor file in Company Home | Data Dictionary | Web Scripts Extensions space.

Name the file hello.get.desc.xml and type in its content as follows:

Hello

This is first web script in Alfresco.
   
/hello
user 
required


Where:
  • shortname is a human readable name for the Web Script
  • description (optional) is documentation for the Web Script
  • url (one or more) is a URI Template to which the Web Script is bound; variants of the URI template which specify a format do not need to be registered, however, they are useful for documentation purposes
  • format (optional) controls how the content-type of the response can be specified via the URI; valid values are:
    • argument the content-type is specified via the format query string parameter, for example /helloworld?to=dave&format=xml
    • extension the content-type is specified via the URI extension, for example /hello/world.xml?to=dave
    • any either of the above can be used
    • Note: if not specified, the default value is any
    • Note: if the caller does not specify a required content-type at all, the default content-type is taken from the (optional) default attribute of the format element. By default, if not set, the html format is assumed. In some cases, a URI may decide upon a response content-type at runtime. For these URIs, specify an empty format, for example format default=""
  • authentication (optional) is the required level of authentication; valid values are:
    • none specifies that no authentication is required at all
    • guest specifies that at least guest authentication is required
    • user specifies that at least named user authentication is required
    • admin specifies that at least a named admin authentication is required
    • Note: if not specified, the default value is none
    • Note: The optional runas attribute can be used to force the execution of a web script as a specific user. This can only be specified for web scripts that are stored in the Java Class path.


Step2.Create a js(controller) file
In the same space. To create a file which is named hello.get.js with the following content:

function main()
{
 model.fullname = person.properties.firstName;
 if(person.properties.lastName != ""){
  model.fullname += " " + person.properties.lastName;
 }
}

main();

Step3.Create a template file
In the same space. To create a file which is named hello.get.html.ftl with the following content:

Hello ${fullname},Welcome to Alfresco :)
Step4.Register your webscript.
Navigate to http://localhost:8080/alfresco/service/index and press the Refresh Web Scripts button


Step5.Invoke your first web script
Just to browse the http://localhost:8080/alfresco/service/{your descriptor url tag attribute}.
In this example,The url is http://localhost:8080/alfresco/service/hello.
if you use Administrator to login,you should see:

Hello Administator,Welcome to Alfresco :)

Reference:
Web Scripts

沒有留言:

張貼留言

留個話吧:)

其他你感興趣的文章

Related Posts with Thumbnails