1 / 15

JEE Approfondi

Maverick- XStream. JEE Approfondi. 1) Présentation des Frameworks. Maverick Framework MVC Configuration simple par un fichier XML Fournit des transformations (XSLT, FOP) XStream Sérialiser/ Désérialiser des objets JAVA dans des fichiers XML

calum
Download Presentation

JEE Approfondi

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Maverick- XStream JEE Approfondi BOUSQUET Alexis - GUILLEMIN Vincent - PETIT Cédric

  2. 1) Présentation des Frameworks • Maverick • Framework MVC • Configuration simple par un fichier XML • Fournit des transformations (XSLT, FOP) • XStream • Sérialiser/Désérialiser des objets JAVA dans des fichiers XML • Pas de modification du code des objets à sérialiser BOUSQUET Alexis - GUILLEMIN Vincent - PETIT Cédric

  3. 2) Répartition du travail • Installation des 2 Frameworks • Commune • Développement de l’application • Commune • Création du Powerpoint • Commune BOUSQUET Alexis - GUILLEMIN Vincent - PETIT Cédric

  4. 3) Maverick Installation du framework Maverick Télécharger le fichier .jar à l’aide du lien ci-dessous: http://freefr.dl.sourceforge.net/sourceforge/mav/maverick.jar Créez un projet ‘Dynamic Web Project’ sous Eclipse avec comme paramètres: (‘Apache Tomcat v6.0’, ‘Dynamic Web Module 2.5’) Faites un clique droit sur le projet, allez dans Buildpath puis configure Buildpath… Cliquez ensuite sur add Externals JARs puis allez chercher le fichier maverick.jar que vous avez téléchargé précédemment. Copiez le maverick.jar, téléchargé précédemment, dans /WEB-INF/lib . Il faut ensuite ajouter du code XML dans le fichier web.xml et crée un fichier maverick.xml pour configurer le Framework et placez le dans /WEB-INF/lib BOUSQUET Alexis - GUILLEMIN Vincent - PETIT Cédric

  5. 3) Maverick • Modification du fichier web.xml Il faut ajouter les paramètres pour la configuration du servlet <servlet> <display-name>Maverick Dispatcher</display-name> <servlet-name>dispatcher</servlet-name> <servlet-class>org.infohazard.maverick.Dispatcher</servlet-class> <init-param> <param-name>reloadCommand</param-name> <param-value>reload</param-value> </init-param> <load-on-startup>2</load-on-startup> </servlet> <servlet-mapping> <servlet-name>dispatcher</servlet-name> <url-pattern>*.m</url-pattern> </servlet-mapping> BOUSQUET Alexis - GUILLEMIN Vincent - PETIT Cédric

  6. 3) Maverick • Il faut créer le fichier maverick.xml <?xml version="1.0" encoding="UTF-8"?> <maverick version="2.0" default-view-type="document" default-transform-type="document"> <views> <view id="test" path="test.jsp" /> <view id="test2" path="test2.jsp" /> </views> <commands> <command name="commande1"> <controller class="controller.ViewController"/> <viewref="test2"/> <view name="success" path="test2.jsp"> <transformpath="test.jsp" /> </view> </command> </commands> </maverick> BOUSQUET Alexis - GUILLEMIN Vincent - PETIT Cédric

  7. 3) Maverick • Fonctionnement On met cette ligne de code dans la page test.jsp: <c:out value="${wrapped}" escapeXml="false" /> Dans le fichier XML: <view name="success" path="test2.jsp"> <transformpath="test.jsp" /> On se trouve sur la page « test.jsp » et la page « test2.jsp » sera incluse à la place de : <c:out value="${wrapped}" escapeXml="false" /> BOUSQUET Alexis - GUILLEMIN Vincent - PETIT Cédric

  8. 3) Maverick • Problème rencontré Lors de la redirection d’une JSP vers une autre JSP une erreur « Servlet Dispatcher n’est pas disponible » apparait, donc pour la mise en œuvre du projet, nous n’allons pas pouvoir utiliser Maverick, nous utiliserons donc seulement des Servlets et des JSP. BOUSQUET Alexis - GUILLEMIN Vincent - PETIT Cédric

  9. 4) XStream Installation du Framework XstreamTélécharger le fichier .jar à l’aide du lien ci dessous http://repository.codehaus.org/com/thoughtworks/xstream/xstream/1.3.1/xstream-1.3.1.jar Créez un projet ‘Dynamic Web Project’ sous Eclipse avec les paramètres: (‘Apache Tomcat v6.0’, ‘Dynamic Web Module 2.5’) Faites un clique droit sur le projet, allez dans Buildpath puis configure Buildpath… Cliquez ensuite sur addExternalsJARs puis allez chercher le fichier xstream-1.3.1.jar que vous avez téléchargé précédemment. Copiez le xstream-1.3.1.jar, téléchargé précédemment, dans /WEB-INF/lib . BOUSQUET Alexis - GUILLEMIN Vincent - PETIT Cédric

  10. 4) XStream • Relation JAVA – XML • Générer un fichier XML depuis des objets JAVA • Générer des objets JAVA depuis un fichier XML BOUSQUET Alexis - GUILLEMIN Vincent - PETIT Cédric

  11. 4) XStream • Générer un fichier XML depuis des objets JAVA (serialisation) • Instanciation de la classeXstream • XStreamxstream = new XStream(new DomDriver()); • Créer un objet • Contact toto= new Contact("toto", "tutu" , "rue truc" , "h" ); • Pour générer le fichier XML il faut faire appel à Xstream • File fichier = new File("D:/Fichiers XML/toto.xml"); • String xml = xstream.toXML(toto); • Le fichier XML est généré BOUSQUET Alexis - GUILLEMIN Vincent - PETIT Cédric

  12. 4) XStream • Fichier toto.xml généré <objets.Contact> <nom>toto</nom> <prenom>tutu</prenom> <adresse>rue truc</adresse> <sexe>h</sexe> </objets.Contact> BOUSQUET Alexis - GUILLEMIN Vincent - PETIT Cédric

  13. 4) XStream • Générer un objet JAVA depuis un fichier XML • Instanciation de la classeXstream • XStreamxstream = new XStream(new DomDriver()); • Indiquer l’emplacement du fichier XML • FileInputStreamfis = new FileInputStream(new File(" D:/Fichiers XML/toto.xml ")); • On fait appel à Xstream • Contact toto= (Contact) xstream.fromXML(fis); • L’objet est généré BOUSQUET Alexis - GUILLEMIN Vincent - PETIT Cédric

  14. 4) Xstream: Avantages • Facilité d'utilisation • Pas de modification de code des objets à sérialiser. • La rapidité d'exécution et une faible utilisation de la mémoire. BOUSQUET Alexis - GUILLEMIN Vincent - PETIT Cédric

  15. 4) Xstream: Attention • Désérialisation: • Indiquer le bon chemin d’accès du fichier XML • Respecter la structure de l’objet dans le fichier XML BOUSQUET Alexis - GUILLEMIN Vincent - PETIT Cédric

More Related