org.openmrs.module
Class ModuleUtil

java.lang.Object
  extended by org.openmrs.module.ModuleUtil

public class ModuleUtil
extends java.lang.Object

Utility methods for working and manipulating modules


Constructor Summary
ModuleUtil()
           
 
Method Summary
static java.lang.Boolean allowAdmin()
           
static java.lang.Boolean checkForModuleUpdates()
          Iterates over the modules and checks each update.rdf file for an update
protected static void checkMandatoryModulesStarted()
          Looks at the .mandatory properties and at the currently started modules to make sure that all mandatory modules have been started successfully.
protected static void checkOpenmrsCoreModulesStarted()
          Looks at the list of modules in ModuleConstants.CORE_MODULES to make sure that all modules that are core to OpenMRS are started and have at least a minimum version that OpenMRS needs.
static void checkRequiredVersion(java.lang.String version, java.lang.String value)
          This method is an enhancement of compareVersion(String, String) and adds support for wildcard characters and upperbounds.
static int compareVersion(java.lang.String version, java.lang.String value)
          Compares version to value version and value are strings like w.x.y.z Returns 0 if either version or value is null.
static void expandJar(java.io.File fileToExpand, java.io.File tmpModuleDir, java.lang.String name, boolean keepFullPath)
          Expand the given fileToExpand jar to the tmpModuleFile directory If name is null, the entire jar is expanded.
static java.net.URL file2url(java.io.File file)
          Utility method to convert a File object to a local URL.
static java.util.List<java.lang.String> getMandatoryModules()
          Returns all modules that are marked as mandatory.
static Module getModuleForPath(java.lang.String path)
           Gets the module that should handle a path.
static java.io.File getModuleRepository()
          Gets the folder where modules are stored.
static java.util.Collection<java.lang.String> getPackagesFromFile(java.io.File file)
          This loops over all FILES in this jar to get the package names.
static java.lang.String getPathForResource(Module module, java.lang.String path)
          Takes a global path and returns the local path within the specified module.
static java.lang.String getURL(java.net.URL url)
          Downloads the contents of a URL and copies them to a string (Borrowed from oreilly)
static java.io.InputStream getURLStream(java.net.URL url)
          Downloads the contents of a URL and copies them to a string (Borrowed from oreilly)
static boolean ignoreCoreModules()
          Uses the runtime properties to determine if the core modules should be enforced or not.
static java.io.File insertModuleFile(java.io.InputStream inputStream, java.lang.String filename)
          Add the inputStream as a file in the modules repository
static boolean matchRequiredVersions(java.lang.String version, java.lang.String value)
          This method is an enhancement of compareVersion(String, String) and adds support for wildcard characters and upperbounds.
protected static java.io.InputStream openConnectionCheckRedirects(java.net.URLConnection c)
          Convenience method to follow http to https redirects.
static org.springframework.context.support.AbstractRefreshableApplicationContext refreshApplicationContext(org.springframework.context.support.AbstractRefreshableApplicationContext ctx)
           
static org.springframework.context.support.AbstractRefreshableApplicationContext refreshApplicationContext(org.springframework.context.support.AbstractRefreshableApplicationContext ctx, boolean isOpenmrsStartup, Module startedModule)
          Refreshes the given application context "properly" in OpenMRS.
static void shutdown()
          Stops the module system by calling stopModule for all modules that are currently started
static void startup(java.util.Properties props)
          Start up the module system with the given properties.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ModuleUtil

public ModuleUtil()
Method Detail

startup

public static void startup(java.util.Properties props)
                    throws ModuleMustStartException,
                           OpenmrsCoreModuleException
Start up the module system with the given properties.

Parameters:
props - Properties (OpenMRS runtime properties)
Throws:
ModuleMustStartException
OpenmrsCoreModuleException

shutdown

public static void shutdown()
Stops the module system by calling stopModule for all modules that are currently started


insertModuleFile

public static java.io.File insertModuleFile(java.io.InputStream inputStream,
                                            java.lang.String filename)
Add the inputStream as a file in the modules repository

Parameters:
inputStream - InputStream to load
Returns:
filename String of the file's name of the stream

matchRequiredVersions

