List of usage examples for org.apache.commons.validator GenericValidator isBlankOrNull
public static boolean isBlankOrNull(String value)
Checks if the field isn't null and length of the field is greater than zero not including whitespace.
From source file:org.squale.welcom.outils.DateUtil.java
/** * transforme une chaine de date type jdbc en date et heure * //ww w .jav a2 s . c o m * @param psDate date chaine * @return une date et heure * @throws ParseException parse exception * @deprecated utiliser la methode parseAllDate(String date) */ public static java.util.Date parseJdbcToDateHeure(final String psDate) throws ParseException { instanciate(); if (!GenericValidator.isBlankOrNull(psDate)) { return msdf_jdbc_date_heure.parse(psDate); } else { return null; } }
From source file:org.squale.welcom.outils.DateUtil.java
/** * Transforme une chaine en date en prenant en compte les trois types de formats * //from w ww .j av a2 s .c o m * @param date Chaine transformer * @return la date transforme */ public static java.util.Date parseAllDate(final String date) { instanciate(); java.util.Date d = null; if (!GenericValidator.isBlankOrNull(date)) { try { d = msdf_jdbc_date_heure.parse(date); return d; } catch (final ParseException e) { try { d = msdf_jdbc_date.parse(date); return d; } catch (final ParseException pe) { try { final long timeLong = Long.parseLong(date); d = new Date(timeLong); return d; } catch (final NumberFormatException nfe) { return null; } } } } else { return null; } }
From source file:org.squale.welcom.outils.excel.ExcelFactory.java
/** * @param exceldata les datas/*from ww w . j av a 2 s . c om*/ * @param response la response * @param attachementFileName le nom du fichier * @param engine l'engine * @throws ExcelGenerateurException exception pouvant etre levee */ public static void generateExcelToHTTPResponse(final ExcelData exceldata, final HttpServletResponse response, final String attachementFileName, final ExcelEngine engine) throws ExcelGenerateurException { try { if (response.isCommitted()) { throw new ExcelGenerateurException( "Le header a deja t envoy ... impossible d'ajouter le content-disposition"); } final OutputStream os = response.getOutputStream(); response.setContentType(CONTENT_TYPE); if (!GenericValidator.isBlankOrNull(attachementFileName)) { response.setHeader("Content-Disposition", "attachment;filename=" + attachementFileName + ";"); } generateExcel(exceldata, os, engine); } catch (final IOException e) { throw new ExcelGenerateurException(e.getMessage(), e); } }
From source file:org.squale.welcom.outils.excel.ExcelTable.java
/** * Ecrit l'entete des colonne pour l'export excel * //from ww w. j av a2s. c o m * @param fontSize : Taille de la font * @param sheet : Feuille xls * @throws WriteException : Erreur lors de l'criture de la feuille * @throws RowsExceededException : Trop de lignes */ private void writeHeader(final int fontSize, final WritableSheet sheet) throws WriteException, RowsExceededException { for (int i = 0; i < header.size(); i++) { final WritableFont arial10ptBold = new WritableFont(WritableFont.ARIAL, fontSize, WritableFont.BOLD); final WritableCellFormat allThinBold = new WritableCellFormat(arial10ptBold); allThinBold.setBorder(Border.ALL, BorderLineStyle.THIN); String libelle = resources.getMessage(localeRequest, ((HeaderElement) header.get(i)).getKey()); if (GenericValidator.isBlankOrNull(libelle)) { libelle = ((HeaderElement) header.get(i)).getKey(); } final Label label = new Label(i, 0, libelle, allThinBold); sheet.addCell(label); } }
From source file:org.squale.welcom.outils.jdbc.WConnectionPool.java
/** * Retourne la connexion en fonction du NAME definit lors de la creation de la connexion * //from w w w . j av a 2 s . com * @param name nom de la connexion * @return Retourne la connexion * @throws SQLException : Aucune connexion disponnible sous ce nom */ public static Connection getConnection(final String name) throws SQLException { if (GenericValidator.isBlankOrNull(name)) { return getConnection(); } if (!connectionPool.containsKey(name)) { throw new SQLException( "Aucune dataSource declar sous le nom de " + name + ", verifier votre struts config"); } return ((WConnectionPool) connectionPool.get(name)).getInternalConnection(); }
From source file:org.squale.welcom.outils.jdbc.WConnectionPool.java
/** * Returns a JDBC connection from a connection pool or other resource, to be used and closed promptly. * <p>//from w w w .ja v a 2 s. c om * * @return JDBC connection from resource layer. * @exception SQLException on SQL or other errors. May wrap other exceptions depending on implementation. Will not * return null. */ private Connection getInternalConnection() throws SQLException { // la datasource genere DataSource ds = null; try { if (ds == null) { // create parameter list to access naming system final java.util.Hashtable parms = new java.util.Hashtable(); // Ajoute les parametres necessaire pour le jndi addJNDICompatabiliteMode(parms); if (!GenericValidator.isBlankOrNull(connectionString.getProviderUrl())) { parms.put(javax.naming.Context.PROVIDER_URL, connectionString.getProviderUrl()); } final javax.naming.Context ctx = new javax.naming.InitialContext(parms); ds = (javax.sql.DataSource) ctx.lookup(connectionString.getJndiDataSource()); } // use DataSource factory to get data server connection Connection conn = null; if (!GenericValidator.isBlankOrNull(connectionString.getUserName())) { conn = ds.getConnection(connectionString.getUserName(), connectionString.getUserPassword()); } else { conn = ds.getConnection(); } return conn; } catch (final Exception ex) { logStartup.error("WConnectionPool : Echec connexion : " + ex.getMessage()); if ((ex == null) || (ex.getMessage() == null)) { logStartup.error("Verifier la version de votre classes12.zip"); logStartup.error(" ou Verifier la version de votre odbcj14.jar"); } return null; } }
From source file:org.squale.welcom.outils.jdbc.WConnectionString.java
/** * Set les attributes en fonction du parsing * /*from w ww .j a v a 2 s .c o m*/ * @param key : key * @param value : valeur */ private void setAttribute(final String key, final String value) { if (!GenericValidator.isBlankOrNull(key) && !GenericValidator.isBlankOrNull(value)) { if (Util.isEquals(URL, key)) { setUrlJndi(value); } if (Util.isEquals(PASS, key)) { setUserPassword(value); } if (Util.isEquals(USER, key)) { setUserName(value); } if (Util.isEquals(NAME, key)) { setName(value); } if (Util.isEquals(DESCRIPTION, key)) { setDescription(value); } } if (Util.isEquals(DEFAULT, key)) { setParDefault("true"); } }
From source file:org.squale.welcom.outils.jdbc.WMJdbc.java
/** * Surcharge de la methode init//from w ww . ja v a2s. c om * * @throws SQLException Probleme SQL */ protected void init() throws SQLException { try { if (!GenericValidator.isBlankOrNull(connectionName)) { conn = WConnectionPool.getConnection(connectionName); } else { conn = WConnectionPool.getConnection(); } if (conn != null) { if (conn.isClosed()) { log.error("2004-critical-Database--BD close/Relancer le serveur de BD"); } // Enleve l'autocommit conn.setAutoCommit(false); } } catch (final SQLException e) { throw e; } }
From source file:org.squale.welcom.outils.jdbc.wrapper.ConnectionPool.java
/** * Returns a JDBC connection from a connection pool or other resource, to be used and closed promptly. * <p>/*from w ww . j av a2 s .c o m*/ * * @return JDBC connection from resource layer. * @exception SQLException on SQL or other errors. May wrap other exceptions depending on implementation. Will not * return null. */ public static final Connection getConnection() throws SQLException { try { /* Version JNDI */ /** **************************************************** */ if (ds == null) { // create parameter list to access naming system final java.util.Hashtable parms = new java.util.Hashtable(); try { Class.forName("com.ibm.websphere.naming.WsnInitialContextFactory"); parms.put(javax.naming.Context.INITIAL_CONTEXT_FACTORY, "com.ibm.websphere.naming.WsnInitialContextFactory"); } catch (final ClassNotFoundException e) { logStartup.info("Passage en mode compatibilit WAS 3.5 "); } // parms.put(javax.naming.Context.PROVIDER_URL, PROVIDER_URL); // access naming system final javax.naming.Context ctx = new javax.naming.InitialContext(parms); // get DataSource factory object from naming system ds = (javax.sql.DataSource) ctx.lookup(JNDI_DATASOURCE_KEY); } // use DataSource factory to get data server connection Connection conn = null; if (!GenericValidator.isBlankOrNull(USER)) { conn = ds.getConnection(USER, PASSWD); } else { conn = ds.getConnection(); } return conn; } catch (final Exception ex) { logStartup.error("ConnectionPool : Echec connexion : ", ex); if ((ex == null) || (ex.getMessage() == null)) { logStartup.info("Verifier la version de votre classes12.zip"); } return null; } }
From source file:org.squale.welcom.outils.jdbc.WSessionHibernatePersitance.java
/** * Recupere le provider/* ww w . j av a2 s . com*/ * * @return Le persisance provider * @throws JrafPersistenceException Probleme pour trouver le provider */ private static IPersistenceProvider getPersistenceProvider() throws JrafPersistenceException { final String providerName = WelcomConfigurator .getMessage(WelcomConfigurator.ADDONS_CONFIG_HIBERNATE_PROVIDERPERSISTENCE); if (GenericValidator.isBlankOrNull(providerName)) { return PersistenceHelper.getPersistenceProvider(); } else { final IProvider provider = ProviderLocator.getProvider(providerName); if (provider instanceof IPersistenceProvider) { return (IPersistenceProvider) provider; } else { throw new JrafPersistenceException("Le provider '" + providerName + "' declar sous 'addons.config.hibernate.providerpersistence' introuvable dans le dictionnaire JNDI"); } } }