/* * File : CmdReportServer.java * Created : 16-jul-2001 20:23 * By : fbusquets * * JClic - Authoring and playing system for educational activities * * Copyright (C) 2000 - 2005 Francesc Busquets & Departament * d'Educacio de la Generalitat de Catalunya * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details (see the LICENSE file). */ import edu.xtec.jclic.report.*; import java.io.*; import java.text.DateFormat; import java.util.Date; import edu.xtec.util.Messages; import edu.xtec.jclic.ReportServerConstants; import edu.xtec.util.Encryption; import edu.xtec.util.db.ConnectionBeanProvider; import edu.xtec.util.db.PooledConnectionBeanProvider; import edu.xtec.util.db.SingleConnectionBeanProvider; /** * * @author Francesc Busquets (fbusquets@xtec.net) * @version 1.0 */ public class CmdReportServer implements ReportServerEventMaker.Listener, ReportServerConstants { static String iDriver, iUrl, iUser, iPwd; static int iHttpPort, iHttpTimeout; static boolean iCreateTables; static String iTablePrefix; DateFormat dateFormat=DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.MEDIUM); public CmdReportServer(String driver, String url, String user, String pwd, int httpPort, int httpTimeOut, boolean createTables, String tablePrefix) throws Exception{ showValidCommands(); //ReportServerJDBCBridge bridge=new ReportServerJDBCBridge(driver, url, user, pwd); //ConnectionBeanProvider cbp=new PooledConnectionBeanProvider(driver, url, user, pwd, 2, 5, "JClicConnectionPool.log", 1.0); //ConnectionBeanProvider cbp=new SingleConnectionBeanProvider(driver, url, user, pwd, true); ConnectionBeanProvider cbp=ConnectionBeanProvider.getConnectionBeanProvider(true, driver, url, user, pwd, true); ReportServerJDBCBridge bridge=new ReportServerJDBCBridge(cbp, createTables, tablePrefix); reportEventPerformed(new ReportServerEvent(ReportServerEvent.SYSTEM, url, null, ReportServerEvent.CONNECT)); HTTPReportServer httpServer=new HTTPReportServer(new Messages(ReportServer.MSG_BUNDLE)); httpServer.addListener(this); //httpServer.startServer(bridge, httpPort, timeOut); httpServer.startServer(httpPort, httpTimeOut); BufferedReader in=new BufferedReader(new InputStreamReader(System.in)); boolean loop=true; String s=null; while(loop){ try{ s=in.readLine(); Thread.currentThread().sleep(1000); } catch(Exception ex){ loop=false; } if(s!=null){ if(s.equalsIgnoreCase("stop")){ httpServer.stopServer(); } else if(s.equalsIgnoreCase("start")) { httpServer.startServer(httpPort, httpTimeOut); } else if(s.equalsIgnoreCase("exit")){ if(httpServer.serverRunning()) httpServer.stopServer(); loop=false; } else{ showValidCommands(); } } } bridge.end(); bridge=null; reportEventPerformed(new ReportServerEvent(ReportServerEvent.SYSTEM, url, null, ReportServerEvent.DISCONNECT)); } public static void main(String[] args){ String propFile=CFG_FILE; java.util.Properties prop; int i=0; if(args.length>0){ if(args[1].equals("-help")){ displayHelp(); return; } if(!args[0].startsWith("-")){ propFile=args[0]; i++; } } prop=new java.util.Properties(); try{ prop.load(ReportServerConstants.class.getResourceAsStream(CFG_FILE)); if(!CFG_FILE.equals(propFile)){ prop.load(CmdReportServer.class.getResourceAsStream(propFile)); String pwd=prop.getProperty(ConnectionBeanProvider.DB_PASSWORD); if(pwd!=null && pwd.length()>0) prop.setProperty(ConnectionBeanProvider.DB_PASSWORD, Encryption.Decrypt(pwd)); } } catch(Exception ex){ System.err.println("ERROR: Invalid properties file name\n"+ex); displayHelp(); return; } iDriver=prop.getProperty(ConnectionBeanProvider.DB_DRIVER, edu.xtec.jclic.report.BasicJDBCBridge.DEFAULT_ODBC_BRIDGE); iUrl=prop.getProperty(ConnectionBeanProvider.DB_SERVER, edu.xtec.jclic.report.BasicJDBCBridge.DEFAULT_DB); iUser=prop.getProperty(ConnectionBeanProvider.DB_LOGIN, null); iPwd=prop.getProperty(ConnectionBeanProvider.DB_PASSWORD, null); iHttpPort=Integer.parseInt(prop.getProperty(HTTP_PORT, Integer.toString(HTTPReportServer.DEFAULT_PORT))); iHttpTimeout=Integer.parseInt(prop.getProperty(HTTP_TIMEOUT, Integer.toString(HTTPReportServer.DEFAULT_TIMEOUT))); iTablePrefix=prop.getProperty(BasicJDBCBridge.TABLE_PREFIX_KEY, null); iCreateTables="true".equalsIgnoreCase((prop.getProperty(BasicJDBCBridge.CREATE_TABLES_KEY, "true"))); for(; i