public static boolean matchRequiredVersions(java.lang.String version,
                                            java.lang.String value)
This method is an enhancement of compareVersion(String, String) and adds support for wildcard characters and upperbounds.

This method calls checkRequiredVersion(String, String) internally.

The require version number in the config file can be in the following format:

Parameters:
version - openmrs version number to be compared
value - value in the config file for required openmrs version
Returns:
true if the version is within the value
Expected behavior:
allow ranged required version, allow ranged required version with wild card, allow ranged required version with wild card on one end, allow single entry for required version, allow required version with wild card, allow non numeric character required version, allow ranged non numeric character required version, allow ranged non numeric character with wild card, allow ranged non numeric character with wild card on one end, return false when openmrs version beyond wild card range, return false when required version beyond openmrs version, return false when required version with wild card beyond openmrs version, return false when required version with wild card on one end beyond openmrs version, return false when single entry required version beyond openmrs version, allow release type in the version

checkRequiredVersion

public static void checkRequiredVersion(java.lang.String version,
                                        java.lang.String value)
                                 throws ModuleException
This method is an enhancement of compareVersion(String, String) and adds support for wildcard characters and upperbounds.


The require version number in the config file can be in the following format:

Parameters:
version - openmrs version number to be compared
value - value in the config file for required openmrs version
Throws:
ModuleException - if the version is not within the value
Expected behavior:
throw ModuleException if openmrs version beyond wild card range, throw ModuleException if required version beyond openmrs version, throw ModuleException if required version with wild card beyond openmrs version, throw ModuleException if required version with wild card on one end beyond openmrs version, throw ModuleException if single entry required version beyond openmrs version

compareVersion

public static int compareVersion(java.lang.String version,
                                 java.lang.String value)
Compares version to value version and value are strings like w.x.y.z Returns 0 if either version or value is null.

Parameters:
version - String like w.x.y.z
value - String like w.x.y.z
Returns:
the value 0 if version is equal to the argument value; a value less than 0 if version is numerically less than the argument value; and a value greater than 0 if version is numerically greater than the argument value

getModuleRepository

public static java.io.File getModuleRepository()
Gets the folder where modules are stored. ModuleExceptions are thrown on errors

Returns:
folder containing modules

file2url

public static java.net.URL file2url(java.io.File file)
                             throws java.net.MalformedURLException
Utility method to convert a File object to a local URL.

Parameters:
file - a file object
Returns:
absolute URL that points to the given file
Throws:
java.net.MalformedURLException - if file can't be represented as URL for some reason

expandJar

public static void expandJar(java.io.File fileToExpand,
                             java.io.File tmpModuleDir,
                             java.lang.String name,
                             boolean keepFullPath)
                      throws java.io.IOException
Expand the given fileToExpand jar to the tmpModuleFile directory If name is null, the entire jar is expanded. Ifname is not null, then only that path/file is expanded.

Parameters:
fileToExpand - file pointing at a .jar
tmpModuleDir - directory in which to place the files
name - filename inside of the jar to look for and expand
keepFullPath - if true, will recreate entire directory structure in tmpModuleDir relating to name. if false will start directory structure at name
Throws:
java.io.IOException

getURLStream

public static java.io.InputStream getURLStream(java.net.URL url)
Downloads the contents of a URL and copies them to a string (Borrowed from oreilly)

Parameters:
url -
Returns:
InputStream of contents
Expected behavior:
return a valid input stream for old module urls

openConnectionCheckRedirects

protected static java.io.InputStream openConnectionCheckRedirects(java.net.URLConnection c)
                                                           throws java.io.IOException
Convenience method to follow http to https redirects. Will follow a total of 5 redirects, then fail out due to foolishness on the url's part.

Parameters:
c - the URLConnection to open
Returns:
an InputStream that is not necessarily at the same url, possibly at a 403 redirect.
Throws:
java.io.IOException
See Also:
#getURLStream(URL)}

getURL

public static java.lang.String getURL(java.net.URL url)
Downloads the contents of a URL and copies them to a string (Borrowed from oreilly)

Parameters:
url -
Returns:
String contents of the URL
Expected behavior:
return an update rdf page for old https dev urls, return an update rdf page for old https module urls, return an update rdf page for module urls

