KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > enhydra > tool > archive > WarPlan


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

24 package org.enhydra.tool.archive;
25
26 // Toolbox Imports
27
import org.enhydra.tool.common.FileUtil;
28 import org.enhydra.tool.common.PathHandle;
29 import org.enhydra.tool.common.ResUtil;
30
31 // Standard imports
32
import java.io.File JavaDoc;
33 import java.io.FileFilter JavaDoc;
34 import java.util.Arrays JavaDoc;
35 import java.util.ResourceBundle JavaDoc;
36
37 //
38
public class WarPlan extends JarPlan {
39
40     //
41
private String JavaDoc contentRoot = null;
42     private String JavaDoc[] contentFiles = null;
43
44     public WarPlan() {
45         super();
46         Descriptor[] initDD = new Descriptor[2];
47
48         initDD[0] = new Descriptor(true, Descriptor.WEB);
49         initDD[1] = new Descriptor(false, Descriptor.ENHYDRA_WEB);
50         setDescriptors(initDD);
51
52     }
53
54     public String JavaDoc getContentRoot() {
55         return contentRoot;
56     }
57
58     public String JavaDoc[] getContentFiles() {
59         return contentFiles;
60     }
61
62     public void setContentFiles(String JavaDoc[] contPaths) {
63         if (isEqual(getContentFileArray(), contPaths)) {
64             contentFiles = null;
65         } else {
66             contentFiles = contPaths;
67         }
68     }
69
70     public void setContentRoot(String JavaDoc in) throws ArchiveException {
71         if (in == null) {
72             throw new ArchiveException(res.getString("Content_directory_is"));
73         } else {
74             PathHandle path = PathHandle.createPathHandle(in);
75
76             if (isValidate()) {
77                 if (!path.isDirectory()) {
78                     throw new ArchiveException(ResUtil.format(res.getString("Content_directory_not"),
79                                                               path));
80                 }
81             }
82             contentRoot = path.getPath();
83         }
84     }
85
86     public File JavaDoc[] getContentFileArray() {
87         File JavaDoc[] files = new File JavaDoc[0];
88
89         fileList.clear();
90         setFillFilter(new ContentFilter());
91         if (getContentRoot() == null) {
92
93             // done
94
} else if (contentFiles == null) {
95             fillFileList(new File JavaDoc(getContentRoot()));
96         } else {
97             for (int i = 0; i < contentFiles.length; i++) {
98                 File JavaDoc cursor = new File JavaDoc(contentFiles[i]);
99
100                 if (getFillFilter().accept(cursor)) {
101                     fileList.add(cursor);
102                 }
103             }
104         }
105         fileList.trimToSize();
106         files = new File JavaDoc[fileList.size()];
107         files = (File JavaDoc[]) fileList.toArray(files);
108         fileList.clear();
109         return files;
110     }
111
112     public boolean equals(Object JavaDoc 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 && getContentRoot() == null) {}
122             else if (plan.getContentRoot().equals(getContentRoot())) {}
123             else {
124                 equal = false;
125             }
126         }
127         if (equal) {
128             if (!Arrays.equals(plan.getContentFiles(), getContentFiles())) {
129                 equal = false;
130             }
131         }
132         return equal;
133     }
134
135     //
136
private class ContentFilter implements FileFilter JavaDoc {
137         private String JavaDoc[] ddPaths = new String JavaDoc[0];
138         private PathHandle rootPath = null;
139
140         public ContentFilter() {
141             super();
142             ddPaths = new String JavaDoc[getDescriptors().length];
143             rootPath = PathHandle.createPathHandle(getContentRoot());
144         }
145
146         public boolean accept(File JavaDoc file) {
147             boolean include = false;
148             PathHandle filePath = null;
149
150             for (int i = 0; i < ddPaths.length; i++) {
151                 ddPaths[i] = getDescriptors()[i].getPath();
152             }
153             filePath = PathHandle.createPathHandle(file);
154             if (file.isDirectory()) {
155                 include = true;
156             } else if (rootPath.parentOf(filePath)) {
157                 include = true;
158                 for (int i = 0; i < ddPaths.length; i++) {
159                     if (filePath.equals(ddPaths[i])) {
160                         include = false;
161                         break;
162                     }
163                 }
164             }
165             return include;
166         }
167
168     }
169 }
170
Popular Tags