Example usage for org.apache.commons.lang StringUtils startsWithAny

List of usage examples for org.apache.commons.lang StringUtils startsWithAny

Introduction

In this page you can find the example usage for org.apache.commons.lang StringUtils startsWithAny.

Prototype

public static boolean startsWithAny(String string, String[] searchStrings) 

Source Link

Document

Check if a String starts with any of an array of specified strings.

Usage

From source file:com.mirth.connect.connectors.http.HttpDispatcher.java

private boolean isBinaryContentType(String binaryMimeTypes, ContentType contentType) {
    String mimeType = contentType.getMimeType();

    if (connectorProperties.isResponseBinaryMimeTypesRegex()) {
        Pattern binaryMimeTypesRegex = binaryMimeTypesRegexMap.get(binaryMimeTypes);

        if (binaryMimeTypesRegex == null) {
            try {
                binaryMimeTypesRegex = Pattern.compile(binaryMimeTypes);

                if (binaryMimeTypesRegexMap.size() >= MAX_MAP_SIZE) {
                    binaryMimeTypesRegexMap.clear();
                }/*from   w w w .  j  a  va 2 s  .co  m*/

                binaryMimeTypesRegexMap.put(binaryMimeTypes, binaryMimeTypesRegex);
            } catch (PatternSyntaxException e) {
                logger.warn("Invalid binary MIME types regular expression: " + binaryMimeTypes, e);
                return false;
            }
        }

        return binaryMimeTypesRegex.matcher(mimeType).matches();
    } else {
        String[] binaryMimeTypesArray = binaryMimeTypesArrayMap.get(binaryMimeTypes);

        if (binaryMimeTypesArray == null) {
            binaryMimeTypesArray = StringUtils.split(binaryMimeTypes.replaceAll("\\s*,\\s*", ",").trim(), ',');

            if (binaryMimeTypesArrayMap.size() >= MAX_MAP_SIZE) {
                binaryMimeTypesArrayMap.clear();
            }

            binaryMimeTypesArrayMap.put(binaryMimeTypes, binaryMimeTypesArray);
        }

        return StringUtils.startsWithAny(mimeType, binaryMimeTypesArray);
    }
}

From source file:com.mirth.connect.connectors.http.HttpReceiver.java

@Override
public boolean isBinaryContentType(ContentType contentType) {
    String mimeType = contentType.getMimeType();

    if (connectorProperties.isBinaryMimeTypesRegex()) {
        return binaryMimeTypesRegex.matcher(mimeType).matches();
    } else {//w w  w . ja v  a2 s . c  o  m
        return StringUtils.startsWithAny(mimeType, binaryMimeTypesArray);
    }
}

From source file:adalid.commons.velocity.Writer.java

private String pathString(String string) {
    String trimmed = StringUtils.trimToNull(string);
    if (trimmed == null) {
        return null;
    }/*  w w w.jav  a  2 s.  co  m*/
    String trimSplitJoin = trimSplitJoin(trimmed, FILE_SEPARATOR_CHARS, FILE_SEPARATOR);
    return StringUtils.startsWithAny(trimmed, FILE_SEPARATOR_STRINGS) ? FILE_SEPARATOR + trimSplitJoin
            : trimSplitJoin;
}

From source file:adalid.commons.velocity.Writer.java

private boolean isAbsolutePath(String string) {
    String trimmed = StringUtils.trimToNull(string);
    if (trimmed == null) {
        return false;
    }/* w  ww .jav a  2  s  .  com*/
    if (WINDOWS) {
        String left = StringUtils.left(trimmed, 2);
        return left.matches("[a-zA-Z]\\:");
    } else {
        return StringUtils.startsWithAny(trimmed, FILE_SEPARATOR_STRINGS);
    }
}

From source file:net.ymate.module.oauth.client.base.OAuthAccount.java

public OAuthAccount(String id, String serviceUrl, String clientId, String clientSecret) {
    if (StringUtils.isBlank(id)) {
        throw new NullArgumentException("id");
    }//w  ww  . j av a  2  s  .c  o  m
    if (StringUtils.isBlank(serviceUrl)) {
        throw new NullArgumentException("service_url");
    } else if (!StringUtils.startsWithAny(StringUtils.lowerCase(serviceUrl),
            new String[] { "https://", "http://" })) {
        throw new IllegalArgumentException("service_url must be start with 'https://' or 'http://'.");
    }
    if (StringUtils.isBlank(clientId)) {
        throw new NullArgumentException("client_id");
    }
    if (StringUtils.isBlank(clientSecret)) {
        throw new NullArgumentException("client_secret");
    }
    this.id = id;
    this.serviceUrl = serviceUrl;
    this.clientId = clientId;
    this.clientSecret = clientSecret;
}

