Example usage for org.apache.commons.io.filefilter NameFileFilter NameFileFilter

List of usage examples for org.apache.commons.io.filefilter NameFileFilter NameFileFilter

Introduction

In this page you can find the example usage for org.apache.commons.io.filefilter NameFileFilter NameFileFilter.

Prototype

public NameFileFilter(List names, IOCase caseSensitivity) 

Source Link

Document

Constructs a new name file filter for a list of names specifying case-sensitivity.

Usage

From source file:com.mirth.connect.server.launcher.MirthLauncher.java

private static void addExtensionsToClasspath(List<URL> urls, String currentVersion) throws Exception {
    FileFilter extensionFileFilter = new NameFileFilter(
            new String[] { "plugin.xml", "source.xml", "destination.xml" }, IOCase.INSENSITIVE);
    FileFilter directoryFilter = FileFilterUtils.directoryFileFilter();
    File extensionPath = new File(EXTENSIONS_DIR);

    Properties extensionProperties = new Properties();
    File extensionPropertiesFile = new File(appDataDir, EXTENSION_PROPERTIES);

    /*//from  ww w  .  j  a v  a2s.  co  m
     * If the file does not exist yet, an empty Properties object will be used, returning the
     * default of true for all extensions.
     */
    if (extensionPropertiesFile.exists()) {
        extensionProperties.load(new FileInputStream(extensionPropertiesFile));
    }

    if (extensionPath.exists() && extensionPath.isDirectory()) {
        File[] directories = extensionPath.listFiles(directoryFilter);

        for (File directory : directories) {
            File[] extensionFiles = directory.listFiles(extensionFileFilter);

            for (File extensionFile : extensionFiles) {
                try {
                    Document document = DocumentBuilderFactory.newInstance().newDocumentBuilder()
                            .parse(extensionFile);
                    Element rootElement = document.getDocumentElement();

                    boolean enabled = extensionProperties
                            .getProperty(rootElement.getElementsByTagName("name").item(0).getTextContent(),
                                    "true")
                            .equalsIgnoreCase("true");
                    boolean compatible = isExtensionCompatible(
                            rootElement.getElementsByTagName("mirthVersion").item(0).getTextContent(),
                            currentVersion);

                    // Only add libraries from extensions that are not disabled and are compatible with the current version
                    if (enabled && compatible) {
                        NodeList libraries = rootElement.getElementsByTagName("library");

                        for (int i = 0; i < libraries.getLength(); i++) {
                            Element libraryElement = (Element) libraries.item(i);
                            String type = libraryElement.getAttribute("type");

                            if (type.equalsIgnoreCase("server") || type.equalsIgnoreCase("shared")) {
                                File pathFile = new File(directory, libraryElement.getAttribute("path"));

                                if (pathFile.exists()) {
                                    logger.trace("adding library to classpath: " + pathFile.getAbsolutePath());
                                    urls.add(pathFile.toURI().toURL());
                                } else {
                                    logger.error("could not locate library: " + pathFile.getAbsolutePath());
                                }
                            }
                        }
                    }
                } catch (Exception e) {
                    logger.error("failed to parse extension metadata: " + extensionFile.getAbsolutePath(), e);
                }
            }
        }
    } else {
        logger.warn("no extensions found");
    }
}

From source file:com.quinsoft.zeidon.utils.JoeUtils.java

/**
 * Returns java.io.File for a file matching path using CASE-INSENSITIVE file
 * matching.  This makes it easier for us to run on Windows.
 *
 * @param path//  w ww . j a  v  a2  s . co m
 * @return
 */
public static File getFile(String path) {
    try {
        File file = new File(path);
        if (file.exists())
            return file;

        // Try searching for the file without regard to case.
        String parentPath = file.getParent();
        if (StringUtils.isBlank(parentPath))
            return file; // No parent path so just return.

        File dir = new File(parentPath);
        NameFileFilter filter = new NameFileFilter(file.getName(), IOCase.INSENSITIVE);
        String[] files = dir.list(filter);
        if (files == null)
            return file; // We probably didn't find a directory so just return the unknown file.

        if (files.length == 1)
            return new File(parentPath + File.separator + files[0]);

        if (files.length > 1)
            throw new ZeidonException("Found multiple matching entries for %s", path);

        // We didn't find an exact match so just return.
        return file;
    } catch (Exception e) {
        throw ZeidonException.wrapException(e).prependFilename(path);
    }
}

From source file:org.h819.commons.file.MyFileUtils.java

/**
 * Finds files within a given directory. All files found are filtered by an name filter.
 * (? FileUtils.listFiles ?)// www.j av  a 2 s . c o  m
 *
 * @param directory       the directory to search in
 * @param fileNames       file names to apply when finding files.
 * @param recursive       if true all subdirectories are searched as well
 * @param caseSensitivity how to handle case sensitivity, null means case-sensitive (IOCase.SENSITIVE ,  IOCase.INSENSITIVE)
 * @return
 */
public static Collection<File> listFiles(File directory, String[] fileNames, boolean recursive,
        IOCase caseSensitivity) {

    if (recursive)
        return FileUtils.listFiles(directory, new NameFileFilter(fileNames, caseSensitivity),
                TrueFileFilter.INSTANCE);
    else
        return FileUtils.listFiles(directory, new NameFileFilter(fileNames, caseSensitivity), null);

}

