BrightSide Workbench Full Report + Source Code
Elephant/elephant/src/main/java/org/turro/elephant/impl/repository/Repository.java
Go to the documentation of this file.
1 /*
2  * TurrĂ³ i Cutiller Foundation. License notice.
3  * Copyright (C) 2013 Lluis TurrĂ³ Cutiller <http://www.turro.org/>
4  *
5  * This program is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU Affero General Public License as published by
7  * the Free Software Foundation, either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU Affero General Public License for more details.
14  *
15  * You should have received a copy of the GNU Affero General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  */
18 
19 package org.turro.elephant.impl.repository;
20 
21 import java.io.File;
22 import java.util.Set;
23 import org.turro.elephant.context.ElephantContext;
24 import org.turro.elephant.context.IConstructor;
25 
30 public class Repository {
31 
32  protected final IConstructor constructor;
33  protected final String path;
34 
36  this.constructor = constructor;
37  this.path = path;
38  }
39 
40  public boolean hasContent() {
41  File dir = getRoot(null).getFile();
42  return dir.isDirectory() && dir.list().length > 0;
43  }
44 
45  public File[] getFiles(String pattern) {
46  return getFiles(null, pattern);
47  }
48 
49  public File[] getFiles(String root, String pattern) {
50  return getRoot(root).getFiles(pattern);
51  }
52 
53  public File[] getFolders(String pattern) {
54  return getFolders(null, pattern);
55  }
56 
57  public File[] getFolders(String root, String pattern) {
58  return getRoot(null).getFolders(pattern);
59  }
60 
61  public Set<RepositoryFile> getRepositoryFiles(String pattern) {
62  return getRepositoryFiles(null, pattern);
63  }
64 
65  public Set<RepositoryFile> getRepositoryFiles(String root, String pattern) {
66  return getRoot(root).getRepositoryFiles(pattern);
67  }
68 
69  public Set<RepositoryFile> getRepositoryFolders(String pattern) {
70  return getRepositoryFolders(null, pattern);
71  }
72 
73  public Set<RepositoryFile> getRepositoryFolders(String root, String pattern) {
74  return getRoot(root).getRepositoryFolders(pattern);
75  }
76 
77  public RepositoryFile getRoot(String root) {
78  File repository = new File(ElephantContext.getRealPath(
79  path +
80  (root == null ? "" : root)));
81  return new RepositoryFile(repository, constructor);
82  }
83 
84 }
Set< RepositoryFile > getRepositoryFiles(String pattern)
Set< RepositoryFile > getRepositoryFolders(String pattern)