Example usage for org.apache.commons.lang3 StringUtils containsAny

List of usage examples for org.apache.commons.lang3 StringUtils containsAny

Introduction

In this page you can find the example usage for org.apache.commons.lang3 StringUtils containsAny.

Prototype

public static boolean containsAny(CharSequence cs, CharSequence... searchCharSequences) 

Source Link

Document

Checks if the CharSequence contains any of the CharSequences in the given array.

A null CharSequence will return false .

Usage

From source file:com.gargoylesoftware.htmlunit.javascript.host.dom.DOMTokenList.java

/**
 * Removes the specified token from the underlying string.
 * @param token the token to remove/* w  w  w  .  j  av a 2  s. co  m*/
 */
@JsxFunction
public void remove(final String token) {
    if (StringUtils.isEmpty(token)) {
        throw Context.reportRuntimeError("Empty imput not allowed");
    }
    if (StringUtils.containsAny(token, whitespaceChars())) {
        throw Context.reportRuntimeError("Empty imput not allowed");
    }
    String value = getDefaultValue(null);
    int pos = position(value, token);
    while (pos != -1) {
        int from = pos;
        int to = pos + token.length();

        while (from > 0 && isWhitespache(value.charAt(from - 1))) {
            from = from - 1;
        }
        while (to < value.length() - 1 && isWhitespache(value.charAt(to))) {
            to = to + 1;
        }

        final StringBuilder result = new StringBuilder();
        if (from > 0) {
            result.append(value, 0, from);
            if (to < value.length()) {
                result.append(" ");
            }
        }
        result.append(value, to, value.length());

        value = result.toString();
        updateAttribute(value);

        pos = position(value, token);
    }
}

From source file:cc.arduino.packages.Uploader.java

@Override
public void message(String s) {
    // selectively suppress a bunch of avrdude output for AVR109/Caterina that should already be quelled but isn't
    if (!verbose && StringUtils.containsAny(s, STRINGS_TO_SUPPRESS)) {
        s = "";//from www  .java2  s.c o m
    }

    System.err.print(s);

    // ignore cautions
    if (s.toLowerCase().contains("error")) {
        notFoundError = true;
        error = s;
        return;
    }
    if (notFoundError) {
        error = I18n.format(tr("the selected serial port {0} does not exist or your board is not connected"),
                s);
        return;
    }
    if (s.contains("Device is not responding")) {
        error = tr(
                "Device is not responding, check the right serial port is selected or RESET the board right before exporting");
        return;
    }
    if (StringUtils.containsAny(s, AVRDUDE_PROBLEMS)) {
        error = tr(
                "Problem uploading to board.  See http://www.arduino.cc/en/Guide/Troubleshooting#upload for suggestions.");
        return;
    }
    if (s.contains("Expected signature")) {
        error = tr("Wrong microcontroller found.  Did you select the right board from the Tools > Board menu?");
        return;
    }
}

From source file:com.gargoylesoftware.htmlunit.javascript.host.dom.DOMTokenList.java

/**
 * Checks if the specified token is contained in the underlying string.
 * @param token the token to add//from  w  ww.j  a va2  s  .  c  o  m
 * @return true if the underlying string contains token, otherwise false
 */
@JsxFunction
public boolean contains(final String token) {
    if (StringUtils.isEmpty(token)) {
        throw Context.reportRuntimeError("Empty imput not allowed");
    }
    if (StringUtils.containsAny(token, whitespaceChars())) {
        throw Context.reportRuntimeError("Empty imput not allowed");
    }
    return position(getDefaultValue(null), token) > -1;
}

From source file:com.dgtlrepublic.anitomyj.Tokenizer.java

/**
 * Tokenize by Delimiters allowed in {@link Options#allowedDelimiters}
 *
 * @param enclosed whether or not the current {@code range} is enclosed in braces
 * @param range    the token range/*from w  w w.  j  av a 2  s. c  o m*/
 */
