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

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

Introduction

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

Prototype

public static boolean endsWithIgnoreCase(final CharSequence str, final CharSequence suffix) 

Source Link

Document

Case insensitive check if a CharSequence ends with a specified suffix.

null s are handled without exceptions.

Usage

From source file:org.yamj.core.tools.CountryXmlTools.java

@PostConstruct
public void init() {
    String countryFileName = PropertyTools.getProperty("yamj3.country.fileName");
    if (StringUtils.isBlank(countryFileName)) {
        LOG.trace("No valid country file name configured");
        return;/* w ww.j a  va2s. c o  m*/
    }
    if (!StringUtils.endsWithIgnoreCase(countryFileName, "xml")) {
        LOG.warn("Invalid country file name specified: {}", countryFileName);
        return;
    }

    File xmlFile;
    if (StringUtils.isBlank(FilenameUtils.getPrefix(countryFileName))) {
        // relative path given
        String path = System.getProperty("yamj3.home");
        if (StringUtils.isEmpty(path)) {
            path = ".";
        }
        xmlFile = new File(FilenameUtils.concat(path, countryFileName));
    } else {
        // absolute path given
        xmlFile = new File(countryFileName);
    }

    if (!xmlFile.exists() || !xmlFile.isFile()) {
        LOG.warn("Countries file does not exist: {}", xmlFile.getPath());
        return;
    }
    if (!xmlFile.canRead()) {
        LOG.warn("Countries file not readble: {}", xmlFile.getPath());
        return;
    }

    LOG.debug("Initialize countries from file: {}", xmlFile.getPath());

    try {
        XMLConfiguration c = new XMLConfiguration(xmlFile);

        List<HierarchicalConfiguration> countries = c.configurationsAt("country");
        for (HierarchicalConfiguration country : countries) {
            String masterCountry = country.getString("[@name]");
            List<Object> subCountries = country.getList("subcountry");
            for (Object subCountry : subCountries) {
                LOG.debug("New genre added to map: {} -> {}", subCountry, masterCountry);
                COUNTRIES_MAP.put(((String) subCountry).toLowerCase(), masterCountry);
            }
        }

        try {
            this.commonStorageService.updateCountriesXml(COUNTRIES_MAP);
        } catch (Exception ex) {
            LOG.warn("Failed update countries xml in database", ex);
        }
    } catch (Exception ex) {
        LOG.error("Failed parsing country input file: " + xmlFile.getPath(), ex);
    }
}

From source file:org.yamj.core.tools.GenreXmlTools.java

@PostConstruct
public void init() {
    String genreFileName = PropertyTools.getProperty("yamj3.genre.fileName");
    if (StringUtils.isBlank(genreFileName)) {
        LOG.trace("No valid genre file name configured");
        return;/* www  .j  a v a 2s. c  om*/
    }
    if (!StringUtils.endsWithIgnoreCase(genreFileName, "xml")) {
        LOG.warn("Invalid genre file name specified: {}", genreFileName);
        return;
    }

    File xmlFile;
    if (StringUtils.isBlank(FilenameUtils.getPrefix(genreFileName))) {
        // relative path given
        String path = System.getProperty("yamj3.home");
        if (StringUtils.isEmpty(path)) {
            path = ".";
        }
        xmlFile = new File(FilenameUtils.concat(path, genreFileName));
    } else {
        // absolute path given
        xmlFile = new File(genreFileName);
    }

    if (!xmlFile.exists() || !xmlFile.isFile()) {
        LOG.warn("Genres file does not exist: {}", xmlFile.getPath());
        return;
    }
    if (!xmlFile.canRead()) {
        LOG.warn("Genres file not readble: {}", xmlFile.getPath());
        return;
    }

    LOG.debug("Initialize genres from file: {}", xmlFile.getPath());

    try {
        XMLConfiguration c = new XMLConfiguration(xmlFile);

        List<HierarchicalConfiguration> genres = c.configurationsAt("genre");
        for (HierarchicalConfiguration genre : genres) {
            String masterGenre = genre.getString("[@name]");
            List<Object> subGenres = genre.getList("subgenre");
            for (Object subGenre : subGenres) {
                LOG.debug("New genre added to map: {} -> {}", subGenre, masterGenre);
                GENRES_MAP.put(((String) subGenre).toLowerCase(), masterGenre);
            }
        }

        try {
            this.commonStorageService.updateGenresXml(GENRES_MAP);
        } catch (Exception ex) {
            LOG.warn("Failed update genres xml in database", ex);
        }
    } catch (Exception ex) {
        LOG.error("Failed parsing genre input file: " + xmlFile.getPath(), ex);
    }
}

