List of usage examples for org.apache.commons.lang3 StringUtils isEmpty
public static boolean isEmpty(final CharSequence cs)
Checks if a CharSequence is empty ("") or null.
StringUtils.isEmpty(null) = true StringUtils.isEmpty("") = true StringUtils.isEmpty(" ") = false StringUtils.isEmpty("bob") = false StringUtils.isEmpty(" bob ") = false
NOTE: This method changed in Lang version 2.0.
From source file:com.sangupta.shire.config.YmlConfigReader.java
public static String[] readLine(String line) { // check for empty lines if (StringUtils.isEmpty(line)) { return null; }/*www . j a v a2s. co m*/ // clean spaces line = line.trim(); // check for comments if (line.startsWith("#")) { return null; } // check for corrupt property file if (line.startsWith(":")) { throw new RuntimeException("Corrupt YML file, property cannot begin with a colon"); } // read the property int index = line.indexOf(':'); String propertyName = line.substring(0, index).trim(); String propertyValue = ""; if ((index + 1) < line.length()) { propertyValue = line.substring(index + 1).trim(); } String[] tokens = { propertyName, propertyValue }; return tokens; }
From source file:minor.stockQuote.stockQuote.java
@Override public void validate() { if (StringUtils.isEmpty(getStockQuote())) { addFieldError("StockQuote", "Stock Quote cannot be blank"); }/*from w w w .j a v a 2s . c om*/ if (StringUtils.isNumeric(getStockQuote())) { addFieldError("StockQuote", "Stock Quote cannot be numeric"); } if (StringUtils.length(getStockQuote()) > 6) { addFieldError("StockQuote", "Invalid Ticker length"); } }
From source file:com.astamuse.asta4d.data.convertor.String2Long.java
@Override public Long convert(String s) throws UnsupportedValueException { if (StringUtils.isEmpty(s)) { return null; }//from ww w. j a v a 2 s . co m try { return Long.parseLong(s); } catch (NumberFormatException nfe) { throw new UnsupportedValueException(); } }
From source file:com.astamuse.asta4d.data.convertor.String2Bool.java
@Override public Boolean convert(String s) throws UnsupportedValueException { if (StringUtils.isEmpty(s)) { return null; } else {//w w w. ja v a 2 s. c o m return Boolean.parseBoolean(s); } }
From source file:jongo.JongoJetty.java
private static XmlConfiguration getJettyConfiguration() { // First we try from the command line String jettyFile = System.getProperty("jetty.configuration"); if (StringUtils.isEmpty(jettyFile)) { l.info("No jetty.configuration option given. Using etc/jetty.xml"); jettyFile = "etc/jetty.xml"; }/* ww w.j a va 2s . co m*/ Resource jettyXml = null; try { jettyXml = Resource.newSystemResource(jettyFile); } catch (IOException ex) { l.warn("Failed to read Jetty Configuration file: {}. Trying with jetty.xml", jettyFile); } if (jettyXml == null) { jettyFile = "jetty.xml"; try { jettyXml = Resource.newSystemResource(jettyFile); } catch (IOException ex1) { l.error("Failed to read jetty configuration.", ex1); } } XmlConfiguration configuration = null; if (jettyXml != null) { try { configuration = new XmlConfiguration(jettyXml.getInputStream()); } catch (SAXException ex) { l.error("Failed to parse Jetty configuration"); l.error(ex.getMessage(), ex); } catch (IOException ex) { l.error("Failed to read Jetty configuration"); l.error(ex.getMessage(), ex); } } return configuration; }
From source file:com.keybox.manage.db.AuthDB.java
/** * auth user and return auth token if valid auth * * @param auth username and password object * @return auth token if success/*from w w w.j av a2 s . c o m*/ */ public static String login(Auth auth) { //check ldap first String authToken = ExternalAuthUtil.login(auth); if (StringUtils.isEmpty(authToken)) { Connection con = null; try { con = DBUtils.getConn(); //get salt for user String salt = getSaltByUsername(con, auth.getUsername()); //login PreparedStatement stmt = con .prepareStatement("select * from users where enabled=true and username=? and password=?"); stmt.setString(1, auth.getUsername()); stmt.setString(2, EncryptionUtil.hash(auth.getPassword() + salt)); ResultSet rs = stmt.executeQuery(); if (rs.next()) { auth.setId(rs.getLong("id")); authToken = UUID.randomUUID().toString(); auth.setAuthToken(authToken); auth.setAuthType(Auth.AUTH_BASIC); updateLogin(con, auth); } DBUtils.closeRs(rs); DBUtils.closeStmt(stmt); } catch (Exception e) { log.error(e.toString(), e); } DBUtils.closeConn(con); } return authToken; }
From source file:com.astamuse.asta4d.data.convertor.String2Int.java
@Override public Integer convert(String s) throws UnsupportedValueException { if (StringUtils.isEmpty(s)) { return null; }/*from w w w . ja v a 2s. co m*/ try { return Integer.parseInt(s); } catch (NumberFormatException nfe) { throw new UnsupportedValueException(); } }
From source file:de.micromata.genome.gwiki.utils.PropUtils.java
public static OrderedProperties toProperties(String text) { OrderedProperties props = new OrderedProperties(); if (StringUtils.isEmpty(text) == true) { return props; }//w ww . ja v a 2 s .com try { props.load(IOUtils.toInputStream(text, PROPS_ENCODING)); return props; } catch (IOException ex) { throw new RuntimeIOException("Failed to parse Property file: " + ex.getMessage(), ex); } }
From source file:com.adguard.android.filtering.api.HttpServiceClient.java
/** * Downloads string from the specified url. * * @param downloadUrl Download url//from w ww . java 2 s . c om * @return String or null * @throws IOException */ public static String downloadString(String downloadUrl) throws IOException { LOG.debug("Sending HTTP GET request to {}", downloadUrl); final String response = UrlUtils.downloadString(downloadUrl, READ_TIMEOUT, CONNECTION_TIMEOUT); if (StringUtils.isEmpty(response)) { LOG.error("Response for {} is empty", downloadUrl); throw new IOException("Response is empty."); } LOG.debug("Got response:{}", response); return response; }
From source file:Action.UserLoginAction.java
@Override public void validate() { if (StringUtils.isEmpty(user.getUsername())) addFieldError("user.username", "User Name can not be blank"); if (StringUtils.isEmpty(user.getPassword())) addFieldError("user.password", "Password con not be blank"); }