com.photoviewer.server
Class PhotoGenerator

java.lang.Object
  extended bycom.photoviewer.server.PhotoGenerator
All Implemented Interfaces:
java.io.FileFilter

public class PhotoGenerator
extends java.lang.Object
implements java.io.FileFilter

Generate thumbnails and screen size pictures from a master directory. A parallel directory of thumbnail and screen size pictures will be generated and kept synchronized to a directory containing the "master" images.

Author:
Chris Normand, John De Regnaucourt

Field Summary
static java.lang.String COPYRIGHT
           
static java.lang.String DEST_DIR
           
static java.lang.String HTML_POSTFIX
           
static java.lang.String INDEX_PREFIX
           
static java.lang.String JPEG_LEVEL
           
static java.lang.String JPEG_POSTFIX
           
static java.lang.String NORMAL_DIM
           
static java.lang.String SRC_DIR
           
static java.lang.String THUMBNAIL_DIM
           
static java.lang.String TREE_PREFIX
           
static java.lang.String VERSION
           
 
Constructor Summary
PhotoGenerator(java.lang.String[] args)
          /** Instantiate the generator dumping the output to the console.
PhotoGenerator(java.lang.String[] args, java.io.PrintWriter console)
          Instantiate the generator dumping the output to a PrintWriter.
 
Method Summary
 boolean accept(java.io.File f)
          Following the FileFilter interface, do we accept this file (we are looking for JPEG files).
 boolean accept(java.io.File f, java.lang.String ending)
          Question: does the File end with 'ending'.
protected  void buildPage(Path currentPath)
          Build the thumbnails page.
protected  void buildPathTree(Path currentPath)
          Recursively search through the source directories building our com.photoviewer.server.Path tree.
protected  void checkProperties()
          Check to see that the required properties exist.
protected  java.io.File[] createPictures(Path path, java.io.File srcPic)
          Create the display/normal and thumbnail versions of the source picture (if necessary)
protected  void createResizers()
          Create a normal and thumbnail resizer based off of the current properties.
protected  void deleteOldDest(Path currentPath)
          Delete all HTML files (since they are regenerated each time) and any normal and thumbnail pictures that does not have a corresponding picture in the source directory.
static void ExamplePropertiesFile()
           
protected  java.lang.String fileSize(long sz)
           
protected  java.lang.String getDestDir(Path currentPath)
           
protected  float getFloat(java.lang.String key)
           
protected  java.lang.String getGlobalStr(java.lang.String key)
           
protected  int getInt(java.lang.String key)
           
protected  java.lang.String getLocalStr(java.lang.String key)
           
protected  java.lang.String getSrcDir(Path currentPath)
           
protected  void handlePath(Path currentPath)
          Do the work for a particular path.
static void main(java.lang.String[] args)
           
protected  java.lang.String pad(int i)
           
protected  void parseArgs(java.lang.String[] args)
           
protected  void print(int i)
           
protected  void print(java.lang.Object o)
           
protected  void printElapsedtime(long diff)
           
protected  void println(java.lang.Object o)
           
protected  void println(java.lang.String s)
           
protected  void readDefaultProperties(java.lang.String fn)
          Read the initial properties and store them in the default and current properties objects.
protected  java.util.Properties readLocalDescriptions(java.io.File src)
          If a 'descript.ion' file exists, read it to determine individual picture comments.
protected  java.util.Properties readLocalProperties(java.io.File src)
           
protected  java.lang.String readTextFile(java.io.File f)
           
protected  java.lang.String rootNameFor(java.io.File f)
          Given the name of a destination JPG, try to determine the name of source file that created it (removing the thumbnail and normal prefixes).
protected  java.lang.String rootNameFor(java.io.File f, java.lang.String prefix)
           
protected  boolean shouldCreateNormal(Path path, java.io.File src, java.io.File dest)
           
protected  boolean shouldCreateThumbnail(java.io.File src, java.io.File dest)
           
protected  void start()
           
protected  void startAtRoot()
           
protected  java.util.Vector subdirsFor(java.io.File dir)
           
protected  java.lang.String wfn(java.lang.String fn)
          WFN = WebFileName.
protected  java.lang.String xfn(java.lang.String fn)
          Fix descriptions for listing in XML files.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

VERSION

public static final java.lang.String VERSION
See Also:
Constant Field Values

COPYRIGHT

public static final java.lang.String COPYRIGHT
See Also:
Constant Field Values

SRC_DIR

public static final java.lang.String SRC_DIR
See Also:
Constant Field Values

DEST_DIR

public static final java.lang.String DEST_DIR
See Also:
Constant Field Values

THUMBNAIL_DIM

public static final java.lang.String THUMBNAIL_DIM
See Also:
Constant Field Values

NORMAL_DIM

public static final java.lang.String NORMAL_DIM
See Also:
Constant Field Values

JPEG_LEVEL

public static final java.lang.String JPEG_LEVEL
See Also:
Constant Field Values

INDEX_PREFIX

public static final java.lang.String INDEX_PREFIX
See Also:
Constant Field Values

TREE_PREFIX

public static final java.lang.String TREE_PREFIX
See Also:
Constant Field Values

HTML_POSTFIX

public static final java.lang.String HTML_POSTFIX
See Also:
Constant Field Values

JPEG_POSTFIX

public static final java.lang.String JPEG_POSTFIX
See Also:
Constant Field Values
Constructor Detail

PhotoGenerator

public PhotoGenerator(java.lang.String[] args)
/** Instantiate the generator dumping the output to the console. Do a System.exit() when done.


PhotoGenerator

public PhotoGenerator(java.lang.String[] args,
                      java.io.PrintWriter console)
Instantiate the generator dumping the output to a PrintWriter. Do NOT do a System.exit() when done.

Method Detail

accept

public boolean accept(java.io.File f)
Following the FileFilter interface, do we accept this file (we are looking for JPEG files).

Specified by:
accept in interface java.io.FileFilter

accept

public boolean accept(java.io.File f,
                      java.lang.String ending)
Question: does the File end with 'ending'. Used to look for '.jpg' and '.html' files.


buildPage

protected void buildPage(Path currentPath)
                  throws java.lang.Exception
Build the thumbnails page.

Throws:
java.lang.Exception

buildPathTree

protected void buildPathTree(Path currentPath)
                      throws java.lang.Exception
Recursively search through the source directories building our com.photoviewer.server.Path tree.

Throws:
java.lang.Exception

checkProperties

protected void checkProperties()
Check to see that the required properties exist.


createPictures

protected java.io.File[] createPictures(Path path,
                                        java.io.File srcPic)
                                 throws java.lang.Exception
Create the display/normal and thumbnail versions of the source picture (if necessary)

Parameters:
path - Path object representing the current path
srcPic - File representing the current master picture to be processed
Returns:
a File[] with File[0] representing the generated thumbnail, and File[1] representing the generated screen-size image.
Throws:
java.lang.Exception

createResizers

protected void createResizers()
Create a normal and thumbnail resizer based off of the current properties.


deleteOldDest

protected void deleteOldDest(Path currentPath)
                      throws java.lang.Exception
Delete all HTML files (since they are regenerated each time) and any normal and thumbnail pictures that does not have a corresponding picture in the source directory.

Throws:
java.lang.Exception

ExamplePropertiesFile

public static void ExamplePropertiesFile()

fileSize

protected java.lang.String fileSize(long sz)

getDestDir

protected java.lang.String getDestDir(Path currentPath)

getFloat

protected float getFloat(java.lang.String key)

getGlobalStr

protected java.lang.String getGlobalStr(java.lang.String key)

getInt

protected int getInt(java.lang.String key)

getLocalStr

protected java.lang.String getLocalStr(java.lang.String key)

getSrcDir

protected java.lang.String getSrcDir(Path currentPath)

handlePath

protected void handlePath(Path currentPath)
                   throws java.lang.Exception
Do the work for a particular path. This is the start of the recursive loop. Setup all of the 'local' values (properties, resizers, etc.) and build as many thumbnail pages as necessary.

Throws:
java.lang.Exception

main

public static void main(java.lang.String[] args)

pad

protected java.lang.String pad(int i)

parseArgs

protected void parseArgs(java.lang.String[] args)

print

protected void print(int i)

print

protected void print(java.lang.Object o)

printElapsedtime

protected void printElapsedtime(long diff)

println

protected void println(java.lang.Object o)

println

protected void println(java.lang.String s)

readDefaultProperties

protected void readDefaultProperties(java.lang.String fn)
Read the initial properties and store them in the default and current properties objects.


readLocalDescriptions

protected java.util.Properties readLocalDescriptions(java.io.File src)
If a 'descript.ion' file exists, read it to determine individual picture comments. This type of file is used by ACDSee to store file comments.


readLocalProperties

protected java.util.Properties readLocalProperties(java.io.File src)

readTextFile

protected java.lang.String readTextFile(java.io.File f)
                                 throws java.lang.Exception
Throws:
java.lang.Exception

rootNameFor

protected java.lang.String rootNameFor(java.io.File f)
Given the name of a destination JPG, try to determine the name of source file that created it (removing the thumbnail and normal prefixes).


rootNameFor

protected java.lang.String rootNameFor(java.io.File f,
                                       java.lang.String prefix)

shouldCreateNormal

protected boolean shouldCreateNormal(Path path,
                                     java.io.File src,
                                     java.io.File dest)
                              throws java.lang.Exception
Throws:
java.lang.Exception

shouldCreateThumbnail

protected boolean shouldCreateThumbnail(java.io.File src,
                                        java.io.File dest)

start

protected void start()

startAtRoot

protected void startAtRoot()
                    throws java.lang.Exception
Throws:
java.lang.Exception

subdirsFor

protected java.util.Vector subdirsFor(java.io.File dir)

wfn

protected java.lang.String wfn(java.lang.String fn)
WFN = WebFileName. Convert '&' and ' ' into their web equivelent so that the browser won't be confused by the name.


xfn

protected java.lang.String xfn(java.lang.String fn)
Fix descriptions for listing in XML files. This replaces quotes with backslash quote.

Parameters:
fn - String to fix
Returns:
corrected String