Skip to content

Commit

Permalink
SAK-25883 Get the real path to the current root.
Browse files Browse the repository at this point in the history
Then walk back up the tree and into the library folder. This is because
in Tomcat 8 the getRealPath is more strict and returns null when you
attempt to access another context.

In the long run this isn’t a good solution as we should be enabling people
to run without having to unpack webapps but it gets things working.
I haven’t added a null check in here as otherwise when we start looking
at running without unpacked WARs we’ll just lose the i18n.
  • Loading branch information
buckett committed Apr 19, 2015
1 parent a729a86 commit e0d9539
Showing 1 changed file with 5 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1066,16 +1066,19 @@ private String getLocalizedURL(String property) {

Locale locale = new ResourceLoader().getLocale();

// You can only access inside the current context in Tomcat 8.
// Tomcat 8 advises against unpacking the WARs so this isn't a good long term solution.
String rootPath = getPortletConfig().getPortletContext().getRealPath("/");
if (locale != null){
// check if localized file exists for current language/locale/variant
String localizedFile = doc + "_" + locale.toString() + ext;
String filePath = getPortletConfig().getPortletContext().getRealPath(".."+localizedFile);
String filePath = rootPath+ ".."+localizedFile;
if ( (new File(filePath)).exists() )
return localizedFile;

// otherwise, check if localized file exists for current language
localizedFile = doc + "_" + locale.getLanguage() + ext;
filePath = getPortletConfig().getPortletContext().getRealPath(".."+localizedFile);
filePath = rootPath+ ".."+localizedFile;
if ( (new File(filePath)).exists() )
return localizedFile;
}
Expand Down

0 comments on commit e0d9539

Please sign in to comment.