diff options
Diffstat (limited to 'scripting/java/org/openoffice/netbeans/modules/office/actions')
15 files changed, 1617 insertions, 0 deletions
diff --git a/scripting/java/org/openoffice/netbeans/modules/office/actions/BuildParcelAction.java b/scripting/java/org/openoffice/netbeans/modules/office/actions/BuildParcelAction.java new file mode 100644 index 000000000000..a4863b271b42 --- /dev/null +++ b/scripting/java/org/openoffice/netbeans/modules/office/actions/BuildParcelAction.java @@ -0,0 +1,69 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +package org.openoffice.netbeans.modules.office.actions; + +import java.util.Vector; +import java.util.Enumeration; + +import org.openide.nodes.Node; +import org.openide.util.HelpCtx; +import org.openide.util.RequestProcessor; +import org.openide.actions.BuildAllAction; + +import org.openide.compiler.Compiler; +import org.openide.compiler.CompilerJob; +import org.openide.compiler.CompilerTask; + +import org.openoffice.netbeans.modules.office.utils.FrameworkJarChecker; + +public class BuildParcelAction extends BuildAllAction { + public String getName() { + return "Build"; + } + + protected void performAction(Node[] activatedNodes) { + FrameworkJarChecker.mountDependencies(); + + for (int i = 0; i < activatedNodes.length; i++) { + Vector v = new Vector(1); + v.addElement(activatedNodes[i]); + + CompilerJob job = createJob(v.elements(), Compiler.DEPTH_INFINITE); + CompilerTask task = job.start(); + task.waitFinished(); + + if (task.isSuccessful()) { + ParcelFolderCookie cookie = (ParcelFolderCookie) + activatedNodes[i].getCookie(ParcelFolderCookie.class); + + if (cookie != null) + cookie.generate(); + } + } + } +} diff --git a/scripting/java/org/openoffice/netbeans/modules/office/actions/CompileParcelAction.java b/scripting/java/org/openoffice/netbeans/modules/office/actions/CompileParcelAction.java new file mode 100644 index 000000000000..3d5bbc1c0445 --- /dev/null +++ b/scripting/java/org/openoffice/netbeans/modules/office/actions/CompileParcelAction.java @@ -0,0 +1,44 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +package org.openoffice.netbeans.modules.office.actions; + +import org.openide.nodes.Node; +import org.openide.actions.CompileAllAction; + +import org.openoffice.netbeans.modules.office.utils.FrameworkJarChecker; + +public class CompileParcelAction extends CompileAllAction { + public String getName() { + return "Compile"; + } + + protected void performAction(Node[] activatedNodes) { + FrameworkJarChecker.mountDependencies(); + super.performAction(activatedNodes); + } +} diff --git a/scripting/java/org/openoffice/netbeans/modules/office/actions/ConfigureParcelAction.java b/scripting/java/org/openoffice/netbeans/modules/office/actions/ConfigureParcelAction.java new file mode 100644 index 000000000000..b6b5c88809b2 --- /dev/null +++ b/scripting/java/org/openoffice/netbeans/modules/office/actions/ConfigureParcelAction.java @@ -0,0 +1,70 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +package org.openoffice.netbeans.modules.office.actions; + +import org.openide.nodes.Node; +import org.openide.util.HelpCtx; +import org.openide.util.RequestProcessor; +import org.openide.util.actions.CookieAction; + +import org.openoffice.netbeans.modules.office.utils.FrameworkJarChecker; + +public class ConfigureParcelAction extends CookieAction { + + public java.lang.String getName() { + return "Configure"; + } + + protected java.lang.Class[] cookieClasses() { + return new Class[] {ParcelFolderCookie.class}; + } + + protected int mode() { + return CookieAction.MODE_EXACTLY_ONE; + } + + public HelpCtx getHelpCtx() { + return HelpCtx.DEFAULT_HELP; + } + + protected void performAction(final Node[] activatedNodes) + { + FrameworkJarChecker.mountDependencies(); + + RequestProcessor.getDefault().post(new Runnable() { + public void run() { + for (int i = 0; i < activatedNodes.length; i++) { + ParcelFolderCookie pfc = (ParcelFolderCookie) + activatedNodes[i].getCookie(ParcelFolderCookie.class); + if (pfc != null) + pfc.configure(); + } + } + }); + } +} diff --git a/scripting/java/org/openoffice/netbeans/modules/office/actions/DeployParcelAction.java b/scripting/java/org/openoffice/netbeans/modules/office/actions/DeployParcelAction.java new file mode 100644 index 000000000000..f66922801a22 --- /dev/null +++ b/scripting/java/org/openoffice/netbeans/modules/office/actions/DeployParcelAction.java @@ -0,0 +1,244 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +package org.openoffice.netbeans.modules.office.actions; + +import java.io.File; +import java.io.IOException; +import java.util.Hashtable; +import java.util.List; +import java.util.ArrayList; +import java.util.Enumeration; + +import javax.swing.JMenuItem; +import javax.swing.JFileChooser; +import javax.swing.filechooser.FileFilter; +import javax.swing.event.ChangeEvent; +import javax.swing.event.ChangeListener; +import java.awt.event.ActionListener; +import java.awt.event.ActionEvent; + +import org.openide.TopManager; +import org.openide.NotifyDescriptor; +import org.openide.awt.Actions; +import org.openide.nodes.Node; +import org.openide.util.HelpCtx; +import org.openide.util.NbBundle; +import org.openide.util.RequestProcessor; +import org.openide.util.actions.*; +import org.openide.awt.JMenuPlus; + +import org.openoffice.idesupport.SVersionRCFile; +import org.openoffice.idesupport.OfficeInstallation; +import org.openoffice.idesupport.zip.ParcelZipper; +import org.openoffice.idesupport.LocalOffice; + +import org.openoffice.netbeans.modules.office.utils.NagDialog; +import org.openoffice.netbeans.modules.office.options.OfficeSettings; + +public class DeployParcelAction extends CookieAction implements Presenter.Popup { + + private static final String BROWSE_LABEL = "Office Document..."; + private static final String DEPLOY_LABEL = "Deploy To"; + + public String getName () { + return DEPLOY_LABEL; + } + + public HelpCtx getHelpCtx () { + return HelpCtx.DEFAULT_HELP; + } + + public JMenuItem getPopupPresenter() { + JMenuPlus menu = new JMenuPlus(DEPLOY_LABEL); + JMenuItem item, user, share; + final OfficeInstallation oi = OfficeSettings.getDefault().getOfficeDirectory(); + + ActionListener listener = new ActionListener() { + public void actionPerformed(ActionEvent e) { + JMenuItem choice = (JMenuItem)e.getSource(); + String label = choice.getText(); + + Node[] nodes = getActivatedNodes(); + final ParcelCookie parcelCookie = + (ParcelCookie)nodes[0].getCookie(ParcelCookie.class); + + File target = new File(oi.getPath(File.separator + label + + File.separator + "Scripts")); + + File langdir = new File(target, parcelCookie.getLanguage()); + + if (!langdir.exists()) { + boolean response = askIfCreateDirectory(langdir); + if (response == false) { + return; + } + } + + deploy(target); + } + }; + + user = new JMenuItem("user"); + user.addActionListener(listener); + + share = new JMenuItem("share"); + share.addActionListener(listener); + + item = new JMenuPlus(oi.getName()); + item.add(user); + item.add(share); + menu.add(item); + + menu.addSeparator(); + item = new JMenuItem(BROWSE_LABEL); + item.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + File target = getTargetFile(); + if (target == null) + return; + deploy(target); + } + }); + menu.add(item); + + return menu; + } + + protected int mode () { + return MODE_ONE; + } + + protected Class[] cookieClasses () { + return new Class[] { ParcelCookie.class }; + } + + protected void performAction (Node[] activatedNodes) { + // do nothing, should not happen + } + + private void deploy(final File target) { + Node[] nodes = getActivatedNodes(); + final ParcelCookie parcelCookie = + (ParcelCookie)nodes[0].getCookie(ParcelCookie.class); + + RequestProcessor.getDefault().post(new Runnable() { + public void run() { + boolean result = parcelCookie.deploy(target); + + if (result == true && target.isDirectory()) { + showNagDialog(); + // refreshOffice((String)versions.get(label)); + } + } + }); + } + + private boolean askIfCreateDirectory(File directory) { + String message = directory.getAbsolutePath() + " does not exist. " + + "Do you want to create it now?"; + + NotifyDescriptor d = new NotifyDescriptor.Confirmation( + message, NotifyDescriptor.OK_CANCEL_OPTION); + TopManager.getDefault().notify(d); + + if (d.getValue() == NotifyDescriptor.CANCEL_OPTION) + return false; + + boolean result; + try { + result = directory.mkdirs(); + } + catch (SecurityException se) { + result = false; + } + + if (result == false) { + String tmp = "Error creating: " + directory.getAbsolutePath(); + NotifyDescriptor d2 = new NotifyDescriptor.Message( + tmp, NotifyDescriptor.ERROR_MESSAGE); + TopManager.getDefault().notify(d2); + } + return result; + } + + private void refreshOffice(String path) { + ClassLoader syscl = TopManager.getDefault().currentClassLoader(); + LocalOffice office = LocalOffice.create(syscl, path, 8100); + office.refreshStorage("file://" + path + "/program/../user"); + office.disconnect(); + } + + private void showNagDialog() { + String message = "If you currently have Office running you will " + + "need to click on the Tools/Scripting Add-on's/Refresh All Scripts " + + " menu item in Office so that the scripts in this parcel can be detected."; + + OfficeSettings settings = OfficeSettings.getDefault(); + + if (settings.getWarnAfterDirDeploy() == true) { + NagDialog warning = NagDialog.createInformationDialog( + message, "Show this message in future", true); + + warning.show(); + + if (warning.getState() == false) + settings.setWarnAfterDirDeploy(false); + } + } + + private File getTargetFile() { + File target = null; + + JFileChooser chooser = new JFileChooser(); + chooser.setDialogTitle("Deploy Parcel To Office Document"); + chooser.setApproveButtonText("Deploy"); + chooser.setFileSelectionMode(JFileChooser.FILES_ONLY); + chooser.setFileFilter(new FileFilter() { + public boolean accept(File file) { + if (file.isDirectory() || + file.getName().endsWith(".sxw") || + file.getName().endsWith(".sxc") || + file.getName().endsWith(".sxd") || + file.getName().endsWith(".sxi")) + return true; + return false; + } + + public String getDescription() { + return "Office Documents"; + } + }); + + int result = chooser.showDialog(null, null); + + if (result == JFileChooser.APPROVE_OPTION) { + target = chooser.getSelectedFile(); + } + return target; + } +} diff --git a/scripting/java/org/openoffice/netbeans/modules/office/actions/MountDocumentAction.java b/scripting/java/org/openoffice/netbeans/modules/office/actions/MountDocumentAction.java new file mode 100644 index 000000000000..775caf05bd51 --- /dev/null +++ b/scripting/java/org/openoffice/netbeans/modules/office/actions/MountDocumentAction.java @@ -0,0 +1,85 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +package org.openoffice.netbeans.modules.office.actions; + +import org.openide.nodes.Node; +import org.openide.util.HelpCtx; +import org.openide.util.RequestProcessor; +import org.openide.util.actions.CookieAction; + +/** + * + * @author adams + * @version 1.0 + */ +public class MountDocumentAction extends CookieAction +{ + public MountDocumentAction() + { + } + + public java.lang.String getName() + { + return "Mount Document"; //NOI18N + } + + public HelpCtx getHelpCtx() + { + return HelpCtx.DEFAULT_HELP; + } + + protected int mode() + { + // enable duplication for as many qualifying nodes as are selected: + return CookieAction.MODE_ALL; + } + + protected java.lang.Class[] cookieClasses() + { + // just the DuplicateCookie: + return new Class[] {OfficeDocumentCookie.class}; + } + + protected void performAction(final Node[] activatedNodes) + { + RequestProcessor.getDefault().post(new Runnable() + { + public void run() + { + for (int i=0; i<activatedNodes.length; i++) + { + OfficeDocumentCookie cookie = (OfficeDocumentCookie)activatedNodes[i].getCookie(OfficeDocumentCookie.class); + if (cookie != null) + { + cookie.mount(); + } + } + } + }); + } +} diff --git a/scripting/java/org/openoffice/netbeans/modules/office/actions/MountParcelAction.java b/scripting/java/org/openoffice/netbeans/modules/office/actions/MountParcelAction.java new file mode 100644 index 000000000000..7b07c2d098f3 --- /dev/null +++ b/scripting/java/org/openoffice/netbeans/modules/office/actions/MountParcelAction.java @@ -0,0 +1,84 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +package org.openoffice.netbeans.modules.office.actions; + +import org.openide.nodes.Node; +import org.openide.util.HelpCtx; +import org.openide.util.RequestProcessor; +import org.openide.util.actions.CookieAction; + +/** + * + * @author adams + * @version 1.0 + */ +public class MountParcelAction extends CookieAction +{ + public MountParcelAction() + { + } + + public java.lang.String getName() + { + return "Mount Parcel"; //NOI18N + } + + public HelpCtx getHelpCtx() + { + return HelpCtx.DEFAULT_HELP; + } + + protected int mode() + { + // enable duplication for as many qualifying nodes as are selected: + return CookieAction.MODE_ALL; + } + + protected java.lang.Class[] cookieClasses() + { + return new Class[] {ParcelCookie.class}; + } + + protected void performAction(final Node[] activatedNodes) + { + RequestProcessor.getDefault().post(new Runnable() + { + public void run() + { + for (int i=0; i<activatedNodes.length; i++) + { + ParcelCookie mpc = (ParcelCookie)activatedNodes[i].getCookie(ParcelCookie.class); + if (mpc != null) + { + mpc.mount(); + } + } + } + }); + } +} diff --git a/scripting/java/org/openoffice/netbeans/modules/office/actions/OfficeDocumentCookie.java b/scripting/java/org/openoffice/netbeans/modules/office/actions/OfficeDocumentCookie.java new file mode 100644 index 000000000000..2799b08f2af1 --- /dev/null +++ b/scripting/java/org/openoffice/netbeans/modules/office/actions/OfficeDocumentCookie.java @@ -0,0 +1,42 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +package org.openoffice.netbeans.modules.office.actions; + +import java.util.Enumeration; +import javax.swing.event.ChangeListener; +import org.openide.nodes.Node; + +public interface OfficeDocumentCookie extends Node.Cookie +{ + public void mount(); + public Enumeration getParcels(); + public void removeParcel(String name); + + public void addChangeListener(ChangeListener cl); + public void removeChangeListener(ChangeListener cl); +} diff --git a/scripting/java/org/openoffice/netbeans/modules/office/actions/OfficeDocumentSupport.java b/scripting/java/org/openoffice/netbeans/modules/office/actions/OfficeDocumentSupport.java new file mode 100644 index 000000000000..0be80d6786b7 --- /dev/null +++ b/scripting/java/org/openoffice/netbeans/modules/office/actions/OfficeDocumentSupport.java @@ -0,0 +1,143 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +package org.openoffice.netbeans.modules.office.actions; + +import java.io.IOException; +import java.io.File; +import java.beans.PropertyVetoException; +import java.util.Enumeration; +import java.util.Set; +import java.util.HashSet; +import java.util.Iterator; +import javax.swing.event.ChangeListener; +import javax.swing.event.ChangeEvent; + +import org.openide.ErrorManager; +import org.openide.filesystems.FileObject; +import org.openide.filesystems.FileUtil; +import org.openide.filesystems.FileChangeListener; +import org.openide.filesystems.FileEvent; +import org.openide.filesystems.FileAttributeEvent; +import org.openide.filesystems.FileRenameEvent; +import org.openide.cookies.OpenCookie; + +import org.openoffice.idesupport.OfficeDocument; + +import org.openoffice.netbeans.modules.office.options.OfficeSettings; +import org.openoffice.netbeans.modules.office.loader.OfficeDocumentDataObject; +import org.openoffice.netbeans.modules.office.utils.ZipMounter; +import org.openoffice.netbeans.modules.office.utils.ManifestParser; + +public class OfficeDocumentSupport implements OfficeDocumentCookie, OpenCookie, FileChangeListener +{ + protected OfficeDocumentDataObject dataObj; + private boolean isMounted = false; + private OfficeDocument document; + private Set listeners; + + public OfficeDocumentSupport(OfficeDocumentDataObject dataObj) { + this.dataObj = dataObj; + FileObject fo = dataObj.getPrimaryFile(); + try { + this.document = new OfficeDocument(FileUtil.toFile(fo)); + } + catch (Exception e) { + e.printStackTrace(); + } + fo.addFileChangeListener(this); + } + + public void mount() { + File file = FileUtil.toFile(dataObj.getPrimaryFile()); + + try { + ZipMounter.getZipMounter().mountZipFile(file); + isMounted = true; + } + catch (IOException ioe) { + ErrorManager.getDefault().notify(ioe); + } + catch (PropertyVetoException pve) { + ErrorManager.getDefault().notify(pve); + } + } + + public void open () { + File file = FileUtil.toFile(dataObj.getPrimaryFile()); + + OfficeSettings settings = OfficeSettings.getDefault(); + File soffice = new File(settings.getOfficeDirectory().getPath( + File.separator + "soffice")); + + try { + Process p = Runtime.getRuntime ().exec (new String[] { + soffice.getAbsolutePath(), file.getAbsolutePath () + }); + } catch (IOException ioe) { + ErrorManager.getDefault().notify(ioe); + } + } + + public Enumeration getParcels() { + return document.getParcels(); + } + + public void removeParcel(String name) { + document.removeParcel(name); + dataObj.getPrimaryFile().refresh(true); + } + + public void addChangeListener(ChangeListener cl) { + if (listeners == null) + listeners = new HashSet(); + + listeners.add(cl); + } + + public void removeChangeListener(ChangeListener cl) { + if (listeners == null) + return; + + listeners.remove(cl); + } + + public void fileChanged(FileEvent fe) { + if (listeners != null) { + Iterator iter = listeners.iterator(); + + while (iter.hasNext()) + ((ChangeListener)iter.next()).stateChanged(new ChangeEvent(this)); + } + } + + public void fileAttributeChanged(FileAttributeEvent fe) {} + public void fileDataCreated(FileEvent fe) {} + public void fileDeleted(FileEvent fe) {} + public void fileFolderCreated(FileEvent fe) {} + public void fileRenamed(FileRenameEvent fe) {} +} diff --git a/scripting/java/org/openoffice/netbeans/modules/office/actions/ParcelCookie.java b/scripting/java/org/openoffice/netbeans/modules/office/actions/ParcelCookie.java new file mode 100644 index 000000000000..23ace1c11160 --- /dev/null +++ b/scripting/java/org/openoffice/netbeans/modules/office/actions/ParcelCookie.java @@ -0,0 +1,42 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +package org.openoffice.netbeans.modules.office.actions; + +import java.io.File; +import org.openide.nodes.Node; + +public interface ParcelCookie extends Node.Cookie +{ + public File getFile(); + + public String getLanguage(); + + public void mount(); + + public boolean deploy(File target); +} diff --git a/scripting/java/org/openoffice/netbeans/modules/office/actions/ParcelDescriptorEditorSupport.java b/scripting/java/org/openoffice/netbeans/modules/office/actions/ParcelDescriptorEditorSupport.java new file mode 100644 index 000000000000..5f9f67dcfe60 --- /dev/null +++ b/scripting/java/org/openoffice/netbeans/modules/office/actions/ParcelDescriptorEditorSupport.java @@ -0,0 +1,141 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +package org.openoffice.netbeans.modules.office.actions; + +import java.io.IOException; + +import org.openide.cookies.*; +import org.openide.filesystems.FileLock; +import org.openide.filesystems.FileObject; +import org.openide.loaders.DataObject; +import org.openide.text.DataEditorSupport; +import org.openide.windows.CloneableOpenSupport; + +import org.openoffice.netbeans.modules.office.loader.ParcelDescriptorDataObject; + +/** Support for editing a data object as text. + * + * @author tomaso + */ +// Replace OpenCookie with EditCookie or maybe ViewCookie as desired: +public class ParcelDescriptorEditorSupport extends DataEditorSupport implements EditorCookie, OpenCookie, CloseCookie, PrintCookie { + + /** Create a new editor support. + * @param obj the data object whose primary file will be edited as text + */ + public ParcelDescriptorEditorSupport(ParcelDescriptorDataObject obj) { + super(obj, new ParcelDescriptorEnv(obj)); + // Set a MIME type as needed, e.g.: + setMIMEType("text/xml"); + } + + /** Called when the document is modified. + * Here, adding a save cookie to the object and marking it modified. + * @return true if the modification is acceptable + */ + protected boolean notifyModified() { + if (!super.notifyModified()) { + return false; + } + ParcelDescriptorDataObject obj = (ParcelDescriptorDataObject)getDataObject(); + if (obj.getCookie(SaveCookie.class) == null) { + obj.setModified(true); + // You must implement this method on the object: + obj.addSaveCookie(new Save()); + } + return true; + } + + /** Called when the document becomes unmodified. + * Here, removing the save cookie from the object and marking it unmodified. + */ + protected void notifyUnmodified() { + ParcelDescriptorDataObject obj = (ParcelDescriptorDataObject)getDataObject(); + SaveCookie save = (SaveCookie)obj.getCookie(SaveCookie.class); + if (save != null) { + // You must implement this method on the object: + obj.removeSaveCookie(save); + obj.setModified(false); + } + super.notifyUnmodified(); + } + + /** A save cookie to use for the editor support. + * When saved, saves the document to disk and marks the object unmodified. + */ + private class Save implements SaveCookie { + public void save() throws IOException { + saveDocument(); + getDataObject().setModified(false); + } + } + + /** A description of the binding between the editor support and the object. + * Note this may be serialized as part of the window system and so + * should be static, and use the transient modifier where needed. + */ + private static class ParcelDescriptorEnv extends DataEditorSupport.Env { + + //private static final long serialVersionUID = ...L; + + /** Create a new environment based on the data object. + * @param obj the data object to edit + */ + public ParcelDescriptorEnv(ParcelDescriptorDataObject obj) { + super(obj); + } + + /** Get the file to edit. + * @return the primary file normally + */ + protected FileObject getFile() { + return getDataObject().getPrimaryFile(); + } + + /** Lock the file to edit. + * Should be taken from the file entry if possible, helpful during + * e.g. deletion of the file. + * @return a lock on the primary file normally + * @throws IOException if the lock could not be taken + */ + protected FileLock takeLock() throws IOException { + return ((ParcelDescriptorDataObject)getDataObject()).getPrimaryEntry().takeLock(); + } + + /** Find the editor support this environment represents. + * Note that we have to look it up, as keeping a direct + * reference would not permit this environment to be serialized. + * @return the editor support + */ + public CloneableOpenSupport findCloneableOpenSupport() { + return (ParcelDescriptorEditorSupport)getDataObject().getCookie(ParcelDescriptorEditorSupport.class); + } + + } + +} diff --git a/scripting/java/org/openoffice/netbeans/modules/office/actions/ParcelDescriptorParserCookie.java b/scripting/java/org/openoffice/netbeans/modules/office/actions/ParcelDescriptorParserCookie.java new file mode 100644 index 000000000000..925a451efe21 --- /dev/null +++ b/scripting/java/org/openoffice/netbeans/modules/office/actions/ParcelDescriptorParserCookie.java @@ -0,0 +1,42 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +package org.openoffice.netbeans.modules.office.actions; + +import org.w3c.dom.NodeList; +import javax.swing.event.ChangeListener; +import org.openide.nodes.Node; + +public interface ParcelDescriptorParserCookie extends Node.Cookie +{ + // should return a NodeList of org.w3c.dom.Element + public NodeList getScriptElements(); + + public void addChangeListener(ChangeListener cl); + + public void removeChangeListener(ChangeListener cl); +} diff --git a/scripting/java/org/openoffice/netbeans/modules/office/actions/ParcelDescriptorParserSupport.java b/scripting/java/org/openoffice/netbeans/modules/office/actions/ParcelDescriptorParserSupport.java new file mode 100644 index 000000000000..aae9c51b5726 --- /dev/null +++ b/scripting/java/org/openoffice/netbeans/modules/office/actions/ParcelDescriptorParserSupport.java @@ -0,0 +1,121 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +package org.openoffice.netbeans.modules.office.actions; + +import java.io.*; +import java.util.*; +import javax.swing.event.ChangeListener; +import javax.swing.event.ChangeEvent; + +import org.w3c.dom.Document; +import org.w3c.dom.NodeList; +import org.xml.sax.InputSource; +import org.xml.sax.SAXException; + +import org.openide.filesystems.*; +import org.openide.xml.XMLUtil; + +public class ParcelDescriptorParserSupport + implements ParcelDescriptorParserCookie, FileChangeListener +{ + private FileObject fo; + private Document document; + private Set listeners; + + public ParcelDescriptorParserSupport(FileObject fo) + { + this.fo = fo; + fo.addFileChangeListener(this); + } + + private synchronized void parseFile() + { + File file = FileUtil.toFile(fo); + InputSource is; + + try { + is = new InputSource(new FileInputStream(file)); + } + catch (FileNotFoundException fnfe) { + System.out.println("Couldn't find file: " + file.getName()); + return; + } + + document = null; + try { + document = XMLUtil.parse(is, false, false, null, null); + } + catch (IOException ioe) { + System.out.println("IO Error parsing file: " + file.getName()); + } + catch (SAXException se) { + System.out.println("Sax Error parsing file: " + file.getName()); + } + } + + public synchronized NodeList getScriptElements() + { + if (document == null) + parseFile(); + + if (document != null) + return document.getElementsByTagName("script"); + return null; + } + + public void addChangeListener(ChangeListener cl) { + if (listeners == null) + listeners = new HashSet(); + + listeners.add(cl); + } + + public void removeChangeListener(ChangeListener cl) { + if (listeners == null) + return; + + listeners.remove(cl); + } + + public void fileChanged(FileEvent fe) { + parseFile(); + + if (listeners != null) { + Iterator iter = listeners.iterator(); + + while (iter.hasNext()) + ((ChangeListener)iter.next()).stateChanged(new ChangeEvent(this)); + } + } + + public void fileAttributeChanged(FileAttributeEvent fe) {} + public void fileDataCreated(FileEvent fe) {} + public void fileDeleted(FileEvent fe) {} + public void fileFolderCreated(FileEvent fe) {} + public void fileRenamed(FileRenameEvent fe) {} +} diff --git a/scripting/java/org/openoffice/netbeans/modules/office/actions/ParcelFolderCookie.java b/scripting/java/org/openoffice/netbeans/modules/office/actions/ParcelFolderCookie.java new file mode 100644 index 000000000000..714204ffde41 --- /dev/null +++ b/scripting/java/org/openoffice/netbeans/modules/office/actions/ParcelFolderCookie.java @@ -0,0 +1,42 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +package org.openoffice.netbeans.modules.office.actions; + +import org.openide.nodes.Node; + +public interface ParcelFolderCookie extends Node.Cookie +{ + public void generate(); + + public boolean configure(); + + public void setClasspath(String value); + public String getClasspath(); + + public String getLanguage(); +} diff --git a/scripting/java/org/openoffice/netbeans/modules/office/actions/ParcelFolderSupport.java b/scripting/java/org/openoffice/netbeans/modules/office/actions/ParcelFolderSupport.java new file mode 100644 index 000000000000..6644b0e66d44 --- /dev/null +++ b/scripting/java/org/openoffice/netbeans/modules/office/actions/ParcelFolderSupport.java @@ -0,0 +1,257 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +package org.openoffice.netbeans.modules.office.actions; + +import java.util.Vector; +import java.util.StringTokenizer; + +import java.io.*; +import java.beans.PropertyVetoException; +import java.awt.Dialog; + +import org.w3c.dom.Document; +import org.xml.sax.InputSource; +import org.xml.sax.SAXException; + +import org.openide.TopManager; +import org.openide.DialogDescriptor; +import org.openide.ErrorManager; +import org.openide.xml.XMLUtil; +import org.openide.execution.NbClassPath; + +import org.openide.cookies.OpenCookie; +import org.openide.loaders.DataObject; +import org.openide.loaders.DataNode; + +import org.openide.filesystems.FileObject; +import org.openide.filesystems.FileSystem; +import org.openide.filesystems.JarFileSystem; +import org.openide.filesystems.FileUtil; +import org.openide.filesystems.Repository; + +import org.openide.nodes.*; +import org.openide.windows.OutputWriter; + +import org.openoffice.netbeans.modules.office.loader.ParcelFolder; +import org.openoffice.netbeans.modules.office.options.OfficeSettings; +import org.openoffice.netbeans.modules.office.utils.ManifestParser; + +import com.sun.star.script.framework.container.ParcelDescriptor; + +import org.openoffice.idesupport.zip.ParcelZipper; +import org.openoffice.idesupport.filter.FileFilter; +import org.openoffice.idesupport.ui.ConfigurePanel; + +public class ParcelFolderSupport implements ParcelFolderCookie +{ + protected ParcelFolder parcelFolder; + private ConfigurePanel configuror = null; + + public ParcelFolderSupport(ParcelFolder parcelFolder) { + this.parcelFolder = parcelFolder; + } + + public String getLanguage() { + ParcelDescriptor descriptor = getParcelDescriptor(); + + if (descriptor == null) { + return ""; + } + else { + return descriptor.getLanguage(); + } + } + + public String getClasspath() { + ParcelDescriptor descriptor = getParcelDescriptor(); + + if (descriptor == null) { + return ""; + } + else { + return descriptor.getLanguageProperty("classpath"); + } + } + + public void setClasspath(String value) { + ParcelDescriptor descriptor = getParcelDescriptor(); + + if (descriptor != null) { + descriptor.setLanguageProperty("classpath", value); + + try { + descriptor.write(); + } + catch (IOException ioe) { + ErrorManager.getDefault().notify(ioe); + } + } + } + + private ParcelDescriptor getParcelDescriptor() { + FileObject primary = parcelFolder.getPrimaryFile(); + + File contents = FileUtil.toFile( + primary.getFileObject(ParcelZipper.CONTENTS_DIRNAME)); + + return ParcelDescriptor.getParcelDescriptor(contents); + } + + public void generate() { + ParcelFolder.ParcelFolderNode node = + (ParcelFolder.ParcelFolderNode)parcelFolder.getNodeDelegate(); + + FileObject parcelBase = parcelFolder.getPrimaryFile(); + FileObject contentsBase = + parcelBase.getFileObject(ParcelZipper.CONTENTS_DIRNAME); + + File parcelDir = FileUtil.toFile(parcelBase); + File contentsDir = FileUtil.toFile(contentsBase); + + // The Location property is not displayed so just + // use the Parcel Recipe directory as the target directory + File targetDir = FileUtil.toFile(parcelFolder.getPrimaryFile()); + File targetfile = new File(targetDir, File.separator + + parcelBase.getName() + "." + ParcelZipper.PARCEL_EXTENSION); + + boolean proceed = configure(); + if (proceed == false) { + return; + } + + final OutputWriter out = + ParcelSupport.getOutputWindowWriter(parcelDir.getName() + " (generating)"); + try { + out.println("Generating: " + parcelDir.getName(), null); + ParcelZipper.getParcelZipper().zipParcel(contentsDir, targetfile, node.getFileFilter()); + out.println("\nGENERATION SUCCESSFUL."); + out.println("\nRight click on the generated parcel to deploy it"); + + if (targetDir.equals(parcelDir)) { + parcelBase.refresh(true); + } + } + catch (IOException ioe) { + out.println("GENERATION FAILED: reason: " + ioe.getClass().getName() + ": "+ ioe.getMessage()); + } + finally + { + if( out != null) + { + out.close(); + } + } + } + + public boolean configure() { + + FileObject primary = parcelFolder.getPrimaryFile(); + + File contents = FileUtil.toFile( + primary.getFileObject(ParcelZipper.CONTENTS_DIRNAME)); + + Vector classpath = getConfigureClasspath(); + classpath.addElement(contents.getAbsolutePath()); + + try { + ParcelDescriptor descriptor = getParcelDescriptor(); + if (descriptor == null) { + descriptor = ParcelDescriptor.createParcelDescriptor(contents); + } + + if (configuror == null) { + configuror = new ConfigurePanel(contents.getAbsolutePath(), + classpath, descriptor); + } + else { + configuror.reload(contents.getAbsolutePath(), classpath, + descriptor); + } + } + catch (IOException ioe) { + ErrorManager.getDefault().notify(ioe); + return false; + } + + DialogDescriptor dd = new DialogDescriptor(configuror, + ConfigurePanel.DIALOG_TITLE); + + Dialog dialog = TopManager.getDefault().createDialog(dd); + dialog.show(); + + if (dd.getValue() == DialogDescriptor.OK_OPTION) { + try { + ParcelDescriptor descriptor = configuror.getConfiguration(); + descriptor.write(); + } + catch (Exception e) { + ErrorManager.getDefault().notify(e); + } + } + else { + return false; + } + return true; + } + + private Vector getConfigureClasspath() { + Vector result = new Vector(); + + String classpath = NbClassPath.createRepositoryPath().getClassPath(); + if ( System.getProperty( "os.name" ).startsWith( "Windows" ) ) + { + // under windows path is enclosed by quotes + // e.g. C:\path1;d:\path2 would appear as + // "C:\path1;d:\path2" therefore for us + // we need to remove 1 character at either end of the + // classpath returned from "createRepositoryPath().getClassPath()" + + if ( classpath.startsWith("\"") && classpath.endsWith("\"") ) + { + StringBuffer buff = new StringBuffer(classpath); + buff.delete(0,1); + buff.delete( buff.length() - 1, buff.length() ); + classpath = buff.toString(); + } + } + StringTokenizer tokens = new StringTokenizer(classpath, File.pathSeparator); + + while(tokens.hasMoreTokens()) + result.addElement(tokens.nextToken()); + + OfficeSettings settings = OfficeSettings.getDefault(); + File classesDir = new File(settings.getOfficeDirectory().getPath( + File.separator + "program" + File.separator + "classes")); + File[] jarfiles = classesDir.listFiles(); + + for (int i = 0; i < jarfiles.length; i++) + result.addElement(jarfiles[i].getAbsolutePath()); + + return result; + } +} diff --git a/scripting/java/org/openoffice/netbeans/modules/office/actions/ParcelSupport.java b/scripting/java/org/openoffice/netbeans/modules/office/actions/ParcelSupport.java new file mode 100644 index 000000000000..5c9fa8b02789 --- /dev/null +++ b/scripting/java/org/openoffice/netbeans/modules/office/actions/ParcelSupport.java @@ -0,0 +1,191 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +package org.openoffice.netbeans.modules.office.actions; + +import java.io.File; +import java.io.IOException; +import java.beans.PropertyVetoException; +import java.util.Enumeration; +import java.util.Calendar; + +import org.openide.TopManager; +import org.openide.NotifyDescriptor; +import org.openide.windows.OutputWriter; +import org.openide.windows.InputOutput; + +import org.openide.ErrorManager; +import org.openide.nodes.Node; +import org.openide.filesystems.Repository; +import org.openide.filesystems.FileSystem; +import org.openide.filesystems.FileObject; +import org.openide.filesystems.FileUtil; +import org.openide.filesystems.FileEvent; + +import org.openoffice.idesupport.zip.ParcelZipper; + +import org.openoffice.netbeans.modules.office.options.OfficeSettings; +import org.openoffice.netbeans.modules.office.utils.NagDialog; +import org.openoffice.netbeans.modules.office.utils.ZipMounter; +import org.openoffice.netbeans.modules.office.utils.ManifestParser; + +public class ParcelSupport implements ParcelCookie +{ + private FileObject fo; + private ParcelZipper zipper = ParcelZipper.getParcelZipper(); + private String language = null; + + public ParcelSupport(FileObject fo) { + this.fo = fo; + } + + public File getFile() { + return FileUtil.toFile(fo); + } + + public String getLanguage() { + if (language == null) { + try { + language = zipper.getParcelLanguage(getFile()); + } + catch (IOException ioe) { + return null; + } + } + return language; + } + + public void mount() + { + File parcel = FileUtil.toFile(fo); + + if (parcel != null) { + try { + ZipMounter.getZipMounter().mountZipFile(parcel); + } + catch (IOException ioe) { + ErrorManager.getDefault().notify(ioe); + } + catch (PropertyVetoException pve) { + ErrorManager.getDefault().notify(pve); + } + } + } + + public boolean deploy(File target) { + File source = FileUtil.toFile(fo); + + if (!target.isDirectory()) { + OfficeSettings settings = OfficeSettings.getDefault(); + String message = "If you already have this document open in " + + "Office, please close it before continuing. Click OK to " + + "continue deployment."; + + if (settings.getWarnBeforeDocDeploy() == true) { + NagDialog warning = NagDialog.createConfirmationDialog( + message, "Show this message in future", true); + + boolean result = warning.show(); + + if (warning.getState() == false) + settings.setWarnBeforeDocDeploy(false); + + if (result == false) + return false; + } + } + + OutputWriter out = + getOutputWindowWriter(fo.getName() + " (deploying)"); + + try { + if (zipper.isOverwriteNeeded(source, target) == true) + if (promptForOverwrite(source, target) == false) + return false; + } + catch (IOException ioe) { + out.println("DEPLOYMENT FAILED: reason: " + + ioe.getClass().getName() + ": "+ ioe.getMessage()); + return false; + } + + try { + out.println("Deploying: " + fo.getName() + + "\nTo: " + target.getAbsolutePath(), null); + + zipper.deployParcel(source, target); + + out.println("\nDEPLOYMENT SUCCESSFUL."); + + FileObject[] fileobjs = FileUtil.fromFile(target); + if (fileobjs != null) { + for (int i = 0; i < fileobjs.length; i++) + fileobjs[i].refresh(true); + } + } + catch (IOException ioe) { + out.println("DEPLOYMENT FAILED: reason: " + + ioe.getClass().getName() + ": "+ ioe.getMessage()); + return false; + } + finally { + if( out != null) + out.close(); + } + return true; + } + + public static OutputWriter getOutputWindowWriter(String title) { + InputOutput io = TopManager.getDefault().getIO(title, false); + io.setFocusTaken(true); + io.setOutputVisible(true); + + OutputWriter out = io.getOut(); + try { + out.reset(); + } + catch( IOException e) { + e.printStackTrace(System.err); + } + out.println(Calendar.getInstance().getTime() + ":\n"); + return out; + } + + private boolean promptForOverwrite(File source, File target) { + String message = source.getName() + " has already been deployed " + + "to this target. Do you wish to overwrite it?"; + + NotifyDescriptor d = new NotifyDescriptor.Confirmation( + message, NotifyDescriptor.OK_CANCEL_OPTION); + TopManager.getDefault().notify(d); + + if (d.getValue() == NotifyDescriptor.CANCEL_OPTION) + return false; + else + return true; + } +} |