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:com.smokejumperit.gradle.report.DependencyLicenseReport.java

private static boolean fileNameLooksLikeHtml(File file) {
    String fileName = file.getName();
    if (StringUtils.endsWithIgnoreCase(fileName, ".html")) {
        return true;
    }/*w  ww.ja va 2  s.  com*/
    if (StringUtils.endsWithIgnoreCase(fileName, ".htm")) {
        return true;
    }
    return false;
}

From source file:com.sketchy.utils.image.SketchyImage.java

public static void save(SketchyImage sketchyImage, File file) throws Exception {
    if (!file.getParentFile().canWrite()) {
        throw new Exception("Can not write to File: " + file.getPath() + "!");
    }//from w  w w.ja  v  a 2  s  .c om

    if (!StringUtils.endsWithIgnoreCase(file.getName(), ".png")) {
        throw new Exception("Can not save SketchyImage! Must be a .png file!");
    }

    Iterator<ImageWriter> imageWriters = ImageIO.getImageWritersByFormatName("png");
    ImageWriter imageWriter = null;
    if (imageWriters.hasNext()) { // Just get first one
        imageWriter = imageWriters.next();
    }
    if (imageWriter == null) {
        // this should never happen!! if so.. we got problems
        throw new Exception("Can not find ImageReader for .png Files!");
    }

    ImageOutputStream os = null;
    try {
        os = ImageIO.createImageOutputStream(file);
        imageWriter.setOutput(os);

        ImageWriteParam imageWriterParam = imageWriter.getDefaultWriteParam();
        IIOMetadata metadata = imageWriter.getDefaultImageMetadata(
                ImageTypeSpecifier.createFromBufferedImageType(BufferedImage.TYPE_BYTE_BINARY),
                imageWriterParam);

        String metaDataFormatName = metadata.getNativeMetadataFormatName();
        IIOMetadataNode metaDataNode = (IIOMetadataNode) metadata.getAsTree(metaDataFormatName);

        NodeList childNodes = metaDataNode.getElementsByTagName("pHYs");
        IIOMetadataNode physNode = null;
        if (childNodes.getLength() == 0) {
            physNode = new IIOMetadataNode("pHYs");
            physNode.setAttribute("pixelsPerUnitXAxis",
                    Integer.toString((int) Math.ceil(sketchyImage.dotsPerMillimeterWidth * 1000)));
            physNode.setAttribute("pixelsPerUnitYAxis",
                    Integer.toString((int) Math.ceil(sketchyImage.dotsPerMillimeterHeight * 1000)));
            physNode.setAttribute("unitSpecifier", "meter"); // always meter
            metaDataNode.appendChild(physNode);
        } else {
            for (int nodeIdx = 0; nodeIdx < childNodes.getLength(); nodeIdx++) {
                physNode = (IIOMetadataNode) childNodes.item(nodeIdx);
                physNode.setAttribute("pixelsPerUnitXAxis",
                        Integer.toString((int) Math.ceil(sketchyImage.dotsPerMillimeterWidth * 1000)));
                physNode.setAttribute("pixelsPerUnitYAxis",
                        Integer.toString((int) Math.ceil(sketchyImage.dotsPerMillimeterHeight * 1000)));
                physNode.setAttribute("unitSpecifier", "meter"); // always meter
                metaDataNode.appendChild(physNode);
            }
        }
        metadata.setFromTree(metaDataFormatName, metaDataNode);
        imageWriter.write(new IIOImage(sketchyImage.image, null, metadata));
        os.flush();
    } catch (Exception e) {
        throw new Exception("Error Saving SketchyImage File: " + file.getPath() + "!  " + e.getMessage());
    } finally {
        IOUtils.closeQuietly(os);
    }
}

From source file:com.stefanbrenner.droplet.ui.actions.SaveFileAction.java

protected void showFileChooser() {
    int returnVal = fileChooser.showSaveDialog(getFrame());
    if (returnVal == JFileChooser.APPROVE_OPTION) {

        // Get the selected file
        File file = fileChooser.getSelectedFile();

        // check if file extension fits
        if (StringUtils.containsIgnoreCase(file.getName(), ".") //$NON-NLS-1$
                && !(StringUtils.endsWithIgnoreCase(file.getName(),
                        "." + IDropletContext.DROPLET_FILE_EXTENSION))) {
            JOptionPane.showMessageDialog(getFrame(), Messages.getString("SaveFileAction.extensionNotAllowed"), //$NON-NLS-1$
                    Messages.getString("SaveFileAction.wrongExtension"), //$NON-NLS-1$
                    JOptionPane.ERROR_MESSAGE);
            showFileChooser();//from w ww. j a  v  a2 s.  c  o m
            return;
        } else { // automatically add droplet file extension
            if (!StringUtils.endsWithIgnoreCase(file.getName(), "." + IDropletContext.DROPLET_FILE_EXTENSION)) {
                String newPath = StringUtils.join(file.getPath(), "." + IDropletContext.DROPLET_FILE_EXTENSION);
                file = new File(newPath);
            }
        }

        // check if file already exists
        if (file.exists()) {
            int retVal = JOptionPane.showConfirmDialog(getFrame(),
                    Messages.getString("SaveFileAction.overwriteFile"), Messages.getString("SaveFileAction.1"), //$NON-NLS-1$ //$NON-NLS-2$
                    JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE);

            if (retVal == JOptionPane.NO_OPTION) {
                showFileChooser();
                return;
            }
        }

        saveFile(file);

        // set file to context
        getDropletContext().setFile(file);

    }
}

