Search

Edition: Futurama Website

Module: Futurama HTML

User: Developer

Prerequisites

-

Introduction

Introduction of Futurama Intermediate Control Output, developed to customize the HTML output of Futurama.

 

Introduction

In the Futurama Editor a developer can create webpages, using the suitable output objects. These output objects are rendered to HTML. See the support page of each of the output objects to see how each of these objects are rendered. Up to Futurama Version 5.3.0 the way Futurama renders the HTML pages is completely defined within Futurama and cannot be adjusted by the Futurama developer. From Futurama Version 5.3.0 it is possible to add an extra processing step in order to change the HTML that default is rendered by Futurama. This extra processing step is called FICO, which is short for Futurama Intermediate Control Ouput. At this page FICO is explained.

Futurama HTML lifecycle

In order to understand the way Futurama creates the HTML that is shown in the user’s web-browser, see the next steps. Starting point is a web-application created in the Futurama Editor by a Futurama Developer. This web-application is created by using the different Futurama output objects. Mentioned below the steps that Futurama takes to interpret this definition and translate this to the HTML to be rendered:

  1. First step is the rendering of the webpage and all of the output objects (web controls) to a markup language called FICO (Futurama Intermediate Control Output), which is a certain format of XML;
  2. Step two is the transformation of this FICO XML to HTML using an XSLT-file. Default the file xhtml1.0.xsl is used which is part of the site release code (to be used when installing/updating the Futurama HTML code). At his point it is possible to use another XSLT-file in order to customize the HTML. See this support page in order to understand how can be configured to use another XSLT-file then the default. When an alternative XSLT-file is defined, Futurama will use this file to convert the FICO to HTML;
  3. The resulting HTML is sent to the browser, where the end-user sees the resulting webpage.   

In the situation you want to create an alternative XSLT to change the HTML rendered it is important to know what in step 2 the FICO XML is that is automatically generated by Futurama. Knowing this structure, it is possible to create an XSLT-file in order to define your custom HTML. See the next paragraph to see how this FICO XML can be retrieved and what is the method to write your own XSLT.

Structure FICO XML

In the previous paragraph the concept of the FICO XML is introduced. The FICO XML has a generic structure containing both the web controls to be transformed to HTML and a couple of extra parameters which allows differentiation during the transformation process. An example of the FICO XML is:

<RenderInput xmlns="http://www.actuit.nl/futurama/render/2015/08">
	<FICO>
		<WebPage id="id2" xmlns="http://www.actuit.nl/futurama/fico/2015/06">
			<WebLabel id="id7" cssclass="labelClass">
				<text>Hello World!</text>
			</WebLabel>
		</WebPage>
	</FICO>
	<Folder>test</Folder>
	<MetaTags>
		<Scripts>
			<Script>
				<File>Scripts/jquery-1.4.1.min.js</File>
				<Type>text/javascript</Type>
			</Script>
			<Script>
				<File>Scripts/FuturamaScripts.js</File>
				<Type>text/javascript</Type>
			</Script>
		</Scripts>
		<UserAgent>Mozilla/5.0 (Windows NT 10.0; WOW64; rv:44.0) Gecko/20100101 Firefox/44.0</UserAgent>
	</MetaTags>
</RenderInput>

Within the RenderInput element the next information is available:

  • FICO:  this contains the FICO XML that needs to be transformed;
  • Folder: this is the name of the Futurama application folder. This allows the creation of a template that only has to be applied to that specific application;
  • MetaTags: the metatags Futurama default generates;
  • Scripts: the scripts Futurama default uses.
  • UserAgent (From Futurama 6.0): This text is supplied by the user’s browser, and allows render customizations to be done specific to a browser.

With this input there are two transformations you can perform. The first is a simple transformation of the contained FICO to HTML. This is the default behavior, but can also be forced by setting an XSLT parameter with name “retrievalmode” and value “html”.

The second transformation retrieves a RenderOutput element, which has the following fields:

  • DocType: This is the document type, and specifies which version of HTML is to be expected.
  • MetaTag: This contains a list of MetaTags that can include new metatags
  • Scripts: This contains a list of script tags that can include javascript files.
  • UserAgent (From Futurama 6.0): This text is supplied by the user’s browser, and allows render customizations to be done specific to a browser.

For a detailed explanation about the XML adjustments that are needed see this page: Change/Add HTML headers with FICO

Creating customized XSLT

Although completely possible, writing a new XSLT-file would be very complex and overly time consuming, as developers mostly want to change a single element of the transformed output. For this reason it is recommended to extend the existing XSLT, and override parts of this template to ones own specification. Below an example is shown how to change the HTML of a weblabel. First is shown how to retrieve the FICO XML, and then is explained how to create an XSLT-file to change the HTML.

Capturing FICO output in the Log file

During the FICO translation procedure, the FICO XML can be seen in a logfile. Follow the next steps to see this XML:

  1. enable the logging (see for configuration this page) as well as the debug messages;
  2. open your web-application in a browser;
  3. open the logfile;
  4. check the Debug message ‘input for render XSLT’;
  5. see the input for the render XSLT by unescaping the value. 

Creating an extension XSL file

First create an empty extension XSLT file called for example "extension.xsl". If this is already done previously go to the next step. Make sure it is filled with the following content:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fut="http://www.actuit.nl/futurama/fico/2015/06" xmlns:ren="http://www.actuit.nl/futurama/render/2015/08" exclude-result-prefixes="fut ren">

	<xsl:import href="xhtml1.0.xsl"/>

	<xsl:output method="xml" indent="no" omit-xml-declaration="yes"/>

	<!--Render all other elements according to import-->
	<xsl:template match="/">
		<xsl:apply-imports/>
	</xsl:template>

</xsl:stylesheet>