private void tokenizeByDelimiters(boolean enclosed, TokenRange range) {
    String delimiters = getDelimiters(range);

    if (delimiters.isEmpty()) {
        addToken(TokenCategory.kUnknown, enclosed, range);
        return;
    }

    for (int i = range.getOffset(), end = range.getOffset() + range.getSize(); i < end;) {
        Integer found = IntStream.range(i, Math.min(end, filename.length()))
                .filter(c -> StringUtils.containsAny(String.valueOf(filename.charAt(c)), delimiters))
                .findFirst().orElse(end);

        TokenRange subrange = new TokenRange(i, found - i);
        if (subrange.getSize() > 0) {
            addToken(TokenCategory.kUnknown, enclosed, subrange);
        }

        if (found != end) {
            addToken(TokenCategory.kDelimiter, enclosed,
                    new TokenRange(subrange.getOffset() + subrange.getSize(), 1));
            i = found + 1;
        } else {
            break;
        }
    }

    validateDelimiterTokens();
}

From source file:gov.nih.nci.firebird.nes.person.NesPersonServiceBean.java

private List<Person> searchByEmail(String email) {
    if (StringUtils.containsAny(email, INVALID_EMAIL_ADDRESS_CHARACTERS)) {
        return Collections.emptyList();
    }//from  w w  w  .  j av  a 2 s  .c om
    Person searchPerson = new Person();
    searchPerson.setEmail(email);
    searchPerson.setPostalAddress(null);
    gov.nih.nci.coppa.po.Person example = PersonTranslator.buildNesPerson(searchPerson);
    return search(example);
}

From source file:eu.operando.proxy.service.ProxyService.java

