dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #07340
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 2079: DHIS2-live Work in progress - added xml config with multiple database support. GUI + translation ...
------------------------------------------------------------
revno: 2079
committer: Bob Jolliffe bobjolliffe@xxxxxxxxx
branch nick: trunk
timestamp: Tue 2010-09-07 22:23:11 +0100
message:
DHIS2-live Work in progress - added xml config with multiple database support. GUI + translation to hibernate properties still required
removed:
dhis-live/src/main/java/org/hisp/dhis/SimpleConfigReader.java
added:
dhis-live/src/main/resources/Config.xsd
dhis-live/src/main/resources/defaultConfig.xml
modified:
dhis-live/pom.xml
dhis-live/src/main/java/org/hisp/dhis/TrayApp.java
dhis-live/src/main/java/org/hisp/dhis/WebAppServer.java
dhis-live/src/main/resources/messages_en.properties
--
lp:dhis2
https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk
Your team DHIS 2 developers is subscribed to branch lp:dhis2.
To unsubscribe from this branch go to https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk/+edit-subscription
=== modified file 'dhis-live/pom.xml'
--- dhis-live/pom.xml 2010-06-26 19:26:25 +0000
+++ dhis-live/pom.xml 2010-09-07 21:23:11 +0000
@@ -1,174 +1,200 @@
<project xmlns="http://maven.apache.org/POM/4.0.0"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
-
- <modelVersion>4.0.0</modelVersion>
- <groupId>org.hisp.dhis</groupId>
- <artifactId>dhis-live</artifactId>
- <packaging>jar</packaging>
- <version>1.0-SNAPSHOT</version>
- <name>DHIS Live</name>
-
- <url>http://maven.apache.org</url>
-
- <build>
- <finalName>dhis2-live</finalName>
- <defaultGoal>install</defaultGoal>
- <plugins>
- <!-- Maven Assembly -->
- <plugin>
- <artifactId>maven-assembly-plugin</artifactId>
- <version>2.2-beta-3</version>
- <configuration>
- <descriptorRefs>
- <descriptorRef>jar-with-dependencies</descriptorRef>
- </descriptorRefs>
- <archive>
- <manifest>
- <mainClass>org.hisp.dhis.TrayApp</mainClass>
- </manifest>
- </archive>
- </configuration>
- <executions>
- <execution>
- <id>make-assembly</id> <!-- this is used for inheritance merges -->
- <phase>package</phase> <!-- append to the packaging phase. -->
- <goals>
- <goal>single</goal> <!-- goals == mojos -->
- </goals>
- </execution>
- </executions>
-
- </plugin>
- <!-- Maven Compiler -->
- <plugin>
- <artifactId>maven-compiler-plugin</artifactId>
- <version>2.0.2</version>
- <configuration>
- <debug>true</debug>
- </configuration>
- </plugin>
- <!-- Launch4J -->
- <plugin>
- <groupId>org.bluestemsoftware.open.maven.plugin</groupId>
- <artifactId>launch4j-plugin</artifactId>
- <version>1.5.0.0</version>
- <executions>
- <execution>
- <id>default</id>
- <phase>package</phase>
- <goals>
- <goal>launch4j</goal>
- </goals>
- <configuration>
- <dontWrapJar>true</dontWrapJar>
- <headerType>gui</headerType>
- <outfile>${project.build.directory}/dhis2-live.exe</outfile>
- <jar>dhis2-live.jar</jar>
- <errTitle>dhis2</errTitle>
- <priority>normal</priority>
- <downloadUrl>http://java.com/download</downloadUrl>
- <supportUrl>http://dhis2.org</supportUrl>
- <customProcName>false</customProcName>
- <stayAlive>false</stayAlive>
- <manifest></manifest>
- <icon>${basedir}/util/launch4j/favicon.ico</icon>
- <singleInstance>
- <mutexName>dhis-live.mutex</mutexName>
- <windowTitle></windowTitle>
- </singleInstance>
- <jre>
- <minVersion>1.6.0_14</minVersion>
- </jre>
- <splash>
- <file>${basedir}/util/launch4j/dhis2-splash.bmp</file>
- <waitForWindow>false</waitForWindow>
- <timeout>12</timeout>
- <timeoutErr>false</timeoutErr>
- </splash>
- </configuration>
- </execution>
- <execution>
- <id>emedded</id>
- <phase>package</phase>
- <goals>
- <goal>launch4j</goal>
- </goals>
- <configuration>
- <dontWrapJar>true</dontWrapJar>
- <headerType>gui</headerType>
- <outfile>${project.build.directory}/dhis2-live-embedded.exe</outfile>
- <jar>dhis2-live.jar</jar>
- <errTitle>dhis2</errTitle>
- <priority>normal</priority>
- <downloadUrl>http://java.com/download</downloadUrl>
- <supportUrl>http://dhis2.org</supportUrl>
- <customProcName>false</customProcName>
- <stayAlive>false</stayAlive>
- <manifest></manifest>
- <icon>${basedir}/util/launch4j/favicon.ico</icon>
- <singleInstance>
- <mutexName>dhis-live.mutex</mutexName>
- <windowTitle></windowTitle>
- </singleInstance>
- <jre>
- <path>jre6</path>
- <minVersion>1.6.0_14</minVersion>
- </jre>
- <splash>
- <file>${basedir}/util/launch4j/dhis2-splash.bmp</file>
- <waitForWindow>false</waitForWindow>
- <timeout>12</timeout>
- <timeoutErr>false</timeoutErr>
- </splash>
- </configuration>
- </execution>
-
- </executions>
- </plugin>
- </plugins>
- </build>
-
- <dependencies>
- <dependency>
- <groupId>org.mortbay.jetty</groupId>
- <artifactId>jetty</artifactId>
- <version>6.1.15</version>
- <type>jar</type>
- </dependency>
- <dependency>
- <groupId>org.mortbay.jetty</groupId>
- <artifactId>jsp-2.1</artifactId>
- <version>6.1.14</version>
- </dependency>
- <dependency>
- <groupId>org.mortbay.jetty</groupId>
- <artifactId>jetty-util</artifactId>
- <version>6.1.15</version>
- <type>jar</type>
- </dependency>
- <dependency>
- <groupId>jetty</groupId>
- <artifactId>servlet-api</artifactId>
- <version>2.5-6.0.0</version>
- <type>jar</type>
- </dependency>
- <dependency>
- <groupId>commons-logging</groupId>
- <artifactId>commons-logging</artifactId>
- <version>1.1</version>
- <scope>compile</scope>
- <exclusions>
- <exclusion>
- <groupId>avalon-framework</groupId>
- <artifactId>avalon-framework</artifactId>
- </exclusion>
- <exclusion>
- <groupId>logkit</groupId>
- <artifactId>logkit</artifactId>
- </exclusion>
- </exclusions>
- </dependency>
- </dependencies>
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>org.hisp.dhis</groupId>
+ <artifactId>dhis-live</artifactId>
+ <packaging>jar</packaging>
+ <version>1.0-SNAPSHOT</version>
+ <name>DHIS Live</name>
+
+ <url>http://maven.apache.org</url>
+
+ <build>
+ <finalName>dhis2-live</finalName>
+ <defaultGoal>install</defaultGoal>
+
+ <plugins>
+ <!--jaxb plugin-->
+ <plugin>
+ <groupId>org.jvnet.jaxb2.maven2</groupId>
+ <artifactId>maven-jaxb2-plugin</artifactId>
+ <executions>
+ <execution>
+ <configuration>
+ <generatePackage>org.hisp.dhis.config</generatePackage>
+ </configuration>
+ <goals>
+ <goal>generate</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+
+
+ <!-- Maven Assembly -->
+ <plugin>
+ <artifactId>maven-assembly-plugin</artifactId>
+ <version>2.2-beta-3</version>
+ <configuration>
+ <descriptorRefs>
+ <descriptorRef>jar-with-dependencies</descriptorRef>
+ </descriptorRefs>
+ <archive>
+ <manifest>
+ <mainClass>org.hisp.dhis.TrayApp</mainClass>
+ </manifest>
+ </archive>
+ </configuration>
+ <executions>
+ <execution>
+ <id>make-assembly</id> <!-- this is used for inheritance merges -->
+ <phase>package</phase> <!-- append to the packaging phase. -->
+ <goals>
+ <goal>single</goal> <!-- goals == mojos -->
+ </goals>
+ </execution>
+ </executions>
+
+ </plugin>
+ <!-- Maven Compiler -->
+ <plugin>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <version>2.0.2</version>
+ <configuration>
+ <source>1.6</source>
+ <target>1.6</target>
+ </configuration>
+ </plugin>
+ <!-- Launch4J -->
+ <plugin>
+ <groupId>org.bluestemsoftware.open.maven.plugin</groupId>
+ <artifactId>launch4j-plugin</artifactId>
+ <version>1.5.0.0</version>
+ <executions>
+ <execution>
+ <id>default</id>
+ <phase>package</phase>
+ <goals>
+ <goal>launch4j</goal>
+ </goals>
+ <configuration>
+ <dontWrapJar>true</dontWrapJar>
+ <headerType>gui</headerType>
+ <outfile>${project.build.directory}/dhis2-live.exe</outfile>
+ <jar>dhis2-live.jar</jar>
+ <errTitle>dhis2</errTitle>
+ <priority>normal</priority>
+ <downloadUrl>http://java.com/download</downloadUrl>
+ <supportUrl>http://dhis2.org</supportUrl>
+ <customProcName>false</customProcName>
+ <stayAlive>false</stayAlive>
+ <manifest></manifest>
+ <icon>${basedir}/util/launch4j/favicon.ico</icon>
+ <singleInstance>
+ <mutexName>dhis-live.mutex</mutexName>
+ <windowTitle></windowTitle>
+ </singleInstance>
+ <jre>
+ <minVersion>1.6.0_14</minVersion>
+ </jre>
+ <splash>
+ <file>${basedir}/util/launch4j/dhis2-splash.bmp</file>
+ <waitForWindow>false</waitForWindow>
+ <timeout>12</timeout>
+ <timeoutErr>false</timeoutErr>
+ </splash>
+ </configuration>
+ </execution>
+ <execution>
+ <id>emedded</id>
+ <phase>package</phase>
+ <goals>
+ <goal>launch4j</goal>
+ </goals>
+ <configuration>
+ <dontWrapJar>true</dontWrapJar>
+ <headerType>gui</headerType>
+ <outfile>${project.build.directory}/dhis2-live-embedded.exe</outfile>
+ <jar>dhis2-live.jar</jar>
+ <errTitle>dhis2</errTitle>
+ <priority>normal</priority>
+ <downloadUrl>http://java.com/download</downloadUrl>
+ <supportUrl>http://dhis2.org</supportUrl>
+ <customProcName>false</customProcName>
+ <stayAlive>false</stayAlive>
+ <manifest></manifest>
+ <icon>${basedir}/util/launch4j/favicon.ico</icon>
+ <singleInstance>
+ <mutexName>dhis-live.mutex</mutexName>
+ <windowTitle></windowTitle>
+ </singleInstance>
+ <jre>
+ <path>jre6</path>
+ <minVersion>1.6.0_14</minVersion>
+ </jre>
+ <splash>
+ <file>${basedir}/util/launch4j/dhis2-splash.bmp</file>
+ <waitForWindow>false</waitForWindow>
+ <timeout>12</timeout>
+ <timeoutErr>false</timeoutErr>
+ </splash>
+ </configuration>
+ </execution>
+
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.mortbay.jetty</groupId>
+ <artifactId>jetty</artifactId>
+ <version>6.1.15</version>
+ <type>jar</type>
+ </dependency>
+ <dependency>
+ <groupId>org.mortbay.jetty</groupId>
+ <artifactId>jsp-2.1</artifactId>
+ <version>6.1.14</version>
+ </dependency>
+ <dependency>
+ <groupId>org.mortbay.jetty</groupId>
+ <artifactId>jetty-util</artifactId>
+ <version>6.1.15</version>
+ <type>jar</type>
+ </dependency>
+ <dependency>
+ <groupId>jetty</groupId>
+ <artifactId>servlet-api</artifactId>
+ <version>2.5-6.0.0</version>
+ <type>jar</type>
+ </dependency>
+ <dependency>
+ <groupId>commons-logging</groupId>
+ <artifactId>commons-logging</artifactId>
+ <version>1.1</version>
+ <scope>compile</scope>
+ <exclusions>
+ <exclusion>
+ <groupId>avalon-framework</groupId>
+ <artifactId>avalon-framework</artifactId>
+ </exclusion>
+ <exclusion>
+ <groupId>logkit</groupId>
+ <artifactId>logkit</artifactId>
+ </exclusion>
+ </exclusions>
+ </dependency>
+ <dependency>
+ <groupId>com.sun.xml.bind</groupId>
+ <artifactId>jaxb-impl</artifactId>
+ <version>2.1.13</version>
+ </dependency>
+
+ </dependencies>
</project>
+
=== removed file 'dhis-live/src/main/java/org/hisp/dhis/SimpleConfigReader.java'
--- dhis-live/src/main/java/org/hisp/dhis/SimpleConfigReader.java 2010-09-06 17:50:24 +0000
+++ dhis-live/src/main/java/org/hisp/dhis/SimpleConfigReader.java 1970-01-01 00:00:00 +0000
@@ -1,107 +0,0 @@
-/*
- * Copyright (c) 2004-2010, University of Oslo
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- * * Redistributions of source code must retain the above copyright notice, this
- * list of conditions and the following disclaimer.
- * * Redistributions in binary form must reproduce the above copyright notice,
- * this list of conditions and the following disclaimer in the documentation
- * and/or other materials provided with the distribution.
- * * Neither the name of the HISP project nor the names of its contributors may
- * be used to endorse or promote products derived from this software without
- * specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
- * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-package org.hisp.dhis;
-
-
-import java.util.Properties;
-import java.io.*;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-
-/**
- *
- * @author Jason P. Pickering
- */
-class SimpleConfigReader
-{
-
- private static final String CONFIG_FILE = "conf/dhis2live.cfg";
-
- private static final int DEFAULT_JETTY_PORT = 8080;
-
- private static final String PREFERRED_BROWSER_PROPERTY = "preferredBrowser";
-
- private static final String JETTY_PORT_PROPERTY = "jettyPort";
-
- private static final Log log = LogFactory.getLog( SimpleConfigReader.class );
-
- protected Properties getDefaultProperties()
- {
- FileInputStream configInputStream;
- Properties defaultProps = new Properties();
- try
- {
- configInputStream = new FileInputStream( CONFIG_FILE );
- defaultProps.load( configInputStream );
- configInputStream.close();
- } catch ( FileNotFoundException e )
- {
- log.info( "No properties file found." );
- } catch ( IOException ex )
- {
- log.error( "There was an input/output error while loading the properties file." );
- }
- return defaultProps;
- }
-
- protected String preferredBrowserPath()
- {
- String thisBrowserPath = null;
- if ( getDefaultProperties().containsKey( PREFERRED_BROWSER_PROPERTY ) )
- {
- try
- {
- thisBrowserPath = getDefaultProperties().getProperty( PREFERRED_BROWSER_PROPERTY );
- log.info( "Browser path reported as" + thisBrowserPath );
- } catch ( Exception e )
- {
- log.error( "Could not load preferred browser property" );
- thisBrowserPath = null;
- }
- }
- return thisBrowserPath;
- }
-
- protected int preferredJettyPort()
- {
- int preferredJettyPort = WebAppServer.DEFAULT_JETTY_PORT;
- if ( getDefaultProperties().containsKey( JETTY_PORT_PROPERTY ) )
- {
- try
- {
- preferredJettyPort = Integer.parseInt( getDefaultProperties().getProperty( JETTY_PORT_PROPERTY ) );
- } catch ( NumberFormatException e )
- {
- log.error( "Port is not in the specified format.Using default." );
- preferredJettyPort = WebAppServer.DEFAULT_JETTY_PORT;
- }
- }
- log.info( "Preferred jetty port will be configured to be " + preferredJettyPort );
-
- return preferredJettyPort;
- }
-}
=== modified file 'dhis-live/src/main/java/org/hisp/dhis/TrayApp.java'
--- dhis-live/src/main/java/org/hisp/dhis/TrayApp.java 2010-09-06 17:50:24 +0000
+++ dhis-live/src/main/java/org/hisp/dhis/TrayApp.java 2010-09-07 21:23:11 +0000
@@ -31,13 +31,22 @@
import java.awt.event.*;
import java.net.URI;
import java.net.URL;
+import java.util.logging.Level;
+import java.util.logging.Logger;
import javax.swing.*;
import java.io.*;
import java.util.Locale;
import java.util.ResourceBundle;
+import javax.xml.bind.JAXBContext;
+import javax.xml.bind.JAXBElement;
+import javax.xml.bind.JAXBException;
+import javax.xml.bind.Marshaller;
+import javax.xml.bind.Unmarshaller;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import org.hisp.dhis.config.ConfigType;
+import org.hisp.dhis.config.ConfigType.DatabaseConnections.Connection;
import org.mortbay.component.LifeCycle;
/**
@@ -51,6 +60,10 @@
private static final String CONFIG_DIR = "/conf";
+ private static final String CONFIG_FILE_NAME = "/conf/config.xml";
+
+ private static final String CONFIG_DEFAULT = "/defaultConfig.xml";
+
private static final String STOPPED_ICON = "/icons/stopped.png";
private static final String STARTING_ICON = "/icons/starting.gif";
@@ -59,18 +72,32 @@
private static final String RUNNING_ICON = "/icons/running.png";
- private static final String CONFIG_FILE = "conf/dhis2live.cfg";
-
private WebAppServer appServer;
private TrayIcon trayIcon;
private String installDir;
- private SimpleConfigReader configReader;
+ // the configuration
+ private ConfigType config;
private static ResourceBundle messages = ResourceBundle.getBundle( "messages", Locale.getDefault() );
+ private static TrayApp instance;
+
+// -------------------------------------------------------------------------
+ // Getters and setters
+ // -------------------------------------------------------------------------
+ public ConfigType getConfig()
+ {
+ return config;
+ }
+
+ public void setConfig( ConfigType config )
+ {
+ this.config = config;
+ }
+
// -------------------------------------------------------------------------
// Main method
// -------------------------------------------------------------------------
@@ -93,7 +120,8 @@
{
try
{
- new TrayApp();
+ TrayApp trayApp = TrayApp.getInstance();
+ trayApp.init();
} catch ( Exception ex )
{
log.fatal( "TrayApp Initialization failure", ex );
@@ -103,10 +131,21 @@
}
}
- // -------------------------------------------------------------------------
- // Constructor
- // -------------------------------------------------------------------------
- public TrayApp() throws AWTException, InterruptedException
+ // TrayApp is singleton - hide constructor
+ private TrayApp()
+ {
+ }
+
+ public static TrayApp getInstance()
+ {
+ if ( instance == null )
+ {
+ instance = new TrayApp();
+ }
+ return instance;
+ }
+
+ public void init() throws AWTException, InterruptedException
{
log.info( "Initialising DHIS 2 Live..." );
@@ -128,6 +167,27 @@
}
}
+ InputStream configStream = null;
+ try
+ {
+ configStream = new java.io.FileInputStream( installDir + CONFIG_FILE_NAME );
+ } catch ( FileNotFoundException ex )
+ {
+ log.info( "Can't locate external config - falling back to default");
+ configStream = TrayApp.class.getResourceAsStream( CONFIG_DEFAULT );
+ }
+
+ readConfigFromStream(configStream);
+
+ log.info( "Locale: " + config.getLocaleLanguage() + ":" + config.getLocaleCountry());
+
+ // get the selected database
+ ConfigType.DatabaseConnections.Connection conn =
+ (ConfigType.DatabaseConnections.Connection) config.getDatabaseConnections().getSelected();
+
+ log.info( "Selected db: "+conn.getName() + "; " + conn.getUserName() + ":" +conn.getPassword() + " "+ conn.getURL());
+
+
System.setProperty( "dhis2.home", installDir + CONFIG_DIR );
System.setProperty( "jetty.home", installDir );
@@ -168,11 +228,10 @@
if ( cmd.equals( messages.getString( "CMD_EXIT" ) ) )
{
shutdown();
- }
+ }
}
}
- ;
};
openItem.addActionListener( listener );
@@ -182,7 +241,7 @@
appServer = new WebAppServer();
try
{
- appServer.init( installDir, this );
+ appServer.init( );
} catch ( Exception e )
{
log.fatal( "Application server could not be initialized" );
@@ -239,12 +298,9 @@
private String defaultPreferredBrowserPath()
{
- //initialize a return variable.false denotes failure. true success
- configReader = new SimpleConfigReader();
- String preferredBrowserPath = null;
+ String preferredBrowserPath = config.getPreferredBrowser();
try
{
- preferredBrowserPath = configReader.preferredBrowserPath();
log.info( "Config reports browser path to be" + preferredBrowserPath );
boolean browserIsValid = new File( preferredBrowserPath ).exists();
if ( !browserIsValid )
@@ -396,7 +452,7 @@
*
* @return a <code>String</code> value representing the installation directory
*/
- private static String getInstallDir()
+ public static String getInstallDir()
{
// find a resource
String resourceString = TrayApp.class.getResource( "/icons/" ).toString();
@@ -414,4 +470,45 @@
result = result.replaceAll( "%20", " " );
return result;
}
+
+ private void readConfigFromStream(InputStream configStream)
+ {
+ try
+ {
+ JAXBContext jc = JAXBContext.newInstance( "org.hisp.dhis.config" );
+ //Create unmarshaller
+ Unmarshaller um = jc.createUnmarshaller();
+ //Unmarshal XML contents of the file myDoc.xml into your Java object instance.
+ JAXBElement<ConfigType> configElement =
+ (JAXBElement<ConfigType>) um.unmarshal( configStream );
+
+ config = configElement.getValue();
+
+ // rather than just logging these errors they should rather bubble a message to the UI
+ } catch ( JAXBException ex )
+ {
+ log.error( "Error parsing config file", ex );
+ }
+
+ }
+
+ private void writeConfigToFile()
+ {
+ try
+ {
+ JAXBContext jc = JAXBContext.newInstance( "org.hisp.dhis.config" );
+ //Create marshaller
+ Marshaller m = jc.createMarshaller();
+ //Marshal object into file.
+ m.marshal( config, new FileOutputStream( installDir + CONFIG_FILE_NAME ) );
+
+ // rather than just logging these errors they should rather bubble a message to the UI
+ } catch ( FileNotFoundException ex )
+ {
+ log.error( "Can't find config.xml file", ex );
+ } catch ( JAXBException ex )
+ {
+ log.error( "Error serializing config to file", ex );
+ }
+ }
}
=== modified file 'dhis-live/src/main/java/org/hisp/dhis/WebAppServer.java'
--- dhis-live/src/main/java/org/hisp/dhis/WebAppServer.java 2010-09-06 17:50:24 +0000
+++ dhis-live/src/main/java/org/hisp/dhis/WebAppServer.java 2010-09-07 21:23:11 +0000
@@ -64,17 +64,16 @@
protected Connector connector;
- private SimpleConfigReader configReader;
-
public WebAppServer()
{
server = new Server();
connector = new SelectChannelConnector();
}
- public void init( String installDir, LifeCycle.Listener serverListener )
+ public void init( )
throws Exception
{
+ String installDir = TrayApp.getInstallDir();
try
{
int portFromConfig = this.getPortFromConfig();
@@ -109,7 +108,7 @@
}
server.setHandler( handlers );
- server.addLifeCycleListener( serverListener );
+ server.addLifeCycleListener( TrayApp.getInstance() );
}
public void start()
@@ -132,17 +131,6 @@
private int getPortFromConfig()
{
- configReader = new SimpleConfigReader();
- int preferredJettyPort = DEFAULT_JETTY_PORT;
- try
- {
- int portFromConfig = configReader.preferredJettyPort();
- preferredJettyPort = portFromConfig;
- } catch ( Exception e )
- {
- log.error( "There was a problem reading the preferred jetty port. Using default." );
- preferredJettyPort = DEFAULT_JETTY_PORT;
- }
- return preferredJettyPort;
+ return TrayApp.getInstance().getConfig().getPort();
}
}
=== added file 'dhis-live/src/main/resources/Config.xsd'
--- dhis-live/src/main/resources/Config.xsd 1970-01-01 00:00:00 +0000
+++ dhis-live/src/main/resources/Config.xsd 2010-09-07 21:23:11 +0000
@@ -0,0 +1,46 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
+ xmlns="http://www.dhis.org/schema/config"
+ targetNamespace="http://www.dhis.org/schema/config" elementFormDefault="qualified">
+
+ <xs:complexType name="ConfigType">
+ <xs:sequence>
+ <xs:element name="LocaleLanguage" type="xs:string" default="en" />
+ <xs:element name="LocaleCountry" type="xs:string" default="GB" />
+ <xs:element name="Port" type="xs:int" default="8080" />
+ <xs:element name="Host" type="xs:string" default="localhost" />
+ <xs:element name="PreferredBrowser" type="xs:string" default="" />
+ <xs:element name="DatabaseConnections">
+ <xs:complexType>
+ <xs:sequence>
+ <xs:element name="Connection" maxOccurs="unbounded">
+ <xs:complexType>
+ <xs:sequence>
+ <xs:element name="Name" type="xs:string"/>
+ <xs:element name="Type">
+ <xs:simpleType>
+ <xs:restriction base="xs:string">
+ <xs:enumeration value="H2"/>
+ <xs:enumeration value="Postgresql"/>
+ <xs:enumeration value="Mysql"/>
+ </xs:restriction>
+ </xs:simpleType>
+ </xs:element>
+ <xs:element name="URL" type="xs:string"/>
+ <xs:element name="UserName" type="xs:string"/>
+ <xs:element name="Password" type="xs:string" default="" minOccurs="0"/>
+ </xs:sequence>
+ <xs:attribute name="ID" type="xs:ID" use="required"/>
+ </xs:complexType>
+ </xs:element>
+ </xs:sequence>
+ <xs:attribute name="selected" type="xs:IDREF"/>
+ </xs:complexType>
+ </xs:element>
+ </xs:sequence>
+ </xs:complexType>
+
+ <xs:element name="Config" type="ConfigType">
+ </xs:element>
+
+</xs:schema>
=== added file 'dhis-live/src/main/resources/defaultConfig.xml'
--- dhis-live/src/main/resources/defaultConfig.xml 1970-01-01 00:00:00 +0000
+++ dhis-live/src/main/resources/defaultConfig.xml 2010-09-07 21:23:11 +0000
@@ -0,0 +1,35 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- Default configuration for dhis2-live -->
+<!-- Bob Jolliffe 07/09/2010 -->
+
+<Config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://www.dhis.org/schema/config Config.xsd"
+ xmlns="http://www.dhis.org/schema/config">
+ <LocaleLanguage>en</LocaleLanguage>
+ <LocaleCountry>GB</LocaleCountry>
+ <Port>8080</Port>
+ <Host>localhost</Host>
+ <PreferredBrowser/>
+ <DatabaseConnections selected="conn1">
+ <Connection ID="conn1">
+ <Name>DHIS2 demo database</Name>
+ <Type>H2</Type>
+ <URL>jdbc:h2:./database/demo;AUTO_SERVER=TRUE</URL>
+ <UserName>sa</UserName>
+ </Connection>
+ <Connection ID="conn2">
+ <Name>Postgresql example</Name>
+ <Type>Postgresql</Type>
+ <URL>jdbc:postgresql://localhost/demo</URL>
+ <UserName>dhis</UserName>
+ <Password>dhis</Password>
+ </Connection>
+ <Connection ID="conn3">
+ <Name>Mysql example</Name>
+ <Type>Postgresql</Type>
+ <URL>jdbc:mysql://localhost/demo</URL>
+ <UserName>dhis</UserName>
+ <Password>dhis</Password>
+ </Connection>
+ </DatabaseConnections>
+</Config>
=== modified file 'dhis-live/src/main/resources/messages_en.properties'
--- dhis-live/src/main/resources/messages_en.properties 2010-09-06 17:50:24 +0000
+++ dhis-live/src/main/resources/messages_en.properties 2010-09-07 21:23:11 +0000
@@ -1,4 +1,5 @@
CMD_OPEN = Open DHIS 2 Live
+CMD_CONFIG = Configure
CMD_EXIT = Exit
CMD_SETTINGS = Settings
CMD_DATABASE = Databases