cancel
Showing results for 
Search instead for 
Did you mean: 
pmonks2
Champ in-the-making
Champ in-the-making
Since their inception, Alfresco WCM Web Forms have supported an inclusion mechanism based on the standard XML Schema include and import constructs.  Originally this mechanism read the included assets from the Web Project where the user was creating the content, but since v2.2SP3 the preferred mechanism has been to reference a Web Script instead (in fact the legacy mechanism may be deprecated in a future release).



One question that this new approach raises is how to support inclusion of static XSDs, as Web Scripts are inherently dynamic and introduce some unnecessary overhead for the simple static case.  The good news is that Alfresco ships with a Web Script that simply reads a file from the repository and returns its contents:

/api/path/content{property}/{store_type}/{store_id}/{path}?a={attach?}





An example usage is:

/api/path/content/workspace/SpacesStore/Company Home/Data Dictionary/Presentation Templates/readme.ftl





Using the Web Script inclusion mechanism for Web Forms, we can use this Web Script to include or import any XSD file stored in the DM repository.  For example, if we have a file called 'my-include.xsd' in the 'Company Home' space that contains the following content:

<?xml version='1.0'?>

<xs:schema xmlns:xs='http://www.w3.org/2001/XMLSchema'

           xmlns:alf='http://www.alfresco.org/'

           targetNamespace='http://www.alfresco.org/'

           elementFormDefault='qualified'>

  <xs:complexType abstract='true' name='IncludedComplexType'>

    <xs:sequence>

      <xs:element name='Title'

                  type='xs:normalizedString'

                  minOccurs='1'

                  maxOccurs='1' />

      <xs:element name='Summary'

                  type='xs:string'

                  minOccurs='0'

                  maxOccurs='1' />

      <xs:element name='Keyword'

                  type='xs:normalizedString'

                  minOccurs='0'

                  maxOccurs='unbounded' />

    </xs:sequence>

  </xs:complexType>

</xs:schema>





We could include it into a Web Form XSD using an include statement such as the following:

<?xml version='1.0'?>

<xs:schema xmlns:xs='http://www.w3.org/2001/XMLSchema'

           xmlns:alf='http://www.alfresco.org/'

           targetNamespace='http://www.alfresco.org/'

           elementFormDefault='qualified'>

  <xs:include schemaLocation='webscript://api/path/content/workspace/SpacesStore/Company Home/my-include.xsd?ticket={ticket}' />

  <xs:complexType name='MyWebFormType'>

    <xs:complexContent>

      <xs:extension base='alf:IncludedComplexType'>

        <xs:sequence>

          <xs:element name='Body'

                      type='xs:string'

                      minOccurs='1'

                      maxOccurs='1' />

        </xs:sequence>

      </xs:extension>

    </xs:complexContent>

  </xs:complexType>

  <xs:element name='MyWebForm' type='alf:MyWebFormType' />

</xs:schema>





This is clearly faster and easier than developing a custom Web Script to either emit the XML Schema shown above, or to return the contents of a specific XSD file from the repository!



This approach also provides a solution to another question: how does one neatly package up a Web Form, along with all of its dependencies, ready for deployment to another Alfresco environment?



By storing included XSD files in Company Home > Data Dictionary > Web Forms, we give ourselves the option to package up the entire Web Forms space as an ACP file and deploy that ACP file to any other Alfresco environment, knowing that we've captured not only all of the Web Forms in the source environment, but all dependent XSD files as well.

37 Comments