-
Log in to SkyVault Share:
- Open a web browser and enter the URL: http://localhost:8080/share
- If prompted, log in with the user name admin and password admin.
- Click on the Repository link in the Share header.
- Navigate to Data Dictionary > Web Scripts Extensions > org > example.
-
Create a web script description document for your configuration sample:
- In the Create menu, select XML.
-
Enter the name for the web script in the Name field
as:
configuration.get.desc.xml
-
Type the following in the content box:
<webscript> <shortname>Configuration Sample</shortname> <description>Response driven from configuration</description> <url>/config</url> <authentication>user</authentication> </webscript>
- Click Create.
- Navigate back to the org/example folder using the breadcrumb trail.
-
Create a configuration file for your configuration sample:
- In the Create menu, select XML.
-
Enter the name in the Name field:
configuration.get.config.xml
-
Type the following in the content box:
<greeting> <text>Hello</text> <repeat>3</repeat> </greeting>
- Click Create.
- Navigate back to the org/example folder using the breadcrumb trail.
-
Create a controller script for your configuration sample:
- In the Create menu, select Plain Text.
-
Enter the name in the Name field:
configuration.get.js
-
Type the following in the content box:
var greeting = new XML(config.script); model.repeat = parseInt(greeting.repeat);
- Click Create.
- Navigate back to the org/example folder using the breadcrumb trail.
-
Create a response template for your configuration sample:
- In the Create menu, select Plain Text.
-
Enter the name in the Name field, such as:
configuration.get.html.ftl
-
Type the following in the content box:
<#list 1..repeat as i> ${config.script.greeting.text} </#list>
- Click Create.
- Navigate back to the org/example folder using the breadcrumb trail.
-
Register the web script with SkyVault Content Services.
- In a web browser, create a new tab.
- In the newly created tab, enter the URL: http://localhost:8080/alfresco/service/index
- If prompted, log in with the user name admin and password admin.
- Click Refresh Web Scripts. The number of web scripts available will increment.
The configuration file name configuration.get.config.xml adheres to the naming convention defined by the Web Script Framework. Configuration file names are structured as:
<web script id>.<http method>.config.xml
The <web script id> identifies the web script and must be the same as the web script ID defined in the file name of the associated web script description document. The <http method> specifies which HTTP method initiates the web script and must be the same as the associated web script description document.
Finally, all configuration file names must end with .config.xml, which indicates to the Web Script Framework that the file is a configuration file.
Configuration is expressed as any valid XML. In your sample, you specify the greeting text to render and the number of times to repeat the greeting. Controller scripts access the configuration XML through the root object named config.script. Additionally, E4X, a JavaScript XML API, is used to traverse the XML structure and extract values.
... var greeting = new XML(config.script); model.repeat = greeting.repeat; ...
Your sample extracts the number of times to repeat the greeting from the configuration XML and places the value into the Web script model with the name repeat.
-
Test your configuration sample by typing the following in your command line:
curl -uadmin:admin "http://localhost:8080/alfresco/service/config"
The response is:
Hello Hello Hello
You are here
Configuring a web script
When developing a web script, you can implement capabilities that provide flexibility
in how they behave. The Web Script Framework supports this by allowing each web script to
carry a configuration file, which the web script can interrogate to alter its behavior.
This task demonstrates how to create a web script whose response is driven by a
configuration file.
You have altered the configuration by modifying the configuration XML file, or by
creating a new configuration file of the same name in a web script location that comes earlier
in the Web Script Framework search path.
© 2017 TBS-LLC. All Rights Reserved. Follow @twitter