From source file:pcgen.gui2.PcgFileFilter.java

/**
 *  Accept all directories and all pcg files
 *
 * @param  f  The file to be checked// w w w  .ja  v a  2  s .c o m
 * @return    Whether the file is accepted
 */
@Override
public boolean accept(File f) {
    if (f.isDirectory()) {
        return true;
    }
    return StringUtils.endsWithIgnoreCase(f.getName(), ".pcg");
}

From source file:pcgen.persistence.CampaignFileLoader.java

/**
 * Recursively looks inside a given directory for PCC files
 * and adds them to the {@link #campaignFiles campaignFiles} list.
 * @param aDirectory The directory to search.
 *///  w  w  w  . j  av a2  s.c  om
private void findPCCFiles(final File aDirectory) {
    final FilenameFilter pccFileFilter = (parentDir,
            fileName) -> StringUtils.endsWithIgnoreCase(fileName, ".pcc")
                    || new File(parentDir, fileName).isDirectory();

    if (!aDirectory.exists() || !aDirectory.isDirectory()) {
        return;
    }
    for (final File file : aDirectory.listFiles(pccFileFilter)) {
        if (file.isDirectory()) {
            findPCCFiles(file);
            continue;
        }
        campaignFiles.add(file.toURI());
    }
}

From source file:qtiscoringengineTester.EQQtiTester.java

private static void testAllFiles(Object[] args) {
    final ScoreCounter scoreCounter = new ScoreCounter();
    final String folder = sanitizeFileNameForUri((String) args[5]);
    final int MAXFILES = (Integer) args[6];
    final String itemIdsToScore = (String) args[7];
    try {/*from w  w w  .  j  a va 2s.c  o  m*/
        final Set<String> itemsToScoreSet = buildItemsToScore(itemIdsToScore);
        final Map<String, String> rubricsMap = mapRubricPathToItemId(folder,
                new _Ref<Map<String, String>>(new HashMap<String, String>()));

        int fileCounter = 1;
        List<File> files = (List<File>) Arrays.asList(new File(folder).listFiles());
        Collections.shuffle(files);
        for (File file : files) {
            String absoluteFilePath = file.getAbsolutePath();
            if (StringUtils.endsWithIgnoreCase(absoluteFilePath, ".tsv")) {
                final Map<String, String> parameters = getItemIdForResponsefile(file.getName());
                if (parameters == null)
                    continue;
                final String itemId = parameters.get("itemid");
                final String format = parameters.get("format");

                if (StringUtils.isEmpty(itemId))
                    continue;

                // is it in the set? if the set is null then basically we are scoring
                // everything else we are only scoring if it exists in the set.
                if (itemsToScoreSet != null && !itemsToScoreSet.contains(itemId))
                    continue;

                if (fileCounter == MAXFILES)
                    break;
                ++fileCounter;

                final String rubricPath = sanitizeFileNameForUri(rubricsMap.get(itemId));
                if (StringUtils.isEmpty(rubricPath)) {
                    _logger.error(String.format("Error: No rubric found for item id %s", itemId));
                    scoreCounter.incrementMissingRubrics();
                    continue;
                }

                _logger.error(String.format("Processing input file %s with item id %s using rubric %s.",
                        file.getAbsolutePath(), itemId, rubricPath));

                //restartPython ();

                FormQtiTester qtiTester = new FormQtiTester(new ItemSpecification() {
                    {
                        this._itemId = itemId;
                        this._bankId = "NA";
                        this._rubricFilePath = rubricPath;
                        this._format = format;
                    }
                }, scoreCounter);

                qtiTester.processResponseFiles(file.getAbsolutePath());
            }
        }

    } catch (Exception exp) {
        exp.printStackTrace();
        _logger.error(exp.getMessage(), exp);
    }

    _logger.error(scoreCounter.toString());
}