From source file:org.kalypso.utils.shape.ShapeUtilities.java

/**
 * Find all files of a shape file (i.e. .shp, .dbf and ..shx), but only if they really exist.
 * /*from  w  ww.j a v a 2  s  . com*/
 * @param shapeFile
 *          Path to the file with extension '.shp'.
 */
public static IFile[] getExistingShapeFiles(final IFile shapeFile) throws CoreException {
    final IContainer parent = shapeFile.getParent();
    final IPath basePath = shapeFile.getFullPath().removeFileExtension();

    final String name = basePath.lastSegment();
    final FileFilter filter = new NameFileFilter(new String[] { name + ShapeFile.EXTENSION_SHP,
            name + ShapeFile.EXTENSION_DBF, name + ShapeFile.EXTENSION_SHX }, IOCase.SYSTEM);
    final FileFilterVisitor visitor = new FileFilterVisitor(filter);
    parent.accept(visitor);
    return visitor.getFiles();
}

From source file:org.pentaho.platform.plugin.services.pluginmgr.FileSystemXmlPluginProvider.java

@Override
protected void processDirectory(List<IPlatformPlugin> plugins, File folder, IPentahoSession session)
        throws PlatformPluginRegistrationException {
    // see if there is a plugin.xml file
    FilenameFilter filter = new NameFileFilter("plugin.xml", IOCase.SENSITIVE); //$NON-NLS-1$
    File[] kids = folder.listFiles(filter);
    if (kids == null || kids.length == 0) {
        return;/*from w  w w.  j  a  v  a2 s.c  o  m*/
    }
    boolean hasLib = false;
    filter = new NameFileFilter("lib", IOCase.SENSITIVE); //$NON-NLS-1$
    kids = folder.listFiles(filter);
    if (kids != null && kids.length > 0) {
        hasLib = kids[0].exists() && kids[0].isDirectory();
    }
    // we have found a plugin.xml file
    // get the file from the repository
    String path = "system" + File.separatorChar + folder.getName() + File.separatorChar + "plugin.xml"; //$NON-NLS-1$ //$NON-NLS-2$
    Document doc = null;
    try {
        File f = new File(PentahoSystem.getApplicationContext().getSolutionPath(path));
        InputStream in = new FileInputStream(f);
        StringBuilder sb = new StringBuilder();
        byte[] b = new byte[2048];
        int n = in.read(b);
        while (n != -1) {
            sb.append(new String(b, 0, n));
            n = in.read(b);
        }
        String xml = sb.toString();
        doc = DocumentHelper.parseText(xml);
        if (doc != null) {
            plugins.add(createPlugin(doc, session, folder.getName(), hasLib));
        }
    } catch (Exception e) {
        throw new PlatformPluginRegistrationException(Messages.getInstance()
                .getErrorString("PluginManager.ERROR_0005_CANNOT_PROCESS_PLUGIN_XML", path), e); //$NON-NLS-1$
    }
    if (doc == null) {
        throw new PlatformPluginRegistrationException(Messages.getInstance()
                .getErrorString("PluginManager.ERROR_0005_CANNOT_PROCESS_PLUGIN_XML", path)); //$NON-NLS-1$
    }
}

From source file:org.pentaho.platform.plugin.services.pluginmgr.SystemPathXmlPluginProvider.java

protected void processDirectory(List<IPlatformPlugin> plugins, File folder, IPentahoSession session)
        throws PlatformPluginRegistrationException {
    // see if there is a plugin.xml file
    FilenameFilter filter = new NameFileFilter("plugin.xml", IOCase.SENSITIVE); //$NON-NLS-1$
    File[] kids = folder.listFiles(filter);
    if (kids == null || kids.length == 0) {
        return;/*from ww  w  .j av a 2s .c om*/
    }
    boolean hasLib = false;
    filter = new NameFileFilter("lib", IOCase.SENSITIVE); //$NON-NLS-1$
    kids = folder.listFiles(filter);
    if (kids != null && kids.length > 0) {
        hasLib = kids[0].exists() && kids[0].isDirectory();
    }
    // we have found a plugin.xml file
    // get the file from the repository
    String path = "system" + RepositoryFile.SEPARATOR + folder.getName() + RepositoryFile.SEPARATOR //$NON-NLS-1$
            + "plugin.xml"; //$NON-NLS-1$
    Document doc = null;
    try {
        try {
            org.dom4j.io.SAXReader reader = new org.dom4j.io.SAXReader();
            reader.setEntityResolver(new SolutionURIResolver());
            doc = reader.read(ActionSequenceResource.getInputStream(path, LocaleHelper.getLocale()));
        } catch (Throwable t) {
            // XML document can't be read. We'll just return a null document.
        }
        if (doc != null) {
            plugins.add(createPlugin(doc, session, folder.getName(), hasLib));
        }
    } catch (Exception e) {
        throw new PlatformPluginRegistrationException(Messages.getInstance()
                .getErrorString("PluginManager.ERROR_0005_CANNOT_PROCESS_PLUGIN_XML", path), e); //$NON-NLS-1$
    }
    if (doc == null) {
        throw new PlatformPluginRegistrationException(Messages.getInstance()
                .getErrorString("PluginManager.ERROR_0005_CANNOT_PROCESS_PLUGIN_XML", path)); //$NON-NLS-1$
    }
}