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.openlca.io.EcoSpoldUnitFetch.java

private void parseZip(ZipFile zipFile) throws Exception {
    final Enumeration<? extends ZipEntry> entries = zipFile.entries();
    while (entries.hasMoreElements()) {
        ZipEntry entry = entries.nextElement();
        if (entry.isDirectory())
            continue;
        if (StringUtils.endsWithIgnoreCase(entry.getName(), ".xml")) {
            try (InputStream in = zipFile.getInputStream(entry)) {
                parser.parse(in, handler);
            }/*from   w w  w  .  j  av a 2s.c om*/
        }
    }
}

From source file:org.opens.tanaguru.rules.elementchecker.text.TextEndsWithChecker.java

/**
 * /*from ww  w. j a  v  a2 s  .  c  o m*/
 * @param element
 * @param elementText
 * @return failed whether the text belongs to a blacklist, need_more_info
 * instead
 */
private TestSolution checkTextElementEndsWithExtension(Element element, String elementText) {
    // the test is made through the getter to force the initialisation
    if (element == null || elementText == null || CollectionUtils.isEmpty(getExtensions())) {
        return TestSolution.NOT_APPLICABLE;
    }
    for (String extension : extensions) {
        if (StringUtils.endsWithIgnoreCase(elementText, extension)) {

            if (StringUtils.isNotBlank(textEndsWithMessageCode)) {
                addSourceCodeRemark(getFailureSolution(), element, textEndsWithMessageCode);
            }
            return getFailureSolution();
        }
    }
    if (!getSuccessSolution().equals(TestSolution.PASSED)
            && !getSuccessSolution().equals(TestSolution.NOT_APPLICABLE)
            && StringUtils.isNotBlank(textNotEndsWithMessageCode)) {
        addSourceCodeRemark(getSuccessSolution(), element, textNotEndsWithMessageCode);
    }
    return getSuccessSolution();
}

From source file:org.pepstock.jem.util.TimeUtils.java

/**
 * Returns the milliseconds corrisponding to a string in the format:
 * - [0-9]+[d|h|m]/*w w  w.j  a  va2s  . co m*/
 * like:
 * - 2d (two days) or
 * - 3h (three hours) or
 * - 15m (fifteen minutes)
 * and so on.
 * 
 * @param tokenValue the value to be parsed
 * @return the milliseconds identified by parameter
 * @throws ParseException if the parameter cannot be parsed
 */
public static long parseDuration(String tokenValue) throws ParseException {
    // validate the value!
    if (!(StringUtils.endsWithIgnoreCase(tokenValue, D_STRING)
            || StringUtils.endsWithIgnoreCase(tokenValue, H_STRING)
            || StringUtils.endsWithIgnoreCase(tokenValue, M_STRING))) {
        throw new ParseException("Invalid time unit!");
    }

    // parse the date value
    int timeUnitIndex = tokenValue.length() - 1;
    char timeUnit = tokenValue.charAt(timeUnitIndex);
    int timeValue;
    try {
        timeValue = Integer.parseInt(tokenValue.substring(0, timeUnitIndex));
    } catch (NumberFormatException e) {
        throw new ParseException("Invalid time value!", e);
    }

    long time;
    switch (timeUnit) {
    case D:
        time = timeValue * DAY;
        break;
    case H:
        time = timeValue * HOUR;
        break;
    case M:
        time = timeValue * MINUTE;
        break;
    default:
        throw new ParseException("Invalid time unit!");
    }

    return time;
}

From source file:org.phenotips.data.permissions.internal.VCFAccessRestrictionEventListener.java

@Override
public void onEvent(Event event, Object source, Object data) {
    XWikiContext context = (XWikiContext) data;
    XWikiRequest request = context.getRequest();

    String path = request.getRequestURI();
    String filename;//from   w w  w  .java 2  s.co  m
    try {
        filename = URLDecoder.decode(getFileName(path), "UTF-8");
    } catch (UnsupportedEncodingException e) {
        // This really shouldn't happen, UTF-8 is mandatory
        return;
    }

    if (StringUtils.endsWithIgnoreCase(filename, ".vcf")) {
        XWikiDocument doc = context.getDoc();
        Patient patient = this.patients.get(doc.getDocumentReference().toString());
        PatientAccess access = this.permissions.getPatientAccess(patient);
        if (!access.hasAccessLevel(this.edit)) {
            ((CancelableEvent) event).cancel();
        }
    }
}

