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: * Paul Mahar
021: *
022: */
023: package org.enhydra.tool.archive;
024:
025: // Toolbox Imports
026: import org.enhydra.tool.common.FileUtil;
027: import org.enhydra.tool.common.PathHandle;
028: import org.enhydra.tool.common.ResUtil;
029:
030: // Standard imports
031: import java.io.File;
032: import java.io.FileFilter;
033: import java.util.Arrays;
034: import java.util.ResourceBundle;
035:
036: //
037: public class WarPlan extends JarPlan {
038:
039: //
040: private String contentRoot = null;
041: private String[] contentFiles = null;
042:
043: public WarPlan() {
044: super ();
045: Descriptor[] initDD = new Descriptor[2];
046:
047: initDD[0] = new Descriptor(true, Descriptor.WEB);
048: initDD[1] = new Descriptor(false, Descriptor.ENHYDRA_WEB);
049: setDescriptors(initDD);
050:
051: }
052:
053: public String getContentRoot() {
054: return contentRoot;
055: }
056:
057: public String[] getContentFiles() {
058: return contentFiles;
059: }
060:
061: public void setContentFiles(String[] contPaths) {
062: if (isEqual(getContentFileArray(), contPaths)) {
063: contentFiles = null;
064: } else {
065: contentFiles = contPaths;
066: }
067: }
068:
069: public void setContentRoot(String in) throws ArchiveException {
070: if (in == null) {
071: throw new ArchiveException(res
072: .getString("Content_directory_is"));
073: } else {
074: PathHandle path = PathHandle.createPathHandle(in);
075:
076: if (isValidate()) {
077: if (!path.isDirectory()) {
078: throw new ArchiveException(ResUtil.format(res
079: .getString("Content_directory_not"), path));
080: }
081: }
082: contentRoot = path.getPath();
083: }
084: }
085:
086: public File[] getContentFileArray() {
087: File[] files = new File[0];
088:
089: fileList.clear();
090: setFillFilter(new ContentFilter());
091: if (getContentRoot() == null) {
092:
093: // done
094: } else if (contentFiles == null) {
095: fillFileList(new File(getContentRoot()));
096: } else {
097: for (int i = 0; i < contentFiles.length; i++) {
098: File cursor = new File(contentFiles[i]);
099:
100: if (getFillFilter().accept(cursor)) {
101: fileList.add(cursor);
102: }
103: }
104: }
105: fileList.trimToSize();
106: files = new File[fileList.size()];
107: files = (File[]) fileList.toArray(files);
108: fileList.clear();
109: return files;
110: }
111:
112: public boolean equals(Object comp) {
113: WarPlan plan = null;
114: boolean equal = false;
115:
116: if (comp instanceof WarPlan) {
117: plan = (WarPlan) comp;
118: equal = super .equals(comp);
119: }
120: if (equal) {
121: if (plan.getContentRoot() == null
122: && getContentRoot() == null) {
123: } else if (plan.getContentRoot().equals(getContentRoot())) {
124: } else {
125: equal = false;
126: }
127: }
128: if (equal) {
129: if (!Arrays.equals(plan.getContentFiles(),
130: getContentFiles())) {
131: equal = false;
132: }
133: }
134: return equal;
135: }
136:
137: //
138: private class ContentFilter implements FileFilter {
139: private String[] ddPaths = new String[0];
140: private PathHandle rootPath = null;
141:
142: public ContentFilter() {
143: super ();
144: ddPaths = new String[getDescriptors().length];
145: rootPath = PathHandle.createPathHandle(getContentRoot());
146: }
147:
148: public boolean accept(File file) {
149: boolean include = false;
150: PathHandle filePath = null;
151:
152: for (int i = 0; i < ddPaths.length; i++) {
153: ddPaths[i] = getDescriptors()[i].getPath();
154: }
155: filePath = PathHandle.createPathHandle(file);
156: if (file.isDirectory()) {
157: include = true;
158: } else if (rootPath.parentOf(filePath)) {
159: include = true;
160: for (int i = 0; i < ddPaths.length; i++) {
161: if (filePath.equals(ddPaths[i])) {
162: include = false;
163: break;
164: }
165: }
166: }
167: return include;
168: }
169:
170: }
171: }
|