001: /*
002: * Copyright 2002 Sun Microsystems, Inc. All rights reserved.
003: * PROPRIETARY/CONFIDENTIAL. Use of this product is subject to license terms.
004: */
005:
006: package com.sun.portal.ffj.actions;
007:
008: import java.io.IOException;
009: import java.io.File;
010:
011: import org.netbeans.modules.web.core.WebExecSupport;
012:
013: import org.openide.TopManager;
014: import org.openide.ErrorManager;
015:
016: import org.openide.loaders.XMLDataObject;
017: import org.openide.loaders.DataObject;
018: import org.openide.loaders.DataObjectNotFoundException;
019:
020: import org.openide.filesystems.FileObject;
021: import org.openide.filesystems.FileSystem;
022:
023: import org.openide.cookies.ExecCookie;
024:
025: import org.openide.nodes.Node;
026:
027: import org.openide.NotifyDescriptor;
028:
029: import org.openide.util.HelpCtx;
030: import org.openide.util.NbBundle;
031:
032: import org.openide.util.actions.NodeAction;
033:
034: import com.sun.portal.ffj.filesystems.PSFileSystem;
035: import com.sun.portal.ffj.util.PortletWebInf;
036:
037: public class PortletXMLExecuteAction extends NodeAction {
038:
039: public String getName() {
040: return NbBundle.getMessage(ExecuteAction.class,
041: "LBL_PortletXMLExecuteAction");
042: }
043:
044: public HelpCtx getHelpCtx() {
045: return HelpCtx.DEFAULT_HELP;
046: // If you will provide context help then use:
047: // return new HelpCtx (ExecuteAction.class);
048: }
049:
050: protected boolean restart() {
051: return false;
052: }
053:
054: protected boolean enable(Node[] nodes) {
055: return true;
056: }
057:
058: protected void performAction(Node[] nodes) {
059:
060: TopManager.getDefault().saveAll();
061:
062: PSFileSystem psFS = (PSFileSystem) PSFileSystem
063: .getPSFilesystem(true);
064: File pwwi = new File(psFS.getRootDirectory(), "WEB-INF");
065: File pwxml = new File(pwwi, "portlet-web.xml");
066: File owxml = new File(pwwi, "old-web.xml");
067: if (!owxml.exists() && pwxml.exists()) {
068:
069: String mp = psFS.getRootDirectory().getPath();
070: String msg = NbBundle.getMessage(
071: PortletXMLExecuteAction.class, "MSG_FirstPortlet",
072: mp);
073: NotifyDescriptor d = new NotifyDescriptor.Confirmation(msg,
074: NotifyDescriptor.OK_CANCEL_OPTION);
075: Object resp = TopManager.getDefault().notify(d);
076:
077: if (resp == NotifyDescriptor.CANCEL_OPTION) {
078: return;
079: }
080:
081: File wxml = new File(pwwi, "web.xml");
082: wxml.renameTo(owxml);
083: pwxml.renameTo(wxml);
084: }
085:
086: XMLDataObject xob = (XMLDataObject) (nodes[0])
087: .getCookie(DataObject.class);
088:
089: FileObject fobj = xob.getPrimaryFile();
090: String pf = PSFileSystem.getAbsolutePathName(fobj.getParent());
091: PortletWebInf winf = new PortletWebInf(new File(pf, "WEB-INF"));
092:
093: try {
094: FileSystem fs = fobj.getFileSystem();
095: FileObject pxml = fs.find("WEB-INF", "portlet", "xml");
096:
097: winf.prepareExec(pxml, fobj);
098:
099: FileObject testjsp = winf.getTestJSP(pxml);
100: ExecCookie cookie = (ExecCookie) DataObject.find(testjsp)
101: .getCookie(ExecCookie.class);
102:
103: if (restart()) {
104: org.netbeans.modules.web.execution.WebDefaultExecPerformer
105: .setIncremental(false);
106: // ServerExecutor.forceReload();
107: }
108:
109: cookie.start();
110: } catch (Exception ex) {
111: TopManager.getDefault().getErrorManager().notify(
112: ErrorManager.USER, ex);
113: }
114: }
115: }
|