From source file:net.ymate.module.oauth.client.base.OAuthAccount.java

public OAuthAccount(String id, String serviceUrl, String clientId, String clientSecret, String redirectUri) {
    this(id, serviceUrl, clientId, clientSecret);
    if (StringUtils.isNotBlank(redirectUri) && !StringUtils.startsWithAny(StringUtils.lowerCase(serviceUrl),
            new String[] { "https://", "http://" })) {
        throw new IllegalArgumentException("redirect_uri must be start with 'https://' or 'http://'.");
    }//from  w w w  .  j a v  a2  s  .  c o  m
    this.redirectUri = redirectUri;
}

From source file:org.apache.sling.installer.hc.OsgiInstallerHealthCheck.java

/**
 * @param group//from ww  w. j  a va 2  s .  c o m
 *            the resource group to evaluate
 * @param hcLog
 *            the log to fill during the health check
 * @return the type of resources in this group ("bundle" or "config") or empty string, if the group was not
 *         considered by this health check
 */
private String evaluateGroup(ResourceGroup group, FormattingResultLog hcLog) {
    Resource invalidResource = null;
    String resourceType = "";
    // go through all resources within the given group
    for (Resource resource : group.getResources()) {
        // check for the correct type
        resourceType = resource.getType();
        switch (resourceType) {
        case InstallableResource.TYPE_CONFIG:
            if (!checkConfigurations) {
                LOG.debug("Skip resource '{}', configuration checks are disabled", resource.getEntityId());
                return "";
            }
            break;
        case InstallableResource.TYPE_BUNDLE:
            if (!checkBundles) {
                LOG.debug("Skip resource '{}', bundle checks are disabled", resource.getEntityId());
                return "";
            }
            break;
        default:
            LOG.debug("Skip resource '{}' as it is neither a bundle nor a configuration but a {}",
                    resource.getEntityId(), resourceType);
            return "";
        }
        if (StringUtils.startsWithAny(resource.getURL(), urlPrefixes)) {
            switch (resource.getState()) {
            case IGNORED: // means a considered resource was found and it is invalid
                // still the other resources need to be evaluated
            case INSTALL:
                if (invalidResource == null) {
                    invalidResource = resource;
                }
                break;
            default:
                // means a considered resource was found and it is valid
                // no need to evaluate other resources from this group
                return resourceType;
            }
        } else {
            LOG.debug("Skipping resource '{}' as its URL is not starting with any of these prefixes'{}'",
                    resource, StringUtils.join(urlPrefixes, ","));
        }
    }
    if (invalidResource != null) {
        if (resourceType.equals(InstallableResource.TYPE_CONFIG)) {
            hcLog.critical(
                    "The installer state of the OSGi configuration resource '{}' is {}, config might have been manually overwritten!",
                    invalidResource, invalidResource.getState());
        } else {
            hcLog.critical(
                    "The installer state of the OSGi bundle resource '{}' is {}, probably because a later or the same version of that bundle is already installed!",
                    invalidResource, invalidResource.getState());
        }
        return resourceType;
    } else {
        return ""; // do not count this group, as only non-considered resources have been in there
    }

}

From source file:org.b3log.latke.util.Callstacks.java

/**
 * Prints call stack with the specified logging level.
 * /*  w ww .jav  a  2 s.c  o m*/
 * @param logLevel the specified logging level
 * @param carePackages the specified packages to print, for example, ["org.b3log.latke", "org.b3log.solo"], {@code null} to care 
 * nothing
 * @param exceptablePackages the specified packages to skip, for example, ["com.sun", "java.io", "org.b3log.solo.filter"], 
 * {@code null} to skip nothing
 */
