Search in sources :

Example 6 with NameFileFilter

use of org.apache.commons.io.filefilter.NameFileFilter in project MtgDesktopCompanion by nicho92.

the class FileDAO method listCollectionFromCards.

@Override
public List<MagicCollection> listCollectionFromCards(MagicCard mc) throws SQLException {
    String id = IDGenerator.generate(mc);
    File f = new File(directory, CARDSDIR);
    List<MagicCollection> ret = new ArrayList<>();
    Collection<File> res = FileUtils.listFiles(f, new NameFileFilter(id), TrueFileFilter.INSTANCE);
    for (File result : res) ret.add(new MagicCollection(result.getParentFile().getParentFile().getName()));
    return ret;
}
Also used : NameFileFilter(org.apache.commons.io.filefilter.NameFileFilter) ArrayList(java.util.ArrayList) File(java.io.File) MagicCollection(org.magic.api.beans.MagicCollection)

Example 7 with NameFileFilter

use of org.apache.commons.io.filefilter.NameFileFilter in project pentaho-platform by pentaho.

the class FileSystemXmlPluginProvider method processDirectory.

@Override
protected void processDirectory(List<IPlatformPlugin> plugins, File folder, IPentahoSession session) throws PlatformPluginRegistrationException {
    // see if there is a plugin.xml file
    // $NON-NLS-1$
    FilenameFilter filter = new NameFileFilter("plugin.xml", IOCase.SENSITIVE);
    File[] kids = folder.listFiles(filter);
    if (kids == null || kids.length == 0) {
        return;
    }
    boolean hasLib = false;
    // $NON-NLS-1$
    filter = new NameFileFilter("lib", IOCase.SENSITIVE);
    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
    // $NON-NLS-1$ //$NON-NLS-2$
    String path = "system" + File.separatorChar + folder.getName() + File.separatorChar + "plugin.xml";
    Document doc;
    try {
        File f = new File(PentahoSystem.getApplicationContext().getSolutionPath(path));
        InputStream in = new FileInputStream(f);
        SAXReader reader = XMLParserFactoryProducer.getSAXReader(null);
        doc = reader.read(in);
        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), // $NON-NLS-1$
        e);
    }
    if (doc == null) {
        throw new PlatformPluginRegistrationException(Messages.getInstance().getErrorString("PluginManager.ERROR_0005_CANNOT_PROCESS_PLUGIN_XML", // $NON-NLS-1$
        path));
    }
}
Also used : NameFileFilter(org.apache.commons.io.filefilter.NameFileFilter) FilenameFilter(java.io.FilenameFilter) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) SAXReader(org.dom4j.io.SAXReader) Document(org.dom4j.Document) File(java.io.File) PlatformPluginRegistrationException(org.pentaho.platform.api.engine.PlatformPluginRegistrationException) FileInputStream(java.io.FileInputStream) PlatformPluginRegistrationException(org.pentaho.platform.api.engine.PlatformPluginRegistrationException)

Aggregations

File (java.io.File)7 NameFileFilter (org.apache.commons.io.filefilter.NameFileFilter)7 FilenameFilter (java.io.FilenameFilter)2 ArrayList (java.util.ArrayList)2 NotFileFilter (org.apache.commons.io.filefilter.NotFileFilter)2 Document (org.dom4j.Document)2 PlatformPluginRegistrationException (org.pentaho.platform.api.engine.PlatformPluginRegistrationException)2 IllegalArtifactLocationException (com.thoughtworks.go.domain.exception.IllegalArtifactLocationException)1 FileInputStream (java.io.FileInputStream)1 InputStream (java.io.InputStream)1 HashSet (java.util.HashSet)1 AndFileFilter (org.apache.commons.io.filefilter.AndFileFilter)1 IOFileFilter (org.apache.commons.io.filefilter.IOFileFilter)1 WildcardFileFilter (org.apache.commons.io.filefilter.WildcardFileFilter)1 MatchPatterns (org.codehaus.plexus.util.MatchPatterns)1 SAXReader (org.dom4j.io.SAXReader)1 Test (org.junit.Test)1 MagicCollection (org.magic.api.beans.MagicCollection)1 RepositoryFile (org.pentaho.platform.api.repository2.unified.RepositoryFile)1 SolutionURIResolver (org.pentaho.platform.engine.services.SolutionURIResolver)1