Package org.glassfish.appclient.common
Class Util
- java.lang.Object
-
- org.glassfish.appclient.common.Util
-
public class Util extends Object
Implements several stateless utility methods.- Author:
- tjquinn
-
-
Constructor Summary
Constructors Constructor Description Util()
Creates a new instance of Util
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static File
copyToTempFile(File inputFile, String prefix, String suffix, boolean retainFile)
Copy an existing file into a temporary file.static String
getMainClassNameForAppClient(ModuleDescriptor moduleDescr)
Returns the main class name for the app client represented by the module descriptor.static String
loadResource(Class contextClass, String resourcePath)
Retrieves a resource as a String.static URL
locateClass(Class target)
Finds the jar file or directory that contains the current class and returns its URI.static String
replaceTokens(String s, Properties values)
Searches for placeholders of the form ${token-name} in the input String, retrieves the property with name token-name from the Properties object, and (if found) replaces the token in the input string with the property value.static String
URLtoCodeBase(URL classPathElement)
Returns a codeBase expression, usable in a policy file, for the specified URL.static File
writeTextToTempFile(String content, String prefix, String suffix)
Writes the provided text to a temporary file marked for deletion on exit.static File
writeTextToTempFile(String content, String prefix, String suffix, boolean retainFile)
Writes the provided text to a temporary file marked for deletion on exit.
-
-
-
Method Detail
-
replaceTokens
public static String replaceTokens(String s, Properties values)
Searches for placeholders of the form ${token-name} in the input String, retrieves the property with name token-name from the Properties object, and (if found) replaces the token in the input string with the property value.- Parameters:
s
- String possibly containing tokensvalues
- Properties object containing name/value pairs for substitution- Returns:
- the original string with tokens substituted using their values from the Properties object
-
getMainClassNameForAppClient
public static String getMainClassNameForAppClient(ModuleDescriptor moduleDescr) throws IOException, FileNotFoundException, SAXParseException
Returns the main class name for the app client represented by the module descriptor.- Parameters:
moduleDescr
- the module descriptor for the app client of interest- Returns:
- main class name of the app client
- Throws:
IOException
FileNotFoundException
SAXParseException
-
writeTextToTempFile
public static File writeTextToTempFile(String content, String prefix, String suffix, boolean retainFile) throws IOException, FileNotFoundException
Writes the provided text to a temporary file marked for deletion on exit.- Parameters:
content
- the content to be writtenprefix
- prefix for the temp file, conforming to the File.createTempFile requirementssuffix
- suffix for the temp fileretainFile
- whether to keep the file- Returns:
- File object for the newly-created temp file
- Throws:
IOException
- for any errors writing the temporary fileFileNotFoundException
- if the temp file cannot be opened for any reason
-
writeTextToTempFile
public static File writeTextToTempFile(String content, String prefix, String suffix) throws IOException, FileNotFoundException
Writes the provided text to a temporary file marked for deletion on exit.- Parameters:
content
- the content to be writtenprefix
- for the temp file, conforming to the File.createTempFile requirementssuffix
- for the temp file- Returns:
- File object for the newly-created temp file
- Throws:
IOException
- for any errors writing the temporary fileFileNotFoundException
- if the temp file cannot be opened for any reason
-
locateClass
public static URL locateClass(Class target)
Finds the jar file or directory that contains the current class and returns its URI.- Parameters:
target
- the class, the containing jar file or directory of which is of interest- Returns:
- URL to the containing jar file or directory
-
loadResource
public static String loadResource(Class contextClass, String resourcePath) throws IOException
Retrieves a resource as a String.This method does not save the template in a cache. Use the instance method getTemplate for that purpose.
- Parameters:
contextClass
- a class, the class loader of which should be used for searching for the templateresourcePath
- the path of the resource to load, relative to the contextClass- Returns:
- the resource's contents
- Throws:
IOException
- if the resource is not found or in case of error while loading it
-
copyToTempFile
public static File copyToTempFile(File inputFile, String prefix, String suffix, boolean retainFile) throws IOException, FileNotFoundException
Copy an existing file into a temporary file.- Parameters:
inputFile
- existing file- Returns:
- File object for the temporary file
- Throws:
IOException
FileNotFoundException
-
URLtoCodeBase
public static String URLtoCodeBase(URL classPathElement) throws FileNotFoundException, URISyntaxException
Returns a codeBase expression, usable in a policy file, for the specified URL.- Parameters:
classPathElement
- the URL to be converted- Returns:
- the codeBase expression
- Throws:
FileNotFoundException
URISyntaxException
-
-