RbUtils 0.13

org.ktc.rbutils.rb.check
Class FileChecker

java.lang.Object
  extended by org.ktc.rbutils.api.i18n.AbstractLocalized
      extended by org.ktc.rbutils.api.audit.AbstractProcessor
          extended by org.ktc.rbutils.api.audit.AbstractFileProcessor
              extended by org.ktc.rbutils.rb.check.FileChecker
All Implemented Interfaces:
FileProcessor, Processor, Localized

public class FileChecker
extends AbstractFileProcessor

Check a properties file against a ResourceBundle.

Since:
RbUtils 0.1.0
Version:
$Revision: 1.5 $
Author:
redfish, ktcguru

Field Summary
protected  PropertiesRB propertiesRB
          The properties source file.
protected  ResourceBundle rbFile
          The RB class file to be inspected.
protected  List rbKeys
          List of keys in the resourcebundle.
 
Fields inherited from class org.ktc.rbutils.api.audit.AbstractFileProcessor
className, fileLocale, fileName
 
Fields inherited from class org.ktc.rbutils.api.audit.AbstractProcessor
loggers
 
Fields inherited from class org.ktc.rbutils.api.i18n.AbstractLocalized
classResource
 
Constructor Summary
FileChecker(File root, File rbSrcFile)
          Instanciates a new FileChecker.
 
Method Summary
protected  boolean acceptKey(String key)
          Tests whether or not the specified key should be checked.
protected  void checkIfValuesInSync(String key)
          Checks if value in rb and properties are in sync.
protected  boolean checkIsRbMissing()
          Checks if the ResourceBundle relying on the properties file exists.
protected  boolean checkLocalesInSync()
          Checks if the Locale of the properties and the rb are in sync.
protected  void checkUnreachedRbKeys()
          Checks that all keys in the resourcebundle have been reached during the check.
protected  String getFormattedPropsValue(String key)
          Returns the formatted value of this key in the properties.
protected  String getFormattedRbKey(String key)
          Formats a key into another one whichwill be used to get the corresponding value in the rb file.
protected  String getFormattedRbValue(String key)
          Returns the formatted value of the formatted value of this key in the rb.
protected  ResourceBundle loadBundle()
          Loads the ResourceBundle relying on the properties file and stores it in the rbfile field.
 void performCheck()
          Performs the check of properties file.
 
Methods inherited from class org.ktc.rbutils.api.audit.AbstractFileProcessor
fireError, fireInformation, fireProcessFileEnded, fireProcessFileStarted
 
Methods inherited from class org.ktc.rbutils.api.audit.AbstractProcessor
addLogger, addLoggers, fireException
 
Methods inherited from class org.ktc.rbutils.api.i18n.AbstractLocalized
getMessage
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.ktc.rbutils.api.audit.Processor
addLogger, addLoggers, fireException
 

Field Detail

propertiesRB

protected PropertiesRB propertiesRB
The properties source file.


rbFile

protected ResourceBundle rbFile
The RB class file to be inspected.


rbKeys

protected final List rbKeys
List of keys in the resourcebundle. This list will be used to check if keys are not reached during the check.

Since:
RbUtils 0.9.3.3
Constructor Detail

FileChecker

public FileChecker(File root,
                   File rbSrcFile)
            throws IOException
Instanciates a new FileChecker.

Parameters:
root - the root directory of the properties file.
rbSrcFile - the properties file used for the check.
Throws:
NullArgumentException - if a parameter is null.
FileNotFoundException - if a parameter is a File that does not exist in the filesystem.
NotDirectoryException - if root is not a directory in the filesystem.
NotFileException - if rbSrcFile is not a file in the filesystem.
IOException - if problems occured on Properties file load.
Method Detail

performCheck

public void performCheck()
Performs the check of properties file.

First, we look if a ResourceBundle is found in the classpath. If so, we check all keys of the properties file to check synchronization with the ResourceBundle.
Errors are reported via the registered loggers.


loadBundle

protected ResourceBundle loadBundle()
Loads the ResourceBundle relying on the properties file and stores it in the rbfile field.
Also initialized the rbKeys field.

This must be the first step before launching checks.

Returns:
the loaded bundle.
Throws:
MissingResourceException - if the bundle cannot be loaded.
Since:
RbUtils 0.9.3.3

checkIsRbMissing

protected boolean checkIsRbMissing()
Checks if the ResourceBundle relying on the properties file exists.

First, tries to load the bundle using loadBundle(). If the load fails, the method fire errors to all listeners and returns true. Returns false otherwise.

Returns:
true is the ResourceBundle cannot be loaded; false otherwise.
Since:
RbUtils 0.9.3.3

checkLocalesInSync

protected boolean checkLocalesInSync()
Checks if the Locale of the properties and the rb are in sync.

First, check the locales; if they are not in sync, fire errors to all listeners and returns false.
In this implementation, tests if the RB and properties Locale are the same.

Returns:
true is the RB and the properties file have the same Locale; false otherwise.
Since:
RbUtils 0.9.3.3

acceptKey

protected boolean acceptKey(String key)
Tests whether or not the specified key should be checked.

Parameters:
key - the key to be tested.
Returns:
always true in this implementation.
Since:
RbUtils 0.9.3.3

getFormattedRbKey

protected String getFormattedRbKey(String key)
Formats a key into another one whichwill be used to get the corresponding value in the rb file.

Parameters:
key - the key to be formatted.
Returns:
the intial key in this implementation.
Since:
RbUtils 0.9.3.3

getFormattedPropsValue

protected String getFormattedPropsValue(String key)
Returns the formatted value of this key in the properties.

Parameters:
key - key used to get the formatted value.
Returns:
in this implementation, the value of this key in the properties.
Since:
RbUtils 0.9.3.3

getFormattedRbValue

protected String getFormattedRbValue(String key)
Returns the formatted value of the formatted value of this key in the rb.

Parameters:
key - key used to get the formatted value.
Returns:
in this implementation, the value of this key in the rb.
Since:
RbUtils 0.9.3.3

checkIfValuesInSync

protected void checkIfValuesInSync(String key)
Checks if value in rb and properties are in sync.

This method should not be overriden. Overrides the utility key an value methods instead.

Parameters:
key - the key to be checked.
Since:
RbUtils 0.9.3.3

checkUnreachedRbKeys

protected void checkUnreachedRbKeys()
Checks that all keys in the resourcebundle have been reached during the check.
Fire an error to logger for each unreached key.

Since:
RbUtils 0.9.3.3

Back to the RbUtils Home Page

Copyright © 2005-2009 RbUtils Project. All Rights Reserved.