So-called Application Programming Interfaces (APIs) provide you with extra superpowers to use in your JavaScript code. Server-side scripts are completely processed by the servers instead of clients. When clients request a page containing server-side scripts, the application server processes the scripts and returns an HTML page to the client. Here a new FreeMarker directive called list is used to loop through the document information for the matching nodes. We also use a very handy build-in (!) that will check if the variable has a value (i.e. is not null), if it doesn’t
the right hand side value will be used as default.
As a web script executes it will perform operations such as creating a new document in the repository. In practice you should only carry out exception handling
for exceptions that you know are not handled at a lower layer of Content Services. Not all clients can gracefully handle non-success HTTP response codes, such as the Adobe Flash runtime player, which
is the runtime for Adobe Flex applications. Method overrides are also supported when issuing HTTP GET requests through the alf_method query parameter. This is
particularly useful for testing some non-GET methods by using the web browser. Although a client can use HTTP directly to invoke web scripts, the Web Script Framework also provides many helpers for
invoking web scripts from environments that do not know HTTP.
Dynamic versus static code
Behind the scenes, the Web Script Framework chooses the most appropriate option for specifying the user identity, either
HTTP Basic authentication, ticket, or guest when invoking the web script. If any exception expected to be handled by
the repository is handled by the web script, this can lead to inconsistency of state, and potentially corruption of the
repository. For a match to occur, the value provided for each same named token must be the same.
When developing a web script, you can specify whether its response is to be cached and, if so, how it is to be cached
through the web script descriptor document. The Web Script Framework complies with HTTP caching, in particular with the notions of Last Modified Time and ETag
(a kind of hash), allowing the caching of Web script responses using HTTP-aware caches. A carefully developed web script can be used from multiple environments without the need to change its implementation. For example, a web script for displaying your Content Services checked-out documents can be used standalone
directly in a web browser, as a portlet in a JSR-168 portal, or as a dashlet in Alfresco Share.
Content Stores
A single Content Services server can contain hundreds of web scripts, each implemented with multiple files. To help manage all these web scripts, the Web Script Framework lets you organize web script component files into a
hierarchical folder or package structure, similar to a Java package construct. For example, web scripts are all located in a folder named org/alfresco, which is
reserved by Content Services. The Web Script Framework is designed according to the Model View Controller (MVC) pattern (sometimes referred to as
MVC for the web). The Content Services CMIS (Content Management Interoperability Services)
AtomPub binding is implemented as a series of web scripts. In the following example, a user agent that executes the SCRIPT
will include some dynamically created data in the document.
When it comes to response format JSON is usually a good choice as it is compact and works well with most programming
languages and widget libraries. Repository Web Scripts are the fundamental building blocks used for extending the ReST API in Content Services
to support domain specific content types. This helper provides an implementation of getDescription() but does not provide any execution assistance, which it
delegates to its derived class.
Overriding the default message bundle
Unlike data web scripts, presentation web scripts can be hosted in the Content Services server or in a
separate presentation server. When hosted separately, presentation web scripts in the presentation server interact
with data web scripts in the Alfresco content application server by using the Repository REST API. Web scripts let you implement your own RESTful API without tooling or Java knowledge. No compilation, generators, server restarts, or complex installs are required.
- If not specified, the resource
bundle is treated as the fallback set of values if no other relevant resource bundle for the required language can be found. - In the case of more specialized applications, programmers may write their own server, client, and communications protocol, that can only be used with one another.
- It is useful when reporting error status codes to provide additional information about the error in the response,
such as the cause of the error. - Authoring tools should generate
default scripting language information to help authors avoid creating incorrect
documents. - The descriptor will tell you what
URL that should be used to invoke the Web Script.
A client specifies its preferred language through the HTTP header named Accept-Language, to which the Web Script Framework adheres. The function parameter specifies the name of a client-side JavaScript function to invoke. Some scripts are written in such a way that they require asynchronous loading, meaning that your website could load in a single second, but loading all of the scripts one after another may take several more seconds. Consumers, especially those on mobile devices, really dislike waiting and may give up on your site before it fully loads. And, search engines like Google can punish slow websites by ranking them lower in organic listings. In order to add a script to your website, a vendor or software provider needs permission from you (or in some cases, your OEM).
scripts
This is useful for
providing unique information about a status code or to render a custom human readable interface. Documents that do not specify default scripting language information and
that contain elements that specify an intrinsic event
script are incorrect. User agents may still attempt to interpret incorrectly
specified scripts but are not required to.
The value of the type attribute for a SCRIPT element overrides the default
scripting language for that element. The script may be defined within the contents of the
SCRIPT element or in an external file. If the src
attribute is not set, user agents must interpret the contents of the element as
the script. If the src has a URI value, user agents must ignore the element’s
contents and retrieve the script via the URI. Note that the
charset attribute refers to the character
encoding of the script designated by the src attribute; it does not
concern the content of the
SCRIPT element. With server-side rendering, the page is generally assembled on the server once per each request.
However, the URL-encoded approach is inefficient for sending large quantities of binary data or text containing non-ASCII characters. In really unfortunate circumstances, some clients do not even support HTTP headers; therefore, the Web Script Framework
also supports a query parameter named alf_method for representing the method to override. Many clients have limitations that mean certain HTTP features
are not supported. Rather than dismiss those clients and reduce the scope of where web scripts can be invoked, the
Web Script Framework provides helpers for working around those limitations. Known as views, web script response templates render output in the correct format for specific needs, such as HTML,
Atom, XML, RSS, JSON, CSV, or any combination of these.
A web script is a service bound to a URI that responds to HTTP methods such as GET, POST, PUT, and DELETE. One example that we’ve seen far too often is if a certain website script doesn’t load consistently, it can lead to one out of every 10 form fills not being captured. Identifying and diagnosing problems like this can be incredibly difficult and result in companies without lead monitoring losing out on sales opportunities.
Repository Web Scripts are referred to as Data Web Scripts as they usually return JSON or XML. Before embarking on
implementing a Repository web scripts it is recommended that you establish if the required functionality is uses of a script already
available out-of-the-box. Many operations that you might want to perform may be available, see
Alfresco REST API. The model returned from executeImpl() is passed to the response template for subsequent rendering.