private HttpFiltersSource getFiltersSource() {

    return new HttpFiltersSourceAdapter() {

        //                @Override
        //                public int getMaximumRequestBufferSizeInBytes() {
        //                    // TODO Auto-generated method stub
        //                    return 10 * 1024 * 1024;
        ////from  w  ww  .  j  a  va 2  s  .com
        //                }
        //
        //                @Override
        //                public int getMaximumResponseBufferSizeInBytes() {
        //                    // TODO Auto-generated method stub
        //                    return 10 * 1024 * 1024;
        //                }

        @Override
        public HttpFilters filterRequest(HttpRequest originalRequest) {

            return new HttpFiltersAdapter(originalRequest) {

                @Override
                public HttpObject serverToProxyResponse(HttpObject httpObject) {

                    if (MainUtil.isProxyPaused(mainContext))
                        return httpObject;

                    if (httpObject instanceof HttpMessage) {
                        HttpMessage response = (HttpMessage) httpObject;
                        response.headers().set(HttpHeaderNames.CACHE_CONTROL,
                                "no-cache, no-store, must-revalidate");
                        response.headers().set(HttpHeaderNames.PRAGMA, "no-cache");
                        response.headers().set(HttpHeaderNames.EXPIRES, "0");
                    }
                    try {
                        Method content = httpObject.getClass().getMethod("content");
                        if (content != null) {
                            ByteBuf buf = (ByteBuf) content.invoke(httpObject);
                            boolean flag = false;
                            List<ResponseFilter> responseFilters = db.getAllResponseFilters();
                            if (responseFilters.size() > 0) {

                                String contentStr = buf.toString(Charset.forName("UTF-8")); //Charset.forName(Charset.forName("UTF-8")
                                for (ResponseFilter responseFilter : responseFilters) {

                                    String toReplace = responseFilter.getContent();

                                    if (StringUtils.containsIgnoreCase(contentStr, toReplace)) {
                                        contentStr = contentStr.replaceAll("(?i)" + toReplace,
                                                StringUtils.leftPad("", toReplace.length(), '#'));
                                        flag = true;
                                    }

                                }
                                if (flag) {
                                    buf.clear().writeBytes(contentStr.getBytes(Charset.forName("UTF-8")));
                                }
                            }

                        }
                    } catch (IndexOutOfBoundsException ex) {
                        ex.printStackTrace();
                        Log.e("Exception", ex.getMessage());
                    } catch (NoSuchMethodException | InvocationTargetException | IllegalAccessException ex) {
                        //ignore
                    }
                    return httpObject;
                }

                @Override
                public HttpResponse clientToProxyRequest(HttpObject httpObject) {

                    if (MainUtil.isProxyPaused(mainContext))
                        return null;

                    String requestURI;
                    Set<RequestFilterUtil.FilterType> exfiltrated = new HashSet<>();
                    String[] locationInfo = requestFilterUtil.getLocationInfo();
                    String[] contactsInfo = requestFilterUtil.getContactsInfo();
                    String[] phoneInfo = requestFilterUtil.getPhoneInfo();

                    if (httpObject instanceof HttpMessage) {
                        HttpMessage request = (HttpMessage) httpObject;
                        if (request.headers().contains(CustomHeaderField)) {
                            applicationInfoStr = request.headers().get(CustomHeaderField);
                            request.headers().remove(CustomHeaderField);
                        }

                        if (request.headers().contains(HttpHeaderNames.ACCEPT_ENCODING)) {
                            request.headers().remove(HttpHeaderNames.ACCEPT_ENCODING);
                        }

                        /*
                        Sanitize Hosts
                        */
                        if (!ProxyUtils.isCONNECT(request)
                                && request.headers().contains(HttpHeaderNames.HOST)) {
                            String hostName = request.headers().get(HttpHeaderNames.HOST).toLowerCase();
                            if (db.isDomainBlocked(hostName))
                                return getBlockedHostResponse(hostName);
                        }

                    }

                    if (httpObject instanceof HttpRequest) {

                        HttpRequest request = (HttpRequest) httpObject;
                        requestURI = request.uri();

                        try {
                            requestURI = URLDecoder.decode(requestURI, "UTF-8");
                        } catch (UnsupportedEncodingException e) {
                            e.printStackTrace();
                        }

                        /*
                        Request URI checks
                         */
                        if (StringUtils.containsAny(requestURI, locationInfo)) {
                            exfiltrated.add(RequestFilterUtil.FilterType.LOCATION);
                        }

                        if (StringUtils.containsAny(requestURI, contactsInfo)) {
                            exfiltrated.add(RequestFilterUtil.FilterType.CONTACTS);
                        }

                        if (StringUtils.containsAny(requestURI, phoneInfo)) {
                            exfiltrated.add(RequestFilterUtil.FilterType.PHONEINFO);
                        }

                        if (!exfiltrated.isEmpty()) {
                            mainContext.getNotificationUtil().displayExfiltratedNotification(applicationInfoStr,
                                    exfiltrated);
                            return getForbiddenRequestResponse(applicationInfoStr, exfiltrated);
                        }

                    }

                    try {
                        Method content = httpObject.getClass().getMethod("content");
                        if (content != null) {
                            ByteBuf buf = (ByteBuf) content.invoke(httpObject);

                            String contentStr = buf.toString(Charset.forName("UTF-8"));

                            if (StringUtils.containsAny(contentStr, locationInfo)) {
                                exfiltrated.add(RequestFilterUtil.FilterType.LOCATION);
                            }

                            if (StringUtils.containsAny(contentStr, contactsInfo)) {
                                exfiltrated.add(RequestFilterUtil.FilterType.CONTACTS);
                            }

                            if (StringUtils.containsAny(contentStr, phoneInfo)) {
                                exfiltrated.add(RequestFilterUtil.FilterType.PHONEINFO);
                            }

                            if (!exfiltrated.isEmpty()) {
                                mainContext.getNotificationUtil()
                                        .displayExfiltratedNotification(applicationInfoStr, exfiltrated);
                                return getForbiddenRequestResponse(applicationInfoStr, exfiltrated);
                            }

                        }
                    } catch (IndexOutOfBoundsException ex) {
                        ex.printStackTrace();
                        Log.e("Exception", ex.getMessage());
                    } catch (NoSuchMethodException | InvocationTargetException | IllegalAccessException ex) {
                        //ignore
                    }

                    return null;
                }

            };
        }
    };
}

From source file:com.bellman.bible.service.common.CommonUtils.java

/**
 * StringUtils methods only compare with a single char and hence create lots
 * of temporary Strings This method compares with all chars and just creates
 * one new string for each original string. This is to minimise memory
 * overhead & gc./*from ww  w  .j a  va  2  s .c o m*/
 * 
 * @param str
 * @param removeChars
 * @return
 */
