Example usage for org.apache.commons.io FilenameUtils wildcardMatch

List of usage examples for org.apache.commons.io FilenameUtils wildcardMatch

Introduction

In this page you can find the example usage for org.apache.commons.io FilenameUtils wildcardMatch.

Prototype

public static boolean wildcardMatch(String filename, String wildcardMatcher) 

Source Link

Document

Checks a filename to see if it matches the specified wildcard matcher, always testing case-sensitive.

Usage

From source file:com.github.aliteralmind.codelet.TagletOfTypeProcessor.java

/**
   <p>If the class or file is not allowed to use the customizer, crash. Otherwise, do nothing.</p>
        //from  w w  w  . j  ava  2  s  .co m
 * @exception  IllegalStateException  If
   <br/> &nbsp; &nbsp; <code>{@link org.apache.commons.io.FilenameUtils}.{@link org.apache.commons.io.FilenameUtils#wildcardMatch(String, String) wildcardMatch}({@link #getClassOrFilePortion() getClassOrFilePortion}(), instructions.{@link CustomizationInstructions#getClassNameOrFilePathRestricter() getClassNameOrFilePathRestricter})</code>
   <br/>is {@code false}.
 */
protected void crashIfClassOrFileCannotUseCustomizer(CustomizationInstructions<T> instructions) {
    if (isDebugOn(instance, "zzSourceCodeProcessor.progress")) {
        debugln("Verifying class/file name (\"" + getClassOrFilePortion()
                + "\") against instructions.getClassNameOrFilePathRestricter() (\""
                + instructions.getClassNameOrFilePathRestricter() + "\")");
    }
    if (!FilenameUtils.wildcardMatch(getClassOrFilePortion(),
            instructions.getClassNameOrFilePathRestricter())) {
        throw new IllegalStateException("getClassOrFilePortion()=\"" + getClassOrFilePortion()
                + "\", instructions.getClassNameOrFilePathRestricter()=\""
                + instructions.getClassNameOrFilePathRestricter() + "\"");
    }
}

From source file:com.edgenius.wiki.render.handler.GalleryMacroHandler.java

/**
 * @param string/*from   w  w w .  j a  v  a 2 s  .  c  om*/
 * @return
 */
private List<FileNode> getImageList(String filterStr, String[] visibles) {
    List<String> filter = new ArrayList<String>();
    if (!StringUtils.isEmpty(filterStr)) {
        String[] fs = filterStr.split(",");
        for (String str : fs) {
            if (!StringUtils.isEmpty(str))
                filter.add(str.trim());
        }
    } else {
        //default filter
        for (String str : IMAGE_FILTERS) {
            filter.add(str);
        }
    }

    List<FileNode> matched = new ArrayList<FileNode>();
    for (FileNode node : atts) {
        if (visibles != null) {
            if (!StringUtil.containsIgnoreCase(visibles, node.getNodeUuid()))
                continue;
        } else {
            //normal render, for example, page view. Then only view non-draft
            if (node.getStatus() > 0)
                continue;
        }

        String name = node.getFilename();
        for (String flt : filter) {
            if (FilenameUtils.wildcardMatch(name.toLowerCase(), flt.toLowerCase())) {
                matched.add(node);
                break;
            }
        }
    }
    return matched;
}

From source file:com.edgenius.wiki.render.handler.RepoHandler.java

/**
 * @param string/*from w  w  w  . j  ava  2s .  c  o  m*/
 * @return
 */
private List<FileNode> getFileList(String filterStr, String[] visibles) {
    List<String> filter = new ArrayList<String>();
    if (!StringUtils.isEmpty(filterStr)) {
        String[] fs = filterStr.split(",");
        for (String str : fs) {
            if (!StringUtils.isEmpty(str))
                filter.add(str.trim());
        }
    }
    List<FileNode> matched = new ArrayList<FileNode>();
    for (FileNode node : atts) {
        //as visible list only contain current page's attachment, so skip this step
        if (visibles != null && visibles.length > 0) {
            if (node.getStatus() > 0 && StringUtil.equalsIgnoreCase(node.getIdentifier(), pageUuid)
                    && !StringUtil.containsIgnoreCase(visibles, node.getNodeUuid()))
                continue;
        } else {
            //normal render, for example, page view. Then only view non-draft
            if (node.getStatus() > 0)
                continue;
        }

        String name = node.getFilename();
        if (filter.size() > 0) {
            for (String flt : filter) {
                if (FilenameUtils.wildcardMatch(name.toLowerCase(), flt.toLowerCase())) {
                    matched.add(node);
                    break;
                }
            }
        } else {
            //no filter, then put all attachments
            matched.add(node);
        }
    }
    return matched;
}

