001: /*
002: * Copyright 2003 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.File;
009:
010: import org.openide.nodes.Node;
011:
012: import org.openide.loaders.DataObject;
013:
014: import org.openide.filesystems.FileObject;
015: import org.openide.filesystems.FileSystem;
016: import org.openide.filesystems.FileUtil;
017:
018: import org.openide.util.HelpCtx;
019: import org.openide.util.NbBundle;
020:
021: import org.openide.TopManager;
022: import org.openide.ErrorManager;
023: import org.openide.NotifyDescriptor;
024:
025: import org.openide.util.actions.NodeAction;
026:
027: import org.netbeans.modules.web.context.WebModuleCookie;
028: import org.netbeans.modules.web.context.WebContextObject;
029: import org.netbeans.modules.web.context.PackageWar;
030:
031: import org.netbeans.modules.j2ee.server.ServerInstance;
032:
033: import com.sun.portal.ffj.util.PortletWebInf;
034:
035: public class PortletXMLExportWarAction extends NodeAction {
036:
037: public String getName() {
038: return NbBundle.getMessage(ExecuteAction.class,
039: "LBL_PortletXMLExportWarAction");
040: }
041:
042: public HelpCtx getHelpCtx() {
043: return HelpCtx.DEFAULT_HELP;
044: // If you will provide context help then use:
045: // return new HelpCtx (ExecuteAction.class);
046: }
047:
048: protected void performAction(Node[] nodes) {
049: try {
050: DataObject dob = (DataObject) (nodes[0])
051: .getCookie(DataObject.class);
052: FileObject fobj = dob.getPrimaryFile();
053:
054: FileSystem fs = fobj.getFileSystem();
055: FileObject pxml = fs.find("WEB-INF", "portlet", "xml");
056: File root = FileUtil.toFile(fs.getRoot());
057: PortletWebInf pwinf = new PortletWebInf(new File(root,
058: "WEB-INF"));
059: FileObject winf = pxml.getParent();
060:
061: if (winf != null) {
062: DataObject winfdob = DataObject.find(winf);
063: Node node = winfdob.getNodeDelegate();
064: WebModuleCookie cook = (WebModuleCookie) node
065: .getCookie(WebModuleCookie.class);
066: if (cook != null) {
067: pwinf.prewar(pxml, fobj);
068: performAction(cook);
069: pwinf.postwar(pxml);
070: } else {
071: System.err
072: .println("NO WebModuleCookie in Export WAR!");
073: }
074: } else {
075: System.err.println("NULL parent in Export WAR!");
076: }
077: } catch (Exception ex) {
078: TopManager.getDefault().getErrorManager().notify(
079: ErrorManager.USER, ex);
080: }
081: }
082:
083: // HACK! code snitched from WEB-INFO loader in netbeans.modules.
084:
085: private void performAction(WebModuleCookie cook) {
086:
087: File warFile = PackageWar.fileChooseDialog();
088: if (warFile == null)
089: return; // user canceled the op
090:
091: // WebModuleCookie cook = (WebModuleCookie) nodes[i].getCookie(WebModuleCookie.class);
092:
093: WebContextObject dobj = cook.getContext();
094: ServerInstance si = dobj.getServerInstance();
095: warFile = WebContextObject.getPackager().getResource(dobj,
096: si == null ? null : si.getServer(), null, warFile)
097: .getFile();
098: if (warFile == null)
099: return;
100:
101: TopManager.getDefault().notify(
102: new NotifyDescriptor.Message(NbBundle.getBundle(
103: PortletXMLExportWarAction.class).getString(
104: "PROP_FinishedWar")));
105: }
106:
107: protected boolean enable(Node[] activatedNodes) {
108: return true;
109: }
110: }
|