checkForModuleUpdates

public static java.lang.Boolean checkForModuleUpdates()
                                               throws ModuleException
Iterates over the modules and checks each update.rdf file for an update

Returns:
True if an update was found for one of the modules, false if none were found
Throws:
ModuleException

allowAdmin

public static java.lang.Boolean allowAdmin()
Returns:
true/false whether the 'allow upload' or 'allow web admin' property has been turned on

refreshApplicationContext

public static org.springframework.context.support.AbstractRefreshableApplicationContext refreshApplicationContext(org.springframework.context.support.AbstractRefreshableApplicationContext ctx)
See Also:
ModuleUtil#refreshApplicationContext(AbstractRefreshableApplicationContext, Module)

refreshApplicationContext

public static org.springframework.context.support.AbstractRefreshableApplicationContext refreshApplicationContext(org.springframework.context.support.AbstractRefreshableApplicationContext ctx,
                                                                                                                  boolean isOpenmrsStartup,
                                                                                                                  Module startedModule)
Refreshes the given application context "properly" in OpenMRS. Will first shut down the Context and destroy the classloader, then will refresh and set everything back up again.

Parameters:
ctx - Spring application context that needs refreshing.
isOpenmrsStartup - if this refresh is being done at application startup.
startedModule - the module that was just started and waiting on the context refresh.
Returns:
AbstractRefreshableApplicationContext The newly refreshed application context.

checkMandatoryModulesStarted

protected static void checkMandatoryModulesStarted()
                                            throws ModuleException
Looks at the .mandatory properties and at the currently started modules to make sure that all mandatory modules have been started successfully.

Throws:
ModuleException - if a mandatory module isn't started
Expected behavior:
throw ModuleException if a mandatory module is not started

checkOpenmrsCoreModulesStarted

protected static void checkOpenmrsCoreModulesStarted()
                                              throws OpenmrsCoreModuleException
Looks at the list of modules in ModuleConstants.CORE_MODULES to make sure that all modules that are core to OpenMRS are started and have at least a minimum version that OpenMRS needs.

Throws:
ModuleException - if a module that is core to OpenMRS is not started
OpenmrsCoreModuleException
Expected behavior:
throw ModuleException if a core module is not started

ignoreCoreModules

public static boolean ignoreCoreModules()
Uses the runtime properties to determine if the core modules should be enforced or not.

Returns:
true if the core modules list can be ignored.

getMandatoryModules

public static java.util.List<java.lang.String> getMandatoryModules()
Returns all modules that are marked as mandatory. Currently this means there is a .mandatory=true global property.

Returns:
list of modules ids for mandatory modules
Expected behavior:
return mandatory module ids

getPackagesFromFile

public static java.util.Collection<java.lang.String> getPackagesFromFile(java.io.File file)
This loops over all FILES in this jar to get the package names. If there is an empty directory in this jar it is not returned as a providedPackage.

Parameters:
file - jar file to look into
Returns:
list of strings of package names in this jar

getModuleForPath

public static Module getModuleForPath(java.lang.String path)
 Gets the module that should handle a path. The path you pass in should be a module id (in
 path format, i.e. /ui/springmvc, not ui.springmvc) followed by a resource. Something like
 the following:
   /ui/springmvc/css/ui.css
   
 The first running module out of the following would be returned:
   ui.springmvc.css
   ui.springmvc
   ui
 

Parameters:
path -
Returns:
the running module that matches the most of the given path
Expected behavior:
handle ui springmvc css ui dot css when ui dot springmvc module is running, handle ui springmvc css ui dot css when ui module is running, return null for ui springmvc css ui dot css when no relevant module is running

getPathForResource

public static java.lang.String getPathForResource(Module module,
                                                  java.lang.String path)
Takes a global path and returns the local path within the specified module. For example calling this method with the path "/ui/springmvc/css/ui.css" and the ui.springmvc module, you would get "/css/ui.css".

Parameters:
module -
path -
Returns:
Expected behavior:
handle ui springmvc css ui dot css example

OpenMRS-1.7.x

Generated Apr 27 2012 10:06 PM. NOTE - these libraries are in active development and subject to change