gleimar 2016-10-04 15:13:48 +00:00
parent e4ca608050
commit 3f36403fc9
2 changed files with 57 additions and 0 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 64 KiB

View File

@ -9,14 +9,24 @@ import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.core.io.ClassPathResource; import org.springframework.core.io.ClassPathResource;
import com.rjconsultores.ventaboletos.entidad.Constante;
import com.rjconsultores.ventaboletos.service.ConstanteService;
import com.rjconsultores.ventaboletos.web.utilerias.spring.AppContext;
/** /**
* Servlet implementation class ImageServlet * Servlet implementation class ImageServlet
*/ */
public class ImageServlet extends HttpServlet { public class ImageServlet extends HttpServlet {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
private static final String PATH_IMAGENES = "/com/rjconsultores/ventaboletos/web/cliente/imagenes/"; private static final String PATH_IMAGENES = "/com/rjconsultores/ventaboletos/web/cliente/imagenes/";
private static final String IMAGENE_EMPRESA = "empresa.png";
private static final String IMAGENE_EMPRESA_GENERICA = "empresa_generica.png";
private static Boolean IMAGENE_EMPRESA_GENERICA_CHECKED = null;
/** /**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response) * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
@ -28,6 +38,8 @@ public class ImageServlet extends HttpServlet {
String imagene = request.getParameter("imagene"); String imagene = request.getParameter("imagene");
if (imagene != null) { if (imagene != null) {
// Open the file and output streams // Open the file and output streams
imagene = getNombreImagene(imagene);
InputStream in = getImagene(imagene); InputStream in = getImagene(imagene);
OutputStream out = resp.getOutputStream(); OutputStream out = resp.getOutputStream();
@ -42,6 +54,44 @@ public class ImageServlet extends HttpServlet {
} }
} }
/**
* Muda a imagem para uma imagem generica da empresa.
*
* Utilizado para carregar a imagem padrão ao invés da do custom
*
* @param imagene
* @return
*/
private String getNombreImagene(String imagene){
if (!imagene.equalsIgnoreCase(IMAGENE_EMPRESA)){
return imagene;
}
boolean imageneGenericaEmpresaActivo = false;
if (IMAGENE_EMPRESA_GENERICA_CHECKED == null){
IMAGENE_EMPRESA_GENERICA_CHECKED = false;
ConstanteService constanteService = getConstanteService();
Constante constante = constanteService.buscarPorNomeConstante("IMAGENE_EMPRESA_GENERICA");
if ( (constante != null) && StringUtils.isNotBlank(constante.getValorconstante())){
imageneGenericaEmpresaActivo= Boolean.parseBoolean(constante.getValorconstante());
IMAGENE_EMPRESA_GENERICA_CHECKED = imageneGenericaEmpresaActivo;
}
}
if ( (IMAGENE_EMPRESA_GENERICA_CHECKED != null) && (IMAGENE_EMPRESA_GENERICA_CHECKED) ){
imagene = IMAGENE_EMPRESA_GENERICA;
}
return imagene;
}
private InputStream getImagene(String imagene) { private InputStream getImagene(String imagene) {
InputStream inputStream = null; InputStream inputStream = null;
try { try {
@ -53,4 +103,11 @@ public class ImageServlet extends HttpServlet {
return inputStream; return inputStream;
} }
private ConstanteService getConstanteService() {
ApplicationContext appContext = AppContext.getApplicationContext();
BeanFactory factory = (BeanFactory) appContext;
ConstanteService cs = (ConstanteService) factory.getBean("constanteService");
return cs;
}
} }