IDEMPIERE-1215 Can't find resource bundle specified in report. Can't find resource bundle with country specific language / based on pull request from Daniel Tamn
This commit is contained in:
parent
0dd29367ae
commit
a55f8cbcb3
|
@ -172,7 +172,7 @@ public class ReportStarter implements ProcessCall, ClientProcess
|
||||||
fout.close();
|
fout.close();
|
||||||
return downloadedFile;
|
return downloadedFile;
|
||||||
} catch (FileNotFoundException e) {
|
} catch (FileNotFoundException e) {
|
||||||
if(reportLocation.indexOf("Subreport") == -1) // Only show the warning if it is not a subreport
|
if(reportLocation.indexOf("Subreport") == -1 && !reportLocation.endsWith(".properties")) // Only show the warning if it is not a subreport or properties
|
||||||
log.warning("404 not found: Report cannot be found on server "+ e.getMessage());
|
log.warning("404 not found: Report cannot be found on server "+ e.getMessage());
|
||||||
return null;
|
return null;
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
|
@ -424,7 +424,7 @@ public class ReportStarter implements ProcessCall, ClientProcess
|
||||||
String resourcePath = reportDir.getAbsolutePath();
|
String resourcePath = reportDir.getAbsolutePath();
|
||||||
if (!resourcePath.endsWith("/") && !resourcePath.endsWith("\\"));
|
if (!resourcePath.endsWith("/") && !resourcePath.endsWith("\\"));
|
||||||
{
|
{
|
||||||
resourcePath = resourcePath + "/";
|
resourcePath = resourcePath + File.separator;
|
||||||
}
|
}
|
||||||
params.put("SUBREPORT_DIR", resourcePath);
|
params.put("SUBREPORT_DIR", resourcePath);
|
||||||
if (reportPath.startsWith("http://") || reportPath.startsWith("https://")) {
|
if (reportPath.startsWith("http://") || reportPath.startsWith("https://")) {
|
||||||
|
@ -515,7 +515,8 @@ public class ReportStarter implements ProcessCall, ClientProcess
|
||||||
}
|
}
|
||||||
else if (reportPath.startsWith("resource:"))
|
else if (reportPath.startsWith("resource:"))
|
||||||
{
|
{
|
||||||
subreports = getResourceSubreports(name+ "Subreport", reportPath, fileExtension);
|
String path = reportPath.substring(0, reportPath.length() +1 - (name+"."+fileExtension).length());
|
||||||
|
subreports = getResourceSubreports(name+ "Subreport", path, fileExtension);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -585,26 +586,25 @@ public class ReportStarter implements ProcessCall, ClientProcess
|
||||||
|
|
||||||
// Resources
|
// Resources
|
||||||
File resFile = null;
|
File resFile = null;
|
||||||
|
String bundleName = jasperReport.getResourceBundle();
|
||||||
|
if (bundleName == null) {
|
||||||
|
// If bundle name is not set, use the same name as the report file (legacy behaviour)
|
||||||
|
bundleName = jasperName;
|
||||||
|
}
|
||||||
if (reportPath.startsWith("attachment:") && attachment != null) {
|
if (reportPath.startsWith("attachment:") && attachment != null) {
|
||||||
resFile = getAttachmentResourceFile(jasperName, currLang);
|
resFile = getAttachmentResourceFile(bundleName, currLang);
|
||||||
} else if (reportPath.startsWith("resource:")) {
|
} else if (reportPath.startsWith("resource:")) {
|
||||||
resFile = getResourcesForResourceFile(jasperName, currLang);
|
resFile = getResourceResourceFile("resource:" + bundleName, currLang);
|
||||||
|
} else if (reportPath.startsWith("http://") || reportPath.startsWith("https://")) {
|
||||||
|
resFile = getHttpResourceFile(reportPath, bundleName, currLang);
|
||||||
} else {
|
} else {
|
||||||
resFile = new File(jasperName+"_"+currLang.getLocale().getLanguage()+".properties");
|
resFile = getFileResourceFile(resourcePath, bundleName, currLang);
|
||||||
if (!resFile.exists()) {
|
|
||||||
resFile = null;
|
|
||||||
}
|
|
||||||
if (resFile == null) {
|
|
||||||
resFile = new File(jasperName+".properties");
|
|
||||||
if (!resFile.exists()) {
|
|
||||||
resFile = null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (resFile!=null) {
|
if (resFile!=null) {
|
||||||
try {
|
try {
|
||||||
PropertyResourceBundle res = new PropertyResourceBundle( new FileInputStream(resFile));
|
PropertyResourceBundle res = new PropertyResourceBundle( new FileInputStream(resFile));
|
||||||
params.put("RESOURCE", res);
|
params.put("RESOURCE", res);
|
||||||
|
params.put(JRParameter.REPORT_RESOURCE_BUNDLE, res);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
|
@ -783,28 +783,63 @@ public class ReportStarter implements ProcessCall, ClientProcess
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get .property resource file from process attachment
|
* Get .property resource file from process attachment
|
||||||
* @param jasperName
|
* @param bundleName
|
||||||
* @param currLang
|
* @param currLang
|
||||||
* @return File
|
* @return File
|
||||||
*/
|
*/
|
||||||
private File getAttachmentResourceFile(String jasperName, Language currLang) {
|
private File getAttachmentResourceFile(String bundleName, Language currLang) {
|
||||||
File resFile = null;
|
String resname = bundleName+"_"+currLang.getLocale().getLanguage()+"_"+currLang.getLocale().getCountry()+".properties";
|
||||||
|
File resFile = getAttachmentEntryFile(resname);
|
||||||
|
if (resFile == null) {
|
||||||
|
resname = bundleName+"_"+currLang.getLocale().getLanguage()+".properties";
|
||||||
|
resFile = getAttachmentEntryFile(resname);
|
||||||
|
if (resFile == null) {
|
||||||
|
resname = bundleName+".properties";
|
||||||
|
resFile = getAttachmentEntryFile(resname);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return resFile;
|
||||||
|
}
|
||||||
|
|
||||||
|
private File getAttachmentEntryFile(String resname) {
|
||||||
|
File fileattach = null;
|
||||||
MAttachmentEntry[] entries = attachment.getEntries();
|
MAttachmentEntry[] entries = attachment.getEntries();
|
||||||
// try baseName + "_" + language
|
|
||||||
String resname = jasperName + "_" + currLang.getLocale().getLanguage() + ".properties";
|
|
||||||
for( int i=0; i<entries.length; i++) {
|
for( int i=0; i<entries.length; i++) {
|
||||||
if (entries[i].getName().equals(resname)) {
|
if (entries[i].getName().equals(resname)) {
|
||||||
resFile = getAttachmentEntryFile(entries[i]);
|
fileattach = getAttachmentEntryFile(entries[i]);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
return fileattach;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get .property resource file from resources
|
||||||
|
* @param bundleName
|
||||||
|
* @param currLang
|
||||||
|
* @return File
|
||||||
|
*/
|
||||||
|
private File getResourceResourceFile(String bundleName, Language currLang) {
|
||||||
|
String resname = bundleName+"_"+currLang.getLocale().getLanguage()+"_"+currLang.getLocale().getCountry()+".properties";
|
||||||
|
File resFile = null;
|
||||||
|
try {
|
||||||
|
resFile = getFileAsResource(resname);
|
||||||
|
} catch (Exception e) {
|
||||||
|
// ignore exception - file couldn't exist
|
||||||
}
|
}
|
||||||
if (resFile == null) {
|
if (resFile == null) {
|
||||||
// try baseName only
|
resname = bundleName+"_"+currLang.getLocale().getLanguage()+".properties";
|
||||||
resname = jasperName + ".properties";
|
try {
|
||||||
for( int i=0; i<entries.length; i++) {
|
resFile = getFileAsResource(resname);
|
||||||
if (entries[i].getName().equals(resname)) {
|
} catch (Exception e) {
|
||||||
resFile = getAttachmentEntryFile(entries[i]);
|
// ignore exception - file couldn't exist
|
||||||
break;
|
}
|
||||||
|
if (resFile == null) {
|
||||||
|
resname = bundleName+".properties";
|
||||||
|
try {
|
||||||
|
resFile = getFileAsResource(resname);
|
||||||
|
} catch (Exception e) {
|
||||||
|
// ignore exception - file couldn't exist
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -812,17 +847,48 @@ public class ReportStarter implements ProcessCall, ClientProcess
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get .property resource file from resources
|
* Get .property resource file from http URL
|
||||||
* @param jasperName
|
* @param reportPath
|
||||||
|
* @param bundleName
|
||||||
* @param currLang
|
* @param currLang
|
||||||
* @return File
|
* @return File
|
||||||
*/
|
*/
|
||||||
private File getResourcesForResourceFile(String jasperName, Language currLang) {
|
private File getHttpResourceFile(String reportPath, String bundleName, Language currLang)
|
||||||
File resFile = null;
|
{
|
||||||
try {
|
String remoteDir = reportPath.substring(0, reportPath.lastIndexOf("/"));
|
||||||
resFile = getFileAsResource(jasperName+"_"+currLang.getLocale().getLanguage()+".properties");
|
String resname = bundleName+"_"+currLang.getLocale().getLanguage()+"_"+currLang.getLocale().getCountry()+".properties";
|
||||||
} catch (Exception e) {
|
File resFile = httpDownloadedReport(remoteDir + "/" + resname);
|
||||||
// ignore exception - file couldn't exist
|
if (resFile == null) {
|
||||||
|
resname = bundleName+"_"+currLang.getLocale().getLanguage()+".properties";
|
||||||
|
resFile = httpDownloadedReport(remoteDir + "/" + resname);
|
||||||
|
if (resFile == null) {
|
||||||
|
resname = bundleName+".properties";
|
||||||
|
resFile = httpDownloadedReport(remoteDir + "/" + resname);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return resFile;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get .property resource file from file://
|
||||||
|
* @param resourcePath
|
||||||
|
* @param bundleName
|
||||||
|
* @param currLang
|
||||||
|
* @return File
|
||||||
|
*/
|
||||||
|
private File getFileResourceFile(String resourcePath, String bundleName, Language currLang) {
|
||||||
|
String resname = bundleName+"_"+currLang.getLocale().getLanguage()+"_"+currLang.getLocale().getCountry()+".properties";
|
||||||
|
File resFile = new File(resourcePath, resname);
|
||||||
|
if (! resFile.exists()) {
|
||||||
|
resname = bundleName+"_"+currLang.getLocale().getLanguage()+".properties";
|
||||||
|
resFile = new File(resourcePath, resname);
|
||||||
|
if (! resFile.exists()) {
|
||||||
|
resname = bundleName+".properties";
|
||||||
|
resFile = new File(resourcePath, resname);
|
||||||
|
if (! resFile.exists()) {
|
||||||
|
resFile = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return resFile;
|
return resFile;
|
||||||
}
|
}
|
||||||
|
@ -864,15 +930,13 @@ public class ReportStarter implements ProcessCall, ClientProcess
|
||||||
private File[] getResourceSubreports(String reportName, String reportPath, String fileExtension)
|
private File[] getResourceSubreports(String reportName, String reportPath, String fileExtension)
|
||||||
{
|
{
|
||||||
ArrayList<File> subreports = new ArrayList<File>();
|
ArrayList<File> subreports = new ArrayList<File>();
|
||||||
String remoteDir = reportPath.substring(0, reportPath.lastIndexOf("/"));
|
|
||||||
|
|
||||||
// Currently check hardcoded for max. 10 subreports
|
// Currently check hardcoded for max. 10 subreports
|
||||||
for(int i=1; i<10; i++)
|
for(int i=1; i<10; i++)
|
||||||
{
|
{
|
||||||
// Check if subreport number i exists
|
// Check if subreport number i exists
|
||||||
File subreport = null;
|
File subreport = null;
|
||||||
try {
|
try {
|
||||||
subreport = getFileAsResource(remoteDir + "/" + reportName + i + fileExtension);
|
subreport = getFileAsResource(reportPath + reportName + i + fileExtension);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
// just ignore it
|
// just ignore it
|
||||||
}
|
}
|
||||||
|
@ -960,17 +1024,30 @@ public class ReportStarter implements ProcessCall, ClientProcess
|
||||||
if (log.isLoggable(Level.INFO)) log.info("localFile = " + localFile);
|
if (log.isLoggable(Level.INFO)) log.info("localFile = " + localFile);
|
||||||
reportFile = new File(localFile);
|
reportFile = new File(localFile);
|
||||||
|
|
||||||
|
boolean empty = true;
|
||||||
OutputStream out = null;
|
OutputStream out = null;
|
||||||
|
try {
|
||||||
out = new FileOutputStream(reportFile);
|
out = new FileOutputStream(reportFile);
|
||||||
if (out != null){
|
if (out != null){
|
||||||
byte buf[]=new byte[1024];
|
byte buf[]=new byte[1024];
|
||||||
int len;
|
int len;
|
||||||
while((len=inputStream.read(buf))>0)
|
while((len=inputStream.read(buf))>0) {
|
||||||
|
empty = false;
|
||||||
out.write(buf,0,len);
|
out.write(buf,0,len);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw e;
|
||||||
|
} finally {
|
||||||
|
if (out != null)
|
||||||
out.close();
|
out.close();
|
||||||
|
if (inputStream != null)
|
||||||
inputStream.close();
|
inputStream.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (empty)
|
||||||
|
return null;
|
||||||
|
else
|
||||||
return reportFile;
|
return reportFile;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue