KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > enhydra > tool > archive > wizard > WarType


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.wizard;
25
26 //
27
// ToolBox imports
28
//
29
import org.enhydra.tool.ToolBoxInfo;
30 import org.enhydra.tool.archive.WarPlan;
31 import org.enhydra.tool.archive.ArchiveException;
32 import org.enhydra.tool.archive.ArchiveTool;
33 import org.enhydra.tool.common.PathHandle;
34 import org.enhydra.tool.common.SwingUtil;
35
36 //
37
// Standard imports
38
//
39
import javax.swing.*;
40 import javax.swing.border.*;
41 import java.awt.*;
42 import java.awt.event.ActionEvent JavaDoc;
43 import java.awt.event.ActionListener JavaDoc;
44 import java.io.File JavaDoc;
45 import java.util.ArrayList JavaDoc;
46 import java.util.ResourceBundle JavaDoc;
47 import java.util.jar.Manifest JavaDoc;
48 import java.util.jar.JarInputStream JavaDoc;
49
50 //
51
public class WarType extends ArchiveType {
52     public final static String JavaDoc EXT = "war";
53
54     //
55
protected String JavaDoc getClassIncludeRoot() {
56         return "WEB-INF/CLASSES/";
57     }
58
59     protected final String JavaDoc getSelectionName() {
60         return "Web Application";
61     }
62
63     protected final String JavaDoc getExtension() {
64         return EXT;
65     }
66
67     protected final String JavaDoc getType() {
68         return getExtension();
69     }
70
71     protected final String JavaDoc getDescription() {
72         StringBuffer JavaDoc buf = new StringBuffer JavaDoc();
73
74         buf.append("Create a web application archive for ");
75         buf.append("deploying serlvet classes, libraries, ");
76         buf.append("Java Server Pages and static content.");
77         return buf.toString();
78     }
79
80     protected void initPanels() throws ArchiveException {
81         WarFilePanel filePanel = new WarFilePanel();
82         ContentPanel contentPanel = new ContentPanel();
83         ClassesPanel classesPanel = new ClassesPanel();
84         LibraryPanel libPanel = new LibraryPanel();
85         ArchivePanel[] newPanels = new ArchivePanel[4];
86
87         newPanels[0] = filePanel;
88         newPanels[1] = contentPanel;
89         newPanels[2] = classesPanel;
90         newPanels[3] = libPanel;
91         setWizardPanels(newPanels);
92     }
93
94     protected void initPlan() throws ArchiveException {
95         WarPlan warPlan = null;
96         PathHandle path = null;
97
98         setPlan(new WarPlan());
99         getWarPlan().setArchivePath(getDefaultArchivePath());
100         path = PathHandle.createPathHandle(getWarPlan().getArchivePath());
101         if (path.isFile()) {
102             readArchive(getWarPlan().getArchivePath());
103         }
104     }
105
106     protected boolean readArchive(Manifest JavaDoc manifest, String JavaDoc[] entries) {
107         boolean read = super.readArchive(manifest, entries);
108         PathHandle root = null;
109
110         if (read) {
111             String JavaDoc value = null;
112
113             try {
114                 value = manifest.getMainAttributes().getValue(CONTENT_ROOT);
115                 root = PathHandle.createPathHandle(value);
116                 if (root.isDirectory()) {
117                     PathHandle cursor = null;
118                     String JavaDoc[] content = new String JavaDoc[0];
119                     ArrayList JavaDoc list = new ArrayList JavaDoc();
120
121                     getWarPlan().setContentRoot(root.getPath());
122                     for (int i = 0; i < entries.length; i++) {
123                         if (entries[i].toUpperCase().startsWith("WEB-INF")) {
124
125                             // ignore
126
} else if (entries[i].toUpperCase().startsWith("META-INF")) {
127
128                             // ignore
129
} else {
130                             cursor =
131                                 PathHandle.createPathHandle(root.getPath()
132                                                             + File.separator
133                                                             + entries[i]);
134                             if (cursor.isFile()) {
135                                 list.add(cursor.getPath());
136                             }
137                         }
138                     }
139                     list.trimToSize();
140                     content = new String JavaDoc[list.size()];
141                     content = (String JavaDoc[]) list.toArray(content);
142                     list.clear();
143                     getWarPlan().setContentFiles(content);
144                 }
145             } catch (ArchiveException e) {
146                 e.printStackTrace(System.err);
147             }
148         }
149         return read;
150     }
151
152     private WarPlan getWarPlan() throws ArchiveException {
153         return (WarPlan) getPlan();
154     }
155
156 }
157
Popular Tags