String localeSuffix = "_" + CdfEngine.getEnvironment().getLocale().getLanguage();
targetDashboardBaseMsgFile = !targetDashboardBaseMsgFile.endsWith( localeSuffix ) ?
targetDashboardBaseMsgFile + localeSuffix : targetDashboardBaseMsgFile;
IBasicFile fBaseMsgGlobal = getSystemReader().fetchFile(
globalBaseMessageFile + "_" + CdfEngine.getEnvironment().getLocale().getLanguage() + ".properties" );
String theLine;
if ( !getSystemReader().fileExists( targetDashboardBaseMsgFile + ".properties" ) ) {
File tempMessageFile = null;
String locale = CdfEngine.getEnvironment().getLocale().getLanguage();
try {
// we append the content of global and base message files here,
// then we write the end result to targetDashboardBaseMsgFile
String tempMessageFileName = System.getProperty( "java.io.tmpdir" ) + "tempMessageFile_" + System.currentTimeMillis();
tempMessageFile = new File( tempMessageFileName );
BufferedWriter bwTempBaseMsgTarget = new BufferedWriter( new FileWriter( tempMessageFile, true ) );
// If localized global message file doesn't exists then use the standard base global message file
// and generate a fake global message file. So this way we're sure that we always have the file
String globalBaseMessageFileName = globalBaseMessageFile + "_" + locale + ".properties";
if ( !getSystemReader().fileExists( globalBaseMessageFileName ) ) {
InputStream content = new ByteArrayInputStream( StringUtils.EMPTY.getBytes() );
if( getSystemReader().fileExists( globalBaseMessageFile + ".properties" ) ){
content = getSystemReader().fetchFile( globalBaseMessageFile + ".properties" ).getContents();
}
getSystemWriter().saveFile( globalBaseMessageFileName, content );
fBaseMsgGlobal = getSystemReader().fetchFile( globalBaseMessageFileName );
}
BufferedReader brBaseMsgGlobal = new BufferedReader( new InputStreamReader( fBaseMsgGlobal.getContents() ) );
while ( ( theLine = brBaseMsgGlobal.readLine() ) != null ) {
bwTempBaseMsgTarget.write( theLine + "\n" );
}
brBaseMsgGlobal.close();
// Append specific message file only if it exists otherwise just use the global message files
if ( !StringUtils.isEmpty( sourceDashboardBaseMsgFile ) ) {
IBasicFile msgFile = null;
if ( getUserContentReader().fileExists( sourceDashboardBaseMsgFile + "_" + locale + ".properties" ) ) {
// a local Messages_<locale>.properties exists
msgFile = getUserContentReader().fetchFile( sourceDashboardBaseMsgFile + "_" + locale + ".properties" );
} else if( getUserContentReader().fileExists( sourceDashboardBaseMsgFile + ".properties" ) ) {
// a local Messages_<locale>.properties does not exist, but a local Messages.properties does
msgFile = getUserContentReader().fetchFile( sourceDashboardBaseMsgFile + ".properties" );
}
if( msgFile != null && msgFile.getContents() != null ){
BufferedReader brBaseMsgDashboard = new BufferedReader( new InputStreamReader( msgFile.getContents() ) );
while ( ( theLine = brBaseMsgDashboard.readLine() ) != null ) {
bwTempBaseMsgTarget.write( theLine + "\n" );
}
brBaseMsgDashboard.close();
}