@ -40,65 +40,66 @@ public class siprpServlet extends HttpServlet implements GlobalConstants
public static final String msgGenericError = "Erro" ;
public static final String msgListaEmpresas = "Empresas" ;
public static final String msgAcessoNegado = "Acesso+Negado." ;
public static final String msgLinkFormatError = "URL+inválido." ;
public static final String msgLinkFormatError = "URL+inválido." ;
public static final String msgLogin = "Login" ;
public static final String msgNovaPasswordErrada = "Erro+ao+criar+a+nova+password,+nova+password+inválida." ;
public static final String msgNovaPasswordErrada = "Erro+ao+criar+a+nova+password,+nova+password+inválida." ;
public static final String msgButtonNotSuported = "funcionalidade+ainda+não+suportada." ;
public static final String msgSessionTimeout = "Por+razões+de+segurança+o+tempo+da+sua+sessão+expirou<br>"
+ "Por+favor+efectue+novamente+o+seu+login.<br>" ;
// Templates - Nomes e valores
// public static final String loginTemplate = "login.html";
// public static final String loginTemplate = "login.html";
public static final String indexTemplate = "index.html" ;
public static final String authenticatedUserTemplate = "user.html" ;
public static final String authenticatedUserPrintTemplate = "user_print.html" ;
public static final String errorTemplate = "erro.html" ;
// public static final String errorTemplate = "frame_erro.html";
// public static final String innerErrorTemplate = "erro.html";
// public static final String errorTemplate = "frame_erro.html";
// public static final String innerErrorTemplate = "erro.html";
public static final String mainTemplate = "main.html" ;
// public static final String criticalErrorTemplate = "critical.html";
public static final String templateVector1 = "v1" ;
public static final String templateVector2 = "v2" ;
public static final String templateVector3 = "v3" ;
public static final String templateUserRole = "userRole" ;
public static final String msgTemplate = "msg" ;
public static final String templateQuery = "query" ;
public static final String buttonPressedTemplate = "buttonPressed" ;
// public static final String criticalErrorTemplate = "critical.html";
public static final String templateVector1 = "v1" ;
public static final String templateVector2 = "v2" ;
public static final String templateVector3 = "v3" ;
public static final String templateUserRole = "userRole" ;
public static final String msgTemplate = "msg" ;
public static final String templateQuery = "query" ;
public static final String buttonPressedTemplate = "buttonPressed" ;
// Query Strings , usadas para na template do velocity saber o que mostar
public static final String queryStringErro = "erro" ;
public static final String queryStringEmpresas = "empresas" ;
public static final String queryStringEstabelecimentos = "estabelecimentos" ;
public static final String queryStringTrabalhadores = "trabalhadores" ;
public static final String queryStringTrabalhador = "trabalhador" ;
public static final String queryStringEstabelecimentos = "estabelecimentos" ;
public static final String queryStringTrabalhadores = "trabalhadores" ;
public static final String queryStringTrabalhador = "trabalhador" ;
// Botoes, saber qual o botao escholido, campo value dos forms
// Botoes, saber qual o botao escholido, campo value dos forms
public static final String botaoLogin = "Entrar" ;
public static final String botaoMarcarProximoExame = "Marcar Exame" ;
// Var da Session
public static final String sessionUser = "user" ;
public static final String sessionUserRole = "userRole" ;
public static final String sessionPassword = "password" ;
public static final String sessionEmpresaId = "empresaId" ;
public static final String sessionEstabelecimentoId = "estabelecimentoId" ;
public static final String sessionTrabalhadorId = "trabalhadorId" ;
public static final String sessionUser = "user" ;
public static final String sessionUserRole = "userRole" ;
public static final String sessionPassword = "password" ;
public static final String sessionEmpresaId = "empresaId" ;
public static final String sessionEstabelecimentoId = "estabelecimentoId" ;
public static final String sessionTrabalhadorId = "trabalhadorId" ;
public static final String sessionCompanyName = "sessionCompanyName" ;
public static final String sessionCompanyEmail = "sessionCompanyEmail" ;
public static final int sessionTimeout = 3600 ; // segundos
public static final String servletName = "siprpWeb" ;
public static final String superUserRole = "manager" ;
public static final String servletName = "siprpWeb" ;
public static final String superUserRole = "manager" ;
// // BD
// public static final String bdHost = "127.0.0.1";
// public static final String bdPort = "5436";
// public static final String bdUsername = "siprp";
// public static final String bdPassword = "";
// public static final String bdDriver = "org.postgresql.Driver";
// public static final String bdUrl = "jdbc:postgresql://" + bdHost + ":" + bdPort + "/siprp";
// // BD
// public static final String bdHost = "127.0.0.1";
// public static final String bdPort = "5436";
// public static final String bdUsername = "siprp";
// public static final String bdPassword = "";
// public static final String bdDriver = "org.postgresql.Driver";
// public static final String bdUrl = "jdbc:postgresql://" + bdHost + ":" +
// bdPort + "/siprp";
public static final String bdEmpresaIdRef = "id" ; // campo que contem id da empresa
public static final String bdEmpresaNomeRef = "designacao_social" ; // campo que contem nome da empresa
@ -112,97 +113,100 @@ public class siprpServlet extends HttpServlet implements GlobalConstants
protected static ServletContext CONTEXT ;
// Arrays
public static final String [ ] [ ] trabalhadorDescFields = new String [ ] [ ]
{ // nome que o user ve, nome do campo na tabela
{ "Nome" , "nome" } ,
{ "N\u00ba" , "numero_mecanografico" , } ,
{ "\u00DAltimo Exame" , "ultimo_exame" } ,
{ "Realizado" , "realizado" } ,
{ "Pr\u00F3ximo Exame" , "proximo_exame" } ,
{ "\u00DAltima Consulta" , "ultima_consulta" } ,
{ "Realizada" , "realizada" } ,
{ "Pr\u00F3xima Consulta" , "proxima_consulta" }
} ;
// nome que o user ve, nome do campo na tabela
public static final String [ ] [ ] trabalhadorDescFields = new String [ ] [ ] {
{ "Nome" , "nome" } , { "N\u00ba" , "numero_mecanografico" , } , { "\u00DAltimo Exame" , "ultimo_exame" } , { "Realizado" , "realizado" } ,
{ "Pr\u00F3ximo Exame" , "proximo_exame" } , { "\u00DAltima Consulta" , "ultima_consulta" } , { "Realizada" , "realizada" } ,
{ "Pr\u00F3xima Consulta" , "proxima_consulta" } } ;
public void init ( )
{
try {
try
{
CONTEXT = this . getServletContext ( ) ;
String TEMPLATE_DIR = this . getServletContext ( ) . getRealPath ( "/" ) + "html/" ;
System . out . println ( "DIR: " + TEMPLATE_DIR ) ;
System . out . println ( "DIR: " + TEMPLATE_DIR ) ;
Properties props = new Properties ( ) ;
props . setProperty ( "file.resource.loader.path" , TEMPLATE_DIR ) ;
Velocity . init ( props ) ;
Class . forName ( bdDriver ) ;
Class . forName ( bdDriver ) ;
}
catch ( Exception e )
catch ( Exception e )
{
e . printStackTrace ( ) ;
}
}
public void doGet ( HttpServletRequest req , HttpServletResponse res )
throws IOException
public void doGet ( HttpServletRequest req , HttpServletResponse res ) throws IOException
{
String queryString = req . getQueryString ( ) ;
String backUri = req . getRequestURI ( ) ;
ServletOutputStream out = res . getOutputStream ( ) ;
// res.setContentType( "text/html" );
// res.setContentType( "text/html" );
res . setContentType ( "text/html" ) ;
try
{
System . out . println ( "query: " + queryString ) ;
HttpSession session = req . getSession ( true ) ;
session . setMaxInactiveInterval ( sessionTimeout ) ;
System . out . println ( "query: " + queryString ) ;
HttpSession session = req . getSession ( true ) ;
session . setMaxInactiveInterval ( sessionTimeout ) ;
if ( queryString = = null ) // Reload, 1a vez, etc ...
{
session . invalidate ( ) ;
out . println ( mergeTemplate ( "" , indexTemplate ) ) ;
out . println ( mergeTemplate ( "" , indexTemplate ) ) ;
}
else if ( session . isNew ( ) & & ! ( queryString . indexOf ( queryStringErro ) = = 0 ) ) // session timeout
else if ( session . isNew ( ) & & ! ( queryString . indexOf ( queryStringErro ) = = 0 ) ) // session
// timeout
{
session . invalidate ( ) ;
String msgErro = msgSessionTimeout . replace ( '+' , ' ' ) ;
out . println ( mergeTemplate ( msgErro , indexTemplate ) ) ;
// doErro(queryString, out);
// doErro(queryString, out);
}
else if ( queryString . equals ( queryStringEmpresas ) ) // Listar Empresas
else if ( queryString . equals ( queryStringEmpresas ) ) // Listar
// Empresas
{
new doGetListaEmpresas ( req , res ) ;
new doGetListaEmpresas ( req , res ) ;
}
else if ( queryString . indexOf ( queryStringErro ) = = 0 ) // Listar Empresas
else if ( queryString . indexOf ( queryStringErro ) = = 0 ) // Listar
// Empresas
{
// System.out.println( "entrou" );
doErro ( queryString , out ) ;
// System.out.println( "entrou" );
doErro ( queryString , out ) ;
}
else // interpretar query string
else
// interpretar query string
{
String empresa = null , estabelecimento = null , trabalhador = null ;
String empresa = null , estabelecimento = null , trabalhador = null ;
String query = null ;
int checkInt ;
StringTokenizer sToken = new StringTokenizer ( queryString , "/" ) ;
StringTokenizer sToken = new StringTokenizer ( queryString , "/" ) ;
empresa = sToken . nextToken ( ) ; // empresa ID
checkInt = Integer . parseInt ( empresa ) ; // check int, NumberFormatException
checkInt = Integer . parseInt ( empresa ) ; // check int,
// NumberFormatException
if ( sToken . hasMoreElements ( ) )
if ( sToken . hasMoreElements ( ) )
{
estabelecimento = sToken . nextToken ( ) ; // estabelecimento ID
checkInt = Integer . parseInt ( estabelecimento ) ; // check int, NumberFormatException
if ( sToken . hasMoreElements ( ) )
checkInt = Integer . parseInt ( estabelecimento ) ; // check
// int,
// NumberFormatException
if ( sToken . hasMoreElements ( ) )
{
trabalhador = sToken . nextToken ( ) ; // trabalhador ID
try
{
checkInt = Integer . parseInt ( trabalhador ) ; // check int, NumberFormatException
checkInt = Integer . parseInt ( trabalhador ) ; // check
// int,
// NumberFormatException
}
catch ( NumberFormatException nfex )
catch ( NumberFormatException nfex )
{
query = trabalhador ;
if ( query . indexOf ( "trabalhadores_tudo" ) ! = 0 & & query . indexOf ( "trabalhadores_pendentes" ) ! = 0 & &
query . indexOf ( "_print" ) = = - 1 )
if ( query . indexOf ( "trabalhadores_tudo" ) ! = 0 & & query . indexOf ( "trabalhadores_pendentes" ) ! = 0
& & query . indexOf ( "_print" ) = = - 1 )
{
throw nfex ;
}
@ -212,141 +216,143 @@ System.out.println( "query: " + queryString );
if ( estabelecimento = = null ) // empresa query
{
session . setAttribute ( sessionEmpresaId , empresa ) ; // update HTTP Session
session . setAttribute ( sessionEmpresaId , empresa ) ; // update
// HTTP
// Session
new doGetListaEstabelecimentos ( req , res ) ;
new doGetListaEstabelecimentos ( req , res ) ;
// out.println( mergeTemplate ( empresa, loginTemplate ) ) ;
// out.println( mergeTemplate ( empresa, loginTemplate ) ) ;
}
else if ( trabalhador = = null | | query ! = null ) // estabelecimento query
else if ( trabalhador = = null | | query ! = null ) // estabelecimento
// query
{
session . setAttribute ( sessionEmpresaId , empresa ) ; // update HTTP Session
session . setAttribute ( sessionEstabelecimentoId , estabelecimento ) ;
session . setAttribute ( sessionEmpresaId , empresa ) ; // update
// HTTP
// Session
session . setAttribute ( sessionEstabelecimentoId , estabelecimento ) ;
new doGetListaTrabalhadores ( req , res , query ) ;
new doGetListaTrabalhadores ( req , res , query ) ;
//out.println( mergeTemplate ( " chama oGetListaTrabalhadores", loginTemplate ) ) ;
// out.println( mergeTemplate (
// " chama oGeHashtabletListaTrabalhadores", loginTemplate )
// ) ;
}
else // trabalhador query
else
// trabalhador query
{
session . setAttribute ( sessionEmpresaId , empresa ) ; // update HTTP Session
session . setAttribute ( sessionEstabelecimentoId , estabelecimento ) ;
session . setAttribute ( sessionTrabalhadorId , trabalhador ) ;
session . setAttribute ( sessionEmpresaId , empresa ) ; // update
// HTTP
// Session
session . setAttribute ( sessionEstabelecimentoId , estabelecimento ) ;
session . setAttribute ( sessionTrabalhadorId , trabalhador ) ;
new doGetTrabalhador ( req , res ) ;
new doGetTrabalhador ( req , res ) ;
//out.println( mergeTemplate ( trabalhador, loginTemplate ) ) ;
// out.println( mergeTemplate ( trabalhador, loginTemplate )
// ) ;
}
}
}
catch ( NumberFormatException e ) // argumentos invalidos
{
e . printStackTrace ( ) ;
out . println ( mergeTemplate ( msgLinkFormatError , backUri , errorTemplate ) ) ;
out . println ( mergeTemplate ( msgLinkFormatError , backUri , errorTemplate ) ) ;
}
catch ( IllegalStateException e ) // session timeout
{
e . printStackTrace ( ) ;
out . println ( mergeTemplate ( msgSessionTimeout , errorTemplate ) ) ;
out . println ( mergeTemplate ( msgSessionTimeout , errorTemplate ) ) ;
}
catch ( Exception e )
{
e . printStackTrace ( ) ;
// out.println( mergeTemplate( msgGenericError , backUri, errorTemplate ) );
out . println ( mergeTemplate ( msgGenericError , errorTemplate ) ) ;
// out.println( mergeTemplate( msgGenericError , backUri,
// errorTemplate ) );
out . println ( mergeTemplate ( msgGenericError , errorTemplate ) ) ;
}
// System.out.println( "fim - " + queryString + " bu " + backUri );
// System.out.println( "fim - " + queryString + " bu " + backUri );
}
public void doPost ( HttpServletRequest req , HttpServletResponse res )
throws IOException
public void doPost ( HttpServletRequest req , HttpServletResponse res ) throws IOException
{
ServletOutputStream out = res . getOutputStream ( ) ;
// StringBuffer dbQuery;
// ResultSet2DArray rs;
// Connection con = null ;
// Statement stmt = null ;
// String user, userRole, password;
String buttonPressed = req . getParameter ( "form" ) ;
// StringBuffer dbQuery;
// ResultSet2DArray rs;
// Connection con = null ;
// Statement stmt = null ;
// String user, userRole, password;
String buttonPressed = req . getParameter ( "form" ) ;
res . setContentType ( "text/html" ) ;
try
{
if ( buttonPressed . equals ( botaoLogin ) )
if ( buttonPressed . equals ( botaoLogin ) )
{
new doPostLogin ( req , res ) ;
new doPostLogin ( req , res ) ;
}
else
{
out . println ( mergeTemplate ( msgButtonNotSuported , errorTemplate ) ) ;
out . println ( mergeTemplate ( msgButtonNotSuported , errorTemplate ) ) ;
}
}
/ * catch ( SQLException e )
{
e . printStackTrace ( ) ;
out . println ( mergeTemplate ( msgErroBd , criticalErrorTemplate ) ) ;
} * /
/ *
* catch ( SQLException e ) { e . printStackTrace ( ) ; out . println (
* mergeTemplate ( msgErroBd , criticalErrorTemplate ) ) ; }
* /
catch ( IllegalStateException e ) // session timeout
{
e . printStackTrace ( ) ;
out . println ( mergeTemplate ( msgSessionTimeout , errorTemplate ) ) ;
out . println ( mergeTemplate ( msgSessionTimeout , errorTemplate ) ) ;
}
catch ( Exception e )
{
e . printStackTrace ( ) ;
out . println ( mergeTemplate ( msgGenericError , errorTemplate ) ) ;
out . println ( mergeTemplate ( msgGenericError , errorTemplate ) ) ;
}
}
public String mergeTemplate ( Map values , String template )
public String mergeTemplate ( Map < String , Object > values , String template )
{
VelocityContext context = new VelocityContext ( ) ;
StringWriter output = new StringWriter ( ) ;
try
{
for ( Iterator i = values . keySet ( ) . iterator ( ) ; i . hasNext ( ) ; )
Iterator < String > it = values . keySet ( ) . iterator ( ) ;
while ( it . hasNext ( ) )
{
String key = ( String ) i . next ( ) ;
context . put ( key , values . get ( key ) ) ;
//fpalma
// Object value = values.get( key );
// context.put ( key, value != null ?
// UnicodeChecker.parseToUnicode( "&#x", 2, ";", value.toString(), true )
// : null );
String key = it . next ( ) ;
context . put ( key , values . get ( key ) ) ;
}
Velocity . mergeTemplate ( template , Velocity . ENCODING_DEFAULT , context , output ) ;
Velocity . mergeTemplate ( template , Velocity . ENCODING_DEFAULT , context , output ) ;
return output . toString ( ) ;
}
catch ( Exception e )
catch ( Exception e )
{
e . printStackTrace ( ) ;
}
return null ;
}
public String mergeTemplate ( String msg , String template ) // #1
public String mergeTemplate ( String msg , String template ) // #1
{
VelocityContext context = new VelocityContext ( ) ;
StringWriter output = new StringWriter ( ) ;
try
{
context . put ( msgTemplate , msg ) ;
Velocity . mergeTemplate ( template , Velocity . ENCODING_DEFAULT , context , output ) ;
context . put ( msgTemplate , msg ) ;
Velocity . mergeTemplate ( template , Velocity . ENCODING_DEFAULT , context , output ) ;
return output . toString ( ) ;
}
catch ( Exception e )
catch ( Exception e )
{
e . printStackTrace ( ) ;
}
return null ;
}
public String mergeTemplate ( String msg , String userRole , String template ) // #1
public String mergeTemplate ( String msg , String userRole , String template ) // #1
{
VelocityContext context = new VelocityContext ( ) ;
@ -354,36 +360,35 @@ System.out.println( "query: " + queryString );
try
{
context . put ( msgTemplate , msg ) ;
context . put ( templateUserRole , userRole ) ;
Velocity . mergeTemplate ( template , Velocity . ENCODING_DEFAULT , context , output ) ;
context . put ( msgTemplate , msg ) ;
context . put ( templateUserRole , userRole ) ;
Velocity . mergeTemplate ( template , Velocity . ENCODING_DEFAULT , context , output ) ;
return output . toString ( ) ;
}
catch ( Exception e )
catch ( Exception e )
{
e . printStackTrace ( ) ;
}
return null ;
}
public String mergeTemplate ( String msg , String userRole , String querySelected , Vector vector1 , Vector vector2 , Vector vector3 , String template ) // #2
public String mergeTemplate ( String msg , String userRole , String querySelected , Vector vector1 , Vector vector2 , Vector vector3 , String template ) // #2
{
VelocityContext context = new VelocityContext ( ) ;
StringWriter output = new StringWriter ( ) ;
try
{
context . put ( msgTemplate , msg ) ;
context . put ( templateUserRole , userRole ) ;
context . put ( templateQuery , querySelected ) ;
context . put ( templateVector1 , vector1 ) ;
context . put ( templateVector2 , vector2 ) ;
context . put ( templateVector3 , vector3 ) ;
Velocity . mergeTemplate ( template , Velocity . ENCODING_DEFAULT , context , output ) ;
context . put ( msgTemplate , msg ) ;
context . put ( templateUserRole , userRole ) ;
context . put ( templateQuery , querySelected ) ;
context . put ( templateVector1 , vector1 ) ;
context . put ( templateVector2 , vector2 ) ;
context . put ( templateVector3 , vector3 ) ;
Velocity . mergeTemplate ( template , Velocity . ENCODING_DEFAULT , context , output ) ;
return output . toString ( ) ;
}
catch ( Exception e )
catch ( Exception e )
{
e . printStackTrace ( ) ;
}
@ -394,47 +399,47 @@ System.out.println( "query: " + queryString );
{
}
public void handleSessionTimeout ( HttpServletResponse res , String template )
throws IOException
public void handleSessionTimeout ( HttpServletResponse res , String template ) throws IOException
{
ServletOutputStream out = res . getOutputStream ( ) ;
try
{
out . println ( mergeTemplate ( msgSessionTimeout , template ) ) ;
out . println ( mergeTemplate ( msgSessionTimeout , template ) ) ;
}
catch ( Exception e )
{
e . printStackTrace ( ) ;
}
}
public boolean verificaEstabelecimento ( Connection con , java . lang . String empresaId , java . lang . String estabelecimentoId )
public boolean verificaEstabelecimento ( Connection con , java . lang . String empresaId , java . lang . String estabelecimentoId )
// verifica se o establecimento pertence 'a empresa
{
// Connection con = null ;
Statement stmt = null ;
// Connection con = null ;
Statement stmt = null ;
Virtual2DArray rs ;
String query ;
try
{
//con = DriverManager.getConnection( bdUrl, bdUsername, bdPassword );
query = "SELECT empresa_id FROM estabelecimentos where id='" + estabelecimentoId + "'" ;
if ( con ! = null )
// con = DriverManager.getConnection( bdUrl, bdUsername, bdPassword
// );
query = "SELECT empresa_id FROM estabelecimentos where id='" + estabelecimentoId + "'" ;
if ( con ! = null )
{
stmt = con . createStatement ( ResultSet . TYPE_SCROLL_INSENSITIVE , ResultSet . CONCUR_READ_ONLY ) ;
stmt = con . createStatement ( ResultSet . TYPE_SCROLL_INSENSITIVE , ResultSet . CONCUR_READ_ONLY ) ;
rs = new ResultSet2DArray ( stmt . executeQuery ( query ) ) ;
}
else
{
rs = getExecuter ( ) . executeQuery ( new Select ( query ) ) ;
}
String temp = "" + rs . get ( 0 , 0 ) ; // converter de int para String
if ( con ! = null )
String temp = "" + rs . get ( 0 , 0 ) ; // converter de int para String
if ( con ! = null )
{
stmt . close ( ) ;
}
if ( empresaId . equals ( temp ) ) // estabelecimento pertence 'a empresa
if ( empresaId . equals ( temp ) ) // estabelecimento pertence 'a
// empresa
{
return true ;
}
@ -450,23 +455,25 @@ System.out.println( "query: " + queryString );
return false ;
}
public boolean verificaTrabalhador ( Connection con , java . lang . String estabelecimentoId , java . lang . String trabalhadorId )
public boolean verificaTrabalhador ( Connection con , java . lang . String estabelecimentoId , java . lang . String trabalhadorId )
// verifica se o trabalhador pertence ao estabelecimento
{
// Connection con = null ;
Statement stmt = null ;
// Connection con = null ;
Statement stmt = null ;
ResultSet2DArray rs ;
StringBuffer dbQuery ;
try
{
//con = DriverManager.getConnection( bdUrl, bdUsername, bdPassword );
// con = DriverManager.getConnection( bdUrl, bdUsername, bdPassword
// );
dbQuery = new StringBuffer ( ) ;
dbQuery . append ( "SELECT estabelecimento_id FROM trabalhadores where id='" + trabalhadorId + "'" ) ;
stmt = con . createStatement ( ResultSet . TYPE_SCROLL_INSENSITIVE , ResultSet . CONCUR_READ_ONLY ) ;
rs = new ResultSet2DArray ( stmt . executeQuery ( dbQuery . toString ( ) ) ) ;
String temp = "" + rs . get ( 0 , 0 ) ; // converter de int para String
dbQuery . append ( "SELECT estabelecimento_id FROM trabalhadores where id='" + trabalhadorId + "'" ) ;
stmt = con . createStatement ( ResultSet . TYPE_SCROLL_INSENSITIVE , ResultSet . CONCUR_READ_ONLY ) ;
rs = new ResultSet2DArray ( stmt . executeQuery ( dbQuery . toString ( ) ) ) ;
String temp = "" + rs . get ( 0 , 0 ) ; // converter de int para String
stmt . close ( ) ;
if ( estabelecimentoId . equals ( temp ) ) // estabelecimento pertence 'a empresa
if ( estabelecimentoId . equals ( temp ) ) // estabelecimento pertence
// 'a empresa
{
return true ;
}
@ -482,11 +489,12 @@ System.out.println( "query: " + queryString );
return false ;
}
public void closeSqlCon ( Connection con )
public void closeSqlCon ( Connection con )
{
try
{
if ( con ! = null ) con . close ( ) ;
if ( con ! = null )
con . close ( ) ;
}
catch ( Exception e )
{
@ -495,9 +503,9 @@ System.out.println( "query: " + queryString );
}
public String emailEmpresa ( Connection con , String empresaId )
public String emailEmpresa ( Connection con , String empresaId )
{
Statement stmt = null ;
Statement stmt = null ;
ResultSet2DArray rs ;
StringBuffer dbQuery ;
String returnString ;
@ -505,13 +513,12 @@ System.out.println( "query: " + queryString );
try
{
dbQuery = new StringBuffer ( ) ;
dbQuery . append ( "SELECT email FROM empresas, contactos "
+ "WHERE empresas.id ='" + empresaId + "' AND empresas.contacto_1 = contactos.id" ) ;
stmt = con . createStatement ( ResultSet . TYPE_SCROLL_INSENSITIVE , ResultSet . CONCUR_READ_ONLY ) ;
rs = new ResultSet2DArray ( stmt . executeQuery ( dbQuery . toString ( ) ) ) ;
if ( rs . columnLength ( ) > 0 )
dbQuery . append ( "SELECT email FROM empresas, contactos " + "WHERE empresas.id ='" + empresaId + "' AND empresas.contacto_1 = contactos.id" ) ;
stmt = con . createStatement ( ResultSet . TYPE_SCROLL_INSENSITIVE , ResultSet . CONCUR_READ_ONLY ) ;
rs = new ResultSet2DArray ( stmt . executeQuery ( dbQuery . toString ( ) ) ) ;
if ( rs . columnLength ( ) > 0 )
{
returnString = ( String ) rs . get ( 0 , 0 ) ;
returnString = ( String ) rs . get ( 0 , 0 ) ;
stmt . close ( ) ;
return returnString ;
}
@ -527,28 +534,28 @@ System.out.println( "query: " + queryString );
return null ;
}
public String nomeEmpresa ( Connection con , String empresaId )
public String nomeEmpresa ( Connection con , String empresaId )
{
Statement stmt = null ;
Statement stmt = null ;
Virtual2DArray rs ;
String returnString ;
try
{
String query = "SELECT designacao_social FROM empresas WHERE id ='" + empresaId + "'" ;
if ( con ! = null )
String query = "SELECT designacao_social FROM empresas WHERE id ='" + empresaId + "'" ;
if ( con ! = null )
{
stmt = con . createStatement ( ResultSet . TYPE_SCROLL_INSENSITIVE , ResultSet . CONCUR_READ_ONLY ) ;
stmt = con . createStatement ( ResultSet . TYPE_SCROLL_INSENSITIVE , ResultSet . CONCUR_READ_ONLY ) ;
rs = new ResultSet2DArray ( stmt . executeQuery ( query ) ) ;
}
else
{
rs = getExecuter ( ) . executeQuery ( new Select ( query ) ) ;
}
if ( rs . columnLength ( ) > 0 )
if ( rs . columnLength ( ) > 0 )
{
returnString = ( String ) rs . get ( 0 , 0 ) ;
if ( con ! = null )
returnString = ( String ) rs . get ( 0 , 0 ) ;
if ( con ! = null )
{
stmt . close ( ) ;
}
@ -566,29 +573,29 @@ System.out.println( "query: " + queryString );
return null ;
}
public String nomeEstabelecimento ( Connection con , java . lang . String estabelecimentoId )
public String nomeEstabelecimento ( Connection con , java . lang . String estabelecimentoId )
{
Statement stmt = null ;
Statement stmt = null ;
Virtual2DArray rs ;
StringBuffer dbQuery ;
String returnString ;
try
{
String query = "SELECT nome FROM estabelecimentos WHERE id ='" + estabelecimentoId + "'" ;
if ( con ! = null )
String query = "SELECT nome FROM estabelecimentos WHERE id ='" + estabelecimentoId + "'" ;
if ( con ! = null )
{
stmt = con . createStatement ( ResultSet . TYPE_SCROLL_INSENSITIVE , ResultSet . CONCUR_READ_ONLY ) ;
stmt = con . createStatement ( ResultSet . TYPE_SCROLL_INSENSITIVE , ResultSet . CONCUR_READ_ONLY ) ;
rs = new ResultSet2DArray ( stmt . executeQuery ( query ) ) ;
}
else
{
rs = getExecuter ( ) . executeQuery ( new Select ( query ) ) ;
}
if ( rs . columnLength ( ) > 0 )
if ( rs . columnLength ( ) > 0 )
{
returnString = ( String ) rs . get ( 0 , 0 ) ;
if ( con ! = null )
returnString = ( String ) rs . get ( 0 , 0 ) ;
if ( con ! = null )
{
stmt . close ( ) ;
}
@ -606,9 +613,9 @@ System.out.println( "query: " + queryString );
return null ;
}
public String nomeTrabalhador ( Connection con , java . lang . String trabalhadorId )
public String nomeTrabalhador ( Connection con , java . lang . String trabalhadorId )
{
Statement stmt = null ;
Statement stmt = null ;
ResultSet2DArray rs ;
StringBuffer dbQuery ;
String returnString ;
@ -616,12 +623,12 @@ System.out.println( "query: " + queryString );
try
{
dbQuery = new StringBuffer ( ) ;
dbQuery . append ( "SELECT nome FROM trabalhadores where id='" + trabalhadorId + "'" ) ;
stmt = con . createStatement ( ResultSet . TYPE_SCROLL_INSENSITIVE , ResultSet . CONCUR_READ_ONLY ) ;
rs = new ResultSet2DArray ( stmt . executeQuery ( dbQuery . toString ( ) ) ) ;
if ( rs . columnLength ( ) > 0 )
dbQuery . append ( "SELECT nome FROM trabalhadores where id='" + trabalhadorId + "'" ) ;
stmt = con . createStatement ( ResultSet . TYPE_SCROLL_INSENSITIVE , ResultSet . CONCUR_READ_ONLY ) ;
rs = new ResultSet2DArray ( stmt . executeQuery ( dbQuery . toString ( ) ) ) ;
if ( rs . columnLength ( ) > 0 )
{
returnString = ( String ) rs . get ( 0 , 0 ) ;
returnString = ( String ) rs . get ( 0 , 0 ) ;
stmt . close ( ) ;
return returnString ;
}
@ -637,12 +644,11 @@ System.out.println( "query: " + queryString );
return null ;
}
public void doErro ( String queryString , ServletOutputStream out )
throws Exception
public void doErro ( String queryString , ServletOutputStream out ) throws Exception
{
String split [ ] = queryString . split ( "=" ) ;
String err ;
if ( split . length > 1 )
if ( split . length > 1 )
{
err = split [ 1 ] ;
}
@ -651,21 +657,19 @@ System.out.println( "query: " + queryString );
err = "Erro" ;
}
err = err . replace ( '+' , ' ' ) ;
// out.println( mergeTemplate( err, innerErrorTemplate) );
// out.println( mergeTemplate( err, innerErrorTemplate) );
out . println ( mergeTemplate ( err , errorTemplate ) ) ;
}
protected Executer getExecuter ( )
throws Exception
protected Executer getExecuter ( ) throws Exception
{
ServletContext context = CONTEXT ;
DBManager dbm = ( DBManager ) context . getAttribute ( Singleton . DEFAULT_DBMANAGER ) ;
if ( dbm = = null )
if ( dbm = = null )
{
dbm = new JDBCManager ( bdLocalUrl , bdLocalUsername , bdLocalPassword , 500 , 499 , 1 , null ) ;
dbm = new JDBCManager ( bdLocalUrl , bdLocalUsername , bdLocalPassword , 500 , 499 , 1 , null ) ;
context . setAttribute ( Singleton . DEFAULT_DBMANAGER , dbm ) ;
}
return dbm . getSharedExecuter ( this ) ;
}
}