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

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

Introduction

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

Prototype

public static boolean startsWithIgnoreCase(final CharSequence str, final CharSequence prefix) 

Source Link

Document

Case insensitive check if a CharSequence starts with a specified prefix.

null s are handled without exceptions.

Usage

From source file:com.axibase.tsd.driver.jdbc.content.ContentDescription.java

public boolean isSsl() {
    return StringUtils.startsWithIgnoreCase(host, "https://");
}

From source file:com.sonicle.webtop.core.app.shiro.WTFormAuthFilter.java

@Override
protected boolean onAccessDenied(ServletRequest request, ServletResponse response) throws Exception {
    String ctxRequestUrl = ServletUtils.getContextRequestURI((HttpServletRequest) request);
    if (StringUtils.startsWithIgnoreCase(ctxRequestUrl, PrivateRequest.URL)
            || StringUtils.startsWithIgnoreCase(ctxRequestUrl, PrivateRequest.URL_LEGACY) // for compatibility purpose only!
            || StringUtils.startsWithIgnoreCase(ctxRequestUrl, PushEndpoint.URL)) {
        ServletUtils.toHttp(response).sendError(HttpServletResponse.SC_UNAUTHORIZED, "Unauthorized");
        return false;
    } else {/*  w w  w.ja  va 2  s .  co  m*/
        return super.onAccessDenied(request, response);
    }
}

From source file:de.micromata.genome.gwiki.page.search.expr.SearchUtils.java

private static String enrichFoundWord(String text, String w) {
    StringBuilder sb = new StringBuilder();

    int i;//  w w w. j a  va2s  . com
    for (i = 0; i < text.length(); ++i) {
        if (StringUtils.startsWithIgnoreCase(text.substring(i), w) == true) {
            String bt = text.substring(i, i + w.length());
            sb.append(text.subSequence(0, i));
            if (text.length() > i + w.length()) {
                text = text.substring(i + w.length());
            } else {
                text = "";
            }
            i = 0;
            sb.append("<b><strong><big>").append(bt).append("</big></strong></b>");
        }
    }
    sb.append(text);
    return sb.toString();
}

From source file:com.quinsoft.zeidon.objectdefinition.ViewEntity.java

@Override
public void setAttribute(PortableFileReader reader) {
    String attributeName = reader.getAttributeName();

    switch (attributeName.charAt(0)) {
    case 'A':
        if (reader.getAttributeName().equals("ACT_LIMIT")) {
            activateLimit = Integer.parseInt(reader.getAttributeValue());
        }// www  .  j a va 2  s  .  com
        break;

    case 'C':
        if (reader.getAttributeName().equals("CREATE")) {
            create = reader.getAttributeValue().startsWith("Y");
        } else if (reader.getAttributeName().equals("CARDMAX")) {
            maxcardinality = Integer.parseInt(reader.getAttributeValue());
        } else if (reader.getAttributeName().equals("CARDMIN")) {
            minCardinality = Integer.parseInt(reader.getAttributeValue());
        }
        break;

    case 'D':
        if (reader.getAttributeName().equals("DELETE")) {
            delete = reader.getAttributeValue().startsWith("Y");
        } else if (reader.getAttributeName().equals("DERIVED")) {
            derived = true;
            derivedPath = true;
        } else if (reader.getAttributeName().equals("DEBUGCHG")) {
            // Set up a listener to write stack trace when an entity is changed.
            if (StringUtils.startsWithIgnoreCase(reader.getAttributeValue(), "Y"))
                eventListener = new EventStackTrace();
        }
        if (reader.getAttributeName().equals("DEBUGINCRE")) {
            debugIncrementalFlag = StringUtils.startsWithIgnoreCase(reader.getAttributeValue(), "Y");
        } else if (reader.getAttributeName().equals("DUPENTIN")) {
            duplicateEntity = true;
        }

        break;

    case 'E':
        if (reader.getAttributeName().equals("ERENT_TOK")) {
            erEntityToken = Integer.parseInt(reader.getAttributeValue());
        } else if (reader.getAttributeName().equals("ERREL_TOK")) {
            erRelToken = Integer.parseInt(reader.getAttributeValue());
        } else if (reader.getAttributeName().equals("ERREL_LINK")) {
            erRelLink = reader.getAttributeValue().equals("1");
        } else if (reader.getAttributeName().equals("EXCLUDE")) {
            exclude = reader.getAttributeValue().startsWith("Y");
        }
        break;

    case 'I':
        if (reader.getAttributeName().equals("INCLUDE")) {
            include = reader.getAttributeValue().startsWith("Y");
        } else if (reader.getAttributeName().equals("INCLSRC")) {
            includeSrc = reader.getAttributeValue().startsWith("Y");
        }
        break;

    case 'L':
        if (reader.getAttributeName().equals("LAZYLOAD")) {
            getLazyLoadConfig().setFlag(LazyLoadFlags.IS_LAZYLOAD);
            if (getParent() == null)
                throw new ZeidonException("LAZYLOAD is invalid for root entity");

            LazyLoadConfig parentConfig = getParent().getLazyLoadConfig();
            parentConfig.setFlag(LazyLoadFlags.HAS_LAZYLOAD_CHILD);
        }
        break;

    case 'N':
        if (reader.getAttributeName().equals("NAME")) {
            name = reader.getAttributeValue().intern();
        }
        break;

    case 'P':
        if (reader.getAttributeName().equals("PDELETE")) {
            switch (reader.getAttributeValue().charAt(0)) {
            case 'D':
                parentDelete = true;
                break;

            case 'R':
                restrictParentDelete = true;
                getParent().setCheckRestrictedDelete(true);
                break;

            // It looks like we're supposed to ignore 'E'.
            }
        }
        break;

    case 'R':
        if (reader.getAttributeName().equals("RECURSIVE")) {
            // Check to see if this entity is recursive.
            for (ViewEntity search = parent; search != null; search = search.getParent()) {
                if (search.getErEntityToken() == erEntityToken) {
                    search.recursiveParent = true;
                    this.recursive = true;
                    this.recursiveParentViewEntity = search;
                    break;
                }
            }

            if (!recursive)
                throw new ZeidonException(
                        "Internal error: Recursive flag is set but no recursive parent found. %s", this);
        }
        break;

    case 'U':
        if (reader.getAttributeName().equals("UPDATE")) {
            update = reader.getAttributeValue().startsWith("Y");
        }
        break;
    }
}

