Skip to content

Commit

Permalink
Now logging user and default properties on startup (watch out with us…
Browse files Browse the repository at this point in the history
…er passwords...)
  • Loading branch information
Pierre-Luc Paour committed Sep 28, 2002
1 parent 1a011f4 commit 6380838
Show file tree
Hide file tree
Showing 3 changed files with 114 additions and 82 deletions.
23 changes: 22 additions & 1 deletion com/gallery/GalleryRemote/GalleryProperties.java
Expand Up @@ -48,7 +48,7 @@ public class GalleryProperties extends Properties {
*
*@param p Description of Parameter
*/
public GalleryProperties( GalleryProperties p ) {
public GalleryProperties( Properties p ) {
super( p );
}

Expand Down Expand Up @@ -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) + "|");
}
}
}

153 changes: 74 additions & 79 deletions 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();
}
}

20 changes: 18 additions & 2 deletions com/gallery/GalleryRemote/PropertiesFile.java
Expand Up @@ -101,16 +101,32 @@ 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();
} catch ( FileNotFoundException e ) {
e.printStackTrace();
}
}

return super.getProperty( name );
}


/**
* Read the property file from disk
Expand Down

0 comments on commit 6380838

Please sign in to comment.