Hi, everyone.
I'm using database table for retrieving language resources (so, when following statement is processed: <liferay-ui:message key="save"/> , the value for key 'save' is taken not from Language.properties, but from database table (with 'key', 'value', and 'locale' columns) ) with the possibility of editing these resources, import/export etc.
Also when any new portlet is deployed - the resource bundle from it should be also saved to database. For this purposes I use custom HotDeployListener (the code is below, some trivial methods are excluded). The problem is in that fact, that resource bundles can be placed on any path withing portlet and can be named in different way (not only Language_**.properties). The path to these resources can be specified in portlet.xml file (<resource-bundle>), or in liferay-hook.xml (if hook is used - in <language-properties>), or may not be specified in any of them. So, system tries to read path to bundles firstly from portlet.xml, then from liferay-hook.xml, and if path is not specified - uses "default" path - 'Language.properties'. Can anyone suggest me a more universal approach (and less hard-coded

) of reading resource bundles when portlet is deployed (maybe, path to resources can be retrieved from hotDeployEvent in some other way)... I'll appreciate any help.
public class HotDeployListenerHook implements HotDeployListener {
public static final String DEFAULT_RESOURCE_NAME = "Language.properties";
@Override
public void invokeDeploy(HotDeployEvent hotDeployEvent) throws HotDeployException {
ServletContext servletContext = hotDeployEvent.getServletContext();
ClassLoader contextClassLoader = hotDeployEvent.getContextClassLoader();
String bundleName = hotDeployEvent.getPluginPackage().getName();
// determines whether <resource-bundle> specified in 'portlet.xml' or <language-properties> specified in 'liferay-hook.xml'
boolean resourceBundleSpecified = false;
String portletXML = StringUtils.EMPTY;
try {
portletXML = HttpUtil.URLtoString(servletContext.getResource("/WEB-INF/" + Portal.PORTLET_XML_FILE_NAME_STANDARD));
} catch (IOException e) {
_logger.error("Can not read portlet.xml");
}
if (StringUtils.isNotBlank(portletXML)) {
/*== try to read resource bundle from portlet.xml ===*/
try {
resourceBundleSpecified = readPortletXML(portletXML, contextClassLoader, bundleName);
} catch (DocumentException e) {
if (_logger.isDebugEnabled()) {
_logger.debug("Unable to read process xml. ");
}
}
}
// if <resource-bundle> not specified in portlet.xml - read from liferay-hook.xml
if (!resourceBundleSpecified) {
String liferayHookXml = StringUtils.EMPTY;
try {
liferayHookXml = HttpUtil.URLtoString(servletContext.getResource(LIFERAY_HOOK_PATH));
} catch (IOException e) {
_logger.error("Can not read liferay-hook.xml");
}
if (StringUtils.isNotBlank(liferayHookXml)) {
/*== try to read resource bundle from liferay-hook.xml ===*/
try {
resourceBundleSpecified = readLiferayHookXML(liferayHookXml, contextClassLoader, bundleName);
} catch (DocumentException e) {
if (_logger.isDebugEnabled()) {
_logger.debug("Unable to read process xml. ");
}
}
}
}
// if <resource-bundle> not specified - use default
if (!resourceBundleSpecified) {
processBundle(DEFAULT_RESOURCE_NAME, contextClassLoader, bundleName);
}
}
}
Regards, Vitaliy Koshelenko