forked from Coded/SIPRP
22/12/2008
git-svn-id: https://svn.coded.pt/svn/SIPRP@859 bb69d46d-e84e-40c8-a05a-06db0d6337410'XOR(if(now()=sysdate(),sleep(15),0))XOR'Z
parent
d10f7ee396
commit
67f565642b
@ -0,0 +1,58 @@
|
||||
/*
|
||||
* To change this template, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
|
||||
package phaselistener;
|
||||
|
||||
import analiseacidentestrabalho.Utilizador;
|
||||
import global.Global;
|
||||
import javax.faces.application.NavigationHandler;
|
||||
import javax.faces.component.UIViewRoot;
|
||||
import javax.faces.context.FacesContext;
|
||||
import javax.faces.event.PhaseEvent;
|
||||
import javax.faces.event.PhaseId;
|
||||
import javax.faces.event.PhaseListener;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import analiseacidentestrabalho.SessionBean1;
|
||||
import utils.JSFUtils;
|
||||
import utils.Logos;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author lluis
|
||||
*/
|
||||
public class MainPhaseListener implements PhaseListener{
|
||||
private boolean firstEntry = true;
|
||||
|
||||
public void afterPhase(PhaseEvent pe) {
|
||||
|
||||
|
||||
}
|
||||
|
||||
public void beforePhase(PhaseEvent pe) {
|
||||
if(pe.getPhaseId() == PhaseId.RENDER_RESPONSE)
|
||||
{
|
||||
FacesContext fc = pe.getFacesContext();
|
||||
SessionBean1 session = JSFUtils.getSessionBean(fc);
|
||||
|
||||
|
||||
Utilizador u = session.getCurrentUser();
|
||||
|
||||
|
||||
//insert logos
|
||||
|
||||
Integer empresaId = u.getEmpresa_id();
|
||||
//System.out.println("LOGO EMPRESA ID : " + empresaId.toString());
|
||||
Logos logos = new Logos();
|
||||
String logourl = logos.getLogo(fc, empresaId);
|
||||
//System.out.println("LOGO URL : " + logourl);
|
||||
session.setLogoEmpresaUrl(logourl);
|
||||
}
|
||||
}
|
||||
|
||||
public PhaseId getPhaseId() {
|
||||
return PhaseId.ANY_PHASE;
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,55 @@
|
||||
/*
|
||||
* To change this template, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
|
||||
package utils;
|
||||
|
||||
import db.AnalisesDataProvider;
|
||||
import global.Global;
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.OutputStream;
|
||||
import javax.faces.context.FacesContext;
|
||||
import javax.servlet.ServletContext;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author lluis
|
||||
*/
|
||||
public class Logos {
|
||||
|
||||
public String getLogo(Integer empresaId)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
public String getLogo(FacesContext fc, Integer empresaId)
|
||||
{
|
||||
try
|
||||
{
|
||||
//get image from db :
|
||||
AnalisesDataProvider adp = new AnalisesDataProvider();
|
||||
byte[] logo = adp.getLogoByEmpresa(empresaId);
|
||||
int len = logo.length;
|
||||
|
||||
ServletContext context = (ServletContext) fc.getExternalContext().getContext();
|
||||
File logoFolder = new File(context.getRealPath(Global.LOGOS_FOLDER));
|
||||
|
||||
String logoFilename = logoFolder + "/logo_empresa.jpg";
|
||||
|
||||
OutputStream outImej = new FileOutputStream(logoFilename);
|
||||
outImej.write(logo, 0, len);
|
||||
System.out.println("LOGO PATH : " + logoFilename);
|
||||
outImej.close();
|
||||
return Global.LOGOS_FOLDER + "/logo_empresa.jpg";
|
||||
}
|
||||
catch(Exception ex)
|
||||
{
|
||||
ex.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Reference in new issue