From source file:de.jlo.talendcomp.jasperrepo.RepositoryClient.java

private void list(String folderUri, String filterExpr, boolean recursive, List<ResourceDescriptor> list)
        throws Exception {
    ResourceDescriptor rd = createFolderResourceDescriptor(folderUri, null);
    currentUri = rd.getUriString();/*from   w w  w . ja  va 2s.  c  o  m*/
    boolean dofilter = filterExpr != null && filterExpr.isEmpty() == false;
    final List<ResourceDescriptor> allResults = client.list(rd);
    for (ResourceDescriptor r : allResults) {
        if (isContentResource(r)) {
            if (dofilter == false || FilenameUtils.wildcardMatch(getResourceId(r.getUriString()), filterExpr)) {
                list.add(r);
            }
        }
    }
    for (ResourceDescriptor r : allResults) {
        if (recursive && isFolder(r)) {
            list(folderUri + "/" + r.getName(), filterExpr, recursive, list);
        }
    }
}

From source file:com.htmlhifive.tools.wizard.download.DownloadModule.java

/**
 * ZIP?./*from ww  w.ja v a2 s  .c  om*/
 * 
 * @param libraryNode 
 * @param perLibWork libWork
 * @param folder 
 * @param monitor 
 * @param logger .
 * @return ???????.
 * @throws IOException IO
 * @throws CoreException 
 */
