1 /*
2 * $Id: FileBuilder.java 2993 2011-11-24 19:51:48Z andrewinkler $
3 * ============================================================================
4 * Project gluehloch-homepage-core
5 * Copyright (c) 2004-2007 by Andre Winkler. All rights reserved.
6 * ============================================================================
7 * GNU LESSER GENERAL PUBLIC LICENSE
8 * TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
9 *
10 * This library is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU Lesser General Public
12 * License as published by the Free Software Foundation; either
13 * version 2.1 of the License, or (at your option) any later version.
14 *
15 * This library is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * Lesser General Public License for more details.
19 *
20 * You should have received a copy of the GNU Lesser General Public
21 * License along with this library; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 *
24 */
25
26 package de.awtools.homegen.directory.file;
27
28 import java.io.File;
29 import java.util.List;
30
31 import org.apache.commons.io.filefilter.SuffixFileFilter;
32
33 import de.awtools.homegen.directory.GHBuilder;
34 import de.awtools.homegen.directory.GHDirectory;
35 import de.awtools.homegen.directory.GHFile;
36 import de.awtools.homegen.directory.utils.GHFileUtils;
37
38 /**
39 * Builder Implementierung für das Einscannen eines kompletten
40 * Verzeichnisbaumes.
41 *
42 * @version $LastChangedRevision: 2993 $ $LastChangedDate: 2011-11-24 20:51:48 +0100 (Thu, 24 Nov 2011) $
43 * @author by Andre Winkler, $LastChangedBy: andrewinkler $
44 */
45 public class FileBuilder implements GHBuilder {
46
47 /** Die Dateiendungen die berücksichtigt werden sollen. */
48 private final String suffix;
49
50 /**
51 * Alle Dateien werden in diesem Fall bei der Suche berücksichtigt.
52 */
53 public FileBuilder() {
54 suffix = null;
55 }
56
57 /**
58 * @param _suffix Die Dateiendung die bei der Suche nach Dateien
59 * berücksichtigt werden soll. Z.B. '.xml' berücksichtigt nur XML
60 * Dateien.
61 */
62 public FileBuilder(final String _suffix) {
63 suffix = _suffix;
64 }
65
66 @Override
67 public GHDirectory buildRootDirectory(final File directory) {
68 return (new DirectoryImpl(directory));
69 }
70
71 @Override
72 public GHDirectory buildDirectory(final GHDirectory parentDirectory,
73 final File directory, final String dirName) {
74
75 DirectoryImpl snippetDirectory = new DirectoryImpl(parentDirectory,
76 directory, dirName, parentDirectory.getLevelFromRoot() + 1);
77
78 parentDirectory.addDirectory(snippetDirectory);
79 return snippetDirectory;
80 }
81
82 @Override
83 public GHFile buildFile(final File file, final GHDirectory directory,
84 final String name) {
85
86 return (new FileImpl(file, directory, name));
87 }
88
89 @Override
90 public List<File> findFiles(final GHDirectory parentDirectory) {
91 List<File> xhtmlSnippets = null;
92 if (suffix == null) {
93 xhtmlSnippets = GHFileUtils.findFiles(parentDirectory.getFile());
94 } else {
95 xhtmlSnippets = GHFileUtils.findFiles(parentDirectory.getFile(),
96 new SuffixFileFilter(suffix));
97 }
98 return xhtmlSnippets;
99 }
100
101 }