<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>OCTO talks ! &#187; Flex</title>
	<atom:link href="http://blog.octo.com/tag/flex/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.octo.com</link>
	<description>Le blog d'OCTO Technology, cabinet d'architectes en systèmes d'information</description>
	<lastBuildDate>Thu, 29 Jul 2010 13:32:07 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Une architecture d&#8217;application Flex maintenable</title>
		<link>http://blog.octo.com/une-architecture-dapplication-flex-maintenable/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=une-architecture-dapplication-flex-maintenable</link>
		<comments>http://blog.octo.com/une-architecture-dapplication-flex-maintenable/#comments</comments>
		<pubDate>Mon, 21 Jun 2010 09:34:25 +0000</pubDate>
		<dc:creator>David Rousselie</dc:creator>
				<category><![CDATA[Architecture et technologies]]></category>
		<category><![CDATA[architecture]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[RIA]]></category>
		<category><![CDATA[Testabilité]]></category>

		<guid isPermaLink="false">http://blog.octo.com/?p=11921</guid>
		<description><![CDATA[Le framework Flex permet d&#8217;écrire très rapidement des IHM fonctionnelles, notamment grâce au langage MXML. Celui-ci permet effectivement de décrire l&#8217;interface avec peu de lignes de code. Seulement, voilà, une fois l&#8217;étape du POC passée, les fichiers MXML s&#8217;accumulent, le code ActionScript s&#8217;insinue petit à petit dans le code MXML pour implémenter les handlers d&#8217;événements, [...]


Suggestion d'articles :<ol><li><a href='http://blog.octo.com/quand-spring-sinvite-dans-une-application-flex/' rel='bookmark' title='Permanent Link: Quand Spring s&#8217;invite dans une application Flex &#8230;'>Quand Spring s&#8217;invite dans une application Flex &#8230;</a></li>
<li><a href='http://blog.octo.com/flex-vs-silverlight/' rel='bookmark' title='Permanent Link: Flex vs Silverlight'>Flex vs Silverlight</a></li>
<li><a href='http://blog.octo.com/referencer-les-applications-ria-flex-et-silverlight/' rel='bookmark' title='Permanent Link: Référencer les applications RIA Flex et Silverlight'>Référencer les applications RIA Flex et Silverlight</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fblog.octo.com%2Fune-architecture-dapplication-flex-maintenable%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fblog.octo.com%2Fune-architecture-dapplication-flex-maintenable%2F&amp;style=normal&amp;service=bit.ly" height="61" width="50" /><br />
			</a>
		</div>
<p>Le framework <a href="http://www.adobe.com/devnet/flex/">Flex</a> permet d&#8217;écrire très rapidement des IHM fonctionnelles, notamment grâce au langage MXML. Celui-ci permet effectivement de décrire l&#8217;interface avec peu de lignes de code.</p>
<p>Seulement, voilà, une fois l&#8217;étape du POC passée, les fichiers MXML s&#8217;accumulent, le code ActionScript s&#8217;insinue petit à petit dans le code MXML pour implémenter les handlers d&#8217;événements, les appels de services, la logique métier. Après quelques temps, il devient de plus en plus difficile de savoir <strong>d&#8217;où viennent les données affichées</strong> (ie. quel code a mis à jour la donnée ?), <strong>d&#8217;où provient un appel de service</strong> (surtout d&#8217;où proviennent les valeurs des arguments de cet appel).</p>
<p>Dans cet article, nous verrons quelques bonnes pratiques permettant d&#8217;assurer la maintenabilité d&#8217;une application Flex.<br />
<span id="more-11921"></span></p>
<h2>Séparation des responsabilités</h2>
<p>La première étape consiste à <strong>séparer les responsabilités du code</strong> de l&#8217;application. En effet, lorsqu&#8217;une même méthode doit collecter les données (ex : dans un formulaire), les préparer pour l&#8217;appel d&#8217;un service distant, appeler le service et mettre à jour la vue, il devient difficile de la tester ou de retrouver l&#8217;origine d&#8217;un bug.</p>
<p>Commençons par le <strong>modèle de données</strong> qui gagnera à se retrouver dans des <strong>classes séparées</strong>. En effet, il sera alors plus facile d&#8217;<strong>identifier les données à mettre à jour</strong>. Par exemple, lorsque le résultat d&#8217;un appel de service arrive, les données reçues seront placée dans ce modèle. Plus besoin de se poser la question de savoir si toutes les données ont été mises à jour, elles sont <strong>uniques</strong> et <strong>regroupées dans ces classes de modèle</strong>. On créera, par exemple, <strong>un modèle par vue</strong> (au sens fonctionnel de l&#8217;application).</p>
<p>Ensuite, les <strong>appels de services</strong> méritent eux aussi d&#8217;être <strong>encapsulés dans des classes dédiées</strong> afin de ne pas écrire 3 fois le même code technique et de les écrire de 3 façons différentes. Il deviendra alors <strong>simple d&#8217;ajouter des fonctionnalités communes</strong> aux appels de services (ex : authentification, gestion des exceptions, &#8230;) et de les <strong>remplacer par des mocks dans les tests</strong>.</p>
<p>On retrouve ainsi quelques-unes des recommandations du pattern <a href="http://fr.wikipedia.org/wiki/Mod%C3%A8le-Vue-Contr%C3%B4leur">MVC</a> et de ses cousins (<a href="http://en.wikipedia.org/wiki/Model_View_ViewModel">MVVM</a>, <a href="http://en.wikipedia.org/wiki/Model_View_Presenter">MVP</a>, &#8230;), c&#8217;est toujours bon de se les remémorer de temps à autre.<br />
En Flex, il existe un certain nombre de frameworks comme <a href="http://opensource.adobe.com/wiki/display/cairngorm/Cairngorm">Cairngorm</a>, <a href="http://puremvc.org/">PureMVC</a> ou encore <a href="http://mate.asfusion.com/">Mate</a> (et bien d&#8217;autres) qui vous permettront de mettre en place cette séparation des responsabilités et ainsi d&#8217;améliorer la maintenabilité (en même temps que la testabilité) de votre application. Il ne faut cependant pas obligatoirement sélectionner l&#8217;un de ces frameworks tant que quelques règles d&#8217;organisation du code ont été définies et partagées par tous les développeurs du projet. <strong>Ces frameworks ne sont qu&#8217;un moyen d&#8217;appliquer ces règles</strong>.</p>
<h2>Circulation des données</h2>
<p>La seconde étape consiste à <strong>définir &laquo;&nbsp;un sens de circulation&nbsp;&raquo; des données dans l&#8217;application</strong> afin de faciliter le debuggage de celle-ci (ie. <strong>mieux comprendre d&#8217;où viennent les données et où vont les données</strong>) et de <strong>favoriser la réutilisation et testabilité des composants</strong> Flex écrits.</p>
<p>La partie &laquo;&nbsp;vue&nbsp;&raquo; d&#8217;une application Flex se définie par un arbre de composants (MXML et ActionScript) :</p>
<p><a href="http://blog.octo.com/wp-content/uploads/2010/06/Archi-cliente-Flex1.png"><img class="aligncenter size-full wp-image-11975" title="Arborescence de composants d'une application Flex" src="http://blog.octo.com/wp-content/uploads/2010/06/Archi-cliente-Flex1.png" alt="Arborescence de composants d'une application Flex" width="470" height="376" /></a></p>
<p>Les nœuds de l&#8217;arbre étant des composants conteneurs (*Box, Canvas, List, &#8230;) contenant d&#8217;autres composants plus primitifs (Label, Button, &#8230;) ou d&#8217;autres conteneurs.<br />
Avec une séparation entre le modèle et les appels de services et la vue, il reste que n&#8217;importe quel composant peut se <em>binder</em> sur le modèle de données et peut effectuer un appel de service. Ce composant n&#8217;est alors plus réutilisable dans un autre contexte : il dépend des données sur lesquelles il est bindé et ne peut plus être utilisé pour en afficher d&#8217;autres. Pour lever cette limite, <strong>il faut que les données sur lesquelles il se binde lui soit injectées</strong>.<br />
De même pour les appels de services, pour que le composant puisse être utilisé dans un autre contexte (qui nécessite l&#8217;appel d&#8217;un autre service ou qui ne nécessiterait pas d&#8217;appel du tout), <strong>il faut supprimer la dépendance vers cet appel de service</strong> (ie. le composant ne devrait même pas &laquo;&nbsp;savoir&nbsp;&raquo; qu&#8217;un appel est effectué lorsqu&#8217;un événement intervient).</p>
<p>La solution à ces 2 problèmes de dépendance est de repousser le problème au composant parent <img src='http://blog.octo.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> . Ce composant parent pourra alors, soit <strong>déporter à nouveau le problème à son parent</strong> (en ajoutant des informations au passage si besoin), soit <strong>être lui-même dépendant du modèle et du service</strong>. En fait, à partir d&#8217;un certain seuil dans la hiérarchie de composants (en la remontant), il n&#8217;est plus vraiment envisageable de parler réutilisation (cela peut être le composant racine) et <strong>avoir des dépendances n&#8217;est plus vraiment problématique</strong>.</p>
<p>On obtient alors une circulation des données qui ressemble à ceci :</p>
<p><a href="http://blog.octo.com/wp-content/uploads/2010/06/Archi-cliente-Flex2.png"><img class="aligncenter size-full wp-image-11977" title="Circulation des données dans l'arborescence de composants" src="http://blog.octo.com/wp-content/uploads/2010/06/Archi-cliente-Flex2.png" alt="Circulation des données dans l'arborescence de composants" width="720" height="540" /></a></p>
<p><strong>Les données redescendent la hiérarchie via le binding</strong> (ie. un composant binde ses attributs aux attributs des composants qu&#8217;il contient) :</p>
<p>Dans View1.mxml :</p>
<pre class="brush:xml">&lt;Componentx title="{modelView1.viewTitle}" /&gt;</pre>
<p>Dans ComponentX.mxml :</p>
<pre class="brush:xml">&lt;mx:Label text="{title}" /&gt;</pre>
<p>Et <strong>elles remontent par l&#8217;intermédiaire d&#8217;événements</strong> envoyés par les composants les plus bas dans la hiérarchie. Ces événements sont <strong>retransmis (avec du code ou avec la fonctionnalité de <a href="http://help.adobe.com/en_US/flex/using/WS2db454920e96a9e51e63e3d11c0bf69084-7cdb.html">bubbling</a> qui leur permet de remonter automatiquement la hiérarchie de composants) ou transformés en événement de plus haut niveau</strong> par le composant parent.</p>
<p>Dans ComponentX.mxml :</p>
<pre class="brush:xml">&lt;mx:Button click="dispatchEvent(new AddItemEvent(this.item))" /&gt;</pre>
<p>Dans View1.mxml :</p>
<pre class="brush:xml">&lt;Componentx addItem="serviceProxy.addItem(event.item)" /&gt;</pre>
<p>Ce mode de fonctionnement revient en fait à <strong>définir une API</strong> claire des composants développés :</p>
<ul>
<li>Les attributs exposés reçoivent les données en entrée</li>
<li>Les données ressortent via les événements envoyés par le composant</li>
</ul>
<p>Au passage cela <strong>facilite ainsi la testabilité du composant</strong>. </p>
<h2>Conclusion</h2>
<p>Une fois ces 2 principes appliqués sur une application Flex, celle-ci devrait mieux résister à l&#8217;augmentation de la quantité de code et rester maintenable plus longtemps. Il faut cependant garder à l&#8217;esprit que ces principes ne seront <strong>probablement pas suffisant</strong> et de nouveaux devront être imaginés s&#8217;adaptant au contexte de chaque projet afin de favoriser la lecture du code de l&#8217;application dans sa globalité.</p>


<p>Suggestion d'articles :</p><ol><li><a href='http://blog.octo.com/quand-spring-sinvite-dans-une-application-flex/' rel='bookmark' title='Permanent Link: Quand Spring s&#8217;invite dans une application Flex &#8230;'>Quand Spring s&#8217;invite dans une application Flex &#8230;</a></li>
<li><a href='http://blog.octo.com/flex-vs-silverlight/' rel='bookmark' title='Permanent Link: Flex vs Silverlight'>Flex vs Silverlight</a></li>
<li><a href='http://blog.octo.com/referencer-les-applications-ria-flex-et-silverlight/' rel='bookmark' title='Permanent Link: Référencer les applications RIA Flex et Silverlight'>Référencer les applications RIA Flex et Silverlight</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://blog.octo.com/une-architecture-dapplication-flex-maintenable/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Flex vs Silverlight</title>
		<link>http://blog.octo.com/flex-vs-silverlight/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=flex-vs-silverlight</link>
		<comments>http://blog.octo.com/flex-vs-silverlight/#comments</comments>
		<pubDate>Fri, 06 Nov 2009 10:13:49 +0000</pubDate>
		<dc:creator>David Rousselie</dc:creator>
				<category><![CDATA[Architecture et technologies]]></category>
		<category><![CDATA[.NET]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[RIA]]></category>
		<category><![CDATA[silverlight]]></category>

		<guid isPermaLink="false">http://blog.octo.com/?p=6710</guid>
		<description><![CDATA[Alors que Macromedia (racheté en 2005 par Adobe) était parti seul devant, début 2004, dans le développement d&#8217;applications RIA en sortant la première version de Flex, voilà que fin 2006 (plus de 2 ans après donc), Microsoft dévoile une première version de sa réponse à Flex nommée Silverlight. Seulement, cette première version n&#8217;était là que [...]


Suggestion d'articles :<ol><li><a href='http://blog.octo.com/referencer-les-applications-ria-flex-et-silverlight/' rel='bookmark' title='Permanent Link: Référencer les applications RIA Flex et Silverlight'>Référencer les applications RIA Flex et Silverlight</a></li>
<li><a href='http://blog.octo.com/formation-silverlight-tour-a-paris-les-1920-et-21-janvier/' rel='bookmark' title='Permanent Link: Formation Silverlight Tour à Paris les 19,20 et 21 janvier'>Formation Silverlight Tour à Paris les 19,20 et 21 janvier</a></li>
<li><a href='http://blog.octo.com/quand-spring-sinvite-dans-une-application-flex/' rel='bookmark' title='Permanent Link: Quand Spring s&#8217;invite dans une application Flex &#8230;'>Quand Spring s&#8217;invite dans une application Flex &#8230;</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fblog.octo.com%2Fflex-vs-silverlight%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fblog.octo.com%2Fflex-vs-silverlight%2F&amp;style=normal&amp;service=bit.ly" height="61" width="50" /><br />
			</a>
		</div>
<p>Alors que Macromedia (racheté en 2005 par Adobe) était parti seul devant, début 2004, dans le développement d&#8217;applications RIA en sortant la première version de Flex, voilà que fin 2006 (plus de 2 ans après donc), Microsoft dévoile une première version de sa réponse à Flex nommée Silverlight. Seulement, cette première version n&#8217;était là que pour &laquo;&nbsp;occuper le terrain&nbsp;&raquo; car elle restait encore très loin derrière Flex qui passait à peu près au même moment en version 2. D&#8217;ailleurs, à peine cette première version de Silverlight sortie, Microsoft annonçait déjà les premières versions Alpha de la v2 qui viendrait avec une machine virtuelle plus performante, une version allégée de la CLR .Net, en lieu et place du moteur Javascript de la v1. Alors que la v2 est sortie en fin d&#8217;année dernière, la v3 sort seulement un peu plus de 6 mois après. Il semble donc que malgré son retard, Microsoft produit à un rythme impressionnant de nouvelles versions de Silverlight en apportant à chaque fois un nombre non négligeable de nouvelles fonctionnalités. Même si Adobe continue de faire évoluer sa plateforme et s&#8217;apprête à sortir la version 4 d&#8217;ici la fin de l&#8217;année, les deux technologies sont aujourd&#8217;hui au coude à coude.<br />
Dans cet article, nous ferons un tour panoramique de ces deux technologies afin de pointer leurs similitudes et différences.</p>
<p><span id="more-6710"></span></p>
<h2>Le principe de fonctionnement</h2>
<p>Les deux technologies, que ce soit Flex ou Silverlight, fonctionnent exactement selon le même principe :<br />
Il s&#8217;agit d&#8217;une <strong>application embarquée dans une page HTML</strong> (donc téléchargée depuis un serveur web) dont <strong>l&#8217;exécution s&#8217;effectue sur le poste client</strong> et est totalement <strong>déléguée à un plugin tiers du navigateur web</strong>, le Player Flash pour Flex et un nouveau plugin fourni par Microsoft pour Silverlight.<br />
Flex profite bien évidemment de la popularité de déploiement du Player Flash installé sur une grande majorité des machines connectées à Internet. Pour le plugin Silverlight, tout reste à faire mais Microsoft rattrape vite son retard, notamment en profitant d&#8217;autres canaux de distribution que le navigateur web tel que Windows Update.</p>
<p>Une fois démarrées, ces applications fonctionnent en <strong>mode client-serveur</strong>, c&#8217;est à dire en gardant l&#8217;état de l&#8217;application (ie. la session utilisateur) sur le poste client et en effectuant des appels de services avec le serveur.<br />
<img class="aligncenter size-full wp-image-6716" title="FlexSLArchi" src="http://blog.octo.com/wp-content/uploads/2009/10/FlexSLArchi.png" alt="Architecture client-serveur de Flex et Silverlight" width="256" height="473" /></p>
<h2>Le modèle de programmation</h2>
<p>Concernant le modèle de développement, on retrouve là encore de grandes similitudes entre Flex et Silverlight qui utilisent toutes les deux <strong>un format de fichier XML pour décrire l&#8217;IHM</strong> : MXML pour Flex et XAML pour Silverlight (emprunté à WPF). Ces fichiers XML permettent de décrire l&#8217;agencement des composants graphiques et de paramétrer les propriétés de ces composants.</p>
<p>Exemple MXML :</p>
<pre>
&lt;mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"&gt;
    &lt;mx:Text text="Hello World !" /&gt;
&lt;/mx&gt;
</pre>
<p>Exemple XAML :</p>
<pre>
&lt;UserControl x:Class="SilverlightApplication2.Page"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Width="400" Height="300"&gt;
    &lt;Grid x:Name="LayoutRoot" Background="White"&gt;
        &lt;TextBox Text="Hello World !" /&gt;
    &lt;/Grid&gt;
&lt;/UserControl&lt;
</pre>
<p>Associés à ces fichiers XML, <strong>un langage de programmation objet est utilisé afin de traiter la dynamique de l&#8217;application</strong> : les événements utilisateur et la logique de l&#8217;IHM. Alors que Flex utilise l&#8217;ActionScript 3 qui est le langage de prédilection du Player Flash, Silverlight s&#8217;appuit sur C# (et même d&#8217;autres languages tels que IronPython ou IronRuby). C&#8217;est un gros avantage pour Silverlight qui profite de la maturité de C#, beaucoup plus avancé qu&#8217;ActionScript tant en terme de langage que d&#8217;outillage. En effet, C# a été pensé dès le départ pour le développement d&#8217;application alors qu&#8217;ActionScript a commencé en tant que langage de scripting pour les applets Flash pour ensuite évoluer vers un langage objet typé fortement.</p>
<p>Ce n&#8217;est pas seulement le langage en lui-même dont profite Silverlight mais aussi de tout l&#8217;écosystème .Net. En effet, <strong>une application développée avec Silverlight pourra profiter de la plupart des bibliothèques .Net (après recompilation), mais aussi du grand nombre d&#8217;outils disponibles pour le développement .Net</strong>.<br />
L&#8217;écosystème Flex, qui est en pleine ébullition, rattrape son retard avec des bibliothèques et des outils de développement en tout genre qui sortent régulièrement, notamment grâce à <strong>une communauté très active de projets opensource</strong>. Ils restent cependant jeunes face à .Net.</p>
<p>Enfin, même si la machine virtuelle de Silverlight est récente, <strong>elle a hérité des capacités de la CLR .Net et profite donc de la maturité de celle-ci</strong> comme par exemple des systèmes de compilation Just In Time ou de Garbage Collecting. La machine virtuelle du Player Flash, malgré ses évolutions récentes pour inclure ces mécanismes, reste moins avancée. <strong>Cette dernière profite cependant de la maturité de son moteur de rendu graphique</strong>, le Player Flash ayant toujours été adapté à l&#8217;animation graphique.</p>
<h2>Les composants et le développement</h2>
<h3>Stratégies de chargement d&#8217;une application</h3>
<p>En ce qui concerne les composants disponibles avec chacune des solutions, on retrouve à peu près les même composants en allant piocher dans des bibliothèques tierces. Silverlight vient cependant avec une bibliothèque de base moins complète que celle de Flex qui s&#8217;explique notamment par le choix du <strong>mode de compilation d&#8217;une application qui diffère d&#8217;une solution à l&#8217;autre</strong>.</p>
<p>En effet, <strong>le plugin Silverlight installé sur le poste de l&#8217;utilisateur ne contient pas seulement la machine virtuelle mais aussi la bibliothèque de composants de base</strong> alors que <strong>le Player Flash n&#8217;installe que la machine virtuelle</strong> (qui implémente seulement l&#8217;API bas-niveau de Flash). Cela se traduit par un plugin Flash de 1.8Mo et un plugin Silverlight de 4.7Mo. Le choix d&#8217;inclure la bibliothèque de composants de base dans le plugin Silverlight peut s&#8217;expliquer par le fait que la plupart des applications utiliseront ces composants et <strong>il n&#8217;est ainsi pas nécessaire de les retélécharger en même temps que chaque application</strong>.<br />
De son côté, la solution n&#8217;incluant pas la bibliothèque de base dans le plugin a pour avantage de <strong>décorréler le cycle de vie du Player Flash et du SDK Flex</strong> mais ce n&#8217;est pas la seule raison. En effet, la stratégie de compilation Flex, et notamment la phase de link avec les bibliothèques, diffère de celle de Silverlight. Par défaut, lors de la compilation d&#8217;une application Flex, <strong>les composants disponibles dans les bibliothèques utilisées (dont le SDK et donc les composants de base) ne sont inclus dans le fichier SWF final que s&#8217;ils sont effectivement utilisés par l&#8217;application</strong>. Ainsi, toute la bibliothèque de composants de base Flex n&#8217;est pas inclue dans toutes les applications Flex contrairement à la stratégie de compilation d&#8217;une application Silverlight qui embarquera la totalité des bibliothèques utilisées. Flex implémente d&#8217;autres stratégies de compilation dont une similaire à la stratégie Silverlight (ie. le téléchargement des bibliothèques dans leur globalité) ou encore la possiblité de télécharger le SDK complet, de le mettre en cache et de le partager pour toutes les applications Flex tout en gardant une &laquo;&nbsp;inclusion sélective&nbsp;&raquo; des composants des autres bibliothèques utilisées.<br />
Dans l&#8217;absolu, aucune solution n&#8217;est meilleure qu&#8217;une autre, tout dépendra du contexte de déploiement. <strong>Flex offre cependant une plus grande souplesse en permettant de maitriser plus finement la taille de l&#8217;application</strong>.</p>
<h3>Création de composants</h3>
<p>Une autre différence entre Silverlight et Flex se situe lors de la création de composants personnalisés.<br />
En effet, Silverlight permet de créer deux types de composants, <strong>les composants utilisateurs qui sont écris en XAML</strong> et <strong>les composants personnalisés qui sont complètement écris en C#</strong> pour avoir la main sur le rendu du composants. Le premier type est simple à écrire (XAML + code behind en C# comme le reste de l&#8217;application Silverlight) mais ne permet pas d&#8217;hériter d&#8217;autres composants. Le second, par contre, permet l&#8217;héritage de composants mais doit être écrit totalement en C# et est donc beaucoup plus complexe à écrire.</p>
<p>En Flex, la création de composants reste plus simple. <strong>Pour créer un composant, il suffit de déplacer le morceau de MXML voulu dans un nouveau fichier</strong>. La balise racine de ce morceau de MXML devient le composant parent (en terme d&#8217;héritage objet). Pour avoir la main sur le rendu du composant, il suffit de surcharger la méthode adéquate de ce même composant (en mélangeant le MXML et l&#8217;AS). <strong>Flex favorise donc la création de composants réutilisables en ne proposant qu&#8217;une solution fexible plutôt que de multiples pour chaque cas d&#8217;usage</strong>.</p>
<h3>Description de l&#8217;IHM</h3>
<p>Le XAML permet d&#8217;aller plus loin en terme de description de l&#8217;IHM par rapport à MXML en offrant <strong>la possibilité de pouvoir dessiner avec le langage de balisage</strong>. Cette fonctionnalité est surtout utile pour des outils WYSIWYG (le résultat en XML étant peu Human Friendly) tel que Expression Blend pour Silverlight. Flex n&#8217;offrira cette fonctionnalité qu&#8217;avec la version 4 et son format FXG (http://opensource.adobe.com/wiki/display/flexsdk/FXG+1.0+Specification) manipulable avec les outils de la Creative Suite d&#8217;Adobe (et son future outil FlashCatalyst pour faire le pont entre designers et développeurs).</p>
<h3>Styliser une application</h3>
<p>Pour styliser une application, Flex et Silverlight utilisent là aussi des stratégies différentes :<br />
Tout d&#8217;abord en ce qui concerne le style simple, c&#8217;est à dire les éléments stylisables prévus par le développeur d&#8217;un composant, <strong>Silverlight utilise des balises XAML pour déclarer des styles</strong> qui seront utilisés lors de l&#8217;instanciation d&#8217;un composant (via l&#8217;attribut Style).</p>
<p>Par exemple :</p>
<pre>
&lt;Grid&gt;
  &lt;Grid.Resources&gt;
    &lt;Style TargetType="Button" x:Key="MyStyle"&gt;
      &lt;Setter Property="Stroke" Value="Red"/&gt;
    &lt;/Style&gt;
  &lt;/Grid.Resources&gt;

  &lt;Button Style="{StaticResource MyStyle}" /&gt;
&lt;/Grid&gt;
</pre>
<p><strong>Flex, de son côté, utilise CSS</strong> (adaptés au système de composants Flex bien sûr). Celà permet d&#8217;utiliser une syntaxe connue des développeurs web et moins verbeuse que du XML.</p>
<p>Dans un fichier CSS :</p>
<pre>
Button {
  color: #FF0000;
}</pre>
<p>Dans un fichier MXML :</p>
<pre>
&lt;mx:Style source="style.css" /&gt;
&lt;mx:Button /&gt;
</pre>
<p>Pour aller plus loin dans le style d&#8217;une application, il est utile de pouvoir complètement redessiner les composants. <strong>Silverlight utilise la notion de template qui permet de redéfinir en XAML le rendu d&#8217;un composant</strong> :</p>
<pre>
&lt;Style TargetType="Button" x:Key="MyButton"&gt;
  &lt;Setter Property="Template"&gt;
    &lt;Setter.Value&gt;
      &lt;ControlTemplate TargetType="Button"&gt;
        &lt;Border Background="Red"&gt;
          &lt;TextBlock Text="Fixed text: " /&gt;
          &lt;ContentPresenter Content="{TemplateBinding Content}“ /&gt;
        &lt;/Border&gt;
      &lt;/ControlTemplate&gt;
    &lt;/Setter.Value&gt;
  &lt;/Setter&gt;
&lt;/Style&gt;
</pre>
<p>En Flex par contre, du moins jusqu&#8217;a la version 3, il est possible d&#8217;utiliser des skins Flash réalisées avec le studio Flash ou directement écrites en ActionScript. <strong>La solution de Silverlight est dans ce cas plus abordable et plus flexible puisque le template peut être aussi complexe que nécessaire</strong>, ce n&#8217;est pas juste une skin. Flex supportera de modifier le rendu d&#8217;un composant avec la version 4 en séparant la définition de la vue du reste du composant.</p>
<h3>Système d&#8217;animation</h3>
<p><strong>Les systèmes d&#8217;animation de Silverlight et Flex offrent des possiblités équivalentes tout en ayant des approches différentes</strong>.<br />
En Silverlight, une animation cible une propriété d&#8217;un composant dont elle lissera la transition d&#8217;une valeur à une autre.</p>
<pre>
&lt;Storyboard x:Name="myStory"&gt;
  &lt;DoubleAnimation From="0" To="42" Duration="0:0:2"
                   x:Name="moveAnimationX"
                   Storyboard.TargetName="myButton"
                   Storyboard.TargetProperty="x" /&gt;
  &lt;DoubleAnimation From="0" To="42" Duration="0:0:2"
                   x:Name="moveAnimationY"
                   Storyboard.TargetName="myButton"
                   Storyboard.TargetProperty="y" /&gt;
&lt;/Storyboard&gt;

&lt;Button x:Name="myButton" /&gt;
</pre>
<p>Puis en C# :</p>

<div class="wp_codebox"><table><tr id="p67103"><td class="line_numbers"><pre>1
2
</pre></td><td class="code" id="p6710code3"><pre class="java" style="font-family:monospace;">...
<span style="color: #006633;">myStory</span>.<span style="color: #006633;">Begin</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>Alors qu&#8217;en Flex, une animation est de plus haut niveau et s&#8217;appliquera sur un composant. <strong>Son type déterminera le ou les attributs ciblés et se déclenchera lorsque l&#8217;attribut sera modifié </strong>(il est cependant possible de fonctionner de la même manière qu&#8217;en Silverlight : en déclanchant l&#8217;animation qui modifiera l&#8217;attribut d&#8217;un composant).</p>
<pre>
&lt;mx:Move id="moveEffect" /&gt;

&lt;mx:Button id="myButton" moveEffect="{moveEffect}" /&gt;
</pre>
<p>Puis en ActionScript :</p>

<div class="wp_codebox"><table><tr id="p67104"><td class="line_numbers"><pre>1
2
3
</pre></td><td class="code" id="p6710code4"><pre class="javascript" style="font-family:monospace;">...
<span style="color: #660066;">myButton</span>.<span style="color: #660066;">x</span> <span style="color: #339933;">=</span> <span style="color: #CC0000;">42</span><span style="color: #339933;">;</span>
myButton.<span style="color: #660066;">y</span> <span style="color: #339933;">=</span> <span style="color: #CC0000;">42</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p><strong>La solution Flex est moins verbeuse, le MXML s&#8217;écrit plus facilement par un développeur alors que le XAML est encore une fois, plus destiné aux outils WYSIWYG</strong>.</p>
<h3>Communication Client / Serveur</h3>
<p>Un dernier point de comparaison qui diffère entre Flex et Silverlight est le système de communication client-serveur. <strong>Les deux technologies permettent toutes les deux d&#8217;effectuer des appels XML / HTTP et SOAP / HTTP selon un modèle de sécurité très proche</strong> (ie. appel de service sur le serveur d&#8217;où est téléchargé l&#8217;application et appel entre différents domaines géré avec un fichier de configuration : crossdomain.xml pour Flex et accesspolicy.xml pour Silverlight).</p>
<p>Pour simplifier le parsing du XML, <strong>Silverlight permet d&#8217;utiliser Linq</strong> alors que <strong>Flex utilise E4X</strong> (EcmaScript For XML : une syntaxe proche de l&#8217;objet pour parser du XML). <strong>Ceci permet donc aux 2 technologies de se connecter sur n&#8217;importe quel type de serveur qui sait exposer des WebServices SOAP ou REST</strong>.</p>
<p>Cependant, <strong>elles viennent chacune avec leur technologie d&#8217;appel de services qui permet de grandement simplifier la communication entre le client et le serveur</strong>. En effet, en utilisant des appels de service <strong>WCF en Silverlight</strong><strong> ou </strong><strong>AMF/HTTP en Flex</strong> (disponible en Java, PHP, Python ou Ruby), cela permet de bénéficier <strong>d&#8217;une (dé)sérialisation automatique</strong> que ce soit sur le client ou le serveur et simplifie grandement le développement de ce type d&#8217;applications.</p>
<h2>Conclusion</h2>
<p>Beaucoup de caractéristiques de chacune des technologies Flex et Silverlight n&#8217;ont pas été abordées dans cet article pour se concentrer sur ce qui peut servir à les différencier ou qui permet de mieux faire ressortir les avantages de l&#8217;une ou l&#8217;autre.</p>
<p>Silverlight, malgré le retard avec lequel la première version est sortie, a sû le rattraper en réutilisant la CLR, <strong>plus avancée que le Player Flash</strong>, mais aussi <strong>en s&#8217;appuyant sur tout l&#8217;ecosystème .Net tant en terme de langage avec C#, qu&#8217;en terme d&#8217;outillage</strong>.<br />
Ainsi, aujourd&#8217;hui, <strong>les deux technologies ont des capacités équivalentes</strong> et quand une fonctionnalité n&#8217;existe pas dans l&#8217;une, la version suivante prévoit de combler le vide.</p>
<p>En terme de développement, <strong>Flex semble plus abordable lorsque l&#8217;on s&#8217;attarde sur le code écrit</strong>, tant en XML (MXML est globalement moins verbeux que XAML mais ce n&#8217;est pas un problème si l&#8217;on fait confiance aux outils WYSIWYG de Microsoft), qu&#8217;en AS et C# (pour l&#8217;appel de services par exemple ou la création/le parsing de XML en C# qui utilise une API plus complexe qu&#8217;en AS).</p>
<p>Enfin, <strong>l&#8217;écosystème dans lequel ces applications seront déployées a aussi son importance</strong> puisque, même si Flex et Silverlight s&#8217;intègrent parfaitement partout où il est possible de faire au moins du XML / HTTP, leur technologie de communication respective avec le serveur facilite grandement le développement mais lie du coup la technologie cliente avec la technologie serveur.<br />
<strong>La cible des utilisateurs est aussi un critère déterminant</strong> sachant que pour une cible grand public, le Player Flash reste le plus déployé à l&#8217;heure actuelle alors que pour des applications internes, la disponibilité du plugin Silverlight ou Flash est maitrisable.</p>
<p>Pour aller plus loin sur la comparaison de Flex et Silverlight, allez voir la vidéo de la session <a href="http://usi2009.universite-du-si.com/webcast-5-11-Du.RIA.pour.mon.SI.Microsoft.Silverlight.vs.Adobe.Flex.html">Du RIA pour mon SI Microsoft Silverlight vs Adobe Flex</a> présenté à l&#8217;<a href="http://usi2009.universite-du-si.com">Université du SI 2009</a>.</p>


<p>Suggestion d'articles :</p><ol><li><a href='http://blog.octo.com/referencer-les-applications-ria-flex-et-silverlight/' rel='bookmark' title='Permanent Link: Référencer les applications RIA Flex et Silverlight'>Référencer les applications RIA Flex et Silverlight</a></li>
<li><a href='http://blog.octo.com/formation-silverlight-tour-a-paris-les-1920-et-21-janvier/' rel='bookmark' title='Permanent Link: Formation Silverlight Tour à Paris les 19,20 et 21 janvier'>Formation Silverlight Tour à Paris les 19,20 et 21 janvier</a></li>
<li><a href='http://blog.octo.com/quand-spring-sinvite-dans-une-application-flex/' rel='bookmark' title='Permanent Link: Quand Spring s&#8217;invite dans une application Flex &#8230;'>Quand Spring s&#8217;invite dans une application Flex &#8230;</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://blog.octo.com/flex-vs-silverlight/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Quand Spring s&#8217;invite dans une application Flex &#8230;</title>
		<link>http://blog.octo.com/quand-spring-sinvite-dans-une-application-flex/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=quand-spring-sinvite-dans-une-application-flex</link>
		<comments>http://blog.octo.com/quand-spring-sinvite-dans-une-application-flex/#comments</comments>
		<pubDate>Thu, 23 Apr 2009 13:35:11 +0000</pubDate>
		<dc:creator>David Rousselie</dc:creator>
				<category><![CDATA[Architecture et technologies]]></category>
		<category><![CDATA[développements]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[RIA]]></category>
		<category><![CDATA[spring]]></category>

		<guid isPermaLink="false">http://blog.octo.com/?p=2524</guid>
		<description><![CDATA[Ces derniers temps, il ne se passe pas un mois sans que l&#8217;on entende parler d&#8217;un nouveau framework destiné au développement d&#8217;application Flex. Parmi ceux-ci, deux d&#8217;entre eux retiennent notre attention puisqu&#8217;ils sont hébergés au sein de Spring. Ces deux projets sont Spring Actionscript (en incubation pour le moment) et Spring Flex. Spring Flex n&#8217;est [...]


Suggestion d'articles :<ol><li><a href='http://blog.octo.com/integrer-gwt-spring/' rel='bookmark' title='Permanent Link: Intégrer GWT &#038; Spring'>Intégrer GWT &#038; Spring</a></li>
<li><a href='http://blog.octo.com/comparaison-google-guice-et-spring/' rel='bookmark' title='Permanent Link: Comparaison Google Guice et Spring'>Comparaison Google Guice et Spring</a></li>
<li><a href='http://blog.octo.com/spring-batch-par-quel-bout-le-prendre/' rel='bookmark' title='Permanent Link: Spring-Batch : par quel bout le prendre ?'>Spring-Batch : par quel bout le prendre ?</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fblog.octo.com%2Fquand-spring-sinvite-dans-une-application-flex%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fblog.octo.com%2Fquand-spring-sinvite-dans-une-application-flex%2F&amp;style=normal&amp;service=bit.ly" height="61" width="50" /><br />
			</a>
		</div>
<p>Ces derniers temps, il ne se passe pas un mois sans que l&#8217;on entende parler d&#8217;un nouveau framework destiné au développement d&#8217;application Flex. Parmi ceux-ci, deux d&#8217;entre eux retiennent notre attention puisqu&#8217;ils sont hébergés au sein de Spring. Ces deux projets sont <a href="http://www.springsource.org/extensions/se-springactionscript-as">Spring Actionscript</a> (en incubation pour le moment) et <a href="http://www.springsource.org/spring-flex">Spring Flex</a>.</p>
<p>Spring Flex n&#8217;est qu&#8217;une extension au projet Spring que les développeurs Java connaissent bien. Il permet d&#8217;exposer des classes Java sous forme de services <a href="http://opensource.adobe.com/wiki/display/blazeds/BlazeDS/">BlazeDS</a> depuis la configuration Spring.</p>
<p>Spring ActionScript par contre, est un <strong>conteneur IoC</strong> destiné à la <strong>partie cliente d&#8217;une application Flex</strong>. C&#8217;est sur celui-ci que nous nous attarderons dans cet article.</p>
<p><span id="more-2524"></span></p>
<h3>Les principes de base de Spring Actionscript</h3>
<p>À l&#8217;origine, Spring Actionscript était un framework nommé Prana Framework et ne faisait pas partie de Spring. Son auteur a débuté Prana en suivant les même principes que Spring Java afin qu&#8217;un développeur Java connaissant déjà Spring puisse s&#8217;y retrouver rapidement.<br />
C&#8217;est pourquoi le fichier de configuration ressemble très fortement à celui que l&#8217;on peut trouver en Java :</p>

<div class="wp_codebox"><table><tr id="p25248"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
</pre></td><td class="code" id="p2524code8"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;objects<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	...
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;object</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;remoteObject&quot;</span></span>
<span style="color: #009900;">                <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;mx.rpc.remoting.mxml.RemoteObject&quot;</span> <span style="color: #000066;">abstract</span>=<span style="color: #ff0000;">&quot;true&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;endpoint&quot;</span></span>
<span style="color: #009900;">                       <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;http://localhost:8080/flexapp/messagebroker/amf&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;showBusyCursor&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;true&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/object<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;object</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;myService&quot;</span> <span style="color: #000066;">parent</span>=<span style="color: #ff0000;">&quot;remoteObject&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;destination&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;myService&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/object<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	...
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/objects<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></td></tr></table></div>

<p>De même que pour la récupération d&#8217;un Object (là où Spring Java parle de Bean) :</p>

<div class="wp_codebox"><table><tr id="p25249"><td class="line_numbers"><pre>1
2
3
4
5
</pre></td><td class="code" id="p2524code9"><pre class="javascript" style="font-family:monospace;">applicationContext <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> FlexXMLApplicationContext<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#91;</span><span style="color: #3366CC;">&quot;springas.xml&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span>
applicationContext.<span style="color: #660066;">load</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
...
<span style="color: #003366; font-weight: bold;">var</span> myObject<span style="color: #339933;">:</span> MyObject <span style="color: #339933;">=</span> applicationContext.<span style="color: #660066;">getObject</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;myObject&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
...</pre></td></tr></table></div>

<p>On retrouve donc la notion de <strong>contexte d&#8217;application</strong> depuis lequel on peut retrouver les objets déclarés dans le fichier de configuration.<br />
Une petite différence cependant est la méthode load() de l&#8217;object context. En effet, le fichier de configuration (&laquo;&nbsp;springas.xml&nbsp;&raquo; dans l&#8217;exemple) est<strong> téléchargé par l&#8217;application Flex</strong> sur le serveur (via HTTP donc) lors de l&#8217;appel à cette méthode.</p>
<p>Maintenant que nous avons vu que nous retrouvons les même principes de fonctionnement que Spring Java sur notre application Flex, quand utiliser l&#8217;injection de dépendance de SpringAS ?</p>
<p>Un premier cas d&#8217;utilisation est de déclarer tout ce qui concerne <strong>la configuration de l&#8217;application</strong> comme par exemple la <strong>déclaration des services</strong> (HTTPService, WebService ou RemoteObject). Ceci évite donc d&#8217;avoir à recompiler l&#8217;application lors d&#8217;un changement dans la configuration des services.</p>
<p>Un autre cas d&#8217;utilisation est lorsqu&#8217;une application Flex est architecturée avec des <strong>responsabilités séparées</strong> dans différentes classes ; typiquement avec une <strong>architecture MVC</strong>, MVP ou autre.<br />
Spring Actionscript supporte d&#8217;ailleurs, dans des &laquo;&nbsp;modules&nbsp;&raquo; séparés, <a href="http://opensource.adobe.com/wiki/display/cairngorm/Cairngorm">Cairngorm</a> et <a href="http://puremvc.org/">PureMVC</a>. Ces deux frameworks MVC facilitent l&#8217;organisation du code d&#8217;une application Flex en séparant les responsabilités, mais le couplage entre les classes reste fort  dû à une utilisation abondante du pattern Singleton. SpringAS permet de les découpler en les liant seulement au travers d&#8217;interfaces et en injectant l&#8217;implémentation réelle d&#8217;après le fichier de configuration.</p>
<h3>Intégration avec Spring Flex</h3>
<p>Comme expliqué précédemment, les fichiers de configuration servant à initialiser le context SpringAS sont <strong>téléchargés sur le serveur via HTTP</strong>. Qui dit HTTP, dit URL mais pas forcément fichier. On peut ainsi générer ce fichier de configuration depuis une servlet (ou tout autre mécanisme de génération serveur) ?</p>
<p>Ça devient intéressant en utilisant Spring Flex. Celui-ci permet d&#8217;exposer une classe Java en tant que service Flex (au sens service BlazeDS et donc AMF/HTTP) juste à l&#8217;aide d&#8217;une déclaration dans le fichier de configuration Spring (Java cette fois-ci). Dans le fichier de configuration de SpringAS, on peut retrouver la déclaration des RemoteObjects, le pendant client de ces services Java. Pourquoi réécrire et maintenir cette configuration dans le fichier de configuration SpringAS alors que cela a déjà été fait dans la configuration Spring Java ?<br />
Une simple servlet Java peut ainsi <strong>récupérer la liste des classes Java exposées</strong> en tant que service Flex depuis la configuration Spring Java et <strong>générer la configuration SpringAS</strong> (ici la même configuration que le premier exemple de l&#8217;article) :</p>

<div class="wp_codebox"><table><tr id="p252410"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
</pre></td><td class="code" id="p2524code10"><pre class="java" style="font-family:monospace;">WebApplicationContext context <span style="color: #339933;">=</span> WebApplicationContextUtils.<span style="color: #006633;">getWebApplicationContext</span><span style="color: #009900;">&#40;</span>getServletContext<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #003399;">String</span> eol <span style="color: #339933;">=</span> <span style="color: #003399;">System</span>.<span style="color: #006633;">getProperty</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;line.separator&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
result.<span style="color: #006633;">append</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;&lt; ?xml version=<span style="color: #000099; font-weight: bold;">\&quot;</span>1.0<span style="color: #000099; font-weight: bold;">\&quot;</span> encoding=<span style="color: #000099; font-weight: bold;">\&quot;</span>utf-8<span style="color: #000099; font-weight: bold;">\&quot;</span> ?&gt;&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">append</span><span style="color: #009900;">&#40;</span>eol<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
result.<span style="color: #006633;">append</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;&lt;objects&gt;&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">append</span><span style="color: #009900;">&#40;</span>eol<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #003399;">URL</span> requestURL <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">URL</span><span style="color: #009900;">&#40;</span>request.<span style="color: #006633;">getRequestURL</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">toString</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
result.<span style="color: #006633;">append</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;&lt;object id=<span style="color: #000099; font-weight: bold;">\&quot;</span>remoteObject<span style="color: #000099; font-weight: bold;">\&quot;</span> class=<span style="color: #000099; font-weight: bold;">\&quot;</span>mx.rpc.remoting.mxml.RemoteObject<span style="color: #000099; font-weight: bold;">\&quot;</span> abstract=<span style="color: #000099; font-weight: bold;">\&quot;</span>true<span style="color: #000099; font-weight: bold;">\&quot;</span>&gt;&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">append</span><span style="color: #009900;">&#40;</span>eol<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
result.<span style="color: #006633;">append</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;&lt;property name=<span style="color: #000099; font-weight: bold;">\&quot;</span>endpoint<span style="color: #000099; font-weight: bold;">\&quot;</span> value=<span style="color: #000099; font-weight: bold;">\&quot;</span>http://&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">append</span><span style="color: #009900;">&#40;</span>requestURL.<span style="color: #006633;">getHost</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
result.<span style="color: #006633;">append</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;:&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">append</span><span style="color: #009900;">&#40;</span>requestURL.<span style="color: #006633;">getPort</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
result.<span style="color: #006633;">append</span><span style="color: #009900;">&#40;</span>getServletContext<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">getContextPath</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
result.<span style="color: #006633;">append</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;/spring/messagebroker/amf<span style="color: #000099; font-weight: bold;">\&quot;</span> /&gt;&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">append</span><span style="color: #009900;">&#40;</span>eol<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
result.<span style="color: #006633;">append</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;&lt;property name=<span style="color: #000099; font-weight: bold;">\&quot;</span>showBusyCursor<span style="color: #000099; font-weight: bold;">\&quot;</span> value=<span style="color: #000099; font-weight: bold;">\&quot;</span>true<span style="color: #000099; font-weight: bold;">\&quot;</span> /&gt;&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">append</span><span style="color: #009900;">&#40;</span>eol<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
result.<span style="color: #006633;">append</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;&lt;/object&gt;&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">append</span><span style="color: #009900;">&#40;</span>eol<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #003399;">String</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> beanNames <span style="color: #339933;">=</span> context.<span style="color: #006633;">getBeanNamesForType</span><span style="color: #009900;">&#40;</span>FlexRemotingServiceExporter.<span style="color: #000000; font-weight: bold;">class</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span> beanName<span style="color: #339933;">:</span> beanNames<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	result.<span style="color: #006633;">append</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;&lt;object id=<span style="color: #000099; font-weight: bold;">\&quot;</span>&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">append</span><span style="color: #009900;">&#40;</span>beanName<span style="color: #009900;">&#41;</span>.<span style="color: #006633;">append</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\&quot;</span> parent=<span style="color: #000099; font-weight: bold;">\&quot;</span>remoteObject<span style="color: #000099; font-weight: bold;">\&quot;</span>&gt;&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">append</span><span style="color: #009900;">&#40;</span>eol<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	result.<span style="color: #006633;">append</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;&lt;property name=<span style="color: #000099; font-weight: bold;">\&quot;</span>destination<span style="color: #000099; font-weight: bold;">\&quot;</span> value=<span style="color: #000099; font-weight: bold;">\&quot;</span>&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">append</span><span style="color: #009900;">&#40;</span>beanName<span style="color: #009900;">&#41;</span>.<span style="color: #006633;">append</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\&quot;</span> /&gt;&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">append</span><span style="color: #009900;">&#40;</span>eol<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	result.<span style="color: #006633;">append</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;&lt;/object&gt;&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">append</span><span style="color: #009900;">&#40;</span>eol<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
result.<span style="color: #006633;">append</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;&lt;/objects&gt;&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">append</span><span style="color: #009900;">&#40;</span>eol<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
response.<span style="color: #006633;">getOutputStream</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">print</span><span style="color: #009900;">&#40;</span>result.<span style="color: #006633;">toString</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<h3>Conclusion</h3>
<p>L&#8217;introduction de Spring sur la partie cliente d&#8217;une application peut être intéressante car elle apporte une certaine souplesse en <strong>séparant ce qui est de la configuration du reste du code</strong>, mais aussi en facilitant la testabilité de l&#8217;application en <strong>réduisant le couplage entre classes</strong>. Enfin, la génération de la configuration SpringAS sur le serveur permet d&#8217;imaginer des applications plus flexibles en &laquo;&nbsp;cablant&nbsp;&raquo; l&#8217;application dynamiquement (selon les droits de l&#8217;utilisateur par exemple).</p>
<p>Cependant, quelques problèmes persistent :</p>
<ul>
<li><strong>il n&#8217;est pas possible d&#8217;utiliser d&#8217;annotations pour injecter automatiquement les attributs</strong> d&#8217;une classe alors que Actionscript les supporte. Un début de <a href="http://coenraets.org/blog/2009/03/the-spring-actionscript-framework-%E2%80%93-part-2-autowiring/">solution</a> existe mais n&#8217;est pas encore inclu dans SpringAS,</li>
<li>les classes qui ne sont pas utilisées (ie. qui n&#8217;ont pas de variables du type de la classe) par l&#8217;application principale mais seulement utilisées via le fichier de configuration ne seront <strong>pas inclues dans l&#8217;application à la compilation</strong>. Ceci est dû au fonctionnement du compilateur Flex qui n&#8217;inclut que les classes réellement utilisées. Or il n&#8217;a aucun moyen de déterminer que certaines classes seront utilisées après le chargement du fichier de configuration SpringAS. Pour contourner le problème il faut soit utiliser l&#8217;option &laquo;&nbsp;-includes&nbsp;&raquo; du compilateur et lui lister ces classes afin de le forcer à les inclure, soit déclarer des attributs fictifs (qui ne seront pas réellement utilisés) du type de ces classes dans l&#8217;application principale.</li>
</ul>
<p>Enfin, même si SpringAS apporte de la souplesse à une architecture qui s&#8217;appuie sur Cairngorm, elle n&#8217;en diminue pas la complexité (il y a toujours autant, voir plus, de classes à créer). Un début de framework MVC semble en cours de développement au sein de SpringAS, peut-être nous apportera-t-il à la fois la simplicité et la souplesse. D&#8217;ici là, l&#8217;intérêt d&#8217;utiliser SpringAS pour une application Flex n&#8217;est pas donné et dépendra de chaque application et de son choix d&#8217;architecture.</p>


<p>Suggestion d'articles :</p><ol><li><a href='http://blog.octo.com/integrer-gwt-spring/' rel='bookmark' title='Permanent Link: Intégrer GWT &#038; Spring'>Intégrer GWT &#038; Spring</a></li>
<li><a href='http://blog.octo.com/comparaison-google-guice-et-spring/' rel='bookmark' title='Permanent Link: Comparaison Google Guice et Spring'>Comparaison Google Guice et Spring</a></li>
<li><a href='http://blog.octo.com/spring-batch-par-quel-bout-le-prendre/' rel='bookmark' title='Permanent Link: Spring-Batch : par quel bout le prendre ?'>Spring-Batch : par quel bout le prendre ?</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://blog.octo.com/quand-spring-sinvite-dans-une-application-flex/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Référencer les applications RIA Flex et Silverlight</title>
		<link>http://blog.octo.com/referencer-les-applications-ria-flex-et-silverlight/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=referencer-les-applications-ria-flex-et-silverlight</link>
		<comments>http://blog.octo.com/referencer-les-applications-ria-flex-et-silverlight/#comments</comments>
		<pubDate>Tue, 31 Mar 2009 18:31:18 +0000</pubDate>
		<dc:creator>Mickaël Morier</dc:creator>
				<category><![CDATA[Architecture et technologies]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[référencement]]></category>
		<category><![CDATA[RIA]]></category>
		<category><![CDATA[silverlight]]></category>

		<guid isPermaLink="false">http://blog.octo.com/?p=1527</guid>
		<description><![CDATA[Pourquoi référencer une application dans les moteurs de recherche ? Le référencement est une étape non négligeable du développement d&#8217;un site Internet. Ne pas référencer son application dans les moteurs de recherche revient à imprimer une plaquette publicitaire sans la distribuer. Si les moteurs de recherche savent parfaitement référencer un site HTML, qu&#8217;en est-il des [...]


Suggestion d'articles :<ol><li><a href='http://blog.octo.com/flex-vs-silverlight/' rel='bookmark' title='Permanent Link: Flex vs Silverlight'>Flex vs Silverlight</a></li>
<li><a href='http://blog.octo.com/quand-spring-sinvite-dans-une-application-flex/' rel='bookmark' title='Permanent Link: Quand Spring s&#8217;invite dans une application Flex &#8230;'>Quand Spring s&#8217;invite dans une application Flex &#8230;</a></li>
<li><a href='http://blog.octo.com/une-architecture-dapplication-flex-maintenable/' rel='bookmark' title='Permanent Link: Une architecture d&#8217;application Flex maintenable'>Une architecture d&#8217;application Flex maintenable</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fblog.octo.com%2Freferencer-les-applications-ria-flex-et-silverlight%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fblog.octo.com%2Freferencer-les-applications-ria-flex-et-silverlight%2F&amp;style=normal&amp;service=bit.ly" height="61" width="50" /><br />
			</a>
		</div>
<p><em>Pourquoi référencer une application dans les moteurs de recherche ?</em></p>
<p style="text-align: justify;">Le référencement est une étape non négligeable du développement d&#8217;un site Internet. Ne pas référencer son application dans les moteurs de recherche revient à imprimer une plaquette publicitaire sans la distribuer. Si les moteurs de recherche savent parfaitement référencer un site HTML, qu&#8217;en est-il des applications RIA développées avec des technologies telles que Flex ou Silverlight ?</p>
<p><span id="more-1527"></span><br />
<em>Pourquoi le référencement d&#8217;une application RIA pose-t-il problème ?</em></p>
<p style="text-align: justify;">Les sites HTML standards répondent aux normes du consortium W3C. Il est ainsi facile pour les moteurs de recherche de parser et d&#8217;indexer les différentes pages d&#8217;un site en s&#8217;appuyant sur ces normes. Ces normes permettent également à votre navigateur de comprendre la façon dont il doit afficher la page HTML. Dans le cadre des applications RIA, le serveur envoi un fichier SWF (Flex) ou XAML (Silverlight) à votre navigateur qui doit utiliser des plugins pour interpréter ces fichiers. Les moteurs de recherche sont identiques à votre navigateur, ils ne savent pas encore comment bien indexer ces fichiers (bien que la <a title="spécification du format SWF" href="http://www.adobe.com/devnet/swf/">spécification du format SWF</a> soit publique depuis l&#8217;an dernier). Google et Yahoo! ne se contentent que d&#8217;indexer les textes statiques et suivre les liens hypertextes des SWF. Faites une simple recherche sur Google avec le mot-clé <em>filetype:swf</em> et vous observerez qu&#8217;il comprend le format du fichier et qu&#8217;il en indexe quelques textes, mais il faut avouer que cela est très pauvre. Faites la même recherche avec le mot-clé <em>filetype:xaml</em> et vous constaterez que Google ne comprend rien du tout. Précisons que le faible nombre de texte s&#8217;explique également par la manière dont est exécutée l&#8217;application, les données ne sont pas toujours présentes dans les fichiers SWF et XAML mais proviennent de services. Même si quelques textes sont récupérés des fichiers SWF, on ne peut modifier l&#8217;importance des mots clés. Tous les textes ont la même valeur contrairement à ce que l&#8217;on peut faire en HTML avec les balises titres (h1 à h6).</p>
<p><em>OK, mais ce problème est-il nouveau ?</em></p>
<p style="text-align: justify;">La problématique du référencement des applications RIA n&#8217;est pas nouvelle, elle se posait déjà lorsque les applications Flash fleurissaient sur le net. A cette époque, le haut débit n&#8217;était pas très répandu. Le choix le plus répandu était de diviser le site en deux parties : un site Flash pour les connexions haut débit et un site HTML pour l&#8217;accès bas débit. Cette technique permettait d&#8217;être dans l&#8217;air du temps avec un site Flash tout en garantissant le référencement dans les moteurs de recherche avec la partie HTML.</p>
<p><em>Et les choses ont vraiment changé aujourd&#8217;hui pour le référencement d&#8217;une application Flex ?</em></p>
<p style="text-align: justify;">Aujourd&#8217;hui les débits de connexion Internet ont évoluées ainsi que la technologie Flex qui permet de faire des applications riches permettant d&#8217;interagir avec des fichiers externes contrairement au Flash qui se résumait au fichier SWF. Comme il est impossible de réaliser un bon référencement sur ces fichiers, il faut orienter le référencement vers du contenu HTML alternatif et interdire le référencement des fichiers SWF en configurant le fichier robots.txt comme suit :</p>

<div class="wp_codebox"><table><tr id="p152721"><td class="line_numbers"><pre>1
2
</pre></td><td class="code" id="p1527code21"><pre class="xml" style="font-family:monospace;">User-agent: *
Disallow: /monApplicationFlex.swf</pre></td></tr></table></div>

<p><em>Du contenu HTML alternatif ! Les méthodes n&#8217;ont donc pas évolué ?</em></p>
<p style="text-align: justify;">Aujourd&#8217;hui, on ne construit plus un site alternatif complet mais on ajoute simplement du contenu HTML utile au référencement à la place de l&#8217;application Flex. La librairie JavaScript <a title="SWFObject" href="http://code.google.com/p/swfobject/">SWFObject</a> permet de réaliser cette astuce simplement. Voici un exemple :</p>

<div class="wp_codebox"><table><tr id="p152722"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
</pre></td><td class="code" id="p1527code22"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;html</span> <span style="color: #000066;">xmlns</span>=<span style="color: #ff0000;">&quot;http://www.w3.org/1999/xhtml&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
 <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;head<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
 <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;title<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Exemple d'utilisation de SWFObject<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/title<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
 <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;meta</span> <span style="color: #000066;">http-equiv</span>=<span style="color: #ff0000;">&quot;Content-Type&quot;</span> <span style="color: #000066;">content</span>=<span style="color: #ff0000;">&quot;text/html; charset=iso-8859-1&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
 <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;script</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;text/javascript&quot;</span> <span style="color: #000066;">src</span>=<span style="color: #ff0000;">&quot;swfobject.js&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span><span style="color: #000000; font-weight: bold;">&lt;/script<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
 <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/head<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
 <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;body<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
 <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;div</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;monContenuAlternatif&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
   <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;h1<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Mon application Flex<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/h1<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
   <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;p<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>description de mon application<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/p<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
 <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/div<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
 <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;script</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;text/javascript&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
   swfobject.embedSWF(&quot;monApplicationFlex.swf&quot;, &quot;monContenuAlternatif&quot;, &quot;800&quot;, &quot;400&quot;, &quot;9.0.0&quot;);
 <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/script<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
 <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/body<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/html<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></td></tr></table></div>

<p style="text-align: justify;">Avec cette méthode, les moteurs de recherche ne voient que le contenu HTML alternatif du bloc <em>monContenuAlternatif</em> car ils n&#8217;interprètent pas le JavaScript. Quant aux utilisateurs, ils voient l&#8217;application Flex <em>monApplicationFlex.swf</em> se charger à la place du contenu du bloc <em>monContenuAlternatif</em> s&#8217;ils possèdent le lecteur Flash. L&#8217;intérêt est que l&#8217;on peut produire du contenu HTML hiérarchisé. Ainsi lorsqu&#8217;un moteur de recherche référencera cet exemple, il donnera plus d&#8217;importance au titre &laquo;&nbsp;Mon application Flex&nbsp;&raquo; qu&#8217;au paragraphe &laquo;&nbsp;description de mon application&nbsp;&raquo;. De la sorte, on peut optimiser à souhait le référencement de ce contenu alternatif et avoir un site respectant les standards du web. L&#8217;inconvénient de cette méthode est que les personnes ayant désactivé JavaScript mais possédant le lecteur Flash, ne verront pas se charger l&#8217;application Flex. Adobe revendique que 99% des internautes auraient le lecteur Flash d&#8217;installé tandis que le W3C rapporte un taux d&#8217;activation du JavaScript de seulement 95%.</p>
<p><em>Super mais je n&#8217;ai qu&#8217;un seul contenu alternatif dans ce cas, non ?</em></p>
<p style="text-align: justify;">Au même titre qu&#8217;un site HTML classique, une URL correspond à un contenu, mais rien ne nous empèche que le contenu alternatif soit dynamiquement généré par le serveur. De la même manière, rien ne nous empèche de multiplier le nombre de pages HTML afin que l&#8217;application web soit accessible depuis plusieurs URL.</p>
<p><em>Mais ces différentes URL lanceront la même application Flex, alors pourquoi plusieurs pages ?</em></p>
<p style="text-align: justify;">Tout d&#8217;abord, multiplier le nombre de page d&#8217;une application web est important pour le référencement. C&#8217;est autant de liens retour (backlinks) possible vers notre application, ce qui pourra la rendre plus populaire. En outre, les différentes URL lanceront la même application Flex mais son état peut dépendre de cette URL. Prenons l&#8217;exemple d&#8217;une application Flex répertoriant des livres. Il serait intéressant d&#8217;accéder directement aux livres d&#8217;un auteur depuis une URL. Par exemple, l&#8217;URL www.monsite.com/auteur/octo afficherait la liste des livres publiés par OCTO. Afin que l&#8217;application Flex fasse ce traitement, il suffit de récupérer ces informations de l&#8217;URL et de les transmettre à notre application en variable (FlashVars) :</p>

<div class="wp_codebox"><table><tr id="p152723"><td class="line_numbers"><pre>1
2
3
4
5
6
</pre></td><td class="code" id="p1527code23"><pre class="javascript" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>script type<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;text/javascript&quot;</span><span style="color: #339933;">&gt;</span>
 <span style="color: #003366; font-weight: bold;">var</span> url <span style="color: #339933;">=</span> window.<span style="color: #660066;">location</span>.<span style="color: #660066;">toString</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">// http://www.monsite.com/auteur/octo</span>
 <span style="color: #003366; font-weight: bold;">var</span> value <span style="color: #339933;">=</span> url.<span style="color: #660066;">substr</span><span style="color: #009900;">&#40;</span>url.<span style="color: #660066;">indexOf</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;.com/&quot;</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">0</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> <span style="color: #CC0000;">5</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">// Pour ne garder que auteur/octo</span>
 <span style="color: #003366; font-weight: bold;">var</span> flashvars <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span>url <span style="color: #339933;">:</span> value<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
 swfobject.<span style="color: #660066;">embedSWF</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;monApplicationFlex.swf&quot;</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">&quot;monContenuAlternatif&quot;</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">&quot;800&quot;</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">&quot;400&quot;</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">&quot;9.0.0&quot;</span><span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">null</span><span style="color: #339933;">,</span> flashvars<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #339933;">&lt;/</span>script<span style="color: #339933;">&gt;</span></pre></td></tr></table></div>

<p style="text-align: justify;">Dans cet exemple, notre application Flex récupère &laquo;&nbsp;auteur/octo&nbsp;&raquo; dans la variable <em>url</em> et sait qu&#8217;elle doit afficher les livres de l&#8217;auteur OCTO. On pourrait se dire que ce JavaScript est inutile car Flex gère le <a title="deep linking" href="http://labs.adobe.com/wiki/index.php/Flex_3:Feature_Introductions:_Deep_Linking">deep linking</a> qui permet de bénéficier de tous les avantages de la navigation par URL. Pour cela, Flex s&#8217;appuie sur les fragments suivant les ancres symbolisés par le symbole #. Notre application Flex gèrait naturellement l&#8217;URL www.monsite.com#auteur/octo sans le JavaScript précédent. Le souci est que les fragments suivant les ancres ne sont pas référencés par les moteurs de recherche, ils ne référenceront pas l&#8217;URL www.monsite.com#auteur/octo mais l&#8217;URL www.monsite.com.</p>
<p><em>Intéressant, n&#8217;aurais-je pas pu récupérer ces informations dans ma page HTML au lieu de l&#8217;URL ?</em></p>
<p style="text-align: justify;">C&#8217;est tout à fait envisageable si nos pages sont générées par le serveur, la variable FlashVars <em>url</em> aurait pu être directement valorisée à &laquo;&nbsp;auteur/octo&nbsp;&raquo; par celui-ci. En produisant du code xHTML, il est même possible de transmettre ce code dans une variable FlashVars à l&#8217;application Flex qui le parsera comme un simple fichier XML afin d&#8217;en exploiter les données. Voici un exemple étayant cette méthode :</p>

<div class="wp_codebox"><table><tr id="p152724"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
</pre></td><td class="code" id="p1527code24"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;html</span> <span style="color: #000066;">xmlns</span>=<span style="color: #ff0000;">&quot;http://www.w3.org/1999/xhtml&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
 <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;head<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;title<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Exemple innerHTML<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/title<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;meta</span> <span style="color: #000066;">http-equiv</span>=<span style="color: #ff0000;">&quot;Content-Type&quot;</span> <span style="color: #000066;">content</span>=<span style="color: #ff0000;">&quot;text/html; charset=iso-8859-1&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;script</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;text/javascript&quot;</span> <span style="color: #000066;">src</span>=<span style="color: #ff0000;">&quot;swfobject.js&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span><span style="color: #000000; font-weight: bold;">&lt;/script<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
 <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/head<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
 <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;body<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;div</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;auteur&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
   <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;h1<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>OCTO<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/h1<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
   <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;ul<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;li<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Gestion des Identités<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/li<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;li<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Une Politique pour le Système d'Information<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/li<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
   <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/ul<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/div<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;script</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;text/javascript&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
   var innerHTML = document.getElementById('auteur').innerHTML;
   var flashvars = {auteur : innerHTML};
   swfobject.embedSWF(&quot;monApplicationFlex.swf&quot;, &quot;auteur&quot;, &quot;800&quot;, &quot;400&quot;, &quot;9.0.0&quot;, null, flashvars);
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/script<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
 <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/body<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/html<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></td></tr></table></div>

<p style="text-align: justify;">Dans cet exemple, l&#8217;application Flex reçoit dans sa variable FlashVars <em>auteur</em> le contenu du bloc <em>auteur</em>. En parsant ce contenu XML, l&#8217;application Flex récupère le nom de l&#8217;auteur ainsi que sa liste de livres.</p>
<p><em>Très bien, je vois qu&#8217;il y a plusieurs possibilités pour les applications Flex, mais est-ce pareil pour les applications Silverlight ?</em></p>
<p style="text-align: justify;">Dans son Kit de développement logiciel, Silverlight embarque un fichier JavaScript qui permet d&#8217;avoir le même comportement que SWFObject pour les applications Flex. Voici un simple exemple illustrant cette technique :</p>

<div class="wp_codebox"><table><tr id="p152725"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
</pre></td><td class="code" id="p1527code25"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;html</span> <span style="color: #000066;">xmlns</span>=<span style="color: #ff0000;">&quot;http://www.w3.org/1999/xhtml&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
 <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;head<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
 <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;title<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Exemple d'utilisation de Silverlight<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/title<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
 <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;meta</span> <span style="color: #000066;">http-equiv</span>=<span style="color: #ff0000;">&quot;Content-Type&quot;</span> <span style="color: #000066;">content</span>=<span style="color: #ff0000;">&quot;text/html; charset=iso-8859-1&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
 <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;script</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;text/javascript&quot;</span> <span style="color: #000066;">src</span>=<span style="color: #ff0000;">&quot;Silverlight.js&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span><span style="color: #000000; font-weight: bold;">&lt;/script<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
 <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/head<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
 <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;body<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
 <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;div</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;monContenuAlternatif&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
   <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;h1<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Mon application Flex<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/h1<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
   <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;p<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>description de mon application<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/p<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
 <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/div<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
 <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;script</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;text/javascript&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
   var monContenuAlternatif = document.getElementById(&quot;monContenuAlternatif&quot;);
   Silverlight.createObject(&quot;monApplicationSilverlight.xaml&quot;, monContenuAlternatif, &quot;objectId&quot;, {width:'800', height:'400', minRuntimeVersion:'2.0'});
 <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/script<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
 <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/body<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/html<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></td></tr></table></div>

<p style="text-align: justify;">Les utilisateurs possédant le plugin Silverlight voient l&#8217;application à la place du contenu HTML alernatif que seuls les moteurs de recherche analyseront. Il en est de même avec l&#8217;utilisation de plusieurs URLs. Reprenons notre exemple de l&#8217;URL www.monsite.com/auteur/octo, nous allons récupérer les informations de cette URL et les transmettre à notre application en paramètre d&#8217;initialisation :</p>

<div class="wp_codebox"><table><tr id="p152726"><td class="line_numbers"><pre>1
2
3
4
5
6
</pre></td><td class="code" id="p1527code26"><pre class="javascript" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>script type<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;text/javascript&quot;</span><span style="color: #339933;">&gt;</span>
 <span style="color: #003366; font-weight: bold;">var</span> url <span style="color: #339933;">=</span> window.<span style="color: #660066;">location</span>.<span style="color: #660066;">toString</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">// http://www.monsite.com/auteur/octo</span>
 <span style="color: #003366; font-weight: bold;">var</span> value <span style="color: #339933;">=</span> url.<span style="color: #660066;">substr</span><span style="color: #009900;">&#40;</span>url.<span style="color: #660066;">indexOf</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;.com/&quot;</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">0</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> <span style="color: #CC0000;">5</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">// Pour ne garder que auteur/octo</span>
 <span style="color: #003366; font-weight: bold;">var</span> param <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;url=&quot;</span> <span style="color: #339933;">+</span> value<span style="color: #339933;">;</span>
 Silverlight.<span style="color: #660066;">createObject</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;monApplicationSilverlight.xaml&quot;</span><span style="color: #339933;">,</span> monContenuAlternatif<span style="color: #339933;">,</span> <span style="color: #3366CC;">&quot;objectId&quot;</span><span style="color: #339933;">,</span> <span style="color: #009900;">&#123;</span>width<span style="color: #339933;">:</span><span style="color: #3366CC;">'800'</span><span style="color: #339933;">,</span> height<span style="color: #339933;">:</span><span style="color: #3366CC;">'400'</span><span style="color: #339933;">,</span> minRuntimeVersion<span style="color: #339933;">:</span><span style="color: #3366CC;">'2.0'</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">null</span><span style="color: #339933;">,</span> param<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #339933;">&lt;/</span>script<span style="color: #339933;">&gt;</span></pre></td></tr></table></div>

<p style="text-align: justify;">Par la même méthode, on pourrait facilement transmettre le contenu HTML alternatif en paramètre à notre application Silverlight afin d&#8217;exploiter son contenu.</p>
<p><em>Génial mais n&#8217;y a-t-il pas de techniques supplémentaires avec Silverlight ?</em></p>
<p style="text-align: justify;">Il est existe une qui permet d&#8217;utiliser le fichier XAML de l&#8217;application Silverlight comme source du contenu HTML alternatif car le XAML est un document XML valide. L&#8217;utilisation d&#8217;un fichier XSLT permet de transformer les données intéressantes du XAML en contenu HTML. Regardons à travers un exemple afin de reproduire le contenu HTML de l&#8217;exemple innerHTML :</p>

<div class="wp_codebox"><table><tr id="p152727"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
</pre></td><td class="code" id="p1527code27"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;html</span> <span style="color: #000066;">xmlns</span>=<span style="color: #ff0000;">&quot;http://www.w3.org/1999/xhtml&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
 <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;head<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
 <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;title<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Exemple XSLT avec Silverlight<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/title<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
 <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;meta</span> <span style="color: #000066;">http-equiv</span>=<span style="color: #ff0000;">&quot;Content-Type&quot;</span> <span style="color: #000066;">content</span>=<span style="color: #ff0000;">&quot;text/html; charset=iso-8859-1&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
 <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;script</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;text/javascript&quot;</span> <span style="color: #000066;">src</span>=<span style="color: #ff0000;">&quot;Silverlight.js&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span><span style="color: #000000; font-weight: bold;">&lt;/script<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
 <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/head<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
 <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;body<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
 <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;asp</span> :Xml <span style="color: #000066;">ID</span>=<span style="color: #ff0000;">&quot;XHTML&quot;</span> <span style="color: #000066;">runat</span>=<span style="color: #ff0000;">&quot;server&quot;</span> <span style="color: #000066;">DocumentSource</span>=<span style="color: #ff0000;">&quot;monApplicationSilverlight.xaml&quot;</span> <span style="color: #000066;">TransformSource</span>=<span style="color: #ff0000;">&quot;transform.xslt&quot;</span> <span style="color: #000066;">EnableViewState</span>=<span style="color: #ff0000;">&quot;False&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
 <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;script</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;text/javascript&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
   var auteur = document.getElementById(&quot;auteur&quot;);
   Silverlight.createObject(&quot;monApplicationSilverlight.xaml&quot;, auteur, &quot;objectId&quot;, {width:'800', height:'400', minRuntimeVersion:'2.0'});
 <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/script<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
 <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/body<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/html<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></td></tr></table></div>


<div class="wp_codebox"><table><tr id="p152728"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
</pre></td><td class="code" id="p1527code28"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;canvas</span> <span style="color: #000066;">xmlns</span>=<span style="color: #ff0000;">&quot;http://schemas.microsoft.com/client/2007&quot;</span> <span style="color: #000066;">xmlns:x</span>=<span style="color: #ff0000;">&quot;http://schemas.microsoft.com/winfx/2006/xaml&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
 <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;textblock</span> <span style="color: #000066;">x:Name</span>=<span style="color: #ff0000;">&quot;auteur&quot;</span> <span style="color: #000066;">Text</span>=<span style="color: #ff0000;">&quot;OCTO&quot;</span> <span style="color: #000066;">Foreground</span>=<span style="color: #ff0000;">&quot;Blue&quot;</span> <span style="color: #000066;">FontFamily</span>=<span style="color: #ff0000;">&quot;Arial&quot;</span> <span style="color: #000066;">Canvas.Top</span>=<span style="color: #ff0000;">&quot;50&quot;</span> <span style="color: #000066;">Canvas.Left</span>=<span style="color: #ff0000;">&quot;50&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;linebreak</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;run</span> <span style="color: #000066;">Text</span>=<span style="color: #ff0000;">&quot;Gestion des Identités&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;linebreak</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;run</span> <span style="color: #000066;">Text</span>=<span style="color: #ff0000;">&quot;Une Politique pour le Système d'Information&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
 <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/textblock<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/canvas<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></td></tr></table></div>


<div class="wp_codebox"><table><tr id="p152729"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
</pre></td><td class="code" id="p1527code29"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;xsl</span> :stylesheet <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span> <span style="color: #000066;">xmlns:sl</span>=<span style="color: #ff0000;">&quot;http://schemas.microsoft.com/client/2007&quot;</span> <span style="color: #000066;">xmlns:xsl</span>=<span style="color: #ff0000;">&quot;http://www.w3.org/1999/XSL/Transform&quot;</span> <span style="color: #000066;">exclude-result-prefixes</span>=<span style="color: #ff0000;">&quot;sl&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;xsl</span> :output <span style="color: #000066;">omit-xml-declaration</span>=<span style="color: #ff0000;">&quot;yes&quot;</span> <span style="color: #000066;">indent</span>=<span style="color: #ff0000;">&quot;yes&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
 <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/xsl<span style="color: #000000; font-weight: bold;">&gt;</span></span><span style="color: #000000; font-weight: bold;">&lt;xsl</span> :template <span style="color: #000066;">match</span>=<span style="color: #ff0000;">&quot;/&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;xsl</span> :apply-templates <span style="color: #000066;">select</span>=<span style="color: #ff0000;">&quot;*&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
 <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/xsl<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
 <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;xsl</span> :template <span style="color: #000066;">match</span>=<span style="color: #ff0000;">&quot;sl:Canvas&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
   <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;xsl</span> :apply-templates <span style="color: #000066;">select</span>=<span style="color: #ff0000;">&quot;*&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
 <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/xsl<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
 <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;xsl</span> :template <span style="color: #000066;">match</span>=<span style="color: #ff0000;">&quot;sl:TextBlock&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;div</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;auteur&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
   <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;h1<span style="color: #000000; font-weight: bold;">&gt;</span></span><span style="color: #000000; font-weight: bold;">&lt;xsl</span> :value-of <span style="color: #000066;">select</span>=<span style="color: #ff0000;">&quot;@Text&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span><span style="color: #000000; font-weight: bold;">&lt;xsl</span> :value-of <span style="color: #000066;">select</span>=<span style="color: #ff0000;">&quot;text()&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span><span style="color: #000000; font-weight: bold;">&lt;/h1<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
   <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;ul<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;xsl</span> :apply-templates <span style="color: #000066;">select</span>=<span style="color: #ff0000;">&quot;*&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
   <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/ul<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/div<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
 <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/xsl<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
 <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;xsl</span> :template <span style="color: #000066;">match</span>=<span style="color: #ff0000;">&quot;sl:Run&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;li<span style="color: #000000; font-weight: bold;">&gt;</span></span><span style="color: #000000; font-weight: bold;">&lt;xsl</span> :value-of <span style="color: #000066;">select</span>=<span style="color: #ff0000;">&quot;@Text&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span><span style="color: #000000; font-weight: bold;">&lt;xsl</span> :value-of <span style="color: #000066;">select</span>=<span style="color: #ff0000;">&quot;text()&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span><span style="color: #000000; font-weight: bold;">&lt;/li<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
 <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/xsl<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></td></tr></table></div>

<p>A l&#8217;exécution de notre page ASP.NET, la transformation du contenu de notre application Silverlight représenté par le fichier XAML sera réalisée par le fichier XSLT. Ce qui nous donnera le résultat suivant.</p>

<div class="wp_codebox"><table><tr id="p152730"><td class="line_numbers"><pre>1
2
3
4
5
6
7
</pre></td><td class="code" id="p1527code30"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;div</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;auteur&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
 <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;h1<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>OCTO<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/h1<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
 <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;ul<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;li<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Gestion des Identités<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/li<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;li<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Une Politique pour le Système d'Information<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/li<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
 <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/ul<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/div<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></td></tr></table></div>

<p><em>Serons nous toujours obligé de faire tout ça pour référencer nos applications RIA ?</em></p>
<p style="text-align: justify;">Rien n&#8217;est sur pour l&#8217;instant mais les acteurs majeurs veulent améliorer la situation. Le 1er juillet 2008, Google, Yahoo et Adobe ont annoncé qu&#8217;ils collaboraient ensemble pour améliorer le référencement des fichiers SWF. L&#8217;ouverture de la spécification du format SWF est un pas dans cette direction. Dans l&#8217;avenir, Google, qui ne référence que les textes statiques et les liens hypertextes, souhaite pouvoir référencer les contenus dynamiques des SWF, référencer les images, comprendre le deep linking, agir sur les boutons des formulaires, etc. Nul doute que les algorithmes de référencement des applications Flex vont suivre le chemin parcouru par les sites HTML. Des bonnes pratiques d&#8217;optimisation pour les moteurs de recherche (SEO) pour les applications RIA naîtront au fil du temps.</p>


<p>Suggestion d'articles :</p><ol><li><a href='http://blog.octo.com/flex-vs-silverlight/' rel='bookmark' title='Permanent Link: Flex vs Silverlight'>Flex vs Silverlight</a></li>
<li><a href='http://blog.octo.com/quand-spring-sinvite-dans-une-application-flex/' rel='bookmark' title='Permanent Link: Quand Spring s&#8217;invite dans une application Flex &#8230;'>Quand Spring s&#8217;invite dans une application Flex &#8230;</a></li>
<li><a href='http://blog.octo.com/une-architecture-dapplication-flex-maintenable/' rel='bookmark' title='Permanent Link: Une architecture d&#8217;application Flex maintenable'>Une architecture d&#8217;application Flex maintenable</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://blog.octo.com/referencer-les-applications-ria-flex-et-silverlight/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Et si l&#8217;avenir des IHMs (Web) était à la mixité?</title>
		<link>http://blog.octo.com/et-si-lavenir-des-ihms-etait-a-la-mixite/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=et-si-lavenir-des-ihms-etait-a-la-mixite</link>
		<comments>http://blog.octo.com/et-si-lavenir-des-ihms-etait-a-la-mixite/#comments</comments>
		<pubDate>Sat, 28 Mar 2009 13:30:53 +0000</pubDate>
		<dc:creator>Olivier Mallassi</dc:creator>
				<category><![CDATA[Architecture et technologies]]></category>
		<category><![CDATA[Ajax]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[RIA]]></category>

		<guid isPermaLink="false">http://blog.octo.com/?p=2148</guid>
		<description><![CDATA[Lorsqu&#8217;on regarde une application &#171;&#160;grand public&#160;&#187;, on note au moins les besoins suivants : rien de génial la dedans, interagir avec des données, de consulter et de naviguer dans du contenu mise en forme. A côté de ces besoins, on recherche souvent &#171;&#160;THE&#160;&#187; solution, celle qui va résoudre tous nos problèmes, celle qui va répondre [...]


Suggestion d'articles :<ol><li><a href='http://blog.octo.com/referencer-les-applications-ria-flex-et-silverlight/' rel='bookmark' title='Permanent Link: Référencer les applications RIA Flex et Silverlight'>Référencer les applications RIA Flex et Silverlight</a></li>
<li><a href='http://blog.octo.com/openesbsun-java-caps-6-quel-avenir/' rel='bookmark' title='Permanent Link: OpenESB/Sun Java CAPS  6, quel avenir?'>OpenESB/Sun Java CAPS  6, quel avenir?</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fblog.octo.com%2Fet-si-lavenir-des-ihms-etait-a-la-mixite%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fblog.octo.com%2Fet-si-lavenir-des-ihms-etait-a-la-mixite%2F&amp;style=normal&amp;service=bit.ly" height="61" width="50" /><br />
			</a>
		</div>
<p>Lorsqu&#8217;on regarde une application &laquo;&nbsp;grand public&nbsp;&raquo;, on note au moins les besoins suivants : rien de génial la dedans, interagir avec des données, de consulter et de naviguer dans du contenu mise en forme. A côté de ces besoins, on recherche souvent &laquo;&nbsp;THE&nbsp;&raquo; solution, celle qui va résoudre tous nos problèmes, celle qui va répondre à tous nos besoins. Reste que si une telle technologie existait, on l&#8217;aurait déjà trouvée. Un peu comme les alchimistes qui recherche à transformer le plomb en or&#8230;</p>
<p>J&#8217;ai cette impression que ces applications devront &#8211; au moins à moyen terme &#8211; mixer les technologies. Flex est adapté pour réaliser des interactions utilisateurs trés riches, trés visuelles : slider, <a href="http://blog.xebia.fr/2008/06/19/drag-and-drop-flex/">drag&#038;drop</a>, transitions visuelles et <a href="http://www.camilleroux.com/2008/03/28/effet-flex-effects-mxml-actionscript">autres effets visuels</a>&#8230; . A l&#8217;inverse, HTML reste la technologie la plus adaptée pour gérer du contenu mis en forme, pour assurer la navigabilité dans ce contenu. Dès lors, comment faire communiquer ces deux mondes : Flex et HTML.<br />
<span id="more-2148"></span></p>
<p><a href="http://www.adobe.com/fr/products/flex/">Adobe </a> répond à cette question et propose <a href="http://livedocs.adobe.com/flex/3/langref/flash/external/ExternalInterface.html">l&#8217;ExternalInterface</a>. Cette classe permet d&#8217;exécuter des méthodes JavaScript depuis Flex ou des méthodes Flex depuis JavaScript et bien entendu de passer des arguments; des données d&#8217;un monde à l&#8217;autre.</p>
<h2>Communiquer entre les deux mondes&#8230;</h2>
<p>Pour interagir avec JavaScript et HTML depuis une application Flex, l&#8217;objet <code>ExternalInterface </code>propose une méthode <code>call() </code>qui permet de préciser le nom de la méhtode JavaScript a appeler ainsi que les paramètres qui seront transmis. Au niveau HTML, on définit cette fameuse méthode JavaScript point d&#8217;entrée dans le monde HTML</p>

<div class="wp_codebox"><table><tr id="p214837"><td class="line_numbers"><pre>1
2
3
4
5
6
</pre></td><td class="code" id="p2148code37"><pre class="javascript" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>script<span style="color: #339933;">&gt;</span>
<span style="color: #003366; font-weight: bold;">function</span> setSelectedItem<span style="color: #009900;">&#40;</span>obj<span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>	
	<span style="color: #006600; font-style: italic;">//do what you wanna do</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #339933;">&lt;/</span>script<span style="color: #339933;">&gt;</span></pre></td></tr></table></div>

<p>Au niveau du code Flex</p>

<div class="wp_codebox"><table><tr id="p214838"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
</pre></td><td class="code" id="p2148code38"><pre class="javascript" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>mx <span style="color: #339933;">:</span>Application....
<span style="color: #339933;">&lt;</span>mx<span style="color: #339933;">:</span>Script<span style="color: #339933;">&gt;</span>	
	<span style="color: #339933;">&lt;</span> <span style="color: #339933;">!</span><span style="color: #009900;">&#91;</span>CDATA<span style="color: #009900;">&#91;</span>
		<span style="color: #003366; font-weight: bold;">import</span> mx.<span style="color: #660066;">controls</span>.<span style="color: #000066;">Alert</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #003366; font-weight: bold;">private</span> <span style="color: #003366; font-weight: bold;">function</span> clickHandle<span style="color: #009900;">&#40;</span>e<span style="color: #339933;">:</span>Event<span style="color: #009900;">&#41;</span> <span style="color: #339933;">:</span> <span style="color: #000066; font-weight: bold;">void</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #006600; font-style: italic;">//appel de méthode JS</span>
			<span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>ExternalInterface.<span style="color: #660066;">available</span><span style="color: #009900;">&#41;</span>
			<span style="color: #009900;">&#123;</span>
				ExternalInterface.<span style="color: #660066;">call</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;setSelectedItem&quot;</span><span style="color: #339933;">,</span> selItem.<span style="color: #660066;">text</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span>
		<span style="color: #009900;">&#125;</span>	
&nbsp;
		<span style="color: #339933;">&lt;</span>mx<span style="color: #339933;">:</span>VBox<span style="color: #339933;">&gt;</span>
			<span style="color: #339933;">&lt;</span>mx <span style="color: #339933;">:</span>TextInput id<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;selItem&quot;</span><span style="color: #339933;">/&gt;</span>
			<span style="color: #339933;">&lt;</span>mx <span style="color: #339933;">:</span>Button click<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;clickHandle(event)&quot;</span><span style="color: #339933;">/&gt;</span>
		<span style="color: #339933;">&lt;/</span>mx<span style="color: #339933;">&gt;</span></pre></td></tr></table></div>

<p>La méthode <code>setSelectedItem</code> définie dans le JavaScript sera exécutée sur l&#8217;évènement &laquo;&nbsp;click&nbsp;&raquo; depuis l&#8217;application Flex&#8230;</p>
<p>Passer du monde JavaScript au monde Flex n&#8217;est guère plus complexe. Au niveau du code HTML tout d&#8217;abord où l&#8217;on note : </p>
<li>
<ul>le passage de paramètres à la méthode Flex</ul>
</li>
<li>
<ul>une subtilité liée au navigateur : les applications Flash ne sont pas référencées de la même manière suivant que l&#8217;on utilise Internet Explorer ou des navigateurs de type Mozilla</ul>
</li>

<div class="wp_codebox"><table><tr id="p214839"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
</pre></td><td class="code" id="p2148code39"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">function</span> getMyApp<span style="color: #009900;">&#40;</span>appName<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>navigator.<span style="color: #660066;">appName</span>.<span style="color: #660066;">indexOf</span> <span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;Microsoft&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">!=-</span><span style="color: #CC0000;">1</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #000066; font-weight: bold;">return</span> window<span style="color: #009900;">&#91;</span>appName<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span> <span style="color: #000066; font-weight: bold;">else</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #000066; font-weight: bold;">return</span> document<span style="color: #009900;">&#91;</span>appName<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #003366; font-weight: bold;">function</span> callFlexMethod<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #003366; font-weight: bold;">var</span> param <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;blabla;
	var param2 = 12;
        getMyApp(&quot;</span>myApp<span style="color: #3366CC;">&quot;).myFlexFunction(param, param2);
    }
&nbsp;
 &lt;div id=&quot;</span>fromJS<span style="color: #3366CC;">&quot;&gt;
 	&lt;button onclick=&quot;</span>callFlexMethod<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><span style="color: #3366CC;">&quot;&gt;click !!&lt;/button&gt; 
 &lt;/div&gt;</span></pre></td></tr></table></div>

<p>Au niveau du code Flex enfin, on note l&#8217;utilisation de la méthode <code>addCallback()</code>. Cette méthode permet d&#8217;enregistrer les méthodes exposées par l&#8217;application Flex et donc accessible depuis le JS de la page HTML.</p>

<div class="wp_codebox"><table><tr id="p214840"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
</pre></td><td class="code" id="p2148code40"><pre class="javascript" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>mx <span style="color: #339933;">:</span>Application ... <span style="color: #660066;">creationComplete</span><span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;initApp()&quot;</span><span style="color: #339933;">&gt;</span>
	<span style="color: #339933;">&lt;/</span>mx<span style="color: #339933;">&gt;&lt;</span>mx <span style="color: #339933;">:</span>Script<span style="color: #339933;">&gt;</span>	
	<span style="color: #003366; font-weight: bold;">public</span> <span style="color: #003366; font-weight: bold;">function</span> initApp<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">:</span><span style="color: #000066; font-weight: bold;">void</span> <span style="color: #009900;">&#123;</span>
        	ExternalInterface.<span style="color: #660066;">addCallback</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;myFlexFunction&quot;</span><span style="color: #339933;">,</span>myFunc<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
     <span style="color: #009900;">&#125;</span>  
&nbsp;
     <span style="color: #003366; font-weight: bold;">public</span> <span style="color: #003366; font-weight: bold;">function</span> myFunc<span style="color: #009900;">&#40;</span>s<span style="color: #339933;">:</span>String<span style="color: #339933;">,</span> i<span style="color: #339933;">:</span>uint<span style="color: #009900;">&#41;</span><span style="color: #339933;">:</span><span style="color: #000066; font-weight: bold;">void</span>
     <span style="color: #009900;">&#123;</span>
     	<span style="color: #000066; font-weight: bold;">try</span>
     	<span style="color: #009900;">&#123;</span>
		<span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>i<span style="color: #339933;">&gt;</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#41;</span>
	     		selItem.<span style="color: #660066;">text</span> <span style="color: #339933;">=</span> s<span style="color: #339933;">;</span>
...
     	<span style="color: #009900;">&#125;</span> <span style="color: #000066; font-weight: bold;">catch</span> <span style="color: #009900;">&#40;</span>e<span style="color: #339933;">:</span>Error<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #006600; font-style: italic;">//gestion des erreurs</span>
     	<span style="color: #009900;">&#125;</span>
     <span style="color: #009900;">&#125;</span>
		<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">&gt;</span>
	<span style="color: #339933;">&lt;/</span>mx<span style="color: #339933;">&gt;</span>
			<span style="color: #339933;">&lt;</span>mx <span style="color: #339933;">:</span>VBox<span style="color: #339933;">&gt;</span>
				<span style="color: #339933;">&lt;</span>mx <span style="color: #339933;">:</span>TextInput id<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;selItem&quot;</span><span style="color: #339933;">/&gt;</span>
...
			<span style="color: #339933;">&lt;/</span>mx<span style="color: #339933;">&gt;</span></pre></td></tr></table></div>

<h2> Et le <a href="http://livedocs.adobe.com/flex/3/html/help.html?content=ajaxbridge_1.html">Flex Ajax Bridge</a>?</h2>
<p>Un des <a href="http://livedocs.adobe.com/flex/3/html/help.html?content=ajaxbridge_1.html">inconvénients</a> que l&#8217;on peut voir à <code>l'ExternalInterface </code>reste le  caractère manuel de la tâche. Manuelle sur au moins deux points : </p>
<li>
<ul>la définition des méthodes qu&#8217;il est possible d&#8217;appeler</ul>
</li>
<li>
<ul>le &laquo;&nbsp;boiler plate code&nbsp;&raquo; qu&#8217;il est nécessaire de mettre en oeuvre pour établir le dialogue</ul>
</li>
<p>Alors Adobe propose un <a href="http://livedocs.adobe.com/flex/3/html/help.html?content=ajaxbridge_1.html">bridge </a> (concrètement un fichier js qu&#8217;il est possible de générer depuis Flex Builder) permettant de plus facilement faire interagir les deux mondes. Imaginez le composant graphique suivant dans votre application Flex:</p>

<div class="wp_codebox"><table><tr id="p214841"><td class="line_numbers"><pre>1
2
3
4
</pre></td><td class="code" id="p2148code41"><pre class="javascript" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>fab <span style="color: #339933;">:</span>FABridge xmlns<span style="color: #339933;">:</span>fab<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;bridge.*&quot;</span> <span style="color: #339933;">/&gt;</span>
...
<span style="color: #339933;">&lt;</span>mx <span style="color: #339933;">:</span>TextInput id<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;selItem&quot;</span><span style="color: #339933;">/&gt;</span>
...</pre></td></tr></table></div>

<p>En fait, ce bridge permet de manipuler des objets ActionScript depuis le monde JavaScript, sans aucun ajout de code. Bref, d&#8217;utiliser l&#8217;ensemble des APIs fournies par ActionScript depuis JavaScript.</p>

<div class="wp_codebox"><table><tr id="p214842"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
</pre></td><td class="code" id="p2148code42"><pre class="javascript" style="font-family:monospace;">...
<span style="color: #339933;">&lt;</span>script<span style="color: #339933;">&gt;</span>
<span style="color: #003366; font-weight: bold;">function</span> doIt<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
 	<span style="color: #003366; font-weight: bold;">var</span> flexApp <span style="color: #339933;">=</span> FABridge.<span style="color: #660066;">flash</span>.<span style="color: #660066;">root</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #003366; font-weight: bold;">var</span> flexObj <span style="color: #339933;">=</span> flexApp.<span style="color: #660066;">getSelItem</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	...
	<span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span>value.<span style="color: #660066;">getTextWidth</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> <span style="color: #3366CC;">'  '</span> <span style="color: #339933;">+</span> value.<span style="color: #660066;">getText</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #339933;">&lt;/</span>script<span style="color: #339933;">&gt;</span>
...</pre></td></tr></table></div>

<p><em><strong>Remarque </strong>: les méthodes <code>getTextWidth()</code> et <code>getText()</code> sont &laquo;&nbsp;celles&nbsp;&raquo; définies sur l&#8217;API ActionScript de TextInput</em></p>
<p>Faire communiquer le monde HTML/Javascript et le monde Flex est donc plutôt simple. L&#8217;ExternalInterface propose certes une solution assez manuelle mais présente peut-être l&#8217;avantage de bien définir les &laquo;&nbsp;ponts&nbsp;&raquo; entre les deux mondes. A contrario, le &laquo;&nbsp;Flex Ajax Bridge&nbsp;&raquo; permet à JavaScript d&#8217;accéder à l&#8217;ensemble des <a href="http://www.bobbyvandersluis.com/swfobject/flex3/flex_updated/FABridge/index.html">APIs ActionScript</a>. Un bridge trés ouvert qui enrichi drastiquement JavaScript mais qui couple fortement les deux mondes, les deux IHMs.</p>


<p>Suggestion d'articles :</p><ol><li><a href='http://blog.octo.com/referencer-les-applications-ria-flex-et-silverlight/' rel='bookmark' title='Permanent Link: Référencer les applications RIA Flex et Silverlight'>Référencer les applications RIA Flex et Silverlight</a></li>
<li><a href='http://blog.octo.com/openesbsun-java-caps-6-quel-avenir/' rel='bookmark' title='Permanent Link: OpenESB/Sun Java CAPS  6, quel avenir?'>OpenESB/Sun Java CAPS  6, quel avenir?</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://blog.octo.com/et-si-lavenir-des-ihms-etait-a-la-mixite/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Envie de by-passer la Same Origin Policy ?</title>
		<link>http://blog.octo.com/envie-de-by-passer-la-same-origin-policy/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=envie-de-by-passer-la-same-origin-policy</link>
		<comments>http://blog.octo.com/envie-de-by-passer-la-same-origin-policy/#comments</comments>
		<pubDate>Thu, 30 Oct 2008 23:17:41 +0000</pubDate>
		<dc:creator>Olivier Mallassi</dc:creator>
				<category><![CDATA[Architecture et technologies]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[RIA]]></category>
		<category><![CDATA[Same Origin Policy]]></category>

		<guid isPermaLink="false">http://new-blog.octo.com/2008/10/31/envie-de-by-passer-la-same-origin-policy/</guid>
		<description><![CDATA[L'agrégation d'IHM ! ou nouveau buzz, les mashups ! Bref, ce besoin d'agréger dans le navigateur des informations provenant de sites multiples peut se trouver freiné par une règle de sécurité séculaire (enfin depuis Netscape 2.0...) : la Same Origine Policy.]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fblog.octo.com%2Fenvie-de-by-passer-la-same-origin-policy%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fblog.octo.com%2Fenvie-de-by-passer-la-same-origin-policy%2F&amp;style=normal&amp;service=bit.ly" height="61" width="50" /><br />
			</a>
		</div>
<p>L&#8217;agrégation d&#8217;IHM ! ou nouveau buzz, les mashups ! Bref, ce besoin d&#8217;agréger dans le navigateur des informations provenant de sites multiples peut se trouver freiné par une règle de sécurité séculaire (enfin depuis Netscape 2.0&#8230;) : la Same Origine Policy.<br />
<span id="more-146"></span></p>
<p>La Same Origin Policy a pris naissance avec Netscape 2.0 et vise à empêcher l&#8217;accès &#8211; en lecture ou en écriture &#8211; à des serveurs dont le nom de domaine est différent de celui dont provient le document, la page en cours&#8230;Derrière cette limitation, se cache l&#8217;idée de confiance et la volonté d&#8217;empêcher un document d&#8217;un domaine A de voir son intégrité modifiée par un document d&#8217;un domaine B.</p>
<p>La Same Origin Policy induit donc la notion de domaine, et donc que deux domaines seront identiques à la condition qu&#8217;ils aient le même protocole (http, https&#8230;), le même  &nbsp;&raquo; host &nbsp;&raquo; et le même port. </p>
<p>Il y a cependant quelques passe-droits à cette &nbsp;&raquo; policy &nbsp;&raquo; que sont les iframe et l&#8217;accès à des ressources de type JavaScript. Autrement dit, il est tout à fait possible depuis une ressource d&#8217;un domaine <a href="http://www.myhost.com/">www.myhost.com:80</a> de référencer une ressource JavaScript du domaine <a href="http://www.myhost.com:7777/" class="broken_link">www.myhost.com:7777</a>. Comme illustrer sur le schéma suivant, la ressource file.js peut être référencée et utilisée. En revanche, il est impossible de faire d&#8217;accéder à cette ressource depuis un objet de type XmlHttpRequest.</p>
<p align="center"><img width="372" height="287" src="/wp-content/uploads/images/01.png" alt="" /></p>
<p align="left">C&#8217;est même sur ce principe que reposent certaines optimisations de distribution des ressources. Un nom de domaine pour les images, un nom de domaines pour les css&#8230;</p>
<h4>&laquo;&nbsp;Same Origin Policy&nbsp;&raquo; et Flex</h4>
<p align="left">Flex propose sa solution pour contourner la Same Origin Policy : un fichier domain.xml qui permet de définir quels sont les domaines autorisés à requêter le domaine ayant le fichier en question&#8230;Compliqué ? pas tant que ça. </p>
<p align="left">Imaginons deux domaines : <a href="http://www.company.com/">www.company.com</a> qui servirait le fichier swf et services.company.com qui proposerait une API quelconque, là n&#8217;est pas le débat.<br />Par défaut, les requêtes émises depuis le client (donc la ressource swf associée au domaine <a href="http://www.company.com/">www.company.com</a>) ne sont pas autorisées à requêter le domaine services.company.com. </p>
<p align="left">Considérons maintenant l&#8217;exemple de fichier domain.xml suivant :</p>

<div class="wp_codebox"><table><tr id="p14643"><td class="line_numbers"><pre>1
2
3
4
5
6
</pre></td><td class="code" id="p146code43"><pre class="xml" style="font-family:monospace;">&nbsp;
<span style="color: #009900;">&lt; ?xml <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span><span style="color: #000000; font-weight: bold;">?&gt;</span></span>
   <span style="color: #009900;">&lt; !DOCTYPE cross-domain-policy SYSTEM <span style="color: #ff0000;">&quot;http://www.macromedia.com/xml/dtds/cross-domain-policy.dtd&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
   <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;cross</span> -domain-policy<span style="color: #000000; font-weight: bold;">&gt;</span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;allow</span> -access-from <span style="color: #000066;">domain</span>=<span style="color: #ff0000;">&quot;*.company.com&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
   <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/cross<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></td></tr></table></div>

<p align="left">Ce fichier, une fois déposé sur le serveur au domaine services.company.com autorise les requêtes de toutes ressources provenant des domaines de type *.company.com et a fortiori <a href="http://www.company.com/">www.company.com</a>.</p>
<p align="left">Autrement dit, ce fameux fichier doit être mis à disposition sur les serveurs pouvant être accédés par d&#8217;autres domaines et non pas l&#8217;inverse.</p>
<h4>
<p align="left">Same Origin Policy et JavaScript</p>
</h4>
<p>En technologie JavaScript, rien n&#8217;est nativement prévu et il est de prime abord impossible de faire une requête http vers un domaine, un host différent du document en cours. Le lecteur averti (je l&#8217;adore celle là <img src='http://blog.octo.com/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' />  ) aura remarqué l&#8217;utilisation de &nbsp;&raquo; prime abord &laquo;&nbsp;. </p>
<p>Néanmoins et comme présenté plus haut, la &nbsp;&raquo; Same Origin Policy &nbsp;&raquo; n&#8217;empêche absolument pas de référencer des urls de domaines différents dans une balise <script type="text/javascript">.</script></p>
<p>script. Et c&#8217;est là que ca devient génial !Prenez le code suivant (attention aux espaces superflus) :</p>

<div class="wp_codebox"><table><tr id="p14644"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
</pre></td><td class="code" id="p146code44"><pre class="javascript" style="font-family:monospace;">&nbsp;
<span style="color: #339933;">&lt;</span>html<span style="color: #339933;">&gt;</span>
    <span style="color: #339933;">&lt;</span>head<span style="color: #339933;">&gt;</span>
        <span style="color: #339933;">&lt;</span>script src<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;lib/prototype/prototype.js&quot;</span> type<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;text/javascript&quot;</span><span style="color: #339933;">&gt;</span>
        <span style="color: #339933;">&lt;/</span>script<span style="color: #339933;">&gt;</span>
    <span style="color: #339933;">&lt;/</span>head<span style="color: #339933;">&gt;</span>
    <span style="color: #339933;">&lt;</span>body<span style="color: #339933;">&gt;</span>
        <span style="color: #339933;">&lt;</span>h3<span style="color: #339933;">&gt;</span>Same Origin Policy Sample<span style="color: #339933;">&lt;/</span>h3<span style="color: #339933;">&gt;</span>
        <span style="color: #339933;">&lt;</span>script<span style="color: #339933;">&gt;</span> <span style="color: #006600; font-style: italic;">//balise script #1</span>
            <span style="color: #003366; font-weight: bold;">function</span> processIt<span style="color: #009900;">&#40;</span>data<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
                <span style="color: #000066; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">var</span> i <span style="color: #339933;">=</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">;</span> i <span style="color: #339933;">&lt;</span> data.<span style="color: #660066;">responseData</span>.<span style="color: #660066;">results</span>.<span style="color: #660066;">length</span><span style="color: #339933;">;</span> i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                    document.<span style="color: #000066; font-weight: bold;">write</span><span style="color: #009900;">&#40;</span>data.<span style="color: #660066;">responseData</span>.<span style="color: #660066;">results</span><span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span>.<span style="color: #660066;">title</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                    document.<span style="color: #000066; font-weight: bold;">write</span><span style="color: #009900;">&#40;</span>data.<span style="color: #660066;">responseData</span>.<span style="color: #660066;">results</span><span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span>.<span style="color: #660066;">visibleUrl</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                    document.<span style="color: #000066; font-weight: bold;">write</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;&lt;br/&gt;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                <span style="color: #009900;">&#125;</span>
            <span style="color: #009900;">&#125;</span>
        <span style="color: #339933;">&lt;/</span>script<span style="color: #339933;">&gt;</span>
        <span style="color: #339933;">&lt;</span>script src<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;http://ajax.googleapis.com/ajax/services/search/web?v=1.0&amp;q=Octo%20Technology&amp;callback=processIt&quot;</span><span style="color: #339933;">&gt;</span> <span style="color: #006600; font-style: italic;">//balise script #2</span>
        <span style="color: #339933;">&lt;/</span>script<span style="color: #339933;">&gt;</span>
    <span style="color: #339933;">&lt;/</span>body<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;/</span>html<span style="color: #339933;">&gt;</span></pre></td></tr></table></div>

<p>La première balise script parse le résultat d&#8217;un objet &nbsp;&raquo; data &nbsp;&raquo; qui est un tableau. La seconde balise script référence une url google qui dans un navigateur retourne :</p>

<div class="wp_codebox"><table><tr id="p14645"><td class="line_numbers"><pre>1
</pre></td><td class="code" id="p146code45"><pre class="javascript" style="font-family:monospace;">processIt<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span><span style="color: #3366CC;">&quot;responseData&quot;</span><span style="color: #339933;">:</span>   <span style="color: #009900;">&#123;</span><span style="color: #3366CC;">&quot;results&quot;</span><span style="color: #339933;">:</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#123;</span><span style="color: #3366CC;">&quot;GsearchResultClass&quot;</span><span style="color: #339933;">:</span><span style="color: #3366CC;">&quot;GwebSearch&quot;</span><span style="color: #339933;">,</span><span style="color: #3366CC;">&quot;unescapedUrl&quot;</span><span style="color: #339933;">:</span><span style="color: #3366CC;">&quot;http://www.octo.com/&quot;</span><span style="color: #339933;">,</span><span style="color: #3366CC;">&quot;url&quot;</span><span style="color: #339933;">:</span><span style="color: #3366CC;">&quot;http://www.octo.com/&quot;</span><span style="color: #339933;">,</span><span style="color: #3366CC;">&quot;visibleUrl&quot;</span><span style="color: #339933;">:</span><span style="color: #3366CC;">&quot;www.octo.com&quot;</span><span style="color: #339933;">,</span><span style="color: #3366CC;">&quot;cacheUrl&quot;</span><span style="color: #339933;">:</span><span style="color: #3366CC;">&quot;http://www.google.com/search?  q<span style="color: #000099; font-weight: bold;">\u</span>003dcache:8jNCWXNMhgEJ:www.octo.com&quot;</span><span style="color: #339933;">,</span><span style="color: #3366CC;">&quot;title&quot;</span><span style="color: #339933;">:</span><span style="color: #3366CC;">&quot;<span style="color: #000099; font-weight: bold;">\u</span>003cb<span style="color: #000099; font-weight: bold;">\u</span>003eOCTO Technology<span style="color: #000099; font-weight: bold;">\u</span>003c/b<span style="color: #000099; font-weight: bold;">\u</span>003e - Cabinet  d<span style="color: #000099; font-weight: bold;">\u</span>0026#39;architectes en Systèmes d<span style="color: #000099; font-weight: bold;">\u</span>0026#39;Information&quot;</span><span style="color: #339933;">,</span><span style="color: #3366CC;">&quot;………</span></pre></td></tr></table></div>

<p>Le truc intéressant avec les données retournées, c&#8217;est leur format : une méthode processIt &#8211; qui prend le nom définit dans le paramètre callback de l&#8217;url &#8211; qui prend en paramètre un tableau complexe au format JSON. </p>
<p>A l&#8217;exécution, le navigateur interprète la seconde balise script et récupère la ressource référencée dans l&#8217;attribut src, ie. le flux proposant une méthode avec en paramètre un tableau de valeurs. Ainsi la seconde balise script devient un simple appel à la méthode processResult, elle-même définie dans le document associé au domain &nbsp;&raquo; 127.0.0.1 &laquo;&nbsp;, avec des paramètres particuliers&#8230;</p>
<p>Au final, la page suivante s&#8217;affiche (vous aurez noté le haut travail de design <img src='http://blog.octo.com/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' />  ) :</p>
<p align="center"><img width="562" height="742" src="/wp-content/uploads/images/02.png" alt="" style="width: 486px; height: 700px;" /></p>
<p align="left">L&#8217;autre point intéressant est les requêtes envoyées par le navigateur. </p>
<p align="center"><img width="615" height="297" src="/wp-content/uploads/images/Sans titre(1).jpg" alt="" /></p>
<p align="left">On note bien que le chargement du document depuis le domain &nbsp;&raquo; 127.0.0.1 &nbsp;&raquo; réalise un GET sur une ressource du domaine ajax.google.com.</p>
<h4>Pour conclure&#8230;</h4>
<p align="left">Contourner la &nbsp;&raquo; same origin policy &nbsp;&raquo; est donc possible de façon assez simple et permet d&#8217;adresser une partie des problématiques de mashup. L&#8217;exemple précédent, bien que simpliste, permet sans problème d&#8217;imaginer de modifier dynamiquement &#8211; ie via JavaScript &#8211; la seconde balise script &#8211; ie. le DOM &#8211; et notamment la valeur de l&#8217;attribut src. Il serait ainsi possible de réagir à d&#8217;autres interactions d&#8217;un utilisateur, ailleurs dans le document&#8230;</p>
<p align="left">Reste néanmoins à savoir si le contournement de cette policy est la meilleure idée que vous ayez eu jusqu&#8217;à présent car comme dans toute zone de confiance, il vous faudra être certain de la qualité des flux JSON échangés&#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.octo.com/envie-de-by-passer-la-same-origin-policy/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
