nu.staldal.lagoon.core
Class LagoonProcessor

java.lang.Object
  extended by nu.staldal.lagoon.core.LagoonProcessor
All Implemented Interfaces:
LagoonContext

public class LagoonProcessor
extends java.lang.Object
implements LagoonContext

The main worker class of the Lagoon core. Initialized with the sitemap, a source dir and a target storage URL. Then building the website may be done several times, until destroy() is invoked. This class is not thread-safe. The methods must not be invoked concurrently from different threads.


Constructor Summary
LagoonProcessor(java.lang.String targetURL, Element sitemapTree, java.io.File sourceDir, java.lang.String password, java.io.PrintWriter log, java.io.PrintWriter err)
          Constructs and initializes a LagoonProcessor.
 
Method Summary
 boolean build(boolean force)
          Perform the building of the website.
 boolean canCheckFileHasBeenUpdated(java.lang.String url)
          Tell whether the given source can be checked for dependency.
 void deleteClassInRepository(java.lang.String className)
          Delete a Java class file from the repository.
 void destroy()
          Dispose this object and release any resources it holds.
 java.lang.String getFileURLRelativeTo(java.lang.String url, java.lang.String base)
          Get an URL representing the given file or directory.
 java.lang.Object getObjectFromRepository(java.lang.String key)
          Get an object from the repository.
 java.lang.String getProperty(java.lang.String key)
          Return the value of a project property.
 java.io.File getSourceRootDir()
          Get an absolute File object representing the source root directory.
 java.io.File getTempDir()
          Get the temp directory.
 java.lang.Class loadClassFromRepository(java.lang.String className)
          Load a Java class file from the repository.
 boolean putObjectIntoRepository(java.lang.String key, java.lang.Object obj)
          Store an object into the repository.
 java.io.InputStream readFileFromRepository(java.lang.String key)
          Read from a file in the repository.
 void reloadClasses()
          Reload classes.
 java.io.OutputStream storeClassInRepository(java.lang.String className)
          Store a Java class file in the repository.
 java.io.OutputStream storeFileInRepository(java.lang.String key)
          Store a file in the repository.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

LagoonProcessor

public LagoonProcessor(java.lang.String targetURL,
                       Element sitemapTree,
                       java.io.File sourceDir,
                       java.lang.String password,
                       java.io.PrintWriter log,
                       java.io.PrintWriter err)
                throws java.io.IOException,
                       LagoonException,
                       AuthenticationException,
                       AuthenticationMissingException
Constructs and initializes a LagoonProcessor.

Parameters:
targetURL - where to put the generated files, must be an absolute URL or a local file path
sitemapTree - the Sitemap as an XTree
sourceDir - where the source files are
password - password to access the target storage, or null if not nessesary.
log - where to write progress messages.
err - where to write error messages.
Throws:
java.io.IOException
LagoonException
AuthenticationException
AuthenticationMissingException
Method Detail

build

public boolean build(boolean force)
              throws java.io.IOException
Perform the building of the website. May be invoked multiple times. Synchronous, returns when the building is complete.

Parameters:
force - force a rebuild of all files, otherwise dependency checking is used to check which files that needs rebuilding.
Returns:
true if successful, false if any non-fatal error occured
Throws:
java.io.IOException - if any fatal error occur

destroy

public void destroy()
             throws java.io.IOException
Dispose this object and release any resources it holds. This causes the FileStorage to be closed.

Throws:
java.io.IOException

getTempDir

public java.io.File getTempDir()
Description copied from interface: LagoonContext
Get the temp directory.

Specified by:
getTempDir in interface LagoonContext

readFileFromRepository

public java.io.InputStream readFileFromRepository(java.lang.String key)
Description copied from interface: LagoonContext
Read from a file in the repository. Read from the returned InputStream and close() it.

Specified by:
readFileFromRepository in interface LagoonContext
Parameters:
key - the key to locate the file
Returns:
an InputStream to read the file from, or null if the file wasn't found.

