KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > enhydra > kelp > forte > actions > DeploymentAction


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  * Lisa Reese
21  *
22  */

23 package org.enhydra.kelp.forte.actions;
24
25 // OpenIDE
26
import org.openide.nodes.Node;
27 import org.openide.util.HelpCtx;
28 import org.openide.util.NbBundle;
29 import org.openide.util.actions.CallableSystemAction;
30 import org.openide.TopManager;
31 import org.openide.loaders.DataFolder;
32 import org.openide.loaders.DataObject;
33 import org.openide.src.ClassElement;
34 import org.openide.DialogDescriptor;
35 import org.openide.filesystems.FileSystem;
36 import org.openide.filesystems.FileObject;
37
38 // ToolBox
39
import org.enhydra.tool.common.SwingUtil;
40 import org.enhydra.tool.common.event.HelpEvent;
41 import org.enhydra.tool.common.event.HelpListener;
42
43 // AddinCore
44
import org.enhydra.kelp.KelpInfo;
45 import org.enhydra.kelp.common.deployer.CoreDeployTool;
46 import org.enhydra.kelp.common.deployer.DeployButtonPanel;
47 import org.enhydra.kelp.common.deployer.DeployButtonListener;
48 import org.enhydra.kelp.common.node.OtterFileNode;
49
50 // AddinForte
51
import org.enhydra.kelp.forte.node.ForteProject;
52
53 // JDK
54
import java.awt.Dialog JavaDoc;
55 import java.awt.event.ActionListener JavaDoc;
56 import java.awt.event.ActionEvent JavaDoc;
57 import java.net.URL JavaDoc;
58 import java.net.MalformedURLException JavaDoc;
59
60 // mn 08.06.2002
61
import java.io.File JavaDoc;
62 import java.io.FileInputStream JavaDoc;
63 import java.io.FileOutputStream JavaDoc;
64 /**
65  * Action sensitive to some cookie that does something useful.
66  *
67  * @author rees0234
68  */

69 public class DeploymentAction extends CallableSystemAction implements HelpListener {
70     private static String JavaDoc anchor = "deploywizard";
71
72     // implements HelpListener
73
public void onHelp(HelpEvent event) {
74         URL JavaDoc url = null;
75         String JavaDoc[] home = new String JavaDoc[2];
76         home[0] = System.getProperty("netbeans.home");
77         home[1] = System.getProperty("netbeans.user");
78         StringBuffer JavaDoc buf = new StringBuffer JavaDoc();
79         buf.append(KelpInfo.getAddinHelpURL(home));
80         buf.append('#').append(anchor);
81         try {
82           url = new URL JavaDoc(buf.toString());
83           TopManager.getDefault().showUrl(url);
84         } catch (MalformedURLException JavaDoc e) {
85           e.printStackTrace(System.err);
86         }
87     }
88
89     public void performAction() {
90         // do work based on the current node selection, e.g.:
91
// SourceCookie cookie = (SourceCookie) nodes[0].getCookie (SourceCookie.class);
92
// etc.
93
String JavaDoc[] options = DeployButtonPanel.getOptions();
94         CoreDeployTool tool = new CoreDeployTool();
95         DeployButtonListener listener = new DeployButtonListener(tool);
96         ForteProject project = new ForteProject();
97         tool.getInnerPanel().initPreferredSize();
98         tool.setProject(project);
99         DialogDescriptor dscr = new DialogDescriptor(tool.getInnerPanel(),
100                 tool.getTitle(), true, options, options[1],
101                 DialogDescriptor.BOTTOM_ALIGN, HelpCtx.DEFAULT_HELP,
102                 listener);
103         Dialog JavaDoc dlg = TopManager.getDefault().createDialog(dscr);
104         tool.addHelpListener(this);
105         dlg.show();
106
107         // mn 08.06.2002
108
// Added coping of WEB-INF directory, since deployer doesn't do it.
109
if (project.getDeployType() == ForteProject.TYPE_WEBAPP) {
110             String JavaDoc prjRoot = project.getRootPath();
111
112             File JavaDoc srcdir = new File JavaDoc(prjRoot+"/src/WEB-INF");
113             File JavaDoc srcfile = new File JavaDoc(prjRoot+"/src/WEB-INF/web.xml");
114
115             if (!(srcdir.exists() && srcfile.exists())) return;
116
117                 File JavaDoc contentDir = new File JavaDoc(prjRoot+"/output/content");
118                 if (!contentDir.exists()) {
119                 if(!contentDir.mkdir()) return;
120             }
121             
122             File JavaDoc destdir = new File JavaDoc(prjRoot+"/output/content/WEB-INF");
123             File JavaDoc destfile = new File JavaDoc(prjRoot+"/output/content/WEB-INF/web.xml");
124
125             FileInputStream JavaDoc in;
126             FileOutputStream JavaDoc out;
127
128             if (!destdir.mkdir()) return;
129             try {
130                 destfile.createNewFile();
131
132                 in = new FileInputStream JavaDoc(srcfile);
133                 out = new FileOutputStream JavaDoc(destfile);
134             }
135             catch (Exception JavaDoc e) {
136                 if (destfile.exists()) destfile.delete();
137                 destdir.delete();
138                 return;
139             }
140
141             byte buf[] = new byte[1024];
142             int count, length;
143
144             count = 0;
145             length = 0;
146
147             try {
148                 while (length != srcfile.length()) {
149                     count = in.read(buf);
150                     out.write(buf, 0, count);
151                     length += count;
152                 }
153                 in.close();
154                 out.close();
155             }
156             catch (Exception JavaDoc e) {
157             }
158         }
159     }
160
161     public String JavaDoc getName() {
162         return CoreDeployTool.getDefaultTitle();
163     }
164
165     public boolean isEnabled()
166     {
167         FileObject root = new ForteProject().getRootFolder();
168         if (root == null)
169             return false;
170         if (root.getChildren().length <= 0)
171             return false;
172         else
173             return true;
174     }
175
176
177     protected String JavaDoc iconResource() {
178         return "smallicon.gif";
179     }
180
181     public HelpCtx getHelpCtx() {
182         return HelpCtx.DEFAULT_HELP;
183
184         // If you will provide context help then use:
185
// return new HelpCtx (DeployementAction.class);
186
}
187
188     /**
189      * Perform extra initialization of this action's singleton.
190      * PLEASE do not use constructors for this purpose!
191      */

192     protected void initialize() {
193         // mn 08.06.2002
194
super.initialize();
195         putProperty(javax.swing.Action.SHORT_DESCRIPTION,
196                     NbBundle.getMessage(DeploymentAction.class,
197                                         "HINT_Deployment_Action"));
198     }
199
200 }
201
Popular Tags