1 | package com.medias.megapoli.utils; |
---|
2 | |
---|
3 | import com.medias.annuaire.Annuaire; |
---|
4 | import com.medias.mail.MailFactory; |
---|
5 | import com.medias.utils.hibernate.CommunicationBD; |
---|
6 | import com.medias.xml.hierarchie.Hierarchie; |
---|
7 | import org.hibernate.HibernateException; |
---|
8 | |
---|
9 | import javax.servlet.ServletException; |
---|
10 | import javax.servlet.http.HttpServlet; |
---|
11 | import java.io.FileInputStream; |
---|
12 | import java.util.Hashtable; |
---|
13 | import java.util.Properties; |
---|
14 | |
---|
15 | |
---|
16 | /** |
---|
17 | * @author Caroline Combaz |
---|
18 | * Created on 02 fev. 2005 |
---|
19 | */ |
---|
20 | public class MegapoliInitialisation |
---|
21 | extends HttpServlet |
---|
22 | { |
---|
23 | |
---|
24 | /** |
---|
25 | * |
---|
26 | */ |
---|
27 | private static final long serialVersionUID = 1L; |
---|
28 | // Le chemin vers les images des plates-formes |
---|
29 | public static String pathImages; |
---|
30 | |
---|
31 | /** |
---|
32 | * Constructeur par defaut |
---|
33 | */ |
---|
34 | public MegapoliInitialisation() |
---|
35 | { |
---|
36 | super(); |
---|
37 | } |
---|
38 | |
---|
39 | /** |
---|
40 | * Destruction de la servlet |
---|
41 | */ |
---|
42 | public void destroy() |
---|
43 | { |
---|
44 | super.destroy(); // Just puts "destroy" string in log |
---|
45 | } |
---|
46 | |
---|
47 | /** |
---|
48 | * Initialisation de la servlet : |
---|
49 | * <ul> |
---|
50 | * <li>un objet representant l'arborescence de fichiers du site de depot est cree et place au niveau de l'application, |
---|
51 | * <li>l'arborescence de dossiers est egalement creee, |
---|
52 | * <li>la vue representant cette arborescence, et permettant a l'utilisateur de deposer de nouveaux fichiers est generee. |
---|
53 | * </ul> |
---|
54 | * |
---|
55 | * @throws ServletException if an error occure |
---|
56 | */ |
---|
57 | public void init() |
---|
58 | throws ServletException |
---|
59 | { |
---|
60 | System.out.println( "************** INITIALISATION MEGAPOLI **************" ); |
---|
61 | String root = this.getServletContext().getRealPath( "" ); |
---|
62 | String webinf = this.getServletContext().getRealPath( "WEB-INF" ); |
---|
63 | |
---|
64 | //on charge le fichier de proprietes |
---|
65 | Properties prop = new Properties(); |
---|
66 | try |
---|
67 | { |
---|
68 | prop.load( new FileInputStream( webinf + "/megapoli.properties" ) ); |
---|
69 | } |
---|
70 | catch( Exception e ) |
---|
71 | { |
---|
72 | e.printStackTrace(); |
---|
73 | } |
---|
74 | //on initialise l'objet représentant l'arborescence de fichiers du site de dépot et on le place au niveau de l'appli |
---|
75 | String uploadRoot = prop.getProperty( "data.upload.root" ); |
---|
76 | String uploadFile = prop.getProperty( "data.upload.desc" ); |
---|
77 | String accessRoot = prop.getProperty( "data.access.root" ); |
---|
78 | this.getServletContext().setAttribute( "DataDescPathName", uploadFile ); |
---|
79 | pathImages = prop.getProperty( "data.img" ); |
---|
80 | Hashtable<String, String> uploadStylesheets = new Hashtable<String, String>(); |
---|
81 | uploadStylesheets.put( Hierarchie.TREE, webinf + prop.getProperty( "data.upload.tree.stylesheet" ) ); |
---|
82 | uploadStylesheets.put( Hierarchie.FILES, webinf + prop.getProperty( "data.upload.files.stylesheet" ) ); |
---|
83 | Hashtable<String, String> uploadViews = new Hashtable<String, String>(); |
---|
84 | uploadViews.put( Hierarchie.TREE, root + prop.getProperty( "data.upload.tree.view" ) ); |
---|
85 | uploadViews.put( Hierarchie.FILES, root + prop.getProperty( "data.upload.files.view" ) ); |
---|
86 | Hierarchie uploadTree = new Hierarchie( uploadFile, uploadRoot, uploadStylesheets, uploadViews ); |
---|
87 | uploadTree.setDataRoot2( accessRoot ); |
---|
88 | try |
---|
89 | { |
---|
90 | uploadTree.createTree(); |
---|
91 | uploadTree.createTreeView(); |
---|
92 | } |
---|
93 | catch( Exception e ) |
---|
94 | { |
---|
95 | e.printStackTrace(); |
---|
96 | } |
---|
97 | this.getServletContext().setAttribute( "APP_UPLOADTREE", uploadTree ); |
---|
98 | |
---|
99 | //on fait de même avec l'arborescence de fichiers du site de consultation |
---|
100 | this.getServletContext().setAttribute( "uploadDir", uploadRoot ); |
---|
101 | this.getServletContext().setAttribute( "accessDir", accessRoot ); |
---|
102 | // String accessFile = prop.getProperty ("data.access.desc"); |
---|
103 | // Hashtable<String, String> accessStylesheets = new Hashtable<String, String> (); |
---|
104 | // accessStylesheets.put (Hierarchie.TREE, webinf + prop.getProperty ("data.access.tree.stylesheet")); |
---|
105 | // accessStylesheets.put (Hierarchie.FILES, webinf + prop.getProperty ("data.access.files.stylesheet")); |
---|
106 | // Hashtable<String, String> accessViews = new Hashtable<String, String> (); |
---|
107 | // accessViews.put (Hierarchie.TREE,root + prop.getProperty ("data.access.tree.view")); |
---|
108 | // accessViews.put (Hierarchie.FILES,root + prop.getProperty ("data.access.files.view")); |
---|
109 | |
---|
110 | // Hierarchie accessTree = new Hierarchie (accessFile, accessRoot, accessStylesheets, accessViews); |
---|
111 | // try { |
---|
112 | // accessTree.createTreeView (); |
---|
113 | // } |
---|
114 | // catch (Exception e) { |
---|
115 | // e.printStackTrace (); |
---|
116 | // } |
---|
117 | // this.getServletContext ().setAttribute ("APP_ACCESSTREE", accessTree); |
---|
118 | |
---|
119 | //on charge l'annuaire et on le met aussi au niveau de l'appli... |
---|
120 | Annuaire annu = new Annuaire( prop.getProperty( "annuaire" ) ); |
---|
121 | this.getServletContext().setAttribute( "APP_ANNUAIRE", annu ); |
---|
122 | |
---|
123 | //et idem pour l'utilitaire d'envoi des mails |
---|
124 | MailFactory mail = new MailFactory( prop.getProperty( "mail.host" ) ); |
---|
125 | this.getServletContext().setAttribute( "APP_MAILFACTORY", mail ); |
---|
126 | String webmaster = prop.getProperty( "mail.webmaster" ); |
---|
127 | this.getServletContext().setAttribute( "APP_WEBMASTER", webmaster ); |
---|
128 | String urlCGI = prop.getProperty( "url.extractcgi" ); |
---|
129 | this.getServletContext().setAttribute( "APP_CGI", urlCGI ); |
---|
130 | final String mailPI = prop.getProperty( "mail.PI" ); |
---|
131 | this.getServletContext().setAttribute( "APP_PI", mailPI ); |
---|
132 | |
---|
133 | // Initialisation d'Hibernate |
---|
134 | try |
---|
135 | { |
---|
136 | CommunicationBD.open(); |
---|
137 | CommunicationBD.getList( "select count(*) from Jeu" ); |
---|
138 | // System.out.println("nombre de jeux insérés="+nbjeux.get(0)); |
---|
139 | CommunicationBD.close(); |
---|
140 | } |
---|
141 | catch( HibernateException e ) |
---|
142 | { |
---|
143 | e.printStackTrace(); |
---|
144 | } |
---|
145 | } |
---|
146 | } |
---|