2.17.2: 2011-06-17

net.sf.basedb.clients.web.extensions
Class ExtensionsDirectory

java.lang.Object
  extended by net.sf.basedb.clients.web.extensions.ExtensionsDirectory

public class ExtensionsDirectory
extends Object

Represents a directory with extensions. This class can automatically detect changes and install, update or uninstall extensions when files are added, changed or removed from the specified directory. Resources, such as images, JSP files, etc. are automatically extracted from JAR files and placed in the resources directory, which is a directory that should be accessible from the web server.

Version:
2.7
Author:
nicklas
Last modified
$Date:2008-03-20 12:15:25 +0100 (Thu, 20 Mar 2008) $

Field Summary
private  File extensionsDir
           
private  Set<File> ignore
           
private  Map<String,ExtensionsFile> installedExtensions
           
private  Map<File,ExtensionsFile> installedFiles
           
private static Logger log
           
private  PathConverter pathConverter
           
private  File resourcesDir
           
private  String resourcesUrl
           
private  String rootUrl
           
private  Set<File> staticIgnore
           
private  VariableConverter variableConverter
           
 
Constructor Summary
ExtensionsDirectory(File extensionsDir, File resourcesDir, String rootUrl, String resourcesUrl)
           
 
Method Summary
 void addIgnore(File file)
          Add a file to the ignore list.
(package private)  void addRegistered(String id, ExtensionsFile file)
           
private  XmlLoader createXmlLoader()
          Creates a new XmlLoader and registers the variableConverter and pathConverter with it.
private  void extractResources(boolean forceUpdate, ScanResults results)
          Extract resources from JAR files.
 File getExtensionDirectory()
          Get the file object representing the directory where extensions are installed.
 ExtensionsFile getFile(String filename)
          Get information about an installed extensions file.
(package private)  ExtensionsFile getFileByExtensionId(String extensionId)
          Get information about the file a given extension or extension point is defined in.
 Iterator<ExtensionsFile> getFiles()
          Get an iterator returning all XML/JAR files which contains installed extensions.
(package private)  List<String> getRegistered(ExtensionsFile file)
           
 File getResourcesDirectory()
          Get the file object representing the directory where resource files are extracted.
 String getResourcesUrl()
          Get the URL that points to the resources directory when accessed through the web server.
 String getResourcesUrl(ExtensionsFile extFile)
          Get the URL that points to the resources directory for a specific extensions file when accessed through the web server.
 String getRootUrl()
          Get the URL that points to the root directory when accessed through the web server.
 String getServletsUrl(ExtensionsFile extFile)
          Get the URL that points to the servlet directory for a specific extensions file when accessed through the web server.
(package private)  ScanResults installAndUpdateExtensions(Registry registry, ServletContext servletContext, boolean manualScan, boolean forceUpdate)
          Scan the directory for new/modified/deleted extension files and perform neccesary changed in the registry.
private  void loadDefinitions(boolean forceUpdate, ScanResults results)
          Load the extension definitions from XML files.
private  void loadServlets(ServletContext servletContext, boolean forceUpdate, ScanResults results)
          Load servlet definitions from JAR files.
private  void registerExtensions(Registry registry, boolean forceUpdate, ScanResults results)
          Register extensions with the registry.
 void removeIgnore(File file)
          Remove a file from the ignore list.
(package private)  void removeRegistered(String id, ExtensionsFile file)
           
private  void resetIgnore()
          Clears all files that has been added to the ignore set.
private  int[] scanForNewAndUpdated(boolean forceUpdate, ScanResults results)
          Scan for new extensions.
private  int unregisterDeleted(Registry registry, ScanResults results)
          Unregister extensions/extension points that no longer exists.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

log

private static final Logger log

extensionsDir

private final File extensionsDir

resourcesDir

private final File resourcesDir

resourcesUrl

private final String resourcesUrl

rootUrl

private final String rootUrl

installedFiles

private final Map<File,ExtensionsFile> installedFiles

installedExtensions

private final Map<String,ExtensionsFile> installedExtensions

staticIgnore

private final Set<File> staticIgnore

ignore

private final Set<File> ignore

variableConverter

private final VariableConverter variableConverter

pathConverter

private final PathConverter pathConverter
Constructor Detail

ExtensionsDirectory

public ExtensionsDirectory(File extensionsDir,
                           File resourcesDir,
                           String rootUrl,
                           String resourcesUrl)
Method Detail

getExtensionDirectory

public File getExtensionDirectory()
Get the file object representing the directory where extensions are installed.

Returns:
A file object

getResourcesDirectory

public File getResourcesDirectory()
Get the file object representing the directory where resource files are extracted.

