Using policy libraries

A project can act as a library providing policies for other projects. Such a library can contain a set of policies and assets that can be used by other projects. The main purpose of this mechanism is to allow page authors to easily use reusable components.

A project can act as a library providing policies for other projects. Such a library can contain a set of policies and assets that can be used by other projects. The main purpose of this mechanism is to allow page authors to easily use reusable components.

Identifying libraries

Libraries can be developed by various providers and used together in a number of different configurations and therefore each library needs to have a unique identifier for reference purposes. The library identifier is an http URL. It must end with a slash character ('/') and cannot contain any query parameters nor fragment components.

Project identifiers are defined by library providers and it is the providers' responsibility to ensure that the given identifier is unique. The identifiers should conform to the following conventions: a project identifier should be prefixed with a domain name owned by the project provider and it should be unique across all provider's projects.

Locating libraries

Page authors who want to use a library can bundle it with their projects. Authors can also make the library available locally on the hosting environment or some remote policy server. A single project can make use of any number of libraries.

The default set of libraries can be specified in the projects section of the mcs-config.xml configuration file using the library element. Its identity attribute uniquely identifies the library. The location attribute defines the location of the library. It can be a relative path or any valid URL with the file or http scheme but without any query parameters nor fragment components. The value of the attribute must end with a slash ('/').

Please note that if a named project is to be treated as a library, then it also needs to have a unique identifier. It can be specified using the identity attribute.

<projects>
  <default>
    <xml-policies directory="/opt/MCS/repository/xml-repository" />
    <assets base-url="/mcs/" />
  </default>
  <project name="build-in-components"
           identity="http://www.antennasoftware.com/components/build-in-amp-web-server-components/">
    <xml-policies directory="/opt/MCS/repository/build-in-components" />
    <assets base-url="/build-in-components/" />
  </project>
  <libraries>
    <library identity="http://cool-components.com/buttons/"
             location="../libraries/cool-buttons/"/>
    <library identity="http://smart-solutions.com/reusable-components/layouts/"
             location="file:///opt/mcs/libraries/smart-layouts-2/"/>
    <library identity="http://smart-solutions.com/reusable-components/layouts-2.0/"
             location="file:///opt/mcs/libraries/smart-layouts-2/"/>
    <library identity="http://cool-components.com/image-galeries/"
             location="http://our-own-library-cache.volantis.com/cool-image-galeries/"/>
  </libraries>
</projects>

Authors can override the settings for the default project by placing a mcs-project.xml file either in the same directory as an XDIME page being processed, or somewhere on the path to it. In this case, relative paths are resolved against the location of the mcs-project.xml file. Note that if the location attribute uses the http schema, an http URL can be mapped to itself in order to override the mapping from the server configuration with the original location.

<project>
  <xml-policies directory="policies/"/>
  <assets base-url="assets/"/>
  <libraries>
    <library identity="http://cool-components.com/buttons/"
             location="../libraries/cool-buttons/"/>
    <library identity="http://smart-solutions.com/reusable-components/layouts/"
             location="file:///opt/mcs/libraries/smart-layouts-2/"/>
    <library identity="http://smart-solutions.com/reusable-components/layouts-2.0/" 
             location="file:///opt/mcs/libraries/smart-layouts-2/"/>
    <library identity="http://cool-components.com/image-galeries/" 
             location="http://our-own-library-cache.volantis.com/cool-image-galeries/"/>
  </libraries>
</project>

Remote and local references

The use of the http schema results in a remote reference. For example:

<libraries>
  <library identity="http://cool-components.com/"
           location="http://my.acme.com/libraries-cache/cool-components/" />
</libraries>

Resolving the http://cool-components.com/buttons/toggle-button.mbnd policy URL with the previously specified library location will result in a remote reference with the following path http://my.acme.com/libraries-cache/cool-components/buttons/toggle-button.mbnd. The mcs-project.xml file will be taken from http://my.acme.com/libraries-cache/cool-components/mcs-project.xml.

The use of the file schema results in a local reference. For example:

<libraries>
  <library identity="http://cool-components.com/" 
           location="file:///opt/mcs/libraries/cool-components/" />
</libraries>

Resolving the http://cool-components.com/buttons/toggle-button.mbnd policy URL with the previously specified library location will result in a local reference with the following path /buttons/toggle-button.mbnd. The mcs-project.xml file will be taken from file:///opt/mcs/libraries/cool-components/mcs-project.xml.

Related topics