2 * To change this license header, choose License Headers in Project Properties.
3 * To change this template file, choose Tools | Templates
4 * and open the template in the editor.
6 package net.korabo.app.orientdb;
8 import com.orientechnologies.orient.server.OServer;
9 import com.orientechnologies.orient.server.OServerMain;
11 import java.io.FileOutputStream;
13 import java.util.Properties;
14 import javax.servlet.ServletContextEvent;
15 import javax.servlet.ServletContextListener;
16 import javax.servlet.annotation.WebListener;
17 import net.korabo.lib.KConstant;
18 import net.korabo.lib.StreamUtil;
19 import net.korabo.lib.UriUtil;
20 import net.korabo.lib.file.FileUriUtil;
21 import net.korabo.lib.file.ResourceFilesUtil;
22 import net.korabo.lib.file.SysFilesUtil;
23 import net.korabo.lib.settings.KSettingsUtil;
30 public class AppServletContextListener implements ServletContextListener{
33 public void contextDestroyed(ServletContextEvent sce) {
34 // throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
35 System.out.println("ServletContextListener destroyed");
39 public void contextInitialized(ServletContextEvent sce) {
40 // throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
41 SysFilesUtil.getVarMap().replace(SysFilesUtil.V_CFGBASE, "VAADIN01");
42 String home = SysFilesUtil.findDataUriPath();
43 String orientDB = UriUtil.concatPath(home, "OrientDB");
44 String orientDBcfg = UriUtil.concatPath(orientDB, "config", "orientdb-server-config.xml");
45 String orientDBwww = UriUtil.concatPath(orientDB, "www");
46 Properties props = System.getProperties();
47 props.setProperty("ORIENTDB_HOME", orientDB);
48 props.setProperty("orientdb.www.path", orientDBwww);
51 File cfgFile = FileUriUtil.getFileFor(orientDBcfg);
52 SysFilesUtil.chkAndMake(cfgFile);
53 if (cfgFile.length() == 0){
55 String rp = ResourceFilesUtil.findPathFromClasspath("net.korabo.app.orientdb.smplconfig.xml");
56 StreamUtil.copy(FileUriUtil.getUriFor(rp).toURL().openStream(), new FileOutputStream(cfgFile),true);
58 OServer server = OServerMain.create();
59 server.startup(FileUriUtil.getFileFor(orientDBcfg));
61 } catch (Exception e) {
62 System.out.println(e.getMessage() + e.getStackTrace());
65 System.out.println("ServletContextListener started.");