IDEMPIERE-1309 Improve JasperReport support for loading of resources (image, text file, etc )

This commit is contained in:
Heng Sin Low 2013-08-28 17:34:39 +08:00
parent a174382caf
commit cf87e78e05
2 changed files with 30 additions and 14 deletions

View File

@ -376,6 +376,12 @@ public class ReportStarter implements ProcessCall, ClientProcess
reportResult(AD_PInstance_ID, "Can not find report", trxName);
return false;
}
if (reportPath.startsWith("@#LocalHttpAddr@")) {
String localaddr = Env.getContext(Env.getCtx(), "#LocalHttpAddr");
if (!Util.isEmpty(localaddr)) {
reportPath = reportPath.replace("@#LocalHttpAddr@", localaddr);
}
}
JasperData data = null;
File reportFile = null;
@ -421,7 +427,13 @@ public class ReportStarter implements ProcessCall, ClientProcess
resourcePath = resourcePath + "/";
}
params.put("SUBREPORT_DIR", resourcePath);
params.put("RESOURCE_DIR", resourcePath);
if (reportPath.startsWith("http://") || reportPath.startsWith("https://")) {
int i = reportPath.lastIndexOf("/");
String httpPath = reportPath.substring(0, i+1);
params.put("RESOURCE_DIR", httpPath);
} else {
params.put("RESOURCE_DIR", resourcePath);
}
if (jasperReport != null && pi.getTable_ID() > 0 && Record_ID <= 0 && pi.getRecord_IDs() != null && pi.getRecord_IDs().length > 0)
{
@ -576,7 +588,7 @@ public class ReportStarter implements ProcessCall, ClientProcess
if (reportPath.startsWith("attachment:") && attachment != null) {
resFile = getAttachmentResourceFile(jasperName, currLang);
} else if (reportPath.startsWith("resource:")) {
resFile = getResourcesForResourceFile(jasperName, currLang);
resFile = getResourcesForResourceFile(jasperName, currLang);
} else {
resFile = new File(jasperName+"_"+currLang.getLocale().getLanguage()+".properties");
if (!resFile.exists()) {
@ -826,17 +838,15 @@ public class ReportStarter implements ProcessCall, ClientProcess
MAttachmentEntry[] entries = attachment.getEntries();
for(int i = 0; i < entries.length; i++) {
// @Trifon
if (!entries[i].getName().equals(name)
&& (entries[i].getName().toLowerCase().endsWith(".jrxml")
|| entries[i].getName().toLowerCase().endsWith(".jasper")
|| entries[i].getName().toLowerCase().endsWith(".jpg")
|| entries[i].getName().toLowerCase().endsWith(".png")
)
)
if (!entries[i].getName().equals(name))
{
File reportFile = getAttachmentEntryFile(entries[i]);
if (reportFile != null)
subreports.add(reportFile);
if (reportFile != null) {
if (entries[i].getName().toLowerCase().endsWith(".jrxml")
|| entries[i].getName().toLowerCase().endsWith(".jasper")) {
subreports.add(reportFile);
}
}
}
}
File[] subreportsTemp = new File[0];

View File

@ -359,7 +359,13 @@ public class AdempiereWebUI extends Window implements EventListener<Event>, IWeb
}
Env.setContext(ctx, "#UIClient", "zk");
StringBuilder localHttpAddr = new StringBuilder(Executions.getCurrent().getScheme());
localHttpAddr.append("://").append(Executions.getCurrent().getLocalAddr());
int port = Executions.getCurrent().getLocalPort();
if (port > 0 && port != 80) {
localHttpAddr.append(":").append(port);
}
Env.setContext(ctx, "#LocalHttpAddr", localHttpAddr.toString());
Clients.response(new AuScript("zAu.cmd0.clearBusy()"));
}