org.vrspace.client
Class VrmlUploader

java.lang.Object
  extended byorg.vrspace.client.VrmlUploader
All Implemented Interfaces:
java.util.Observer

public class VrmlUploader
extends java.lang.Object
implements java.util.Observer

Recursively uploads files to the server.

The uploader recursively searches the files that have .wrl extensions, looking for url lists in url tags, and in EXTERNPROTOs. Each list found is searched for for files existing on the local file system. If a discovered file has a .wrl extension, then it will be searched as well. This recursion continues up to the level maxRecursion ( defaults to zero ).

After a VrmlUploader is instantiated, various options can be set for the transfer (see below). The upload method is used to initiate the transfer. Files sent to this method with a .wrl extension will be uploaded as VrmlFiles, unless uploadAllAsFile is false. In that case, all .wrl files are uploaded as Files. If includeNonWrl is false, then all non-vrml files encountered while searching (see below) are not uploaded.

Example 1: upload( "sample.wrl" ) with maxRecursion level 0, and includeNonWrl set to false. In this case, only sample.wrl is uploaded.

Example 2: now includeNonWrl is set to true. This causes sample.wrl to be searched for all url list. Every non .wrl file found will be uploaded.

Example 3: includeNonWrl false, maxRecusion 1. Sample.wrl and every .wrl file discovered within it is uploaded.

Various options are available for the upload:

inputStream - an InputStream for providing upload parameters, used in conjunction with useInputStream. Defaults to System.in.

outputStream - a PrintStream, defaulting to System.out, that writes the responses to the upload commands sent to the server.

silent - turns outputStream off.

uploadAs - files normally uploaded as VrmlFile are uploaded as whatever class is specified.

logger - turns the logger on and off

Warning: All files uploaded with .wrl extensions are expected to be uncompresssed, and will be automatically compressed by the server.


Nested Class Summary
 class VrmlUploader.URLParser
          Recursively parses given files, searching for url lists, in particular, other files on the local files system.
 
Field Summary
protected  java.util.HashMap cachedFiles
           
protected  boolean closeConnectionOnCompletion
           
protected  Connection connection
           
protected  boolean excludeExternProto
           
protected  java.util.HashMap files
           
protected  java.lang.String host
           
protected  boolean includeNonWrl
           
protected  java.io.InputStream inputStream
           
protected  java.lang.String login
           
protected  int maxRecursion
           
protected  java.util.Collection nonVrmlPaths
           
protected  int numberLeftToUpload
           
protected  java.io.PrintStream outputStream
           
protected  java.lang.String password
           
protected  int port
           
protected  boolean silent
           
protected  boolean stopLoggerOnCompletion
           
protected  java.lang.String uploadAs
           
protected  boolean useInputStream
           
protected  java.util.Collection vrmlPaths
           
 
Constructor Summary
VrmlUploader()
           
VrmlUploader(Connection connection, java.lang.String login, java.lang.String password)
           
VrmlUploader(java.lang.String host, int port, java.lang.String login, java.lang.String password)
           
 
Method Summary
protected  void consoleLogin()
          Retrieves all upload information from input via a Console (except for the file name).
protected  void copyURL(java.lang.String path, java.lang.String destPath, java.io.OutputStream out)
          Copy file/url path to destpath
 java.io.OutputStream getOutputStream()
           
static void main(java.lang.String[] args)
          Command Line Usage: java VrmlUploader [options] file
 void println(java.lang.String string)
          Printlns the string to outputStream if silent is false.
protected  boolean requestUpload(java.lang.String checkedPath)
          Request for the given file to be uploaded.
protected  void requestUploads()
          Request that the cachedFiles and files be uploaded to the server.
 void setExcludeExternProto(boolean excludeExternProto)
           
 void setIncludeNonWrl(boolean includeNonWrl)
           
 void setInputStream(java.io.InputStream inputStream)
           
 void setLogging(boolean logging)
           
 void setMaxRecursion(int maxRecursion)
           
 void setOutputStream(java.io.OutputStream outputStream)
           
 void setSilent(boolean silent)
           
 void setStopLoggerOnCompletion(boolean stopLoggerOnCompletion)
           
 void setUploadAs(java.lang.String uploadAs)
           
 void setUseInputStream(boolean useInputStream)
           
 void shutdown()
          Shutdown the connection, and turn the Logger thread off if shutdownOnCompletion is true.
 void update(java.util.Observable conn, java.lang.Object cmd)
          Implements the observer interface.
 void upload(java.util.List paths)
          Uploads the list of files specified.
 void upload(java.util.List paths, java.util.List uploadPaths)
           
 void upload(java.lang.String path)
          Uploads the file specified.
 void upload(java.lang.String path, java.lang.String uploadPath)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

connection

protected Connection connection

stopLoggerOnCompletion

protected boolean stopLoggerOnCompletion

closeConnectionOnCompletion

protected boolean closeConnectionOnCompletion

outputStream

protected java.io.PrintStream outputStream

inputStream

protected java.io.InputStream inputStream

host

protected java.lang.String host

port

protected int port

login

protected java.lang.String login

password

protected java.lang.String password

maxRecursion

protected int maxRecursion

includeNonWrl

protected boolean includeNonWrl

excludeExternProto

protected boolean excludeExternProto

silent

protected boolean silent

numberLeftToUpload

protected int numberLeftToUpload

uploadAs

protected java.lang.String uploadAs

useInputStream

protected boolean useInputStream

vrmlPaths

protected java.util.Collection vrmlPaths

nonVrmlPaths

protected java.util.Collection nonVrmlPaths

cachedFiles

protected java.util.HashMap cachedFiles

files

protected java.util.HashMap files
Constructor Detail

VrmlUploader

public VrmlUploader()

VrmlUploader

public VrmlUploader(java.lang.String host,
                    int port,
                    java.lang.String login,
                    java.lang.String password)

VrmlUploader

public VrmlUploader(Connection connection,
                    java.lang.String login,
                    java.lang.String password)
Method Detail

setMaxRecursion

public void setMaxRecursion(int maxRecursion)

setIncludeNonWrl

public void setIncludeNonWrl(boolean includeNonWrl)

setExcludeExternProto

public void setExcludeExternProto(boolean excludeExternProto)

setSilent

public void setSilent(boolean silent)

setStopLoggerOnCompletion

public void setStopLoggerOnCompletion(boolean stopLoggerOnCompletion)

setUploadAs

public void setUploadAs(java.lang.String uploadAs)

setLogging

public void setLogging(boolean logging)

setUseInputStream

public void setUseInputStream(boolean useInputStream)

setInputStream

public void setInputStream(java.io.InputStream inputStream)

getOutputStream

public java.io.OutputStream getOutputStream()

setOutputStream

public void setOutputStream(java.io.OutputStream outputStream)

upload

public void upload(java.lang.String path)
            throws ConnectionException
Uploads the file specified. The file is parsed for the urls it contains, and then each of these files are recursively searched. Once parsing is completed, the server is sent requests for file upload. The update method handles the actual uploading. Note that File.getAbsolutePath() is called on the file to determine the path to upload.

Throws:
ConnectionException

upload

public void upload(java.lang.String path,
                   java.lang.String uploadPath)
            throws ConnectionException
Throws:
ConnectionException

upload

public void upload(java.util.List paths)
            throws ConnectionException
Uploads the list of files specified. Each individual file is parsed for the urls they contain, and then each of these files are recursively searched. Once parsing is completed, the server is sent requests for file upload. The update method handles the actual uploading. Note that File.getAbsolutePath() is called on each file to determine the path to upload.

Throws:
ConnectionException

upload

public void upload(java.util.List paths,
                   java.util.List uploadPaths)
            throws ConnectionException
Throws:
ConnectionException

consoleLogin

protected void consoleLogin()
                     throws ConnectionException
Retrieves all upload information from input via a Console (except for the file name). A console is created, but its thread is not started. The console retrieves host, port, username, password if they haven't already been set in the System properties.

Throws:
ConnectionException

requestUploads

protected void requestUploads()
Request that the cachedFiles and files be uploaded to the server. Exits if these lists are both empty.


requestUpload

protected boolean requestUpload(java.lang.String checkedPath)
                         throws java.io.IOException
Request for the given file to be uploaded. If the file has a wrl extension, request as type uploadAs, otherwise request File.

Throws:
java.io.IOException

update

public void update(java.util.Observable conn,
                   java.lang.Object cmd)
Implements the observer interface. The VrmlUploader has been added as an observer of its Connection. The purpose of this observing is to ignore all messages sent except upload commands and responses. Those messages implement the actual uploading. The responses are printed to outputStream.

Specified by:
update in interface java.util.Observer

copyURL

protected void copyURL(java.lang.String path,
                       java.lang.String destPath,
                       java.io.OutputStream out)
Copy file/url path to destpath


shutdown

public void shutdown()
Shutdown the connection, and turn the Logger thread off if shutdownOnCompletion is true.


println

public void println(java.lang.String string)
Printlns the string to outputStream if silent is false.


main

public static void main(java.lang.String[] args)
Command Line Usage: java VrmlUploader [options] file
 options:
 -h=host
 -p=port 
 -l=username
 -pw=password
 -r=max recursion level   Default: 0
 -uploadPath=path         uploads as if this was full path of file
 -uploadAs=Class          upload .wrl as given Class.  Default: VrmlFile
 -includeNonWrl                  Upload non .wrl files (including .wrl.gz)
 -excludeExternProto             Do not upload EXTERNPROTO urls
 -silent                         Silence output
 -logger                         Debug