KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > web > project > WebProjectModule


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.web.project;
21
22 import java.io.IOException JavaDoc;
23 import java.io.File JavaDoc;
24 import javax.swing.Action JavaDoc;
25 import org.netbeans.api.project.ProjectManager;
26 import org.netbeans.modules.web.project.ui.customizer.WebProjectProperties;
27 import org.netbeans.spi.project.support.ant.EditableProperties;
28 import org.netbeans.spi.project.support.ant.PropertyUtils;
29 import org.openide.ErrorManager;
30 import org.openide.modules.InstalledFileLocator;
31 import org.openide.modules.ModuleInstall;
32 import org.netbeans.spi.project.ActionProvider;
33 import org.netbeans.spi.project.ui.support.FileSensitiveActions;
34 import org.openide.NotifyDescriptor;
35 import org.openide.DialogDisplayer;
36 import org.openide.util.NbBundle;
37
38 /**
39  * Startup and shutdown hooks for web project module. It defines
40  * the project specific actions (e.g.compile/run/debug file) for the
41  * nodes representing JSP and html files. These actions are registered
42  * for their mime types in layer.
43  *
44  * @author Martin Grebac
45  */

46 public class WebProjectModule extends ModuleInstall {
47     public static final String JavaDoc JSPC_CLASSPATH = "jspc.classpath"; //NOI18N
48
public static final String JavaDoc COPYFILES_CLASSPATH = "copyfiles.classpath"; //NOI18N
49

50     public void restored() {
51         
52         ProjectManager.mutex().postWriteRequest(
53                 new Runnable JavaDoc () {
54                     public void run () {
55                         try {
56                             EditableProperties ep = PropertyUtils.getGlobalProperties();
57                             boolean changed = false;
58                             // JSPC classpath
59
StringBuffer JavaDoc sb = new StringBuffer JavaDoc(450);
60                             // Ant is needed in classpath if we are forking JspC into another process
61
sb.append(InstalledFileLocator.getDefault().locate("ant/lib/ant.jar", null, false)) //NOI18N
62
.append(':') // NOI18N
63
//XXX This is fix for issue #74250. This is a hack and should be solved in the glassfish's jasper
64
// also it must be moved before J2EE_PLATFORM_CLASSPATH, because a server (JBoss) can expose
65
// old jsp api, and the compiler is not then able compile some jsp pages with tag lib declarations
66
.append(InstalledFileLocator.getDefault().locate("modules/ext/servlet2.5-jsp2.1-api.jar", null, false)) //NOI18N
67
.append(":${" + WebProjectProperties.J2EE_PLATFORM_CLASSPATH + "}:") // NOI18N
68
.append(InstalledFileLocator.getDefault().locate("modules/ext/glassfish-jspparser.jar", null, false)) //NOI18N
69
.append(':') // NOI18N
70
.append(InstalledFileLocator.getDefault().locate("modules/ext/glassfish-logging.jar", null, false)) //NOI18N
71
.append(':') // NOI18N
72
.append(InstalledFileLocator.getDefault().locate("modules/ext/commons-logging-1.0.4.jar", null, false)); //NOI18N
73

74                             String JavaDoc jspc_cp_old = ep.getProperty(JSPC_CLASSPATH);
75                             String JavaDoc jspc_cp = sb.toString();
76                             if (jspc_cp_old == null || !jspc_cp_old.equals (jspc_cp)) {
77                                 ep.setProperty(JSPC_CLASSPATH, jspc_cp);
78                                 changed = true;
79                             }
80                             File JavaDoc copy_files = InstalledFileLocator.getDefault().locate("ant/extra/copyfiles.jar", null, false); //NOI18N
81
if (copy_files == null) {
82                                 String JavaDoc msg = NbBundle.getMessage(WebProjectModule.class,"MSG_CopyFileMissing"); //NOI18N
83
DialogDisplayer.getDefault().notify(new NotifyDescriptor.Message(msg, NotifyDescriptor.ERROR_MESSAGE));
84                             } else {
85                                 String JavaDoc copy_files_old = ep.getProperty(COPYFILES_CLASSPATH);
86                                 if (copy_files_old == null || !copy_files_old.equals(copy_files.toString())) {
87                                     ep.setProperty(COPYFILES_CLASSPATH, copy_files.toString());
88                                     changed = true;
89                                 }
90                             }
91                             if (changed) {
92                                 PropertyUtils.putGlobalProperties (ep);
93                             }
94                         } catch (IOException JavaDoc ioe) {
95                             ErrorManager.getDefault().notify (ioe);
96                         }
97                     }
98                 }
99         );
100     }
101     
102     public static Action JavaDoc compile() {
103         return FileSensitiveActions.fileCommandAction(
104                        ActionProvider.COMMAND_COMPILE_SINGLE,
105                        NbBundle.getMessage(WebProjectModule.class, "LBL_CompileFile_Action"), // NOI18N
106
null );
107     }
108             
109     public static Action JavaDoc run() {
110         return FileSensitiveActions.fileCommandAction(
111                        ActionProvider.COMMAND_RUN_SINGLE,
112                        NbBundle.getMessage(WebProjectModule.class, "LBL_RunFile_Action"), // NOI18N
113
null );
114     }
115     
116     public static Action JavaDoc debug() {
117         return FileSensitiveActions.fileCommandAction(
118                        ActionProvider.COMMAND_DEBUG_SINGLE,
119                        NbBundle.getMessage(WebProjectModule.class, "LBL_DebugFile_Action"), // NOI18N
120
null );
121     }
122
123     public static Action JavaDoc htmlRun() {
124         return FileSensitiveActions.fileCommandAction(
125                        ActionProvider.COMMAND_RUN_SINGLE,
126                        NbBundle.getMessage(WebProjectModule.class, "LBL_RunFile_Action"), // NOI18N
127
null );
128     }
129
130     public static Action JavaDoc htmlDebug() {
131         return FileSensitiveActions.fileCommandAction(
132                        ActionProvider.COMMAND_DEBUG_SINGLE,
133                        NbBundle.getMessage(WebProjectModule.class, "LBL_DebugFile_Action"), // NOI18N
134
null );
135     }
136     
137 }
138
Popular Tags