From source file:de.adorsys.multibanking.hbci.model.HbciMapping.java

public static List<StandingOrder> createStandingOrders(GVRDauerList gvrDauerList) {
    GVRDauerList.Dauer[] lines = gvrDauerList.getEntries();
    List<StandingOrder> standingOrders = new ArrayList<>();

    for (int i = 0; i < lines.length; ++i) {
        GVRDauerList.Dauer line = lines[i];
        StandingOrder auftrag = new StandingOrder();

        if (line.firstdate != null) {
            auftrag.setFirstExecutionDate(
                    line.firstdate.toInstant().atZone(ZoneId.systemDefault()).toLocalDate());
        }/* www. j a v a 2 s  . c o m*/
        if (line.lastdate != null) {
            auftrag.setLastExecutionDate(
                    line.lastdate.toInstant().atZone(ZoneId.systemDefault()).toLocalDate());
        }
        auftrag.setAmount(line.value.getBigDecimalValue());
        auftrag.setOrderId(line.orderid);
        auftrag.setOtherAccount(toBankAccount(line.other));
        auftrag.setUsage(getUsage(Arrays.asList(line.usage)));
        auftrag.setExecutionDay(line.execday);

        Cycle cycle = null;
        if (!StringUtils.endsWithIgnoreCase("M", line.timeunit)) {
            cycle = Cycle.WEEKLY;
        } else {
            switch (line.turnus) {
            case 1:
                cycle = Cycle.MONTHLY;
                break;
            case 2:
                cycle = Cycle.TWO_MONTHLY;
                break;
            case 3:
                cycle = Cycle.QUARTERLY;
                break;
            case 6:
                cycle = Cycle.HALF_YEARLY;
                break;
            case 12:
                cycle = Cycle.YEARLY;
                break;
            }
        }
        auftrag.setCycle(cycle);

        standingOrders.add(auftrag);
    }
    return standingOrders;

}

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

private static ColumnMetaData getColumnMetaData(String schema, int ind, final Object obj) {
    final Map<String, Object> property = (Map<String, Object>) obj;
    final Integer index = (Integer) property.get(INDEX_PROPERTY);
    final int columnIndex = index != null ? index - 1 : ind;
    final String name = (String) property.get(NAME_PROPERTY);
    final String title = (String) property.get(TITLE_PROPERTY);
    final String table = (String) property.get(TABLE_PROPERTY);
    final String datatype = property.get(DATATYPE_PROPERTY).toString(); // may be represented as a json object (hashmap)
    final String propertyUrl = (String) property.get(PROPERTY_URL);
    final AtsdType atsdType = EnumUtil.getAtsdTypeByOriginalName(datatype);
    final int nullable = StringUtils.endsWithIgnoreCase(propertyUrl, "Tag") ? 1 : 0;
    return new ColumnMetaDataBuilder().withColumnIndex(columnIndex).withSchema(schema).withTable(table)
            .withName(name).withTitle(title).withAtsdType(atsdType).withNullable(nullable).build();
}

From source file:com.orm.androrm.migration.MigrationHelper.java

public List<String> getRelationTableNames(String table) {
    List<String> result = new ArrayList<String>();
    String sql = "SELECT name FROM sqlite_master WHERE type='table' AND (name LIKE '" + table
            + "#_%' OR name LIKE '%#_" + table + "' ESCAPE '#')";

    Cursor c = getCursor(sql);/*from   w  w  w  .j av  a2  s.c o m*/

    while (c.moveToNext()) {
        String name = c.getString(c.getColumnIndexOrThrow("name"));

        if (!name.equalsIgnoreCase(table) && (StringUtils.startsWithIgnoreCase(name, table)
                || StringUtils.endsWithIgnoreCase(name, table))) {

            result.add(name);
        }
    }

    close(c);
    return result;
}

From source file:com.sonicle.webtop.core.app.servlet.Login.java

