-
Log in to SkyVault Explorer:
- Open a web browser and enter the URL: http://localhost:8080/SkyVault
- If prompted, log in with the user name admin and password admin.
- Navigate to Company Home > Data Dictionary > Web Scripts Extensions.
-
Create a folder to represent the top-level package structure (skip this step if the
org space already exists):
- In the Create menu, click Create Space.
- Enter the name for the folder in the Name field, such as: org
- Click Create Space.
-
Create a sub-package (skip this step if the example space
already exists):
- Navigate to Company Home > Data Dictionary > Web Scripts Extensions > org.
- In the Create menu, click Create Space.
- Enter the name for the folder in the Name field, such as: example
- Navigate to Company Home > Data Dictionary > Web Scripts Extensions > org > example.
-
Create a web script description document for your configuration sample:
- In the Create menu, click Create Content.
-
Enter the name for the web script in the Name field
as:
configuration.get.desc.xml
- In the Content Type list, select XML.
- Click Next.
-
Type the following in the Enter Content box:
<webscript> <shortname>Configuration Sample</shortname> <description>Response driven from configuration</description> <url>/config</url> <authentication>user</authentication> </webscript>
- Click Next, click Finish, and then click OK.
-
Create a configuration file for your configuration sample:
- In the Create menu, click Create Content.
-
Enter the name in the Name field, such as:
configuration.get.config.xml
- In the Content Type list, select XML.
- Click Next.
-
Type the following in the Enter Content box:
<greeting> <text>Hello</text> <repeat>3</repeat> </greeting>
- Click Next, click Finish, and then click OK.
-
Create a controller script for your configuration sample:
- In the Create menu, click Create Content.
-
Enter the name in the Name field, such as:
configuration.get.js
- In the Content Type list, select Plain Text.
- Click Next.
-
Type the following in the Enter Content box:
var greeting = new XML(config.script); model.repeat = parseInt(greeting.repeat);
- Click Next, click Finish, and then click OK.
-
Create a response template for your configuration sample:
- In the Create menu, click Create Content.
-
Enter the name in the Name field, such as:
configuration.get.html.ftl
- In the Content Type list, select Plain Text.
- Click Next.
-
Type the following in the Enter Content box:
<#list 1..repeat as i> ${config.script.greeting.text} </#list>
- Click Next, click Finish, and then click OK.
-
Register the web script with SkyVault.
- In a web browser, 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 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