From source file:it.cnr.isti.hpc.wikipedia.parser.ArticleParser.java

/**
 * @param article//ww w  .  j  av a  2  s . c  o  m
 * @param page
 */
private void setRedirect(Article article, String mediawiki) {
    for (String redirect : redirects)
        if (StringUtils.startsWithIgnoreCase(mediawiki, redirect)) {
            int start = mediawiki.indexOf("[[") + 2;
            int end = mediawiki.indexOf("]]");
            if (start < 0 || end < 0) {
                logger.warn("cannot find the redirect {}\n mediawiki: {}", article.getTitle(), mediawiki);
                continue;
            }
            String r = Article.getTitleInWikistyle(mediawiki.substring(start, end));
            article.setRedirect(r);
            article.setType(Type.REDIRECT);
        }

}

From source file:RestoreService.java

/**
 * execute restore process// w  ww .ja v  a  2 s  . c o m
 *
 * @throws Exception
 */
public void run() throws Exception {
    // load index
    Collection<File> bckIdxCollection = FileUtils.listFiles(repository.getMetaPath(),
            new WildcardFileFilter(bckIdxName + "*"), TrueFileFilter.INSTANCE);

    // TODO Lebeda - check only one index file

    // find files ro restore
    Set<VOBackupFile> oldFileSet = repository.collectBackupedFilesFromIndex(bckIdxCollection);
    Set<VOBackupFile> restoreFileSet = new HashSet<>();
    for (final String path : pathToRestoreList) {
        //noinspection unchecked
        restoreFileSet.addAll((Collection<VOBackupFile>) CollectionUtils.select(oldFileSet, new Predicate() {
            @Override
            public boolean evaluate(Object object) {
                VOBackupFile voBackupFile = (VOBackupFile) object;
                return StringUtils.startsWithIgnoreCase(voBackupFile.getPath(), path + File.separator);
            }
        }));
    }

    // create directory if not exists
    for (String pathForRestore : pathToRestoreList) {
        pathForRestore = changedPathToRestore(pathForRestore, targetPath);
        File baseFile = new File(pathForRestore);
        if (!baseFile.exists()) {
            //noinspection ResultOfMethodCallIgnored
            baseFile.mkdirs(); // TODO Lebeda - oetit hodnotu
        }
    }

    // find files in directory
    List<VOBackupFile> newFileList = new ArrayList<>();
    for (String pathForRestore : pathToRestoreList) {
        pathForRestore = changedPathToRestore(pathForRestore, targetPath);
        //noinspection unchecked
        final Collection<File> fileColection = FileUtils.listFiles(new File(pathForRestore),
                TrueFileFilter.INSTANCE, TrueFileFilter.INSTANCE);

        for (File file : fileColection) {
            newFileList.add(new VOBackupFile(file));
        }
    }

    // delete files not in index (new or changed)
    //noinspection unchecked
    final Collection<VOBackupFile> toDelete = (Collection<VOBackupFile>) CollectionUtils.subtract(newFileList,
            restoreFileSet);
    for (VOBackupFile voBackupFile : toDelete) {
        FileUtils.forceDelete(new File(voBackupFile.getPath()));
        logger.debug("deleted file: {}", voBackupFile.getPath());
    }

    // restore files not in direcroty
    //noinspection unchecked
    final Collection<VOBackupFile> toRestore = (Collection<VOBackupFile>) CollectionUtils
            .subtract(restoreFileSet, newFileList);

    final Collection<VOBackupFile> toTime = new ArrayList<>();
    for (VOBackupFile voBackupFile : toRestore) {
        String path = changedPathToRestore(voBackupFile.getPath(), targetPath);
        if (!voBackupFile.isSymLink()) {
            if (voBackupFile.isDirectory()) {
                File dir = new File(path);
                dir.mkdirs(); // TODO Lebeda - zajistit oeten
                toTime.add(voBackupFile);
                setAdvancedAttributes(voBackupFile, dir);
            } else if (voBackupFile.getSize() == 0) {
                File file = new File(path);
                file.createNewFile(); // TODO Lebeda - oetit
                file.setLastModified(voBackupFile.getModify().getTime());
                setAdvancedAttributes(voBackupFile, file);
            } else if (StringUtils.isNotBlank(voBackupFile.getFileHash())) {
                repository.restoreFile(voBackupFile, path);
            } else {
                // TODO Lebeda - chyba
                //                LoggerTools.log("unable to restore ${it}")
            }
        }
    }

    // symlinks restore at end
    for (VOBackupFile voBackupFile : toRestore) {
        String path = changedPathToRestore(voBackupFile.getPath(), targetPath);
        if (voBackupFile.isSymLink()) {
            Files.createSymbolicLink(Paths.get(path), Paths.get(voBackupFile.getSymlinkTarget()));
        }
    }

    for (VOBackupFile voBackupFile : toTime) {
        String path = changedPathToRestore(voBackupFile.getPath(), targetPath);
        File dir = new File(path);
        dir.setLastModified(voBackupFile.getModify().getTime());
    }

}

