Regalamiunsorriso/decompiled-libs/www/acxent-common-1.0.1/it/acxent/contab/servlet/GetFileSvlt.java

102 lines
3.7 KiB
Java
Raw Normal View History

2026-04-22 18:41:37 +02:00
package it.acxent.contab.servlet;
import it.acxent.anag._AnagAdapter;
import it.acxent.contab.Documento;
import it.acxent.db.DBAdapter;
import it.acxent.reg.EcDc;
import it.acxent.servlet.AcServlet;
import java.io.File;
import java.io.FileInputStream;
import java.sql.Time;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class GetFileSvlt extends AcServlet {
protected void callJsp(HttpServletRequest req, HttpServletResponse res) {
File theFile = null;
FileInputStream fis = null;
try {
if (checkProfile(req, res)) {
Documento doc = new Documento(getApFull(req));
String id = getIdDocumento(req, res);
doc.findByPrimaryKey(Long.valueOf(id));
String fileName = getDocBase() + getDocBase() + doc.getPathTmp();
String ext = fileName.substring(fileName.lastIndexOf('.') + 1, fileName.length());
if (ext.toLowerCase().equals("html") || ext.toLowerCase().equals("jsp") || ext.toLowerCase().equals("php")) {
String thePage = req.getContextPath() + req.getContextPath();
setJspPage(thePage, req);
res.sendRedirect(getJspPage(req));
} else {
fileName = doc.getPathStampaDocumentoFull();
ext = fileName.substring(fileName.lastIndexOf('.') + 1, fileName.length());
theFile = new File(fileName);
res.setContentType("application/" + ext);
if (theFile.exists()) {
if (doc.getDBState() == 1) {
doc.setDataDownload(DBAdapter.getToday());
doc.setOraDownload(new Time(DBAdapter.getTimestamp().getTime()));
doc.setIpDownload(req.getRemoteAddr());
doc.setFlgDownload(1L);
doc.save();
}
fis = new FileInputStream(theFile);
byte[] temp = new byte[1024];
int nByte = 0;
ServletOutputStream sos = res.getOutputStream();
while ((nByte = fis.read(temp)) != -1)
sos.write(temp, 0, nByte);
sos.flush();
fis.close();
sos.close();
} else if (useAlwaysSendRedirect()) {
String absPage = getFileNotFoundJsp(req, res).startsWith("/") ? (
req.getContextPath() + req.getContextPath()) : (
req.getContextPath() + "/" + req.getContextPath());
res.sendRedirect(absPage);
} else {
setJspPage(getFileNotFoundJsp(req, res), req);
res.sendRedirect(getJspPage(req));
}
}
} else {
setJspPage(getFileNotFoundJsp(req, res), req);
res.sendRedirect(getJspPage(req));
}
} catch (Exception e) {
e.printStackTrace();
} finally {
theFile = null;
if (fis != null)
fis = null;
}
}
protected String getFileName(HttpServletRequest req, HttpServletResponse res) {
String fileName = getRequestParameter(req, "id");
fileName = EcDc.decodeDizionario(fileName, _AnagAdapter.KEY_ENCODE_DIZ);
return fileName;
}
protected String getIdDocumento(HttpServletRequest req, HttpServletResponse res) {
String id = getRequestParameter(req, "id2");
id = EcDc.decodeDizionario(id, _AnagAdapter.KEY_ENCODE_DIZ);
return id;
}
protected String getFileNotFoundJsp(HttpServletRequest req, HttpServletResponse res) {
return "/fileNotFound.jsp";
}
protected boolean checkProfile(HttpServletRequest req, HttpServletResponse res) {
return true;
}
protected void processRequest(HttpServletRequest request, HttpServletResponse response) {
callJsp(request, response);
}
protected boolean isSecureServlet(HttpServletRequest req) {
return false;
}
}