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
blog_commenter
Confirmed Champ
Confirmed Champ
Hi,



I tried this and its working for xsd schema.



But when I try to use the same pattern in xsl:import to import global xsl templates for the web forms it doesnt work.

I am adding this to the xsl that is associated to the web form







I also tried include







It gives error

Error generating rendition using Global_CRCnetBASE_landing_page.xsl: javax.xml.transform.TransformerConfigurationException: javax.xml.transform.TransformerException: javax.xml.transform.TransformerException: ElemTemplateElement error: substring-after-last
pmonks2
Champ in-the-making
Champ in-the-making
Kalpesh, xsl:imports aren't available from within XSL-backed renditioning templates but that would make a good enhancement request.  I would also encourage you to investigate Freemarker-backed renditioning templates, as it's a more flexible templating language and (via a forge project) supports inclusion of Web Scripts.
blog_commenter
Confirmed Champ
Confirmed Champ
Including the webscripts in webform,

It will work only with the xsd files ? as we have here in the example including my-include.xsd (or) else we can also add webscripts which has *.xml file  and response template *.ftl (or) /sample/ - webscript url, which one do we need to specify in the include to get the webscripts in webforms?
pmonks2
Champ in-the-making
Champ in-the-making
Saran, you can xs:include or xs:import the response from any Web Script, including custom Web Scripts that dynamically generate XSD.  The only requirement is that the output from the Web Script is a valid XML Schema - that's a requirement of the xs:include / xs:import mechanisms.



And just to clarify, this blog post illustrates the simpler use case of xs:including or xs:importing a static XSD file, without having to develop a custom Web Script (as a Web Script suitable for this purpose is included in Alfresco).  It should be straight forward to extrapolate the custom Web Script use case from this example however, as the only additional moving part is the custom Web Script (and Web Script development is documented in detail elsewhere).
blog_commenter
Confirmed Champ
Confirmed Champ
This is very useful for an XSD standpoint , I've used webscripts to populate dynamic XSDs, and they seemed to work very well.

Is there a way to call webscripts within an XSL file also?
pmonks2
Champ in-the-making
Champ in-the-making
agibson, as I mentioned to Kalpash:

'xsl:imports aren’t available from within XSL-backed renditioning templates but that would make a good enhancement request. I would also encourage you to investigate Freemarker-backed renditioning templates, as it’s a more flexible templating language and (via a forge project) supports inclusion of Web Scripts.'

blog_commenter
Confirmed Champ
Confirmed Champ
Oops , thanks for the info , Here is what I found , http://forge.alfresco.com/scm/?group_id=211



Having trouble with the anonymous access of the subversion repository though is it still available?
pmonks2
Champ in-the-making
Champ in-the-making
Yeah I have a vague recollection that the forge doesn't allow anonymous SVN checkouts (despite suggesting that they are allowed).  It's free to register though, so I'd suggest registering and seeing if you can checkout then.
blog_commenter
Confirmed Champ
Confirmed Champ
Peter , do you have any examples of using the Freemarker WSI , i.e proper syntax to include webscript , also I've added the freemarker wsi to my alfresco.war , but don't really know where to go from there. Any help appreciated
pmonks2
Champ in-the-making
Champ in-the-making
agibson, there's an example included in the source code on the forge project.