Returns:
A file object

getResourcesUrl

public String getResourcesUrl()
Get the URL that points to the resources directory when accessed through the web server. The URL only includes the local server path, not the server name. For example, /base2/resources

Returns:
The URL

getResourcesUrl

public String getResourcesUrl(ExtensionsFile extFile)
Get the URL that points to the resources directory for a specific extensions file when accessed through the web server. The URL only includes the local server path, not the server name. For example, /base2/resources/example-extensions.jar

Returns:
The URL

getServletsUrl

public String getServletsUrl(ExtensionsFile extFile)
Get the URL that points to the servlet directory for a specific extensions file when accessed through the web server. The URL only includes the local server path, not the server name. For example, /base2/extensions/servlet/example-extensions.jar

Returns:
The URL
Since:
2.13

getRootUrl

public String getRootUrl()
Get the URL that points to the root directory when accessed through the web server. The URL only includes the local server path, not the server name. For example, /base2

Returns:
The URL

addIgnore

public void addIgnore(File file)
Add a file to the ignore list. Files in this list will never be checked for extensions again. This is only neccessary for XML/JAR files that doesn't contain extensions.

Parameters:
file - The file to add
See Also:
removeIgnore(File)

removeIgnore

public void removeIgnore(File file)
Remove a file from the ignore list.

Parameters:
file - The file to remove
See Also:
addIgnore(File)

getFiles

public Iterator<ExtensionsFile> getFiles()
Get an iterator returning all XML/JAR files which contains installed extensions.


getFile

public ExtensionsFile getFile(String filename)
Get information about an installed extensions file.

Parameters:
filename - The filename of the file
Returns:
An ExtensionsFile object or null if the given file doesn't exists or isn't an extensions file

getFileByExtensionId

ExtensionsFile getFileByExtensionId(String extensionId)
Get information about the file a given extension or extension point is defined in.

Parameters:
extensionId - The ID of an extension or extension point
Returns:
Information about the file the extension is defined in, or null if no extension with the given ID is found

addRegistered

void addRegistered(String id,
                   ExtensionsFile file)

getRegistered

List<String> getRegistered(ExtensionsFile file)

removeRegistered

void removeRegistered(String id,
                      ExtensionsFile file)

installAndUpdateExtensions

ScanResults installAndUpdateExtensions(Registry registry,
                                       ServletContext servletContext,
                                       boolean manualScan,
                                       boolean forceUpdate)
Scan the directory for new/modified/deleted extension files and perform neccesary changed in the registry.

Parameters:
registry - The registry holding registered extension points and extensions
manualScan - TRUE if this is a manual scan, FALSE if it is an automatic
forceUpdate - TRUE to force an update of unmodified extensions, FALSE to leave them as they are
Returns:
The result of the scan

unregisterDeleted

private int unregisterDeleted(Registry registry,
                              ScanResults results)
Unregister extensions/extension points that no longer exists. This method will also delete extracted resources.


scanForNewAndUpdated

private int[] scanForNewAndUpdated(boolean forceUpdate,
                                   ScanResults results)
Scan for new extensions. This method checks in the extensions directory for *.xml and *.jar files. New files will be validated and added to the installedFiles map if valid or to the ignore set if not valid. Files already in the ignore set are not checked.

Returns:
[0] = num new; [1] = num updated; [2] = num forced update

loadDefinitions

private void loadDefinitions(boolean forceUpdate,
                             ScanResults results)
Load the extension definitions from XML files. Unless forceUpdate is TRUE only new or modified extensions will be loaded.


extractResources

private void extractResources(boolean forceUpdate,
                              ScanResults results)
Extract resources from JAR files. All files in /resources directory inside extension JAR files are extract to the home directory of the extension. Unless forceUpdate is TRUE only resources which has a different length or last modified time than already existing files on the disk will be extracted.


loadServlets

private void loadServlets(ServletContext servletContext,
                          boolean forceUpdate,
                          ScanResults results)
Load servlet definitions from JAR files. Servlets should be defined in META-INF/servlets.xml.


registerExtensions

private void registerExtensions(Registry registry,
                                boolean forceUpdate,
                                ScanResults results)
Register extensions with the registry. Unless forceUpdate is TRUE only new and modified extensions are registered. Extensions files that has the ExtensionsFile.hasError() flag set are automatically disabled.


createXmlLoader

private XmlLoader createXmlLoader()
Creates a new XmlLoader and registers the variableConverter and pathConverter with it.


resetIgnore

private void resetIgnore()
Clears all files that has been added to the ignore set. All files in staticIgnore are re-added.


2.17.2: 2011-06-17