Utility methods useful to various components of MJ.
Treat this class as "thread-safe", since as a utility class it has no (and should
not have) state after initialization.
Methods |
Parse string assumed to contain delimited, possibly quoted values into tokens.
Note that spaces surrounding a delimiter character is trimmed, so tokens
that include spaces should be quoted.
- Parameters:
anInput - string assumed to contain delimited, possibly quoted values.
aDelimiterCharset - one or more delimiter characters.
- Returns:
- list of delimited tokens.
public static java.util.List asDelimitedList(java.lang.String anInput, java.lang.String aDelimiterCharset)
|
Creates a resource as a Java source file on the file system.
- Parameters:
aRootDir - root of directory hierarchy where resource file is to be created.
aFullResourceName - name that includes package name and simple name (e.g., class name) parts,
per Java conventions (e.g., "com.arsi.test.MyClass").
aContent - content of resource to save to file.
- Throws:
MJTranslateException - if an I/O or other error occurs.
- Returns:
- file object that represents newly created resource on file system.
public static java.io.File createJavaSourceCodeResource(java.io.File aRootDir, java.lang.String aFullResourceName, java.lang.String aContent) throws com.arsi.mj.MJTranslateException
|
Creates resource as a file on the file system, where the naming of
the resource may require a package name.
- Parameters:
aRootDir - root of directory hierarchy where resource file is to be created.
aPackageName - package name of resource per Java conventions (e.g., "com.arsi.test.MyClass"),
which is treated as a hierarchy of sub-directories under aRootDir .
aResourceName - simple resource name which is treated as simple file name; if no suffix is
included, ".java" is added, treating resource a Java source file.
aContent - content of resource to save to file.
- Throws:
MJTranslateException - if an I/O or other error occurs.
- Returns:
- file object that represents newly created resource on file system.
public static java.io.File createResource(java.io.File aRootDir, java.lang.String aPackageName, java.lang.String aResourceName, java.lang.String aContent) throws com.arsi.mj.MJTranslateException
|
Escape special character in string with a backslash.
- Parameters:
anInputString - an input string that may contain occurrences of the specified character to be escaped.
aChar - the specified character to escape.
- Returns:
- a copy of the input string where occurrences of the specified character have been
prefixed by backslash escape character.
public static java.lang.String escapeChar(java.lang.String anInputString, char aChar)
|
Get first non-blank token in string before delimiting whitespace.
- Parameters:
aString - a string that may contain tokens delimited by whitespace.
- Returns:
- the first non-blank token delimited by whitespace or end-of-string, or NULL if none.
public static java.lang.String firstTokenBeforeWhitespace(java.lang.String aString)
|
Find the first pragma that has the specified pragma name in a list of pragmas.
- Parameters:
<T> - a pragma subclass.
aPragmaName - name of a valid pragma.
somePragmas - list of pragmas to search for the pragma name.
aClass - pragma class to cast result to.
- Returns:
- first pragma that matches pragma name, or NULL if none.
public static com.arsi.mj.maprpt.parser.pragma.Pragma matchFirstPragma(java.lang.String aPragmaName, java.util.List somePragmas, java.lang.Class aClass)
|
Read input into a string.
- Parameters:
aStream - input stream to read.
- Throws:
IOException - if an I/O occurs reading the input.
- Returns:
- a string containing the text read from the input.
public static java.lang.String readAsString(java.io.InputStream aStream) throws java.io.IOException
|
Bind values associated with template parameters into template.
- Parameters:
anInputString - an input string containing a code template.
someParamValues - name-value pairs where name is the template parameter (assumed to be delimited
by $, e.g., "$person$") and value is String to substitute for parameter.
- Returns:
- string where specified template parameters have been substituted.
public static java.lang.String templateBind(java.lang.String anInputString, java.util.List someParamValues)
|
Bind values associated with template parameters into template.
- Parameters:
anInputString - an input string containing a (partial) code template.
aParam - template parameter (assumed to be delimited by $, e.g., "$person$").
aValue - value is String to substitute for parameter.
- Returns:
- string where specified template parameters have been substituted.
public static java.lang.String templateBind(java.lang.String anInputString, java.lang.String aParam, java.lang.String aValue)
|
Indent each line except the first one in the input string.
- Parameters:
anInputString - the string containing one or more lines to be indented.
anIndent - the number of spaces to indent.
- Returns:
- the indented string.
public static java.lang.String templateIndent(java.lang.String anInputString, int anIndent)
|
Extract parameters identified by "$parameter$" notation in template, and
determine how much the parameter was indented. For example, in
"\n $substitute$\n", "substitute" is indented
five spaces (only whitespace exists between newline and parameter).
- Parameters:
anInputString - an input string containing a code template.
aTemplateId - the ID of the template for error reporting.
- Throws:
MJTranslateException - if an error occurs while extracting parameters from the template.
- Returns:
- list of
TemplateParam that contains the parameters in the template.
public static java.util.List templateParameters(java.lang.String anInputString, java.lang.String aTemplateId) throws com.arsi.mj.MJTranslateException
|
Trim indent from the beginning of each line in a string.
- Parameters:
anInputString - the input string containing lines to be "un-indented".
anIndent - the number of spaces to remove from the beginning of each line.
- Returns:
- the string with indent removed from lines.
public static java.lang.String templateUnindentLines(java.lang.String anInputString, int anIndent)
|
Removes leading spaces from a content string.
- Parameters:
aString - the content to clean up
- Returns:
- the input content without leading spaces
public static java.lang.String truncateLeadingSpaces(java.lang.String aString)
|
Removes leading and trailing spaces from a content string. Internal spaces are unaffected.
- Parameters:
aString - the content to clean up
- Returns:
- the input content without leading/trailing spaces
public static java.lang.String truncateSpaces(java.lang.String aString)
|
Removes trailing spaces from a content string.
- Parameters:
aString - the content to clean up
- Returns:
- the input content without trailing spaces
public static java.lang.String truncateTrailingSpaces(java.lang.String aString)
|
Format full "report-drawer-cabinet" Mapper report identifier suitable for display
to user, e.g., if cabinet=408, drawer='a' and reportNumber=12, returns "12A408".
- Parameters:
aCabinetNumber - number of cabinet of Mapper report.
aDrawerLetter - letter of drawer of Mapper report.
aReportNumber - number of Mapper report.
- Returns:
- the report identifier.
public static java.lang.String userRID(int aCabinetNumber, char aDrawerLetter, int aReportNumber)
|