From source file:com.evolveum.polygon.connector.hcm.FilterHandler.java

private Boolean evaluateAttributeFilter(AttributeFilter filter, String filterType, String p) {
    // LOGGER.ok("Processing trough {0} ", filter);
    if (p == null || p.isEmpty()) {
        return true;
    } else {//from  w  w w . j  a  va  2  s  .c om

        String endTagName = "";
        String evaluatedValue = "";
        String uidAttributeName = "";

        String heplerVariableParts[] = p.split(DELIMITER);

        if (heplerVariableParts.length != 3) {
            return true;
        } else {
            endTagName = heplerVariableParts[0];
            evaluatedValue = heplerVariableParts[1];
            uidAttributeName = heplerVariableParts[2];
        }

        Attribute attribute = filter.getAttribute();
        String attributeValue = AttributeUtil.getAsStringValue(attribute);
        String attributeName = attribute.getName();

        if ((attributeName.equals(UID) && uidAttributeName.equals(endTagName))
                || attributeName.equals(endTagName)) {

            if (EQUALS.equals(filterType)) {
                if (!attributeValue.equals(evaluatedValue)) {
                    return false;
                }
            } else if (CONTAINS.equals(filterType)) {
                if (!StringUtils.containsIgnoreCase(evaluatedValue, attributeValue)) {

                    return false;
                }

            } else if (STARTSWITH.equals(filterType)) {
                if (!StringUtils.startsWithIgnoreCase(evaluatedValue, attributeValue)) {

                    return false;
                }

            } else if (ENDSWITH.equals(filterType)) {
                if (!StringUtils.endsWithIgnoreCase(evaluatedValue, attributeValue)) {

                    return false;
                }

            }
        }
    }
    return true;

}

From source file:com.sonicle.webtop.mail.ICalendarRequest.java

private String getEmail(Property p) {
    if (p == null)
        return NOEMAIL;
    String value = p.getValue();/* www.  java  2s.c o  m*/
    if (value == null)
        return NOEMAIL;
    if (StringUtils.startsWithIgnoreCase(value, "MAILTO:"))
        return value.substring(7);
    return NOEMAIL;
}

From source file:com.incapture.rapgen.parser.SampleCodeParser.java

/**
 * Strip leading 'test' from any function names and apply proper capitalization
 * /* w w w  . j  a  v  a 2 s.co  m*/
 * @param functionName
 *            The function to be adjusted
 * @return functionName without leading 'test' and proper capitalization
 */
String stripTestPrefix(String functionName) {
    if (StringUtils.isBlank(functionName)) {
        return null;
    }
    if (StringUtils.startsWithIgnoreCase(functionName, "test")) {
        return StringUtils.uncapitalize(functionName.substring(4));
    }
    return functionName;
}

From source file:com.yiji.openapi.sdk.util.Servlets.java

@SuppressWarnings("unchecked")
public static Map<String, String> getHeaders(HttpServletRequest request, String prefixName) {
    Enumeration<String> names = request.getHeaderNames();
    String name = null;/* w w  w.  j a  v  a 2 s .c o  m*/
    Map<String, String> map = Maps.newLinkedHashMap();
    while (names.hasMoreElements()) {
        name = names.nextElement();
        if (StringUtils.isNotBlank(prefixName)) {
            if (StringUtils.startsWithIgnoreCase(name, prefixName)) {
                map.put(StringUtils.lowerCase(name), getHeaderValue(request, name));
            }
        } else {
            map.put(StringUtils.lowerCase(name), getHeaderValue(request, name));
        }
    }
    return map;
}