KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > enhydra > kelp > common > importer > ResourceFilter


1 /*
2  * Enhydra Java Application Server Project
3  *
4  * The contents of this file are subject to the Enhydra Public License
5  * Version 1.1 (the "License"); you may not use this file except in
6  * compliance with the License. You may obtain a copy of the License on
7  * the Enhydra web site ( http://www.enhydra.org/ ).
8  *
9  * Software distributed under the License is distributed on an "AS IS"
10  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
11  * the License for the specific terms governing rights and limitations
12  * under the License.
13  *
14  * The Initial Developer of the Enhydra Application Server is Lutris
15  * Technologies, Inc. The Enhydra Application Server and portions created
16  * by Lutris Technologies, Inc. are Copyright Lutris Technologies, Inc.
17  * All Rights Reserved.
18  *
19  * Contributor(s):
20  *
21  */

22 package org.enhydra.kelp.common.importer;
23
24 // Toolbox imports
25
import org.enhydra.tool.common.PathHandle;
26 import org.enhydra.tool.common.ExtensionFilter;
27
28 // Kelp imports
29
import org.enhydra.kelp.common.Constants;
30 import org.enhydra.kelp.common.node.OtterProject;
31
32 // Standard imports
33
import java.io.FileFilter JavaDoc;
34 import java.io.File JavaDoc;
35 //
36
public class ResourceFilter extends ExtensionFilter implements FileFilter JavaDoc {
37     private OtterProject project = null;
38     private boolean resourcePath = false;
39     private String JavaDoc[] contentTypes = null;
40
41     /**
42      * Creates an extension file filter without an extensions set.
43      */

44     public ResourceFilter() {
45         setDirectoryValid(false);
46     }
47
48     public boolean isResourcePath() {
49         return resourcePath;
50     }
51
52     public void setResourcePath(boolean b) {
53         resourcePath = b;
54     }
55
56     /**
57      */

58     public boolean accept(File JavaDoc f) {
59         boolean acceptFile = super.accept(f);
60         PathHandle thisPath = null;
61
62         if (acceptFile && (getProject() == null)) {
63             acceptFile = false;
64         }
65         if (acceptFile && isResourcePath()) {
66             int index = -1;
67             StringBuffer JavaDoc buf = new StringBuffer JavaDoc();
68             buf.append('/');
69             buf.append(Constants.DIR_RESOURCES);
70             buf.append('/');
71
72             thisPath = PathHandle.createPathHandle(f);
73             index = thisPath.getPath().toLowerCase().indexOf(buf.toString());
74             if (index == -1) {
75                 acceptFile = false;
76             }
77         }
78         if (acceptFile) {
79             PathHandle skipPath = null;
80             StringBuffer JavaDoc buf = new StringBuffer JavaDoc();
81
82             thisPath = PathHandle.createPathHandle(f);
83             buf.append(getProject().getRootPath());
84             buf.append(File.separator);
85             buf.append(getProject().getProjectRootName());
86             buf.append('.');
87             buf.append(Constants.TYPE_HTML);
88             skipPath = PathHandle.createPathHandle(buf.toString());
89             if (thisPath.equals(skipPath)) {
90                 acceptFile = false;
91             }
92         }
93         return acceptFile;
94     }
95
96     public OtterProject getProject() {
97         return project;
98     }
99
100     public void setProject(OtterProject p) {
101         project = p;
102         if (contentTypes == null) {
103             contentTypes = project.getContentTypes();
104             for (int i = 0; i < contentTypes.length; i++) {
105                 addExtension(contentTypes[i]);
106             }
107         }
108     }
109
110 }
111
Popular Tags