List of usage examples for org.apache.commons.lang3 StringUtils startsWithIgnoreCase
public static boolean startsWithIgnoreCase(final CharSequence str, final CharSequence prefix)
Case insensitive check if a CharSequence starts with a specified prefix.
null s are handled without exceptions.
From source file:org.mitre.mpf.wfm.camelOps.TestMediaInspectionProcessor.java
License:asdf
/** Tests that the results from an audio file are sane. */ @Test(timeout = 5 * MINUTES)// w w w . j a va 2 s . c o m public void testAudioInspection() throws Exception { log.info("Starting audio inspection test."); // TODO: Implement test. TransientMedia transientMedia = new TransientMedia(next(), ioUtils.findFile("/samples/green.wav").toString()); Exchange exchange = new DefaultExchange(camelContext); exchange.getIn().getHeaders().put(MpfHeaders.JOB_ID, next()); exchange.getIn().setBody(jsonUtils.serialize(transientMedia)); mediaInspectionProcessor.process(exchange); Object responseBody = exchange.getOut().getBody(); Assert.assertTrue("A response body must be set.", responseBody != null); Assert.assertTrue(String.format("Response body must be a byte[]. Actual: %s.", responseBody.getClass()), responseBody instanceof byte[]); // Implied assertion: Deserialization works. TransientMedia responseTransientMedia = jsonUtils.deserialize((byte[]) responseBody, TransientMedia.class); Assert.assertTrue( String.format("The response entity must not fail. Actual: %s. Message: %s.", Boolean.toString(responseTransientMedia.isFailed()), responseTransientMedia.getMessage()), !responseTransientMedia.isFailed()); String targetType = "audio"; Assert.assertTrue( String.format("The medium's type should begin with '%s'. Actual: %s.", targetType, responseTransientMedia.getType()), StringUtils.startsWithIgnoreCase(responseTransientMedia.getType(), targetType)); int targetLength = -1; //`ffprobe -v error -show_entries format=duration -of default=noprint_wrappers=1:nokey=1 green.wav` - actually produces 2.200000 Assert.assertTrue(String.format("The medium's length should be %d. Actual: %d.", targetLength, responseTransientMedia.getLength()), responseTransientMedia.getLength() == targetLength); String targetHash = "237739f8d6ff3459d747f79d272d148d156a696bad93f3ddecc2350c4ee5d9e0"; //`sha256sum green.wav` Assert.assertTrue( String.format("The medium's hash should have matched '%s'. Actual: %s.", targetHash, responseTransientMedia.getSha256()), targetHash.equalsIgnoreCase(responseTransientMedia.getSha256())); log.info("Audio inspection passed."); }
From source file:org.mitre.mpf.wfm.util.IoUtils.java
/** * <p>/*w w w . jav a 2s . c o m*/ * Determines if the path is local or remote. * * If given as http scheme, pings the server to determine if the resource is available. * * If local, attempts to find a file with the given path on the filesystem, and if that fails, * assumes that the file is a resource. * </p> * * @param path The file to find. * @return A URI which should resolve to the file. * @throws WfmProcessingException if path could not be converted to a URI */ public URI findFile(String path) throws WfmProcessingException { if (StringUtils.startsWithIgnoreCase(path.toLowerCase(), "http")) { try { return new URI(path); } catch (URISyntaxException use) { throw new WfmProcessingException(use); } } File file = new File(path); if (file.exists()) { return file.getAbsoluteFile().toURI(); } else { try { URL url = IoUtils.class.getResource(path); if (url != null) { return url.toURI(); } else { throw new WfmProcessingException( String.format("Resource not found when converting %s to URI", path)); } } catch (URISyntaxException use) { throw new WfmProcessingException( String.format("Exception occurred when converting path %s to URI", path), use); } } }
From source file:org.mitre.mpf.wfm.util.MediaTypeUtils.java
/** * Uses the media mimeType and any whitelisted properties to determine how to process * a piece of media./*from w w w.j a va 2 s. c o m*/ * * @param mimeType The mime-type of the media. * @return The MediaType to treat the media as. */ public static MediaType parse(String mimeType) { String trimmedMimeType = TextUtils.trim(mimeType); if (mediaTypeProperties == null) { log.warn("media type properties not loaded."); } else { String typeFromWhitelist = mediaTypeProperties.getProperty("whitelist." + mimeType); if (typeFromWhitelist != null) { log.debug("MediaType Found in whitelist:" + mimeType + " " + typeFromWhitelist); MediaType type = MediaType.valueOf(typeFromWhitelist); if (type != null) { return type; } } } if (StringUtils.startsWithIgnoreCase(trimmedMimeType, "AUDIO")) { return MediaType.AUDIO; } else if (StringUtils.startsWithIgnoreCase(trimmedMimeType, "IMAGE")) { return MediaType.IMAGE; } else if (StringUtils.startsWithIgnoreCase(trimmedMimeType, "VIDEO")) { return MediaType.VIDEO; } else { return MediaType.UNSUPPORTED; } }
From source file:org.openestate.io.daft_ie.DaftIeUtils.java
public static URL parseURL(String value) { value = StringUtils.trimToNull(value); if (value == null) return null; try {/*from w w w . jav a2 s.c om*/ if (!StringUtils.startsWithIgnoreCase(value, "http://") && !StringUtils.startsWithIgnoreCase(value, "https://")) return new URL("http://" + value); else return new URL(value); } catch (MalformedURLException ex) { throw new IllegalArgumentException("Can't parse URL value '" + value + "'!", ex); } }
From source file:org.openestate.io.is24_xml.Is24XmlUtils.java
public static URL parseWebUrl(String value) { value = StringUtils.trimToNull(value); if (value == null) return null; try {//from www .j a v a 2 s .co m if (!StringUtils.startsWithIgnoreCase(value, "http://") && !StringUtils.startsWithIgnoreCase(value, "https://")) return new URL("http://" + value); else return new URL(value); } catch (MalformedURLException ex) { throw new IllegalArgumentException("Can't parse URL value '" + value + "'!", ex); } }
From source file:org.openestate.io.kyero.KyeroUtils.java
public static URL parseImageUrlType(String value) { value = StringUtils.trimToNull(value); if (value == null) return null; try {/*from ww w . j av a 2 s . c o m*/ if (!StringUtils.startsWithIgnoreCase(value, "http://") && !StringUtils.startsWithIgnoreCase(value, "https://")) return new URL("http://" + value); else return new URL(value); } catch (MalformedURLException ex) { throw new IllegalArgumentException("Can't parse URL value '" + value + "'!", ex); } }
From source file:org.openestate.io.kyero.KyeroUtils.java
public static URL parseUrlDataType(String value) { value = StringUtils.trimToNull(value); if (value == null) return null; try {/* w w w. j a v a2 s . c o m*/ if (!StringUtils.startsWithIgnoreCase(value, "http://") && !StringUtils.startsWithIgnoreCase(value, "https://")) return new URL("http://" + value); else return new URL(value); } catch (MalformedURLException ex) { throw new IllegalArgumentException("Can't parse URL value '" + value + "'!", ex); } }
From source file:org.paxml.bean.EmailTag.java
private EmailAttachment makeAttachment(String att) { EmailAttachment r = new EmailAttachment(); r.setDisposition(EmailAttachment.ATTACHMENT); URL url = null;/* w ww .ja v a2 s . co m*/ try { url = new URL(att); if (StringUtils.startsWithIgnoreCase(url.getProtocol(), "file")) { r.setPath(url.getPath()); } else { r.setURL(url); } } catch (MalformedURLException e) { r.setPath(att); } r.setName(FilenameUtils.getName(att)); return r; }
From source file:org.paxml.tag.sql.SqlDataSourceTag.java
public String getDriver() { if (StringUtils.isNotBlank(driver)) { return driver; }//ww w.ja va 2 s .c om // the following opensource drivers are on classpath by default if (StringUtils.startsWithIgnoreCase(url, "jdbc:h2:")) { return "org.h2.Driver"; } else if (StringUtils.startsWithIgnoreCase(url, "jdbc:hsqldb:")) { return "org.hsqldb.jdbc.JDBCDriver"; } else if (StringUtils.startsWithIgnoreCase(url, "jdbc:mysql:")) { return "com.mysql.jdbc.Driver"; } else if (StringUtils.startsWithIgnoreCase(url, "jdbc:postgresql:")) { return "org.postgresql.Driver"; } else if (StringUtils.startsWithIgnoreCase(url, "jdbc:odbc:")) { return "sun.jdbc.odbc.JdbcOdbcDriver"; } else // the following are not opensource db, so not on classpath by default if (StringUtils.startsWithIgnoreCase(url, "jdbc:microsoft:sqlserver:")) { return "com.microsoft.jdbc.sqlserver.SQLServerDriver"; } else if (StringUtils.startsWithIgnoreCase(url, "jdbc:oracle:thin:")) { return "oracle.jdbc.driver.OracleDriver"; } else if (StringUtils.startsWithIgnoreCase(url, "jdbc:as400:")) { return "com.ibm.as400.access.AS400JDBCDriver"; } return driver; }
From source file:org.pepstock.jem.ant.ScriptFactory.java
/** * Reads the script extracting the meta data for JEM. * /* w ww .ja va2 s . co m*/ * @param content script content * @return a lit of properties with JEM properties * @throws Exception if any error occurs */ private Properties getProperties(String content) throws JclFactoryException, IOException { Properties jemProperties = new Properties(); // flag to check if it's inside of meta data reading boolean isInJemConfig = false; // if it's able to parse this script // It's difficult to validate a script. All is based on different // tags used in the comments boolean isScript = false; StringBuilder propertiesStrings = new StringBuilder(); // reads script StringReader contentReader = new StringReader(content); List<String> lines = IOUtils.readLines(contentReader); // scans lines for (String line : lines) { // if is a comment if (StringUtils.startsWithIgnoreCase(line, getCommentCharSequence())) { // removes the first part and trim spaces String postComment = StringUtils.stripStart(line, getCommentCharSequence()).trim(); // checks if is the begin element if (getBeginElement().equalsIgnoreCase(postComment)) { // if flag is true, means the begin element is written twice if (isInJemConfig) { throw new JclFactoryException( AntMessage.JEMA070E.toMessage().getFormattedMessage(getBeginElement())); } // sets flags isInJemConfig = true; isScript = true; } else if (getEndElement().equalsIgnoreCase(postComment)) { // checks if is the end element // if the flag is false, means that there isn't begin element if (!isInJemConfig) { throw new JclFactoryException( AntMessage.JEMA071E.toMessage().getFormattedMessage(getBeginElement())); } // sets false and break isInJemConfig = false; break; } else if (isInJemConfig) { //reads properties if flag is true propertiesStrings.append(postComment).append(System.getProperty("line.separator")); } } else if (isInJemConfig) { // if we are here. that means the comment line stops before closing the metadata throw new JclFactoryException(AntMessage.JEMA071E.toMessage().getFormattedMessage(getEndElement())); } } // if we are here, that means it gets the end before closing the metadata if (isInJemConfig) { throw new JclFactoryException(AntMessage.JEMA071E.toMessage().getFormattedMessage(getEndElement())); } // if we are here, there isn't the begin element and then the script is not of the type of the factory if (!isScript) { throw new JclFactoryException(AntMessage.JEMA071E.toMessage().getFormattedMessage(getBeginElement())); } // loads properties StringReader reader = new StringReader(propertiesStrings.toString()); jemProperties.load(reader); return jemProperties; }