storeFileInRepository

public java.io.OutputStream storeFileInRepository(java.lang.String key)
                                           throws java.io.IOException
Description copied from interface: LagoonContext
Store a file in the repository. Write to the returned OutputStream and close() it.

Specified by:
storeFileInRepository in interface LagoonContext
Parameters:
key - the key to locate the file
Returns:
an OutputStream to write to the file, or null if the repository is unavailable.
Throws:
java.io.IOException

loadClassFromRepository

public java.lang.Class loadClassFromRepository(java.lang.String className)
                                        throws java.lang.ClassNotFoundException
Description copied from interface: LagoonContext
Load a Java class file from the repository.

Specified by:
loadClassFromRepository in interface LagoonContext
Parameters:
className - the class name, no package
Returns:
the Class, never null
Throws:
java.lang.ClassNotFoundException - if the class cannot be loaded

storeClassInRepository

public java.io.OutputStream storeClassInRepository(java.lang.String className)
                                            throws java.io.IOException
Description copied from interface: LagoonContext
Store a Java class file in the repository. Write to the returned OutputStream and close() it.

Specified by:
storeClassInRepository in interface LagoonContext
Parameters:
className - the class name, no package
Returns:
an OutputStream to write to the class, or null if the repository is unavailable.
Throws:
java.io.IOException

deleteClassInRepository

public void deleteClassInRepository(java.lang.String className)
                             throws java.io.IOException
Description copied from interface: LagoonContext
Delete a Java class file from the repository.

Specified by:
deleteClassInRepository in interface LagoonContext
Parameters:
className - the class name, no package
Throws:
java.io.IOException

reloadClasses

public void reloadClasses()
Description copied from interface: LagoonContext
Reload classes.

Specified by:
reloadClasses in interface LagoonContext

getObjectFromRepository

public java.lang.Object getObjectFromRepository(java.lang.String key)
                                         throws java.io.IOException
Description copied from interface: LagoonContext
Get an object from the repository.

Specified by:
getObjectFromRepository in interface LagoonContext
Parameters:
key - the key to locate the object
Returns:
the object, or null if not found
Throws:
java.io.IOException

putObjectIntoRepository

public boolean putObjectIntoRepository(java.lang.String key,
                                       java.lang.Object obj)
                                throws java.io.IOException
Description copied from interface: LagoonContext
Store an object into the repository.

Specified by:
putObjectIntoRepository in interface LagoonContext
Parameters:
key - the key to locate the object
obj - the object to store, must be Serializable
Returns:
true if successful, false if the repository is unavailable.
Throws:
java.io.IOException

canCheckFileHasBeenUpdated

public boolean canCheckFileHasBeenUpdated(java.lang.String url)
Description copied from interface: LagoonContext
Tell whether the given source can be checked for dependency.

Specified by:
canCheckFileHasBeenUpdated in interface LagoonContext
Parameters:
url - URL to the file

getSourceRootDir

public java.io.File getSourceRootDir()
Description copied from interface: LagoonContext
Get an absolute File object representing the source root directory.

Specified by:
getSourceRootDir in interface LagoonContext

getFileURLRelativeTo

public java.lang.String getFileURLRelativeTo(java.lang.String url,
                                             java.lang.String base)
Description copied from interface: LagoonContext
Get an URL representing the given file or directory.

Specified by:
getFileURLRelativeTo in interface LagoonContext
Parameters:
url - URL to the file, if relative it's searched for relative to the base parameter.
base - base URL, must be pseudo-absolute
Returns:
an absolute or pseudo-absolute URL (the url parameter unchanged unless it's relative)

getProperty

public java.lang.String getProperty(java.lang.String key)
Description copied from interface: LagoonContext
Return the value of a project property.

Specified by:
getProperty in interface LagoonContext
Parameters:
key - the property name
Returns:
the property value, or null if the property is not defined.