public static String remove(String str, char[] removeChars) {
    if (StringUtils.isEmpty(str) || !StringUtils.containsAny(str, removeChars)) {
        return str;
    }

    StringBuilder r = new StringBuilder(str.length());
    // for all chars in string
    for (int i = 0; i < str.length(); i++) {
        char strCur = str.charAt(i);

        // compare with all chars to be removed
        boolean matched = false;
        for (int j = 0; j < removeChars.length && !matched; j++) {
            if (removeChars[j] == strCur) {
                matched = true;
            }
        }
        // if current char does not match any in the list then add it to the
        if (!matched) {
            r.append(strCur);
        }
    }
    return r.toString();
}

From source file:com.jkoolcloud.tnt4j.core.UsecTimestamp.java

/**
 * <p>Creates UsecTimestamp from string representation of timestamp in the
 * specified format.</p>// w  w w  . j  ava  2  s . c  o  m
 * <p>This is based on {@link SimpleDateFormat}, but extends its support to
 * recognize microsecond fractional seconds. If number of fractional second
 * characters is greater than 3, then it's assumed to be microseconds.
 * Otherwise, it's assumed to be milliseconds (as this is the behavior of
 * {@link SimpleDateFormat}.
 *
 * @param timeStampStr timestamp string
 * @param formatStr format specification for timestamp string
 * @param timeZone time zone that timeStampStr represents. This is only needed when formatStr does not include
 *                   time zone specification and timeStampStr does not represent a string in local time zone.
 * @param locale locale for date format to use.
 * @throws NullPointerException if timeStampStr is {@code null}
 * @throws IllegalArgumentException if timeStampStr is not in the correct format
 * @throws ParseException if failed to parse string based on specified format
 * @see java.util.TimeZone
 */
public UsecTimestamp(String timeStampStr, String formatStr, TimeZone timeZone, String locale)
        throws ParseException {
    if (timeStampStr == null)
        throw new NullPointerException("timeStampStr must be non-null");

    int usecs = 0;

    SimpleDateFormat dateFormat;

    if (StringUtils.isEmpty(formatStr)) {
        dateFormat = new SimpleDateFormat();
    } else {
        // Java date formatter cannot deal with usecs, so we need to extract those ourselves
        int fmtPos = formatStr.indexOf('S');
        if (fmtPos > 0) {
            int endFmtPos = formatStr.lastIndexOf('S');
            int fmtFracSecLen = endFmtPos - fmtPos + 1;

            if (fmtFracSecLen > 6)
                throw new ParseException(
                        "Date format containing more than 6 significant digits for fractional seconds is not supported",
                        0);

            StringBuilder sb = new StringBuilder();
            int usecPos = timeStampStr.lastIndexOf('.') + 1;
            int usecEndPos;
            if (usecPos > 2) {
                for (usecEndPos = usecPos; usecEndPos < timeStampStr.length(); usecEndPos++) {
                    if (!StringUtils.containsAny("0123456789", timeStampStr.charAt(usecEndPos)))
                        break;
                }

                if (fmtFracSecLen > 3) {
                    // format specification represents more than milliseconds, assume microseconds
                    String usecStr = String.format("%s", timeStampStr.substring(usecPos, usecEndPos));
                    if (usecStr.length() < fmtFracSecLen)
                        usecStr = StringUtils.rightPad(usecStr, fmtFracSecLen, '0');
                    else if (usecStr.length() > fmtFracSecLen)
                        usecStr = usecStr.substring(0, fmtFracSecLen);
                    usecs = Integer.parseInt(usecStr);

                    // trim off fractional part < microseconds from both timestamp and format strings
                    sb.append(timeStampStr);
                    sb.delete(usecPos - 1, usecEndPos);
                    timeStampStr = sb.toString();

                    sb.setLength(0);
                    sb.append(formatStr);
                    sb.delete(fmtPos - 1, endFmtPos + 1);
                    formatStr = sb.toString();
                } else if ((usecEndPos - usecPos) < 3) {
                    // pad msec value in date string with 0's so that it is 3 digits long
                    sb.append(timeStampStr);
                    while ((usecEndPos - usecPos) < 3) {
                        sb.insert(usecEndPos, '0');
                        usecEndPos++;
                    }
                    timeStampStr = sb.toString();
                }
            }
        }

        dateFormat = StringUtils.isEmpty(locale) ? new SimpleDateFormat(formatStr)
                : new SimpleDateFormat(formatStr, Utils.getLocale(locale));
    }

    dateFormat.setLenient(true);
    if (timeZone != null)
        dateFormat.setTimeZone(timeZone);

    Date date = dateFormat.parse(timeStampStr);

    setTimestampValues(date.getTime(), 0, 0);
    add(0, usecs);
}

