001: /*
002: * Enhydra Java Application Server Project
003: *
004: * The contents of this file are subject to the Enhydra Public License
005: * Version 1.1 (the "License"); you may not use this file except in
006: * compliance with the License. You may obtain a copy of the License on
007: * the Enhydra web site ( http://www.enhydra.org/ ).
008: *
009: * Software distributed under the License is distributed on an "AS IS"
010: * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
011: * the License for the specific terms governing rights and limitations
012: * under the License.
013: *
014: * The Initial Developer of the Enhydra Application Server is Lutris
015: * Technologies, Inc. The Enhydra Application Server and portions created
016: * by Lutris Technologies, Inc. are Copyright Lutris Technologies, Inc.
017: * All Rights Reserved.
018: *
019: * Contributor(s):
020: *
021: */
022: package org.enhydra.kelp.common.importer;
023:
024: // Toolbox imports
025: import org.enhydra.tool.common.PathHandle;
026: import org.enhydra.tool.common.ExtensionFilter;
027:
028: // Kelp imports
029: import org.enhydra.kelp.common.Constants;
030: import org.enhydra.kelp.common.node.OtterProject;
031:
032: // Standard imports
033: import java.io.FileFilter;
034: import java.io.File;
035:
036: //
037: public class ResourceFilter extends ExtensionFilter implements
038: FileFilter {
039: private OtterProject project = null;
040: private boolean resourcePath = false;
041: private String[] contentTypes = null;
042:
043: /**
044: * Creates an extension file filter without an extensions set.
045: */
046: public ResourceFilter() {
047: setDirectoryValid(false);
048: }
049:
050: public boolean isResourcePath() {
051: return resourcePath;
052: }
053:
054: public void setResourcePath(boolean b) {
055: resourcePath = b;
056: }
057:
058: /**
059: */
060: public boolean accept(File f) {
061: boolean acceptFile = super .accept(f);
062: PathHandle this Path = null;
063:
064: if (acceptFile && (getProject() == null)) {
065: acceptFile = false;
066: }
067: if (acceptFile && isResourcePath()) {
068: int index = -1;
069: StringBuffer buf = new StringBuffer();
070: buf.append('/');
071: buf.append(Constants.DIR_RESOURCES);
072: buf.append('/');
073:
074: this Path = PathHandle.createPathHandle(f);
075: index = this Path.getPath().toLowerCase().indexOf(
076: buf.toString());
077: if (index == -1) {
078: acceptFile = false;
079: }
080: }
081: if (acceptFile) {
082: PathHandle skipPath = null;
083: StringBuffer buf = new StringBuffer();
084:
085: this Path = PathHandle.createPathHandle(f);
086: buf.append(getProject().getRootPath());
087: buf.append(File.separator);
088: buf.append(getProject().getProjectRootName());
089: buf.append('.');
090: buf.append(Constants.TYPE_HTML);
091: skipPath = PathHandle.createPathHandle(buf.toString());
092: if (this Path.equals(skipPath)) {
093: acceptFile = false;
094: }
095: }
096: return acceptFile;
097: }
098:
099: public OtterProject getProject() {
100: return project;
101: }
102:
103: public void setProject(OtterProject p) {
104: project = p;
105: if (contentTypes == null) {
106: contentTypes = project.getContentTypes();
107: for (int i = 0; i < contentTypes.length; i++) {
108: addExtension(contentTypes[i]);
109: }
110: }
111: }
112:
113: }
|