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.nimbits.client.model.server.ServerModel.java
public ServerModel(final UrlContainer url, EmailAddress emailAddress, final AccessKey accessToken) { if (StringUtils.isEmpty(url.getUrl())) { throw new IllegalArgumentException("url was null"); }//from w ww.j a v a 2 s . c o m this.url = removeProtocol(url); this.accessToken = accessToken; this.protocol = Protocol.http; this.email = emailAddress.getValue(); }
From source file:com.zip.CreateZipWithOutputStreams.java
public static void zipFilesAndEncrypt(String srcFileName, String zipFileName, String password) { ZipOutputStream outputStream = null; InputStream inputStream = null; try {/*from w w w. j a v a 2 s .c om*/ File srcFile = new File(srcFileName); File[] files = new File[0]; if (srcFile.isDirectory()) { files = srcFile.listFiles(); } else { files = new File[1]; files[0] = srcFile; } outputStream = new ZipOutputStream(new FileOutputStream(new File(zipFileName))); ZipParameters parameters = new ZipParameters(); parameters.setCompressionMethod(Zip4jConstants.COMP_DEFLATE); parameters.setCompressionLevel(Zip4jConstants.DEFLATE_LEVEL_NORMAL); if (!StringUtils.isEmpty(password)) { parameters.setEncryptFiles(true); //Zip4j supports AES or Standard Zip Encryption (also called ZipCrypto) //If you choose to use Standard Zip Encryption, please have a look at example //as some additional steps need to be done while using ZipOutputStreams with //Standard Zip Encryption parameters.setEncryptionMethod(Zip4jConstants.ENC_METHOD_AES); parameters.setAesKeyStrength(Zip4jConstants.AES_STRENGTH_256); parameters.setPassword(password); } //Now we loop through each file and read this file with an inputstream //and write it to the ZipOutputStream. int fileNums = files.length; File tmpFile = null; OutputStream os = null; for (int i = 0; i < fileNums; i++) { File file = (File) files[i]; //This will initiate ZipOutputStream to include the file //with the input parameters // parameters.setFileNameInZip("test.txt"); tmpFile = new File(new String(file.getPath().getBytes("ISO-8859-1"), "GBK")); // tmpFile.createNewFile(); FileUtils.writeByteFile(FileUtils.readFileByte(file), tmpFile); // tmpFile = new File(""); outputStream.putNextEntry(tmpFile, parameters); //If this file is a directory, then no further processing is required //and we close the entry (Please note that we do not close the outputstream yet) if (file.isDirectory()) { outputStream.closeEntry(); continue; } inputStream = new FileInputStream(file); byte[] readBuff = new byte[4096]; int readLen = -1; //Read the file content and write it to the OutputStream while ((readLen = inputStream.read(readBuff)) != -1) { outputStream.write(readBuff, 0, readLen); } //Once the content of the file is copied, this entry to the zip file //needs to be closed. ZipOutputStream updates necessary header information //for this file in this step outputStream.closeEntry(); inputStream.close(); } //ZipOutputStream now writes zip header information to the zip file outputStream.finish(); } catch (Exception e) { e.printStackTrace(); } finally { if (outputStream != null) { try { outputStream.close(); } catch (IOException e) { e.printStackTrace(); } } if (inputStream != null) { try { inputStream.close(); } catch (IOException e) { e.printStackTrace(); } } } }
From source file:de.cubicvoxel.workspacefx.field.IntegerField.java
public IntegerField() { textProperty().addListener((observable, oldValue, newValue) -> { if (StringUtils.isEmpty(newValue)) { intValue = null;/*from ww w . ja v a 2 s . co m*/ } else { try { intValue = Integer.parseInt(newValue); } catch (NumberFormatException e) { setText(oldValue); intValue = Integer.parseInt(oldValue); } } }); }
From source file:com.webbfontaine.valuewebb.model.validators.tt.TTServiceDataValidator.java
public void validate() { String currentKey = ttGen.getIdfNum(); if (StringUtils.isEmpty(currentKey) || ErrorHandling.getInstance().hasScopedErrors("idfNum")) { return;//from ww w. j av a2 s. co m } LOGGER.trace("Started for {0}", currentKey); TtGen serviceTt = null; try { serviceTt = new TTDataImporter().resolveServiceAndLoad(ttGen); } catch (Exception e) { LOGGER.warn("Unable to validate DAI/FDI number, warning message will be shown"); addError(Utils.translate("IDF Num.") + ": " + Utils.translate(Messages.IMPOSSIBLE_TO_PROCESS)); } if (serviceTt == null) { ErrorHandling.addFacesMessageError("idfNum", Utils.translate(Messages.IDF_NUMBER_INEXISTENT)); } else { String serviceTIN = StringUtils.trimToEmpty(serviceTt.getImpTin()); String currentTIN = StringUtils.trimToEmpty(ttGen.getImpTin()); if (!currentTIN.equals(serviceTIN)) { ErrorHandling.addFacesMessageError("impTin", Utils.translate(Messages.ALLOWED_VALUE) + ": " + serviceTIN); } String serviceDate = serviceTt.getIdfDate() == null ? "" : DateUtils.dateToString(serviceTt.getIdfDate(), "dd/MM/yyyy"); String currentDate = ttGen.getIdfDate() == null ? "" : DateUtils.dateToString(ttGen.getIdfDate(), "dd/MM/yyyy"); if (!serviceDate.equals(currentDate)) { ErrorHandling.addFacesMessageError("idfDate", Utils.translate(Messages.ALLOWED_VALUE) + ": " + serviceDate); } LOGGER.debug("TT key: {0}, date: {1}, TIN: {2}. Service data key: {3}, date: {4}, TIN: {5}", currentKey, currentDate, currentTIN, serviceTt.getIdfNum(), serviceDate, serviceTIN); } }
From source file:de.cubicvoxel.workspacefx.field.FloatField.java
public FloatField() { textProperty().addListener(((observable, oldValue, newValue) -> { if (StringUtils.isEmpty(newValue)) { floatValue = null;//w w w. ja v a 2 s .com } else { try { floatValue = Double.parseDouble(newValue); } catch (NumberFormatException e) { setText(oldValue); floatValue = Double.parseDouble(oldValue); } } })); }
From source file:com.netflix.spinnaker.clouddriver.artifacts.http.HttpArtifactAccount.java
@JsonIgnore public boolean usesAuth() { return !(StringUtils.isEmpty(username) && StringUtils.isEmpty(password) && StringUtils.isEmpty(usernamePasswordFile)); }
From source file:com.shenit.commons.utils.ShortLinkUtils.java
/** * Shorten url/*from w w w . j a v a2 s. com*/ * @param url URL that not encoded * @param query * @return */ public static String shorten(String url, String query, Object salt) { if (StringUtils.isEmpty(url)) return null; String joinStr = url.indexOf(HttpUtils.QUERY_CHAR) > 0 ? HttpUtils.QUERY_CHAR : HttpUtils.AMP; final String queryParams = (query != null) ? joinStr + query : StringUtils.EMPTY; String saltStr = DataUtils.toString(salt, StringUtils.EMPTY); url = toUrl((url + queryParams)); return StringUtils.isEmpty(url) ? null : Hashing.murmur3_32().hashString(url + HttpUtils.HASH_CHAR + saltStr, StandardCharsets.UTF_8) .toString(); }
From source file:nc.noumea.mairie.annuairev2.saisie.viewmodel.StringSimpleListModel.java
@Override public boolean inSubModel(Object key, Object value) { String searchString = (String) key; if (StringUtils.isEmpty(searchString)) return true; return StringUtils.startsWithIgnoreCase((String) value, searchString); }
From source file:io.wcm.testing.mock.sling.servlet.MockRequestPathInfo.java
@Override public String[] getSelectors() { if (StringUtils.isEmpty(this.selectorString)) { return new String[0]; } else {//from w w w .j a va 2 s . c o m return StringUtils.split(this.selectorString, "."); } }
From source file:com.aboutdata.web.controller.SearchController.java
@RequestMapping(method = RequestMethod.GET) public String displaySearch(String keywords, Model model) { if (StringUtils.isEmpty(keywords)) { //? ??/*from ww w. java2 s .c o m*/ return "/portal/search/single"; } Pageable pageable = new PageRequest(1, 24); Page<PhotosModel> pages = searchService.search(keywords, pageable); model.addAttribute("pages", pages); model.addAttribute("keywords", keywords); return "/portal/search/result"; }