@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    boolean redirect = false;

    if (logger.isTraceEnabled()) {
        logger.trace("X-REQUEST-URI: {}", request.getHeader("X-REQUEST-URI"));
        logger.trace("requestUrl: {}", request.getRequestURL().toString());
        logger.trace("pathInfo: {}", request.getPathInfo());
        logger.trace("baseUrl: {}", getBaseUrl(request));
        logger.trace("forwardServletPath: {}", getRequestForwardServletPath(request));
    }//ww  w .jav  a 2  s .c o m

    if (ServletUtils.isForwarded(request)) {
        String forwardServletPath = getRequestForwardServletPath(request);
        if (StringUtils.startsWithIgnoreCase(forwardServletPath, Login.URL)
                || StringUtils.startsWithIgnoreCase(forwardServletPath, Logout.URL)) {
            redirect = true;
        }
        if (StringUtils.startsWithIgnoreCase(forwardServletPath, PushEndpoint.URL)) {
            WebUtils.getAndClearSavedRequest(request);
            redirect = true;
        }
    } else {
        String requestUrl = request.getRequestURL().toString();
        if (StringUtils.endsWithIgnoreCase(requestUrl, Login.URL)) {
            redirect = true;
        }
    }

    if (redirect) {
        WebUtils.issueRedirect(request, response, "/");
    } else {
        super.doGet(request, response);
    }
}

From source file:com.thoughtworks.go.serverhealth.HealthStateScope.java

public boolean isSame(String scope) {
    return StringUtils.endsWithIgnoreCase(this.scope, scope);
}

From source file:forge.gui.ImportSourceAnalyzer.java

private void identifyAndAnalyze(final File root) {
    // see if we can figure out the likely identity of the source folder and
    // dispatch to the best analysis subroutine to handle it
    final String dirname = root.getName();

    if ("res".equalsIgnoreCase(dirname)) {
        analyzeOldResDir(root);/* w  w w.ja va  2 s.  c  om*/
    } else if ("constructed".equalsIgnoreCase(dirname)) {
        analyzeConstructedDeckDir(root);
    } else if ("draft".equalsIgnoreCase(dirname)) {
        analyzeDraftDeckDir(root);
    } else if ("plane".equalsIgnoreCase(dirname) || "planar".equalsIgnoreCase(dirname)) {
        analyzePlanarDeckDir(root);
    } else if ("scheme".equalsIgnoreCase(dirname)) {
        analyzeSchemeDeckDir(root);
    } else if ("sealed".equalsIgnoreCase(dirname)) {
        analyzeSealedDeckDir(root);
    } else if (StringUtils.containsIgnoreCase(dirname, "deck")) {
        analyzeDecksDir(root);
    } else if ("gauntlet".equalsIgnoreCase(dirname)) {
        analyzeGauntletDataDir(root);
    } else if ("layouts".equalsIgnoreCase(dirname)) {
        analyzeLayoutsDir(root);
    } else if ("pics".equalsIgnoreCase(dirname)) {
        analyzeCardPicsDir(root);
    } else if ("pics_product".equalsIgnoreCase(dirname)) {
        analyzeProductPicsDir(root);
    } else if ("preferences".equalsIgnoreCase(dirname)) {
        analyzePreferencesDir(root);
    } else if ("quest".equalsIgnoreCase(dirname)) {
        analyzeQuestDir(root);
    } else if (null != FModel.getMagicDb().getEditions().get(dirname)) {
        analyzeCardPicsSetDir(root);
    } else {
        // look at files in directory and make a semi-educated guess based on file extensions
        int numUnhandledFiles = 0;
        File[] files = root.listFiles();
        assert files != null;
        for (final File file : files) {
            if (cb.checkCancel()) {
                return;
            }

            if (file.isFile()) {
                final String filename = file.getName();
                if (StringUtils.endsWithIgnoreCase(filename, ".dck")) {
                    analyzeDecksDir(root);
                    numUnhandledFiles = 0;
                    break;
                } else if (StringUtils.endsWithIgnoreCase(filename, ".jpg")) {
                    analyzeCardPicsDir(root);
                    numUnhandledFiles = 0;
                    break;
                }

                ++numUnhandledFiles;
            } else if (file.isDirectory()) {
                identifyAndAnalyze(file);
            }
        }
        numFilesAnalyzed += numUnhandledFiles;
    }
}

From source file:eu.openanalytics.rsb.message.MultiFilesJob.java

/**
 * Add a stream to a job, exploding it if it is a Zip input. Closes the provided
 * data stream./* ww  w. j a v a  2s.  c o m*/
 * 
 * @param contentType
 * @param name
 * @param data
 * @param job
 * @throws IOException
 */
public static void addDataToJob(final String contentType, final String name, final InputStream data,
        final MultiFilesJob job) throws IOException {
    // some browsers send zip file as application/octet-stream, forcing a
    // fallback to an
    // extension check
    if ((Constants.ZIP_CONTENT_TYPES.contains(contentType) || (StringUtils
            .endsWithIgnoreCase(FilenameUtils.getExtension(name), Constants.ZIP_MIME_TYPE.getSubType())))) {
        addZipFilesToJob(data, job);
    } else {
        job.addFile(name, data);
    }
}