private boolean downloadZip(LibraryNode libraryNode, int perLibWork, IContainer folder,
        IProgressMonitor monitor, ResultStatus logger) throws IOException, CoreException {

    boolean result = true;
    boolean addStatus = false;
    ZipFile cachedZipFile = null;
    String cachedSite = null;
    Library library = libraryNode.getValue();

    if (!library.getSite().isEmpty()) {
        int perSiteWork = Math.max(1, perLibWork / library.getSite().size());

        for (Site site : library.getSite()) {
            String siteUrl = site.getUrl();
            String path = H5IOUtils.getURLPath(siteUrl);
            if (path == null) {
                logger.log(Messages.SE0082, siteUrl);
                continue;
            }

            boolean setWorked = false;

            IContainer savedFolder = folder;
            if (site.getExtractPath() != null) {
                savedFolder = savedFolder.getFolder(Path.fromOSString(site.getExtractPath()));
            }

            // ?.
            IFile iFile = null;
            if (path.endsWith(".zip") || path.endsWith(".jar") || site.getFilePattern() != null) {

                // Zip

                // ?????????.
                if (!siteUrl.equals(cachedSite)) {
                    cachedZipFile = download(monitor, perSiteWork, logger, null, siteUrl);
                    setWorked = true;
                    if (!lastDownloadStatus || cachedZipFile == null) {
                        libraryNode.setInError(true);
                        result = false;
                        break;
                    }
                    cachedSite = siteUrl;
                }

                final ZipFile zipFile = cachedZipFile;

                // int perZipWork = Math.max(1, perSiteWork / zipFile.size());

                // Zip.
                for (Enumeration<? extends ZipEntry> e = zipFile.entries(); e.hasMoreElements();) {
                    final ZipEntry zipEntry = e.nextElement();

                    if (site.getFilePattern() != null
                            && !FilenameUtils.wildcardMatch(zipEntry.getName(), site.getFilePattern())) {
                        // ???.
                        continue;
                    }

                    IContainer savedFolder2 = savedFolder;
                    String wildCardStr = StringUtils.defaultString(site.getFilePattern());
                    if (wildCardStr.contains("*") && wildCardStr.contains("/")) {
                        // ??????.
                        wildCardStr = StringUtils.substringBeforeLast(site.getFilePattern(), "/");
                    }

                    String entryName = zipEntry.getName();
                    if (entryName.startsWith(wildCardStr + "/")) {
                        entryName = entryName.substring(wildCardStr.length() + 1);
                    }

                    if (zipEntry.isDirectory()) {
                        // zip?????.
                        if (StringUtils.isNotEmpty(entryName)) {
                            // ?.
                            savedFolder2 = savedFolder2.getFolder(Path.fromOSString(entryName));
                            if (libraryNode.isAddable() && !savedFolder2.exists()) {
                                logger.log(Messages.SE0091, savedFolder2.getFullPath());
                                H5IOUtils.createParentFolder(savedFolder2, null);
                                logger.log(Messages.SE0092, savedFolder2.getFullPath());
                            } else if (libraryNode.getState() == LibraryState.REMOVE && savedFolder2.exists()) {
                                // .
                                logger.log(Messages.SE0095, savedFolder2.getFullPath());
                                H5IOUtils.createParentFolder(savedFolder2, null);
                                logger.log(Messages.SE0096, savedFolder2.getFullPath());
                            }
                        }
                    } else {
                        // zip.

                        // ???.
                        if (site.getReplaceFileName() != null) {
                            iFile = savedFolder2.getFile(Path.fromOSString(site.getReplaceFileName()));
                        } else {
                            iFile = savedFolder2.getFile(Path.fromOSString(entryName));
                        }

                        // ?.
                        updateFile(monitor, 0, logger, iFile, new ZipFileContentsHandler(zipFile, zipEntry));
                        addStatus = true;
                    }
                }
                if (savedFolder.exists() && savedFolder.members().length == 0) {
                    // ????.
                    savedFolder.delete(true, monitor);
                }
            } else {
                // ???.
                if (site.getReplaceFileName() != null) {
                    iFile = savedFolder.getFile(Path.fromOSString(site.getReplaceFileName()));
                } else {
                    // .
                    iFile = savedFolder.getFile(Path.fromOSString(StringUtils.substringAfterLast(path, "/")));
                }

                // .
                download(monitor, perSiteWork, logger, iFile, siteUrl);
                setWorked = true;
                if (!lastDownloadStatus) {

                    // SE0101=ERROR,({0})??????URL={1}, File={2}
                    logger.log(Messages.SE0101,
                            iFile != null ? iFile.getFullPath().toString()
                                    : StringUtils.defaultString(site.getFilePattern()),
                            site.getUrl(), site.getFilePattern());
                    libraryNode.setInError(true);
                } else {
                    addStatus = true;
                }
            }

            // ?????.

            // .
            if (!addStatus) {
                // SE0099=ERROR,???????URL={1}, File={2}
                logger.log(Messages.SE0099, site.getUrl(), iFile != null ? iFile.getFullPath().toString()
                        : StringUtils.defaultString(site.getFilePattern()));
                libraryNode.setInError(true);
                result = false;
            }

            // folder.refreshLocal(IResource.DEPTH_ZERO, null);
            // // SE0102=INFO,????
            // logger.log(Messages.SE0102);
            // logger.log(Messages.SE0068, iFile.getFullPath());

            if (!setWorked) {
                monitor.worked(perSiteWork);
            }
        }
    } else {
        monitor.worked(perLibWork);
    }

    return result;
}

From source file:ffx.ui.ModelingPanel.java

/**
 * <p>//from w w w  .  j a  v  a  2 s. c  o  m
 * deleteLogs</p>
 */
public void deleteLogs() {
    if (activeSystem != null) {
        File file = activeSystem.getFile();
        String name = file.getName();
        String dir = file.getParent();
        int i = JOptionPane.showConfirmDialog(this, "Delete all logs for " + name + " from " + dir + " ?",
                "Delete Logs", JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE);
        if (i == JOptionPane.YES_OPTION) {
            try {
                File files[] = activeSystem.getFile().getParentFile().listFiles();
                for (File f : files) {
                    name = FilenameUtils.getBaseName(f.getAbsolutePath());
                    if (FilenameUtils.wildcardMatch(f.getName(), name + ".log*")) {
                        f.delete();
                    }
                }
            } catch (Exception e) {
            }
            activeSystem.setLogFile(null);
            loadLogSettings();
        }
    }
}

