List of usage examples for org.apache.commons.lang StringUtils isAsciiPrintable
public static boolean isAsciiPrintable(String str)
Checks if the string contains only ASCII printable characters.
From source file:org.eclipse.wb.tests.designer.core.util.base64.Base64UtilsTest.java
public void test_encodeBytes() throws Exception { String encodedString = Base64Utils.encode(UNENCODED_BYTES); assertEquals(ENCODED_BYTES, encodedString); assertTrue(StringUtils.isAsciiPrintable(encodedString)); }
From source file:org.ejbca.core.protocol.cmp.CmpMessageHelper.java
/** @return SenderKeyId of in the header or null none was found. */ public static String getStringFromOctets(final ASN1OctetString octets) { String str = null;// w ww .ja v a 2 s . c o m if (octets != null) { try { str = new String(octets.getOctets(), "UTF-8"); } catch (UnsupportedEncodingException e2) { str = new String(octets.getOctets()); LOG.info("UTF-8 not available, using platform default encoding for keyId."); } if (!StringUtils.isAsciiPrintable(str)) { str = new String(Hex.encode(octets.getOctets())); if (LOG.isDebugEnabled()) { LOG.debug("DEROCtetString content is not asciiPrintable, converting to hex: " + str); } } if (LOG.isDebugEnabled()) { LOG.debug("Found string: " + str); } } return str; }
From source file:org.madsonic.service.TranscodingService.java
/** * Creates a transcoded input stream by interpreting the given command line string. * This includes the following://from ww w . j a v a 2 s . c o m * <ul> * <li>Splitting the command line string to an array.</li> * <li>Replacing occurrences of "%s" with the path of the given music file.</li> * <li>Replacing occurrences of "%t" with the title of the given music file.</li> * <li>Replacing occurrences of "%l" with the album name of the given music file.</li> * <li>Replacing occurrences of "%a" with the artist name of the given music file.</li> * <li>Replacing occurrences of "%f" with the file name of the given file.</li> * <li>Replacing occurrcences of "%b" with the max bitrate.</li> * <li>Replacing occurrcences of "%o" with the video time offset (used for scrubbing).</li> * <li>Replacing occurrcences of "%d" with the video duration (used for HLS).</li> * <li>Replacing occurrcences of "%w" with the video image width.</li> * <li>Replacing occurrcences of "%h" with the video image height.</li> * <li>Prepending the path of the transcoder directory if the transcoder is found there.</li> * </ul> * * @param command The command line string. * @param maxBitRate The maximum bitrate to use. May not be {@code null}. * @param videoTranscodingSettings Parameters used when transcoding video. May be {@code null}. * @param mediaFile The media file. * @param in Data to feed to the process. May be {@code null}. @return The newly created input stream. */ private TranscodeInputStream createTranscodeInputStream(String command, Integer maxBitRate, VideoTranscodingSettings videoTranscodingSettings, MediaFile mediaFile, InputStream in) throws IOException { String filenn = mediaFile.getName(); String title = mediaFile.getTitle(); String album = mediaFile.getAlbumName(); String artist = mediaFile.getArtist(); if (title == null) { title = "Unknown Song"; } if (album == null) { album = "Unknown Album"; } if (artist == null) { artist = "Unknown Artist"; } List<String> result = new LinkedList<String>(Arrays.asList(StringUtil.split(command))); result.set(0, getTranscodeDirectory().getPath() + File.separatorChar + result.get(0)); File tmpFile = null; for (int i = 1; i < result.size(); i++) { String cmd = result.get(i); if (cmd.contains("%b")) { cmd = cmd.replace("%b", String.valueOf(maxBitRate)); } if (cmd.contains("%t")) { cmd = cmd.replace("%t", title); } if (cmd.contains("%f")) { cmd = cmd.replace("%f", filenn); } if (cmd.contains("%l")) { cmd = cmd.replace("%l", album); } if (cmd.contains("%a")) { cmd = cmd.replace("%a", artist); } if (cmd.contains("%o") && videoTranscodingSettings != null) { cmd = cmd.replace("%o", String.valueOf(videoTranscodingSettings.getTimeOffset())); } if (cmd.contains("%d") && videoTranscodingSettings != null) { cmd = cmd.replace("%d", String.valueOf(videoTranscodingSettings.getDuration())); } if (cmd.contains("%w") && videoTranscodingSettings != null) { cmd = cmd.replace("%w", String.valueOf(videoTranscodingSettings.getWidth())); } if (cmd.contains("%h") && videoTranscodingSettings != null) { cmd = cmd.replace("%h", String.valueOf(videoTranscodingSettings.getHeight())); } if (cmd.contains("%s")) { // Work-around for filename character encoding problem on Windows. // Create temporary file, and feed this to the transcoder. String path = mediaFile.getFile().getAbsolutePath(); if (Util.isWindows() && !mediaFile.isVideo() && !StringUtils.isAsciiPrintable(path)) { tmpFile = File.createTempFile("madsonic", "." + FilenameUtils.getExtension(path)); tmpFile.deleteOnExit(); FileUtils.copyFile(new File(path), tmpFile); LOG.debug("Created tmp file: " + tmpFile); cmd = cmd.replace("%s", tmpFile.getPath()); } else { cmd = cmd.replace("%s", path); } } //Build stream URL from HDHOMERUN API if (cmd.contains("%z")) { LOG.info("Preparing HDHOMERUN channel..."); String path = mediaFile.getFile().getAbsolutePath(); String[] channel = FileUtils.readFileToString(new File(path)).split(":"); String stream = "http://" + channel[0] + ":5004/auto/v" + channel[1].trim(); cmd = cmd.replace("%z", stream); } result.set(i, cmd); } return new TranscodeInputStream(new ProcessBuilder(result), in, tmpFile); }
From source file:org.medici.bia.service.user.UserServiceImpl.java
/** * {@inheritDoc}// w ww .j a va 2 s.c o m */ @Override public Integer ratePassword(String password) { if ((password == null) || password.equals("")) return 0; if (password.length() < 8) return 1; if (StringUtils.isAlpha(password)) return 2; if (StringUtils.isAlphanumeric(password)) return 3; if (StringUtils.isAsciiPrintable(password)) return 4; return 0; }
From source file:org.opencb.opencga.storage.hadoop.variant.GenomeHelperTest.java
void assertOrder(List<byte[]> bytes) { String prev = "0"; for (byte[] bytesKey : bytes) { String key = new String(bytesKey); if (StringUtils.isAsciiPrintable(key)) { System.out.println("key = " + key); } else {//from ww w .ja v a 2 s.c o m System.out.println("key = " + Bytes.toHex(bytesKey)); } // System.out.println(prev + ".compareTo(" + key + ") = " + prev.compareTo(key)); assertTrue(prev.compareTo(key) < 0); prev = key; } }
From source file:org.telscenter.sail.webapp.presentation.validators.UserAccountFormValidator.java
/** * @see org.springframework.validation.Validator#validate(java.lang.Object, org.springframework.validation.Errors) *//* ww w .j a va 2 s.c o m*/ public void validate(Object userAccountFormIn, Errors errors) { UserAccountForm userAccountForm = (UserAccountForm) userAccountFormIn; MutableUserDetails userDetails = userAccountForm.getUserDetails(); if (userAccountForm.isNewAccount()) { ValidationUtils.rejectIfEmptyOrWhitespace(errors, "userDetails.password", "error.password-not-specified"); if (errors.getFieldErrorCount("userDetails.password") > 0) { return; } if (userDetails.getPassword().length() > MAX_PASSWORD_LENGTH) { errors.rejectValue("userDetails.password", "error.password-too-long"); return; } if (!StringUtils.isAlphanumeric(userDetails.getPassword())) { errors.rejectValue("userDetails.password", "error.password-illegal-characters"); return; } if (userDetails.getSignupdate() == null) { errors.rejectValue("userDetails.signupdate", "error.signupdate-not-specified"); return; } } else { ValidationUtils.rejectIfEmptyOrWhitespace(errors, "userDetails.username", "error.username-not-specified"); if (!StringUtils.isAlphanumeric(userDetails.getUsername())) { errors.rejectValue("userDetails.username", "error.illegal-characters"); } } ValidationUtils.rejectIfEmptyOrWhitespace(errors, "userDetails.firstname", "error.firstname-not-specified"); ValidationUtils.rejectIfEmptyOrWhitespace(errors, "userDetails.lastname", "error.lastname-not-specified"); if (!StringUtils.isAlphanumeric(userDetails.getFirstname()) || !StringUtils.isAsciiPrintable(userDetails.getFirstname())) { errors.rejectValue("userDetails.firstname", "error.firstname-illegal-characters"); return; } if (!StringUtils.isAlphanumeric(userDetails.getLastname()) || !StringUtils.isAsciiPrintable(userDetails.getLastname())) { errors.rejectValue("userDetails.lastname", "error.lastname-illegal-characters"); return; } if (errors.hasErrors()) userDetails.setPassword(""); }
From source file:org.viafirma.nucleo.X509.CertificadoGenericoFactory.java
/** * Retorna un certificado generico parseando los datos de un certificado X509 * @param certificadoX509 /*from w w w .j av a 2 s . c o m*/ * @return */ public CertificadoGenerico generar(X509Certificate certificadoX509) { CertificadoGenerico certificado = new CertificadoGenerico(); // recuperamos el conjunto de oids Map<String, String> propiedadesOid = X509Handler.getCurrentInstance().readPropertiesOid(certificadoX509); String subject = certificadoX509.getSubjectDN().toString(); // parseo el subject //StringTokenizer tokenizer=new StringTokenizer(subject,",\""); //String [] tokens=subject.split(","); //for (int i = 0; i < tokens.length; i++) { // String parIdValor = tokens[i].trim(); // String id= parIdValor.split("=")[0]; // String valor= parIdValor.split("=")[1]; // propiedadesOid.put(id,valor); //} loadPropiedadesOid(subject, propiedadesOid); // guardo todas las propiedades(pintables) Set<String> keys = propiedadesOid.keySet(); for (Iterator<String> iter = keys.iterator(); iter.hasNext();) { String key = iter.next(); String valor = propiedadesOid.get(key); // FIX: Problema con el encondig utf-8 en openid. String newValue = StringUtils.replaceChars(valor, "??", "aeiounuAEIOU"); if (!StringUtils.isAsciiPrintable(newValue)) { // omitimos el campo iter.remove(); } else { // remplazamos el valor propiedadesOid.put(key, newValue); } } certificado.setPropiedades(propiedadesOid); // identifico el nombre de la CA propietaria del certificado certificado.setCa(certificadoX509.getIssuerDN().getName()); certificado.setNombre(certificado.getPropiedades().get("1.3.6.1.4.1.5734.1.1")); certificado.setApellido1(certificado.getPropiedades().get("1.3.6.1.4.1.5734.1.2")); certificado.setApellido2(certificado.getPropiedades().get("1.3.6.1.4.1.5734.1.3")); certificado.setNumberUserId(certificado.getPropiedades().get("1.3.6.1.4.1.5734.1.4")); certificado.setCn(propiedadesOid.get("CN")); // si no hemos recuperado el nombre en la extensin lo intento recuperar del GIVENNAME. if (StringUtils.isEmpty(certificado.getNombre())) { certificado.setNombre(propiedadesOid.get("GIVENNAME")); } // si no hemos recuperado el nombre APELLIDO. if (StringUtils.isEmpty(certificado.getApellido1())) { certificado.setApellido1(propiedadesOid.get("SURNAME")); } // si no tenemos apelligos, los intentamos recuperar del CN ( cado del edni) // CN="Apelido1 apellido2, nombre (AUTENTICACIN)", if (StringUtils.isEmpty(certificado.getApellido1())) { // TODO, no se recupera correctamente el CN, pero el resultado es el correcto. // Debera de ser StringUtils.substringAfterLast(propiedadesOid.get("CN").replaceAll("\"", ""),",") // pero nos vale con propiedadesOid.get("CN") certificado.setApellido1(propiedadesOid.get("CN")); } // si no hemos recuperado el nombre NIF. if (StringUtils.isEmpty(certificado.getNumberUserId())) { certificado.setNumberUserId(propiedadesOid.get("SERIALNUMBER")); } // si no hemos recuperado el nombre email. if (StringUtils.isEmpty(certificado.getEmail())) { certificado.setEmail(certificado.getPropiedades().get(OID_EMAIL)); } // si sige siendo null lo recupero del oid if (StringUtils.isEmpty(certificado.getEmail())) { certificado.setEmail(propiedadesOid.get("EMAILADDRESS")); } // si no hemos recuperado el pais if (StringUtils.isEmpty(certificado.getPais())) { certificado.setPais(certificado.getPropiedades().get("C")); } // filtrado para que ningun campo sea null if (certificado.getApellido1() == null) { certificado.setApellido1(""); } if (certificado.getApellido2() == null) { certificado.setApellido2(""); } if (certificado.getCa() == null) { certificado.setCa(""); } if (certificado.getEmail() == null) { certificado.setEmail(""); } if (certificado.getNombre() == null) { certificado.setNombre(""); } if (certificado.getPais() == null) { certificado.setPais(""); } if (certificado.getNumberUserId() == null) { certificado.setNumberUserId(""); } // recupero el cargo. String cargo = propiedadesOid.get("T"); if (cargo != null) { certificado.setCargo(cargo); } // recupero el nombre de la organizacin. String organizacion = propiedadesOid.get("O"); if (organizacion != null) { certificado.setOrganizacion(organizacion); } // Detectamos si el certificado est caducado Date hoy = new Date(); if (certificadoX509.getNotAfter().before(hoy)) { // el certificado est caducado. certificado.setCaducado(true); } // recuperar el tpo de certificado loadTipoCertificado(certificado, propiedadesOid, certificado.getCa()); return certificado; }
From source file:vng.paygate.domain.common.NumberUtils.java
public static boolean checkAccountName(String accountName) { if ((StringUtils.isBlank(accountName)) || (accountName.length() > 32) || (accountName.length() < 4)) { return false; }//ww w . j av a 2 s . c o m if ((StringUtils.startsWith(accountName, ".")) || (StringUtils.startsWith(accountName, "_")) || (StringUtils.endsWith(accountName, ".")) || (StringUtils.endsWith(accountName, "_")) || (StringUtils.contains(accountName, "__")) || (StringUtils.contains(accountName, "..")) || (StringUtils.contains(accountName, "_.")) || (StringUtils.contains(accountName, "._"))) { return false; } if ((StringUtils.contains(accountName, ".")) || (StringUtils.contains(accountName, "_"))) { String accountTemp = StringUtils.remove(accountName, "."); accountTemp = StringUtils.remove(accountTemp, "_"); if (StringUtils.isNumeric(accountTemp)) { return true; } } accountName = StringUtils.remove(accountName, "."); accountName = StringUtils.remove(accountName, "_"); if ((!StringUtils.isAlphanumeric(accountName)) || (!StringUtils.isAsciiPrintable(accountName))) { return false; } return true; }