From source file:qtiscoringengineTester.QtiTester.java

private static void testAllFiles(Object[] args) {
    final ScoreCounter scoreCounter = new ScoreCounter();
    final String folder = sanitizeFileNameForUri((String) args[5]);
    final int MAXFILES = (Integer) args[6];
    final String itemIdsToScore = (String) args[7];
    try {//from   w w  w  . j a  va 2 s .c o  m
        final Set<String> itemsToScoreSet = buildItemsToScore(itemIdsToScore);
        final Map<String, String> rubricsMap = mapRubricPathToItemId(folder,
                new _Ref<Map<String, String>>(new HashMap<String, String>()));

        int fileCounter = 1;
        List<File> files = (List<File>) Arrays.asList(new File(folder).listFiles());
        Collections.shuffle(files);
        for (File file : files) {
            String absoluteFilePath = file.getAbsolutePath();
            if (StringUtils.endsWithIgnoreCase(absoluteFilePath, ".tsv")) {
                final Map<String, String> parameters = getItemIdForResponsefile(file.getName());
                if (parameters == null)
                    continue;
                final String itemId = parameters.get("itemid");
                final String format = parameters.get("format");

                if (StringUtils.isEmpty(itemId))
                    continue;

                // is it in the set? if the set is null then basically we are scoring
                // everything else we are only scoring if it exists in the set.
                if (itemsToScoreSet != null && !itemsToScoreSet.contains(itemId))
                    continue;

                if (fileCounter == MAXFILES)
                    break;
                ++fileCounter;

                final String rubricPath = sanitizeFileNameForUri(rubricsMap.get(itemId));
                if (StringUtils.isEmpty(rubricPath)) {
                    _logger.error(String.format("Error: No rubric found for item id %s", itemId));
                    scoreCounter.incrementMissingRubrics();
                    continue;
                }

                _logger.error(String.format("Processing input file %s with item id %s using rubric %s.",
                        file.getAbsolutePath(), itemId, rubricPath));

                restartPython();
                _logger.info("Python started.");

                FormQtiTester qtiTester = new FormQtiTester(new ItemSpecification() {
                    {
                        this._itemId = itemId;
                        this._bankId = "NA";
                        this._rubricFilePath = rubricPath;
                        this._format = format;
                    }
                }, scoreCounter);

                qtiTester.processResponseFiles(file.getAbsolutePath());
            }
        }

    } catch (Exception exp) {
        exp.printStackTrace();
        _logger.error(exp.getMessage(), exp);
    }

    _logger.error(scoreCounter.toString());
}

From source file:therian.util.ReadOnlyUtils.java

public static <T> Deque<T> wrap(Deque<T> deque) {
    @SuppressWarnings("unchecked")
    final Deque<T> result = (Deque<T>) Proxy.newProxyInstance(
            Validate.notNull(deque, "object required to wrap").getClass().getClassLoader(),
            new Class[] { Deque.class }, new InvocationHandler() {
                public Object invoke(Object o, Method method, Object[] objects) throws Throwable {
                    if (StringUtils.startsWithAny(method.getName(), "add", "offer", "poll", "pop", "push",
                            "remove", "clear", "retain")) {
                        throw new UnsupportedOperationException("read-only");
                    }//from w  w w .  j  a  va 2s .c  o  m
                    final Object result = method.invoke(o, objects);
                    if (StringUtils.endsWithIgnoreCase(method.getName(), "iterator")) {
                        final Iterator<?> wrapIterator = (Iterator<?>) result;
                        return new Iterator<Object>() {
                            public boolean hasNext() {
                                return wrapIterator.hasNext();
                            }

                            public Object next() {
                                return wrapIterator.next();
                            }

                            public void remove() {
                            }
                        };
                    }
                    return null;
                }
            });
    return result;
}