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
Thanks Peter,



Sorry, I visited this page after a month time.

Thanks for all the good work and creative samples that help us to reuse it in projects.
blog_commenter
Confirmed Champ
Confirmed Champ
Just to report back on some of my findings , I did get the Freemarker WSI project to work with a simple freemarker page and webscript, considering I am on 3.1 there were a few updates to the java code and spring configuration to get it all working .....It did not however work for XSL inclusion in Web forms, and I haven't had time to figure out exactly why.
pmonks2
Champ in-the-making
Champ in-the-making
agibson, the Freemarker WSI project is not intended to provide an inclusion mechanism for XSL templates - its sole purpose is to provide a way to include the output from a Web Script in a Freemarker template.
blog_commenter
Confirmed Champ
Confirmed Champ
Sorry I mispoke , I meant to say ....



*It did not however work for Freemarker template inclusion in Web forms, and I haven’t had time to figure out exactly why.
pmonks2
Champ in-the-making
Champ in-the-making
Ah ok.  Do you have an account on the Alfresco forge?  If so let me know what it is and I'll add you as a committer to the freemarker-wsi project so that if/when you find out what's breaking you can commit your changes.
blog_commenter
Confirmed Champ
Confirmed Champ
Hi Peter ,



The WSI is working in Web Scripts , but it does not appear to work in Web forms. I have updated the code to work with Enterprise 3.1 , if you want to create a branch I can commit to it .... my Alfresco forge accout is agibson
blog_commenter
Confirmed Champ
Confirmed Champ
Hi Peter,



I'm attempting to have a XSD use this method to include a XSD that, itself has includes.  That second include isn't working.



Thoughts on whether trying to build something like that is a good idea or bad idea?



Thanks,

Karl
blog_commenter
Confirmed Champ
Confirmed Champ
Thank you so much for this info Peter.  Very useful!!
blog_commenter
Confirmed Champ
Confirmed Champ
Ey Peter, quick question, I tried the example you used in this post, but nothing happens! Smiley Frustrated



I create the my-include.xsd file copy pasting the contents of the example, and uploadead it to My Company Home, I create a web from using the same data above (copy paste, again), then when I try to create content with that webform, nothing happens! An empty webform is displayed Smiley Sad



Can you help me?
pmonks2
Champ in-the-making
Champ in-the-making
I suspect the problem is that the blog software replaces various characters (most noticeably double quotes) with UTF alternatives that aren't valid in XML Schemas, which prevents the Web Form from loading properly.