load default config from class path instead of current directory

This commit is contained in:
nifi 2006-08-22 08:56:08 +00:00
parent c32390ab76
commit 8c2765f0f7
2 changed files with 30 additions and 14 deletions

View file

@ -26,7 +26,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $Id: GUI.java,v 1.1 2006/08/21 12:12:51 fros4943 Exp $
* $Id: GUI.java,v 1.2 2006/08/22 08:56:08 nifi Exp $
*/
package se.sics.cooja;
@ -77,7 +77,7 @@ public class GUI extends JDesktopPane {
/**
* Default platform configuration filename.
*/
public static final String PLATFORM_DEFAULT_CONFIG_FILENAME = "cooja_default.config";
public static final String PLATFORM_DEFAULT_CONFIG_FILENAME = "/cooja_default.config";
/**
* User platform configuration filename.
@ -565,11 +565,19 @@ public class GUI extends JDesktopPane {
// logger.info("Loading default platform configuration: " +
// PLATFORM_DEFAULT_CONFIG_FILENAME);
try {
platformConfig.appendConfig(new File(PLATFORM_DEFAULT_CONFIG_FILENAME));
} catch (FileNotFoundException e) {
logger.fatal("Could not find default platform config file: "
+ PLATFORM_DEFAULT_CONFIG_FILENAME);
return false;
InputStream input =
GUI.class.getResourceAsStream(PLATFORM_DEFAULT_CONFIG_FILENAME);
if (input != null) {
try {
platformConfig.appendConfig(input);
} finally {
input.close();
}
} else {
logger.fatal("Could not find default platform config file: "
+ PLATFORM_DEFAULT_CONFIG_FILENAME);
return false;
}
} catch (IOException e) {
logger.fatal("Error when reading default platform config file: "
+ PLATFORM_DEFAULT_CONFIG_FILENAME);

View file

@ -26,7 +26,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $Id: UserPlatformsDialog.java,v 1.1 2006/08/21 12:13:02 fros4943 Exp $
* $Id: UserPlatformsDialog.java,v 1.2 2006/08/22 08:56:08 nifi Exp $
*/
package se.sics.cooja.dialogs;
@ -36,10 +36,10 @@ import java.awt.event.*;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.util.Enumeration;
import java.util.Vector;
import javax.swing.*;
import org.apache.log4j.Logger;
import se.sics.cooja.GUI;
@ -223,11 +223,19 @@ public class UserPlatformsDialog extends JDialog {
// Create default configuration
PlatformConfig config = new PlatformConfig();
try {
config.appendConfig(new File(GUI.PLATFORM_DEFAULT_CONFIG_FILENAME));
} catch (FileNotFoundException ex) {
logger.fatal("Could not find default platform config file: "
+ GUI.PLATFORM_DEFAULT_CONFIG_FILENAME);
return;
InputStream input =
GUI.class.getResourceAsStream(GUI.PLATFORM_DEFAULT_CONFIG_FILENAME);
if (input != null) {
try {
config.appendConfig(input);
} finally {
input.close();
}
} else {
logger.fatal("Could not find default platform config file1: "
+ GUI.PLATFORM_DEFAULT_CONFIG_FILENAME);
return;
}
} catch (IOException ex) {
logger.fatal("Error when reading default platform config file: "
+ GUI.PLATFORM_DEFAULT_CONFIG_FILENAME);