|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.deegree_impl.model.resources.ResourceCompiler
Resources compiler. This class is run from the command-line at compile-time only.
ResourceCompiler
scan for .properties
files and copy their
content to .utf
files using UTF8 encoding. It also check for key validity
(making sure that the same set of keys is defined in every language) and change values
for MessageFormat
compatibility. Lastly, it create a ResourceKeys.java
source file declaring resource keys as integer constants.
ResourceCompiler
and all ResourceKeys
classes don't need to be
included in the final JAR file. They are used at compile-time only and no other classes
should keep reference to them.
Field Summary | |
private java.util.Map |
allocatedIDs
Integer IDs allocated to resource keys. |
private static java.lang.String |
ARGUMENT_COUNT_PREFIX
Prefix for argument count in resource key names. |
private static java.lang.String |
CLASS_NAME
The class name for the interfaces to be generated. |
private static java.lang.String[] |
ORDER
Special order for resource keys starting with the specified prefix. |
private static java.lang.String |
PREFIX
File name prefix for properties and resources files. |
private static java.lang.String |
PROPERTIES_EXT
Extension for properties files. |
private java.util.Map |
resources
Resources keys and their localized values. |
private static java.lang.String |
RESOURCES_EXT
Extension for resources files. |
Constructor Summary | |
private |
ResourceCompiler(java.io.File directory)
Construct a new ResourceCompiler . |
Method Summary | |
int |
compare(java.lang.Object o1,
java.lang.Object o2)
Compare two resource keys. |
private void |
loadPropertyFile(java.io.File file)
Load all properties from a .properties file. |
static void |
main(java.lang.String[] args)
Run the resources compilator. |
private static void |
scanForResources(java.io.File directory)
Scan the specified directory and all subdirectory for resources. |
private static java.lang.String |
toClassName(java.io.File file)
Returns the class name for the specified source file. |
private static java.lang.String |
toMessageFormatString(java.lang.String text)
Change a "normal" text string into a pattern compatible with MessageFormat .
|
private static java.lang.String |
toRelative(java.io.File path)
Make a file path relative to the classpath. |
private static java.io.File |
toSourceFile(java.lang.String classname)
Returns the source file for the specified class. |
private static void |
warning(java.io.File file,
java.lang.String key,
java.lang.String message,
java.lang.Exception exception)
Print a message to the error output stream System.err . |
private void |
writeJavaSource(java.io.File file)
Create a source file for resources keys. |
private static void |
writeMultiLines(java.io.BufferedWriter out,
java.lang.String text)
Write a multi-lines text to the specified output stream. |
private void |
writeUTFFile(java.io.File file)
Write UTF file. |
private static void |
writeWhiteSpaces(java.io.Writer out,
int count)
Write count spaces to the out stream. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Methods inherited from interface java.util.Comparator |
equals |
Field Detail |
private static final java.lang.String[] ORDER
private static final java.lang.String CLASS_NAME
private static final java.lang.String PREFIX
private static final java.lang.String PROPERTIES_EXT
private static final java.lang.String RESOURCES_EXT
private static final java.lang.String ARGUMENT_COUNT_PREFIX
private final java.util.Map allocatedIDs
<Integer,String>
entries.
private final java.util.Map resources
<String,String>
entries.
Constructor Detail |
private ResourceCompiler(java.io.File directory) throws java.io.IOException
ResourceCompiler
. This method will
immediately looks for a ResourceKeys.class
file. If
one is found, integer keys are loaded in order to reuse same values.
directory
- The resource directory. This directory should or
will contains the following input and output files:
resources*.properties
(mandatory input)ResourceKeys.class
(optional input)resources*.utf
(output)ResourceKeys.class
(output)java.io.IOException
- if an input/output operation failed.Method Detail |
private static void scanForResources(java.io.File directory) throws java.io.IOException
directory
- The root directory.
java.io.IOException
- if an input/output operation failed.private void loadPropertyFile(java.io.File file) throws java.io.IOException
.properties
file. Resource keys are
checked for naming convention (i.e. resources expecting some arguments must
have a key ending with "_$n" where "n" is the number of arguments). This
method transform resource values in legal MessageFormat
patterns
when necessary.
file
- Resource file to read.
java.io.IOException
- if an input/output operation failed.private void writeUTFFile(java.io.File file) throws java.io.IOException
loadPropertyFile(java.io.File)
should
be invoked before to writeUTFFile
.
file
- The destination file.
java.io.IOException
- if an input/output operation failed.private static java.io.File toSourceFile(java.lang.String classname)
private static java.lang.String toClassName(java.io.File file)
private static java.lang.String toRelative(java.io.File path) throws java.io.IOException
chdir
) or absolute. This method
find the canonical form of path
and compare it with
canonical forms of every paths in the class path. If a classpath
matchs the begining of path
, then the corresponding
part of path
is removed. If there is more than one
matches, the one resulting in the shortest relative path is choosen.
java.io.IOException
private static java.lang.String toMessageFormatString(java.lang.String text)
MessageFormat
.
The main operation consist in changing ' for '', except for '{' and '}' strings.
private static void warning(java.io.File file, java.lang.String key, java.lang.String message, java.lang.Exception exception)
System.err
.
file
- File that produced the error, or null
if none.key
- Resource key that produced the error, or null
if none.message
- The message string.exception
- An optional exception that is the cause of this warning.private static void writeWhiteSpaces(java.io.Writer out, int count) throws java.io.IOException
count
spaces to the out
stream.
java.io.IOException
- if an input/output operation failed.private static void writeMultiLines(java.io.BufferedWriter out, java.lang.String text) throws java.io.IOException
out
- The output stream.text
- The text to write.
java.io.IOException
- if an input/output operation failed.private void writeJavaSource(java.io.File file) throws java.io.IOException
file
- The destination file.
java.io.IOException
- if an input/output operation failed.public int compare(java.lang.Object o1, java.lang.Object o2)
o1
and o2
are usually String
objects representing resource keys (for
example "MISMATCHED_DIMENSION
"). This method compares
strings as of String.compareTo(java.lang.Object)
, except that string starting
with one of the prefix enumetated in ORDER
will appear last
in the sorted array.
compare
in interface java.util.Comparator
public static void main(java.lang.String[] args) throws java.io.IOException
args
- Command-line arguments.
java.io.IOException
- if an input/output operation failed.
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |