source: ether_megapoli/trunk/service/implementation/com/medias/megapoli/utils/MegapoliInitialisation.java @ 152

Last change on this file since 152 was 152, checked in by vmipsl, 13 years ago

Import medias files and cleanup

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