From source file:me.ryanhamshire.griefprevention.GriefPreventionPlugin.java

public static boolean isSourceIdBlacklisted(String flag, Object source, WorldProperties worldProperties) {
    final List<String> flagList = GPBlacklists.blacklistMap.get(flag);
    final boolean checkFlag = flagList != null && !flagList.isEmpty();
    if (!checkFlag && !GPBlacklists.GLOBAL_SOURCE) {
        return false;
    }/*w  w w. j  a  va2  s.c  om*/

    final GriefPreventionConfig<?> activeConfig = GriefPreventionPlugin.getActiveConfig(worldProperties);
    final String id = GPPermissionHandler.getPermissionIdentifier(source);
    final String idNoMeta = GPPermissionHandler.getIdentifierWithoutMeta(id);

    // Check global
    if (GPBlacklists.GLOBAL_SOURCE) {
        final BlacklistCategory blacklistCategory = activeConfig.getConfig().blacklist;
        final List<String> globalSourceBlacklist = blacklistCategory.getGlobalSourceBlacklist();
        if (globalSourceBlacklist == null) {
            return false;
        }
        for (String str : globalSourceBlacklist) {
            if (FilenameUtils.wildcardMatch(id, str)) {
                return true;
            }
            if (FilenameUtils.wildcardMatch(idNoMeta, str)) {
                return true;
            }
        }
    }
    // Check flag
    if (checkFlag) {
        for (String str : flagList) {
            if (FilenameUtils.wildcardMatch(id, str)) {
                return true;
            }
            if (FilenameUtils.wildcardMatch(idNoMeta, str)) {
                return true;
            }
        }
    }

    return false;
}

From source file:me.ryanhamshire.griefprevention.GriefPreventionPlugin.java

public static boolean isTargetIdBlacklisted(String flag, Object target, WorldProperties worldProperties) {
    final List<String> flagList = GPBlacklists.blacklistMap.get(flag);
    final boolean checkFlag = flagList != null && !flagList.isEmpty();
    if (!checkFlag && !GPBlacklists.GLOBAL_TARGET) {
        return false;
    }/*ww  w  .jav a  2 s .  c  om*/

    final GriefPreventionConfig<?> activeConfig = GriefPreventionPlugin.getActiveConfig(worldProperties);
    final String id = GPPermissionHandler.getPermissionIdentifier(target);
    final String idNoMeta = GPPermissionHandler.getIdentifierWithoutMeta(id);

    // Check global
    if (GPBlacklists.GLOBAL_TARGET) {
        final BlacklistCategory blacklistCategory = activeConfig.getConfig().blacklist;
        final List<String> globalTargetBlacklist = blacklistCategory.getGlobalTargetBlacklist();
        if (globalTargetBlacklist == null) {
            return false;
        }
        for (String str : globalTargetBlacklist) {
            if (FilenameUtils.wildcardMatch(id, str)) {
                return true;
            }
            if (FilenameUtils.wildcardMatch(idNoMeta, str)) {
                return true;
            }
        }
    }
    // Check flag
    if (checkFlag) {
        for (String str : flagList) {
            if (FilenameUtils.wildcardMatch(id, str)) {
                return true;
            }
            if (FilenameUtils.wildcardMatch(idNoMeta, str)) {
                return true;
            }
        }
    }

    return false;
}

From source file:me.ryanhamshire.griefprevention.GriefPreventionPlugin.java

public static boolean containsProfanity(String message) {
    final String[] words = message.split("\\s+");
    for (String banned : DataStore.bannedWords) {
        for (String word : words) {
            if (FilenameUtils.wildcardMatch(word, banned)) {
                return true;
            }//  w w  w  . j av  a 2s.  c  o  m
        }
    }

    return false;
}

From source file:ome.services.scripts.ScriptFileType.java

/**
 * Sets the mimetype on the given {@link OriginalFile}
 * if the name field matches the {@link #pattern wildcard pattern}
 * for this instance.//from w  ww.ja v  a2 s.  c o  m
 */
public boolean setMimetype(OriginalFile ofile) {
    if (FilenameUtils.wildcardMatch(ofile.getName(), pattern)) {
        ofile.setMimetype(mimetype);
        return true;
    }
    return false;
}