From source file:org.phenotips.integration.medsavant.internal.JsonMedSavantServer.java

@Override
public boolean uploadVCF(Patient patient) {
    HttpPost method = null;// w  w w  .j av  a2 s  .  com
    try {
        MultipartEntityBuilder data = MultipartEntityBuilder.create();
        PatientData<String> identifiers = patient.getData("identifiers");
        String url = getMethodURL("UploadManager", "upload");
        String eid = identifiers.get("external_id");
        XWikiContext context = Utils.getContext();
        XWikiDocument doc = context.getWiki().getDocument(patient.getDocument(), context);
        method = new HttpPost(url);

        boolean hasData = false;
        for (XWikiAttachment attachment : doc.getAttachmentList()) {
            if (StringUtils.endsWithIgnoreCase(attachment.getFilename(), ".vcf")
                    && isCorrectVCF(attachment, eid, context)) {
                data.addBinaryBody(patient.getId() + ".vcf", attachment.getContentInputStream(context));
                hasData = true;
            }
        }
        if (hasData) {
            method.setEntity(data.build());
            this.client.execute(method).close();
            return true;
        }
    } catch (Exception ex) {
        this.logger.warn("Failed to upload VCF for patient [{}]: {}", patient.getDocument(), ex.getMessage(),
                ex);
    } finally {
        if (method != null) {
            method.releaseConnection();
        }
    }
    return false;
}

From source file:org.primefaces.extensions.showcase.util.FileContentMarkerUtil.java

public static String readFileContent(String fileName, InputStream is) {
    try {/*from  w  ww.  j ava 2 s.  c om*/
        if (StringUtils.endsWithIgnoreCase(fileName, ".java")) {
            return readFileContent(is, javaFileSettings);
        }

        if (StringUtils.endsWithIgnoreCase(fileName, ".xhtml")) {
            return readFileContent(is, xhtmlFileSettings);
        }

        // Show all files
        return readFileContent(is, new FileContentSettings());
    } catch (Exception e) {
        throw new IllegalStateException("Internal error: file " + fileName + " could not be read", e);
    }
}

From source file:org.talend.core.ui.metadata.celleditor.ModuleListDialog.java

@Override
protected void okPressed() {
    isInner = innerBtn.getSelection();//from ww w .java 2 s .c o m
    if (isInner) {
        if (isJDBCCreate) {
            selecteModuleArray = jarsViewer.getList().getSelection();
        } else {
            selecteModuleArray = null;
            setSelecteModule(jarsViewer.getList().getSelection()[0]);
        }
    } else {
        List<String> pathList = new ArrayList<String>();
        if (isJDBCCreate) {
            pathList.addAll(jarsList);
        } else {
            selecteModuleArray = null;
            pathList.add(selectField.getText());
        }
        String[] jarNames = new String[pathList.size()];
        for (int i = 0; i < pathList.size(); i++) {
            String jarPath = pathList.get(i);
            IPath path = Path.fromOSString(jarPath);
            File source = path.toFile();
            if (!source.exists()) {
                MessageDialog.openWarning(getParentShell(), "File Not Found",
                        path + " is not Found,Please make sure the file is exist!");
                return;
            }
            String lastSegment = path.lastSegment();
            try {
                if (GlobalServiceRegister.getDefault().isServiceRegistered(ILibrariesService.class)) {
                    ILibrariesService service = (ILibrariesService) GlobalServiceRegister.getDefault()
                            .getService(ILibrariesService.class);

                    if (param != null) {

                        IElementParameter componentName = param.getElement()
                                .getElementParameter("COMPONENT_NAME");

                        if (componentName != null && "cConfig".equals(componentName.getValue())) {
                            String versionType = ".SNAPSHOT";
                            selectedJarPath = jarPath;
                            String selectedJarVersionTmp = versionLabel.getText();
                            if (StringUtils.endsWithIgnoreCase(selectedJarVersionTmp, versionType)) {
                                selectedJarVersionTmp = selectedJarVersionTmp.replace(versionType, "-SNAPSHOT");
                            }

                            selectedJarVersion = selectedJarVersionTmp;

                        } else {
                            service.deployLibrary(path.toFile().toURI().toURL());
                        }
                    } else {
                        service.deployLibrary(path.toFile().toURI().toURL());
                    }

                }

            } catch (Exception ee) {
                ExceptionHandler.process(ee);
            }

            setSelecteModule(lastSegment);
            jarNames[i] = lastSegment;
        }
        if (isJDBCCreate) {
            selecteModuleArray = jarNames;
        }
    }
    super.okPressed();
}