public static void printCallstack(final Level logLevel, final String[] carePackages,
        final String[] exceptablePackages) {
    if (null == logLevel) {
        LOGGER.log(Level.WARNING, "Requires parameter[logLevel]");

        return;
    }

    final Throwable throwable = new Throwable();
    final StackTraceElement[] stackElements = throwable.getStackTrace();

    if (null == stackElements) {
        LOGGER.log(Level.WARNING, "Empty call stack");

        return;
    }

    final StringBuilder stackBuilder = new StringBuilder("CallStack [").append(Strings.LINE_SEPARATOR);

    for (int i = 1; i < stackElements.length; i++) {
        final String stackElemClassName = stackElements[i].getClassName();

        if (!StringUtils.startsWithAny(stackElemClassName, carePackages)
                || StringUtils.startsWithAny(stackElemClassName, exceptablePackages)) {
            continue;
        }

        stackBuilder.append("    [className=").append(stackElements[i].getClassName()).append(", fileName=")
                .append(stackElements[i].getFileName()).append(", lineNumber=")
                .append(stackElements[i].getLineNumber()).append(", methodName=")
                .append(stackElements[i].getMethodName()).append(']').append(Strings.LINE_SEPARATOR);
    }
    stackBuilder.append("], fullDepth=[").append(stackElements.length).append("]");

    LOGGER.log(logLevel, stackBuilder.toString());
}

From source file:org.cleverbus.admin.web.msg.MessageLogParser.java

/**
 * Gets lines which corresponds with specified correlation ID from the specified log file.
 *
 * @param logFile the log file/*from  ww  w.j  a v a 2s .  c  o m*/
 * @param correlationId the correlation ID
 * @return log lines
 * @throws IOException when error occurred during file reading
 */
private List<String> getLogLines(File logFile, String correlationId) throws IOException {
    List<String> logLines = new ArrayList<String>();

    Log.debug("Go through the following log file: " + logFile);

    int year = Calendar.getInstance().get(Calendar.YEAR);
    String[] possibleYears = new String[] { String.valueOf(year - 1), String.valueOf(year) };

    InputStream stream = null;
    try {
        if (logFile.getName().endsWith(GZIP_FILE_EXTENSION)) {
            stream = new GZIPInputStream(new BufferedInputStream(new FileInputStream(logFile)));
        } else {
            stream = new BufferedInputStream(new FileInputStream(logFile));
        }

        LineIterator it = IOUtils.lineIterator(stream, Charset.defaultCharset());

        String requestId = null;
        boolean lastCorrectLine = false; // if previous log line belongs to requestId
        while (it.hasNext()) {
            String line = it.nextLine();

            if (requestId == null) {
                if (StringUtils.contains(line, correlationId)) {
                    logLines.add(formatLogLine(line));

                    // finds requestID
                    requestId = getRequestId(line);

                    if (requestId != null) {
                        Log.debug("correlationId (" + correlationId + ") => requestId (" + requestId + ")");
                    }
                }
            } else {
                // adds lines with requestID and lines that belongs to previous log record (e.g. XML request)
                //  it's better to check also correlationID because it's not one request ID
                //  for all repeated scheduled jobs for processing of partly failed messages

                // 2013-05-23 20:22:36,754 [MACHINE_IS_UNDEFINED, ajp-bio-8009-exec-19, /esb/ws/account/v1, ...
                // <checkCustomerCreditRequest xmlns="http://cleverbus.org/ws/AccountService-v1">
                //    <firstName>csd</firstName>
                //    <lastName>acs</lastName>
                //    <birthNumber>111111/1111</birthNumber>
                // </checkCustomerCreditRequest>

                if (StringUtils.contains(line, requestId) || (StringUtils.contains(line, correlationId))
                        || (lastCorrectLine && !StringUtils.startsWithAny(line, possibleYears))) {
                    logLines.add(formatLogLine(line));
                    lastCorrectLine = true;
                } else {
                    lastCorrectLine = false;
                }
            }
        }
    } finally {
        IOUtils.closeQuietly(stream);
    }

    return logLines;
}

From source file:org.kuali.rice.krad.uif.util.MessageStructureUtils.java

/**
 * Process a piece of the message that is assumed to have a valid html tag
 *
 * @param messagePiece String piece with html tag content
 * @param currentMessageComponent the state of the current text based message being built
 * @param view current View// www.jav  a2  s  .c  o  m
 * @return currentMessageComponent with the new textual content generated by this method appended to its
 *         messageText
 */
private static Message processHtmlContent(String messagePiece, Message currentMessageComponent, View view) {
    //raw html
    messagePiece = messagePiece.trim();

    if (StringUtils.startsWithAny(messagePiece, KRADConstants.MessageParsing.UNALLOWED_HTML)
            || StringUtils.endsWithAny(messagePiece, KRADConstants.MessageParsing.UNALLOWED_HTML)) {
        throw new RuntimeException("The following html is not allowed in Messages: "
                + Arrays.toString(KRADConstants.MessageParsing.UNALLOWED_HTML));
    }

    messagePiece = "<" + messagePiece + ">";

    return concatenateStringMessageContent(currentMessageComponent, messagePiece, view);
}