From 63808385a3889e31051e9a3ff609a943f06c4779 Mon Sep 17 00:00:00 2001 From: Pierre-Luc Paour Date: Sat, 28 Sep 2002 10:53:22 +0000 Subject: [PATCH] Now logging user and default properties on startup (watch out with user passwords...) --- .../GalleryRemote/GalleryProperties.java | 23 ++- com/gallery/GalleryRemote/GalleryRemote.java | 153 +++++++++--------- com/gallery/GalleryRemote/PropertiesFile.java | 20 ++- 3 files changed, 114 insertions(+), 82 deletions(-) diff --git a/com/gallery/GalleryRemote/GalleryProperties.java b/com/gallery/GalleryRemote/GalleryProperties.java index 5341718..62e1768 100644 --- a/com/gallery/GalleryRemote/GalleryProperties.java +++ b/com/gallery/GalleryRemote/GalleryProperties.java @@ -48,7 +48,7 @@ public class GalleryProperties extends Properties { * *@param p Description of Parameter */ - public GalleryProperties( GalleryProperties p ) { + public GalleryProperties( Properties p ) { super( p ); } @@ -393,5 +393,26 @@ public String getProperty( String name, String defaultValue ) { return tmp; } } + + + public void logProperties(int level, String module) { + if (module == null) { + module = MODULE; + } + + ArrayList names = new ArrayList(100); + Enumeration e = propertyNames(); + while (e.hasMoreElements()) { + names.add( (String) e.nextElement() ); + } + + Object[] namesArray = names.toArray(); + Arrays.sort(namesArray); + + for (int i = 0; i < namesArray.length; i++) { + String name = (String) namesArray[i]; + Log.log(level, module, name + "= |" + getProperty(name) + "|"); + } + } } diff --git a/com/gallery/GalleryRemote/GalleryRemote.java b/com/gallery/GalleryRemote/GalleryRemote.java index fed9544..bf9125b 100644 --- a/com/gallery/GalleryRemote/GalleryRemote.java +++ b/com/gallery/GalleryRemote/GalleryRemote.java @@ -1,100 +1,95 @@ /* - * Gallery Remote - a File Upload Utility for Gallery - * - * Gallery - a web based photo album viewer and editor - * Copyright (C) 2000-2001 Bharat Mediratta - * - * 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. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - */ +* Gallery Remote - a File Upload Utility for Gallery +* +* Gallery - a web based photo album viewer and editor +* Copyright (C) 2000-2001 Bharat Mediratta +* +* 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. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, write to the Free Software +* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +*/ package com.gallery.GalleryRemote; import java.io.*; import java.util.*; import javax.swing.*; /** - * Main class and entry point of Gallery Remote - * - *@author paour - *@created 11 août 2002 - */ +* Main class and entry point of Gallery Remote +* +*@author paour +*@created 11 août 2002 +*/ public class GalleryRemote { - private static GalleryRemote singleton = null; - - public MainFrame mainFrame = null; - public PropertiesFile properties = null; - public PropertiesFile defaults = null; - - private GalleryRemote() { - defaults = new PropertiesFile("defaults"); + private static GalleryRemote singleton = null; + + public MainFrame mainFrame = null; + public PropertiesFile properties = null; + public PropertiesFile defaults = null; + + private GalleryRemote() { + defaults = new PropertiesFile("defaults"); File f = new File(System.getProperty("user.home") - + File.separator + ".GalleryRemote" - + File.separator); + + File.separator + ".GalleryRemote" + + File.separator); f.mkdirs(); - properties = new PropertiesFile(defaults, f.getPath() - + File.separator + "GalleryRemote"); - } - - private void run() { - try { - // For native Look and Feel, uncomment the following code. - /// * - try { - UIManager.setLookAndFeel( UIManager.getSystemLookAndFeelClassName() ); - } - catch ( Exception e ) { - } - //* / - - logEnvironment(); - - mainFrame = new MainFrame(); - mainFrame.initComponents(); - } - catch ( Exception e ) { + properties = new PropertiesFile(defaults, f.getPath() + + File.separator + "GalleryRemote"); + } + + private void run() { + try { + // For native Look and Feel, uncomment the following code. + /// * + try { + UIManager.setLookAndFeel( UIManager.getSystemLookAndFeelClassName() ); + } + catch ( Exception e ) { + } + //* / + + // log system properties + new GalleryProperties(System.getProperties()).logProperties(Log.INFO, "SysProps"); + + // log properties + properties.logProperties(Log.TRACE, "UsrProps"); + + mainFrame = new MainFrame(); + mainFrame.initComponents(); + } + catch ( Exception e ) { Log.logException(Log.CRITICAL, "Startup", e); - } + } Update update = new Update(); if ( update.check() ) { update.showNotice(); } - } - - public static void logEnvironment() { - Properties props = System.getProperties(); - Enumeration e = props.propertyNames(); - while (e.hasMoreElements()) { - String name = (String) e.nextElement(); - Log.log(Log.INFO, "SysProps", name + "= |" + System.getProperty(name) + "|"); - } - } - - public static GalleryRemote getInstance() { - if (singleton == null) { - singleton = new GalleryRemote(); - } - - return singleton; - } - - // Main entry point - public static void main( String[] args ) { - getInstance().run(); - } + } + + public static GalleryRemote getInstance() { + if (singleton == null) { + singleton = new GalleryRemote(); + } + + return singleton; + } + + // Main entry point + public static void main( String[] args ) { + getInstance().run(); + } } diff --git a/com/gallery/GalleryRemote/PropertiesFile.java b/com/gallery/GalleryRemote/PropertiesFile.java index eccea8e..4d31e8f 100755 --- a/com/gallery/GalleryRemote/PropertiesFile.java +++ b/com/gallery/GalleryRemote/PropertiesFile.java @@ -101,6 +101,23 @@ public synchronized void setFilename( String name ) { *@return The property value */ public String getProperty( String name ) { + checkRead(); + + return super.getProperty( name ); + } + + public Enumeration propertyNames() { + checkRead(); + + return super.propertyNames(); + } + + protected void checkRead() { + if ( defaults != null && defaults instanceof PropertiesFile ) { + // also load defaults + ((PropertiesFile) defaults).checkRead(); + } + if ( !read ) { try { read(); @@ -108,9 +125,8 @@ public String getProperty( String name ) { e.printStackTrace(); } } - - return super.getProperty( name ); } + /** * Read the property file from disk