From source file:org.thorn.emma.model.Html.java

public Set<String> fetchAllUrl() {

    Set<String> urls = new HashSet<String>();

    //css\js??/*from   w  ww  .  ja  v a 2  s.c  o m*/
    Elements[] array = new Elements[] { this.document.select("a[href]"), this.document.select("[src]") };

    for (Elements links : array) {

        for (Element element : links) {
            String href = element.attr("href");

            if (!StringUtils.endsWithIgnoreCase(href, ".js") && !StringUtils.endsWithIgnoreCase(href, ".css")) {
                urls.add(href);
            }
        }
    }

    return urls;
}

From source file:org.wikipedia.nirvana.NumberTools.java

public static int parseFileSize(String s) throws NumberFormatException {
    int size = 0;
    int multi = 1;
    if (StringUtils.endsWithIgnoreCase(s, "K") || StringUtils.endsWithIgnoreCase(s, "")) {
        multi = K;//from   ww w.  j  av a 2s .c  o  m
        s = s.substring(0, s.length() - 1).trim();
    } else if (StringUtils.endsWithIgnoreCase(s, "KB") || StringUtils.endsWithIgnoreCase(s, "")) {
        multi = K;
        s = s.substring(0, s.length() - 2).trim();
    } else if (StringUtils.endsWithIgnoreCase(s, "M") || StringUtils.endsWithIgnoreCase(s, "")) {
        multi = M;
        s = s.substring(0, s.length() - 1).trim();
    } else if (StringUtils.endsWithIgnoreCase(s, "MB") || StringUtils.endsWithIgnoreCase(s, "")) {
        multi = M;
        s = s.substring(0, s.length() - 2).trim();
    }
    size = Integer.parseInt(s);
    return (size * multi);
}

From source file:org.yamj.core.service.mediaimport.MediaImportService.java

@Transactional(propagation = Propagation.REQUIRED)
public void processImage(long id) {
    StageFile stageFile = stagingDao.getStageFile(id);

    if (stageFile.getBaseName().equalsIgnoreCase("poster") || stageFile.getBaseName().equalsIgnoreCase("cover")
            || stageFile.getBaseName().equalsIgnoreCase("folder")) {
        // TODO apply poster to all video files in that directory
        LOG.trace("Generic poster found: {}", stageFile.getBaseName());
    } else if (StringUtils.endsWithIgnoreCase(stageFile.getBaseName(), ".poster")
            || StringUtils.endsWithIgnoreCase(stageFile.getBaseName(), "-poster")) {
        // TODO apply poster to single video
        LOG.trace("Poster found: {}", stageFile.getBaseName());
    } else if (stageFile.getBaseName().equalsIgnoreCase("fanart")
            || stageFile.getBaseName().equalsIgnoreCase("backdrop")
            || stageFile.getBaseName().equalsIgnoreCase("background")) {
        // TODO apply fanart to all video files in that directory
        LOG.trace("Generic fanart found: {}", stageFile.getBaseName());
    } else if (StringUtils.endsWithIgnoreCase(stageFile.getBaseName(), ".fanart")
            || StringUtils.endsWithIgnoreCase(stageFile.getBaseName(), "-fanart")) {
        // TODO apply fanart to single video
        LOG.trace("Fanart found: {}", stageFile.getBaseName());
    }/*w  w w.  j  ava  2  s.c o  m*/
}