From source file:eu.operando.operandoapp.service.ProxyService.java

private HttpFiltersSource getFiltersSource() {
    return new HttpFiltersSourceAdapter() {
        @Override//  www.  ja  v a  2 s.c om
        public HttpFilters filterRequest(HttpRequest originalRequest) {
            return new HttpFiltersAdapter(originalRequest) {
                @Override
                public HttpObject serverToProxyResponse(HttpObject httpObject) {
                    //check for proxy running
                    if (MainUtil.isProxyPaused(mainContext))
                        return httpObject;

                    if (httpObject instanceof HttpMessage) {
                        HttpMessage response = (HttpMessage) httpObject;
                        response.headers().set(HttpHeaderNames.CACHE_CONTROL,
                                "no-cache, no-store, must-revalidate");
                        response.headers().set(HttpHeaderNames.PRAGMA, "no-cache");
                        response.headers().set(HttpHeaderNames.EXPIRES, "0");
                    }
                    try {
                        Method content = httpObject.getClass().getMethod("content");
                        if (content != null) {
                            ByteBuf buf = (ByteBuf) content.invoke(httpObject);
                            boolean flag = false;
                            List<ResponseFilter> responseFilters = db.getAllResponseFilters();
                            if (responseFilters.size() > 0) {
                                String contentStr = buf.toString(Charset.forName("UTF-8")); //Charset.forName(Charset.forName("UTF-8")
                                for (ResponseFilter responseFilter : responseFilters) {
                                    String toReplace = responseFilter.getContent();
                                    if (StringUtils.containsIgnoreCase(contentStr, toReplace)) {
                                        contentStr = contentStr.replaceAll("(?i)" + toReplace,
                                                StringUtils.leftPad("", toReplace.length(), '#'));
                                        flag = true;
                                    }
                                }
                                if (flag) {
                                    buf.clear().writeBytes(contentStr.getBytes(Charset.forName("UTF-8")));
                                }
                            }
                        }
                    } catch (IndexOutOfBoundsException ex) {
                        ex.printStackTrace();
                        Log.e("Exception", ex.getMessage());
                    } catch (NoSuchMethodException | InvocationTargetException | IllegalAccessException ex) {
                        //ignore
                    }
                    return httpObject;
                }

                @Override
                public HttpResponse clientToProxyRequest(HttpObject httpObject) {
                    //check for proxy running
                    if (MainUtil.isProxyPaused(mainContext)) {
                        return null;
                    }

                    //check for trusted access point
                    String ssid = ((WifiManager) getSystemService(Context.WIFI_SERVICE)).getConnectionInfo()
                            .getSSID();
                    String bssid = ((WifiManager) getSystemService(Context.WIFI_SERVICE)).getConnectionInfo()
                            .getBSSID();
                    boolean trusted = false;
                    TrustedAccessPoint curr_tap = new TrustedAccessPoint(ssid, bssid);
                    for (TrustedAccessPoint tap : db.getAllTrustedAccessPoints()) {
                        if (curr_tap.isEqual(tap)) {
                            trusted = true;
                        }
                    }
                    if (!trusted) {
                        return getUntrustedGatewayResponse();
                    }

                    //check for blocked url

                    //check for exfiltration
                    requestFilterUtil = new RequestFilterUtil(getApplicationContext());
                    locationInfo = requestFilterUtil.getLocationInfo();
                    contactsInfo = requestFilterUtil.getContactsInfo();
                    IMEI = requestFilterUtil.getIMEI();
                    phoneNumber = requestFilterUtil.getPhoneNumber();
                    subscriberID = requestFilterUtil.getSubscriberID();
                    carrierName = requestFilterUtil.getCarrierName();
                    androidID = requestFilterUtil.getAndroidID();
                    macAdresses = requestFilterUtil.getMacAddresses();

                    if (httpObject instanceof HttpMessage) {
                        HttpMessage request = (HttpMessage) httpObject;
                        if (request.headers().contains(CustomHeaderField)) {
                            applicationInfo = request.headers().get(CustomHeaderField);
                            request.headers().remove(CustomHeaderField);
                        }
                        if (request.headers().contains(HttpHeaderNames.ACCEPT_ENCODING)) {
                            request.headers().remove(HttpHeaderNames.ACCEPT_ENCODING);
                        }
                        if (!ProxyUtils.isCONNECT(request)
                                && request.headers().contains(HttpHeaderNames.HOST)) {
                            String hostName = ((HttpRequest) request).uri(); //request.headers().get(HttpHeaderNames.HOST).toLowerCase();
                            if (db.isDomainBlocked(hostName))
                                return getBlockedHostResponse(hostName);
                        }
                    }

                    String requestURI;
                    Set<RequestFilterUtil.FilterType> exfiltrated = new HashSet<>();

                    if (httpObject instanceof HttpRequest) {
                        HttpRequest request = (HttpRequest) httpObject;
                        requestURI = request.uri();
                        try {
                            requestURI = URLDecoder.decode(requestURI, "UTF-8");
                        } catch (UnsupportedEncodingException e) {
                            e.printStackTrace();
                        }
                        if (locationInfo.length > 0) {
                            //tolerate location miscalculation
                            float latitude = Float.parseFloat(locationInfo[0]);
                            float longitude = Float.parseFloat(locationInfo[1]);
                            Matcher m = Pattern.compile("\\d+\\.\\d+").matcher(requestURI);
                            List<String> floats_in_uri = new ArrayList();
                            while (m.find()) {
                                floats_in_uri.add(m.group());
                            }
                            for (String s : floats_in_uri) {
                                if (Math.abs(Float.parseFloat(s) - latitude) < 0.5
                                        || Math.abs(Float.parseFloat(s) - longitude) < 0.1) {
                                    exfiltrated.add(RequestFilterUtil.FilterType.LOCATION);
                                }
                            }
                        }
                        if (StringUtils.containsAny(requestURI, contactsInfo)) {
                            exfiltrated.add(RequestFilterUtil.FilterType.CONTACTS);
                        }
                        if (StringUtils.containsAny(requestURI, macAdresses)) {
                            exfiltrated.add(RequestFilterUtil.FilterType.MACADRESSES);
                        }
                        if (requestURI.contains(IMEI) && !IMEI.equals("")) {
                            exfiltrated.add(RequestFilterUtil.FilterType.IMEI);
                        }
                        if (requestURI.contains(phoneNumber) && !phoneNumber.equals("")) {
                            exfiltrated.add(RequestFilterUtil.FilterType.PHONENUMBER);
                        }
                        if (requestURI.contains(subscriberID) && !subscriberID.equals("")) {
                            exfiltrated.add(RequestFilterUtil.FilterType.IMSI);
                        }
                        if (requestURI.contains(carrierName) && !carrierName.equals("")) {
                            exfiltrated.add(RequestFilterUtil.FilterType.CARRIERNAME);
                        }
                        if (requestURI.contains(androidID) && !androidID.equals("")) {
                            exfiltrated.add(RequestFilterUtil.FilterType.ANDROIDID);
                        }
                    }
                    try {
                        Method content = httpObject.getClass().getMethod("content");
                        if (content != null) {
                            ByteBuf buf = (ByteBuf) content.invoke(httpObject);
                            String contentStr = buf.toString(Charset.forName("UTF-8"));
                            if (locationInfo.length > 0) {
                                //tolerate location miscalculation
                                float latitude = Float.parseFloat(locationInfo[0]);
                                float longitude = Float.parseFloat(locationInfo[1]);
                                Matcher m = Pattern.compile("\\d+\\.\\d+").matcher(contentStr);
                                List<String> floats_in_uri = new ArrayList();
                                while (m.find()) {
                                    floats_in_uri.add(m.group());
                                }
                                for (String s : floats_in_uri) {
                                    if (Math.abs(Float.parseFloat(s) - latitude) < 0.5
                                            || Math.abs(Float.parseFloat(s) - longitude) < 0.1) {
                                        exfiltrated.add(RequestFilterUtil.FilterType.LOCATION);
                                    }
                                }
                            }
                            if (StringUtils.containsAny(contentStr, contactsInfo)) {
                                exfiltrated.add(RequestFilterUtil.FilterType.CONTACTS);
                            }
                            if (StringUtils.containsAny(contentStr, macAdresses)) {
                                exfiltrated.add(RequestFilterUtil.FilterType.MACADRESSES);
                            }
                            if (contentStr.contains(IMEI) && !IMEI.equals("")) {
                                exfiltrated.add(RequestFilterUtil.FilterType.IMEI);
                            }
                            if (contentStr.contains(phoneNumber) && !phoneNumber.equals("")) {
                                exfiltrated.add(RequestFilterUtil.FilterType.PHONENUMBER);
                            }
                            if (contentStr.contains(subscriberID) && !subscriberID.equals("")) {
                                exfiltrated.add(RequestFilterUtil.FilterType.IMSI);
                            }
                            if (contentStr.contains(carrierName) && !carrierName.equals("")) {
                                exfiltrated.add(RequestFilterUtil.FilterType.CARRIERNAME);
                            }
                            if (contentStr.contains(androidID) && !androidID.equals("")) {
                                exfiltrated.add(RequestFilterUtil.FilterType.ANDROIDID);
                            }
                        }
                    } catch (IndexOutOfBoundsException ex) {
                        ex.printStackTrace();
                        Log.e("Exception", ex.getMessage());
                    } catch (NoSuchMethodException | InvocationTargetException | IllegalAccessException ex) {
                        //ignore
                    }

                    //check exfiltrated list
                    if (!exfiltrated.isEmpty()) {
                        //retrieve all blocked and allowed domains
                        List<BlockedDomain> blocked = db.getAllBlockedDomains();
                        List<AllowedDomain> allowed = db.getAllAllowedDomains();
                        //get application name from app info
                        String appName = applicationInfo.replaceAll("\\(.+?\\)", "");
                        //check blocked domains
                        //if domain is stored as blocked, return a forbidden response
                        for (BlockedDomain b_dmn : blocked) {
                            if (b_dmn.info.equals(appName)) {
                                return getForbiddenRequestResponse(applicationInfo, exfiltrated);
                            }
                        }
                        //if domain is stored as allowed, return null for actual response
                        for (AllowedDomain a_dmn : allowed) {
                            if (a_dmn.info.equals(appName)) {
                                return null;
                            }
                        }
                        //get exfiltrated info to string array
                        String[] exfiltrated_array = new String[exfiltrated.size()];
                        int i = 0;
                        for (RequestFilterUtil.FilterType filter_type : exfiltrated) {
                            exfiltrated_array[i] = filter_type.name();
                            i++;
                        }
                        //retrieve all pending notifications
                        List<PendingNotification> pending = db.getAllPendingNotifications();
                        for (PendingNotification pending_notification : pending) {
                            //if pending notification includes specific app name and app permissions return response that a pending notification exists
                            if (pending_notification.app_info.equals(applicationInfo)) {
                                return getPendingResponse();
                            }
                        }
                        //if none pending notification exists, display a new notification
                        int notificationId = mainContext.getNotificationId();
                        mainContext.getNotificationUtil().displayExfiltratedNotification(getBaseContext(),
                                applicationInfo, exfiltrated, notificationId);
                        mainContext.setNotificationId(notificationId + 3);
                        //and update statistics
                        db.updateStatistics(exfiltrated);
                        return getAwaitingResponse();
                    }
                    return null;
                }
            };
        }
    };
}

From source file:ch.cyberduck.cli.Terminal.java

protected Exit delete(final SessionPool session, final Path remote) throws BackgroundException {
    final List<Path> files = new ArrayList<Path>();
    for (TransferItem i : new DeletePathFinder().find(input, TerminalAction.delete, remote)) {
        files.add(i.remote);//from   w  w  w.  j ava  2s.co  m
    }
    final DeleteWorker worker;
    if (StringUtils.containsAny(remote.getName(), '*')) {
        worker = new DeleteWorker(new TerminalLoginCallback(reader), files, cache,
                new DownloadGlobFilter(remote.getName()), progress);
    } else {
        worker = new DeleteWorker(new TerminalLoginCallback(reader), files, cache, progress);
    }
    final SessionBackgroundAction<List<Path>> action = new TerminalBackgroundAction<List<Path>>(controller,
            session, worker);
    if (!this.execute(action)) {
        return Exit.failure;
    }
    return Exit.success;
}