cancel
Showing results for 
Search instead for 
Did you mean: 

Reading and comparing name of the files in Mimes folder

Former Member
0 Kudos

Hi All

I have an application which supports internationalization.

This application has some HTML files in different languages and are displayed in a view in HTMLContainer. All these files are placed in mimes --> Components --> Application Package folder.

Logic used to retrieve the files is as below:

1. Get the user login language. Lets take the languages as A, B, C, ............

2.

If (language A)

{

Pick HTML_A file.

} else

If (language B)

{

Pick HTML_B file.

}

If (language C)

{

Pick HTML_C file.

}

Application is working fine till here.

Now,we are planning to extend the support for 20 more languages.

Addition of these many languages will create un-necessary if-else ladder. Same will be the case even if we use switch statement.

To deal with this we decided to keep the name of the file as a static string (HTML_) and to append the language key (A, B, C, ........) later at run time so as to get the full name of the file (HTML_A, HTML_B, .........).

Now, it is quite possible that the user language is different from the languages supported by the application as the name of the HTML file generated (eg. HTML_AB) may not be available and system may throw an error. We will catch this exception and will write the code to pick the HTML files for English language in the catch block of the try-catch.

But this approach does not seem to be working as system is not throwing any error.

Any idea on how to deal with this stuff will be appreciated.

Regards

Vineet Vikram

Accepted Solutions (1)

Accepted Solutions (1)

shabeer_skhan
Explorer
0 Kudos

Hi Vineet,

The following code will throw a 'File not found exception' if the file mentioned is not present in the mimes->components->application folder



	try {
		String resourcePath = WDURLGenerator.getResourcePath(wdComponentAPI.getDeployableObjectPart(),"HelloWorld.html");
		IWDResource resource = WDResourceFactory.createResource(new FileInputStream(new File(resourcePath)),"HelloWorld.html",WDWebResourceType.HTML,true);

	} catch (WDAliasResolvingException e) {
		wdComponentAPI.getMessageManager().reportException(e.getMessage(),true);
	} catch (FileNotFoundException e) {
		wdComponentAPI.getMessageManager().reportException(e.getMessage(),true);
	}

One other way to deal this situation is to maintain a hashmap with language code as key and file name as value. For a language for which file is not maintained the get() of hashmap will return null.

Hope this helps.

Regards,

Shabeer

Answers (0)