This new file must be placed in the root of the Futurama Web application, and set-up in the rendering configuration section.

Change the extension XSL file

As an example suppose a WebLabel is defined with a CssClass ‘labelClass’ and a Text value ‘Hello world!’. The resulting FICO XML of this WebLabel looks like:

<WebLabel cssclass="labelClass" id="id7">
    <Text>Hello World!</Text>
</WebLabel>

Now the XSLT-file can be changed in order to customize the HTML for this weblabel. Open the default xhtml1.0.xsl and search for WebLabel. The XSL template found in this file that applies to this WebLabel looks as follows:

  <!--WebLabel-->
<xsl:template match="fut:WebLabel">
	<span>
		<!--id-->
		<xsl:attribute name="id">
			<xsl:value-of select="@id" />
		</xsl:attribute>
		<!--CssClass-->
		<xsl:call-template name="cssClass"/>

		<!--Tooltip-->
		<xsl:call-template name="toolTip" />

		<!--Value-->
		<xsl:if test="boolean(fut:Text/text())">
			<!--Content-->
			<xsl:value-of select="html:HtmlReEncode(fut:Text)" disable-output-escaping="yes" />
		</xsl:if>
		<xsl:if test="not(boolean(fut:Text/text()))">
			<!--Empty string-->
			<xsl:value-of select="''"/>
		</xsl:if>
	</span>
</xsl:template>

Which in turn generates the following XHTML result:

<span class="labelClass" id="id7">Hello World!</span>

In order to change the way this translation is done, a copy of the XSL template can be placed in the Extension.xsl file, and by changing the span element bij the label element, a different HTML format is chosen, and the result would look like this:

<label class="labelClass" id="id7">Hello World!</label>

Prevention of XSS attacks

When creating your own HTML from FICO code, it is important to keep an eye on the possibilities of XSS attacks. For instance, if you choose to render html attributes with single-quotes instead of double-quotes, and the user enters the text [‘ onclick=’alert(“you have been hacked”);] a popup would be shown. In this example the problem is harmless, but we will always advise to use double-quotes for HTML attributes! For more XSS tips, please view the Output Encoding Rules Summary.

Advanced use – postbacks

When the HTML of  webcontrols is changed it is important to keep in mind that this changes can effect information that is posted back to the server. See the page Postbacks of Futurama webcontrols for more information how Futurama postbacks work.

What can be changed?

The alternative XSLT-file can be used to change the HTML. See below which parts of the final HTML can be changed which this XSLT-file:

  • Metatags (see for an example this page);
  • (Java)scripts (see for an example this page);
  • DocType (see for an example this page);
  • Web controls (see for an example of the WebLabel the previous paragraph ‘Creating customized XSLT’);
  • Graph (see for an example this page).

Changing the behavior of FICO rendering


There are some cases when changing the XSL file isn't enough to achieve a desired method of HTML output. It is possible to change the way some aspects of the FICO render process is done. This is done by specifying a "RenderOptions" element within the XSL transformation file. This allows the following changes in the FICO output:

  • ChartRenderMode: Setting this property lets the GraphConverter object to provide its data in different ways. The possible values are as follows:
    • DataXml: This will let the Graphconverter provide an XML element containing the data about its content, namely the Series and Points that will depict the chart. This can be useful when creating a customized chart object as shown in this sample. Charts rendered this way are rendered clientside and will therefore not be visible in serverside reports.
    • MicrosoftChart (default): This lets the Graphconverter provide a element containing a string with HTML code, that can be copied to the output within the transformation XSL file. This is the default behavior, and contains an image which links to chart.aspx, which will provide the browser with the visual image. This option renders the charts serverside making them also show in server side reports.
    • DataXmlPlusMicrosoftChart: This option provides flexibility by allowing customized charts alongside with default charts. This option has a slight impact on performance.
    • MicrosoftChartDataURI: This mimics the behavior of the 'MicrosoftChart' option, but the image doesn't link to chart.aspx, but its source contains a base64 dataURI containing the binary data of the entire image. For more information, view the wikipedia entry.
  • EncodeOutput: This is a boolean field intended for WebAPI usage, indicating whether the the output of the XSL transformation can be considered valid XML, or whether it should be provided as an encoded string. The default value is 'true'.
    An example for changing this field is as follows: When the JSON variant of WebAPI is used, and the FICO code should be passed through to the consumer of the WebAPI webservice. In this case the transformation XSL can contain a simple 'xsl:copy-of' statetement pushing the raw FICO to the output of the transformation. When the EncodeOutput option is set to 'false', all the FICO elements will be provided as Javascript objects, instead of a string of XML data.
  • RenderTelerikControls: This is a boolean field that is set to "true" by default. When this is set to 'false', then the FICO for WebSlider and DateBox will not contain any prerendered HTML code, but their configured properties. This allows a user to create their own (HTML)rendering of the WebSlider and DateBox

Example

To configure the RenderOptions, the following section must be added/altered within the transformation XSL file:

<xsl:template match="/ren:RenderInput"> 
    <xsl:choose> 
        <!--include other possible retrievalModes here-->  
        <xsl:when test="$retrievalMode = 'options'"> 
            <RenderOptions xmlns="http://www.actuit.nl/futurama/render/2015/08"> 
                <ChartRenderMode>{DataXml/MicrosoftChart/MicrosoftChartDataURI}</ChartRenderMode> 
                <EncodeOutput>{true/false}</EncodeOutput> 
                <RenderTelerikControls>{true/false}</RenderTelerikControls>            
            </RenderOptions> 
        </xsl:when> 
    </xsl:choose> 
</xsl:template>

Related Topics

- Futurama Web API: This document explains the Futurama Web API architecture.

Feedback

If you have any questions about this subject or if you want to provide us feedback please send us an e-mail.

Updated: 2018-10-08