summaryrefslogtreecommitdiff
path: root/scripting/java/org/openoffice/netbeans/modules/office/utils
diff options
context:
space:
mode:
Diffstat (limited to 'scripting/java/org/openoffice/netbeans/modules/office/utils')
-rw-r--r--scripting/java/org/openoffice/netbeans/modules/office/utils/FrameworkJarChecker.java140
-rw-r--r--scripting/java/org/openoffice/netbeans/modules/office/utils/ManifestParser.java97
-rw-r--r--scripting/java/org/openoffice/netbeans/modules/office/utils/NagDialog.java127
-rw-r--r--scripting/java/org/openoffice/netbeans/modules/office/utils/OfficeModule.java68
-rw-r--r--scripting/java/org/openoffice/netbeans/modules/office/utils/PackageRemover.java106
-rw-r--r--scripting/java/org/openoffice/netbeans/modules/office/utils/ZipMounter.java92
6 files changed, 630 insertions, 0 deletions
diff --git a/scripting/java/org/openoffice/netbeans/modules/office/utils/FrameworkJarChecker.java b/scripting/java/org/openoffice/netbeans/modules/office/utils/FrameworkJarChecker.java
new file mode 100644
index 000000000000..a9ac1b4bdaa9
--- /dev/null
+++ b/scripting/java/org/openoffice/netbeans/modules/office/utils/FrameworkJarChecker.java
@@ -0,0 +1,140 @@
+/*************************************************************************
+ *
+ * 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.utils;
+
+import java.io.File;
+import java.io.IOException;
+import java.beans.PropertyVetoException;
+
+import org.openide.filesystems.Repository;
+import org.openide.filesystems.FileSystem;
+import org.openide.filesystems.JarFileSystem;
+
+import org.openoffice.idesupport.SVersionRCFile;
+import org.openoffice.netbeans.modules.office.options.OfficeSettings;
+
+public class FrameworkJarChecker {
+
+ public static void mountDependencies() {
+ String unoilPath = SVersionRCFile.getPathForUnoil(
+ OfficeSettings.getDefault().getOfficeDirectory().getPath());
+
+ if (unoilPath == null)
+ return;
+
+ File unoilFile = new File(unoilPath + File.separator + "unoil.jar");
+ JarFileSystem jfs = new JarFileSystem();
+ try {
+ jfs.setJarFile(unoilFile);
+ }
+ catch (IOException ioe) {
+ return;
+ }
+ catch (PropertyVetoException pve) {
+ return;
+ }
+
+ FileSystem result;
+ try {
+ result =
+ Repository.getDefault().findFileSystem(jfs.getSystemName());
+ }
+ catch(Exception exp) {
+ result = null;
+ }
+ finally {
+ jfs.removeNotify();
+ }
+
+ if(result == null) {
+ // warnBeforeMount();
+ JarFileSystem newjfs = new JarFileSystem();
+ try {
+ newjfs.setJarFile(unoilFile);
+ }
+ catch (IOException ioe) {
+ return;
+ }
+ catch (PropertyVetoException pve) {
+ return;
+ }
+ Repository.getDefault().addFileSystem(newjfs);
+ newjfs.setHidden(true);
+ }
+ }
+
+ public static void unmountDependencies() {
+ String unoilPath = SVersionRCFile.getPathForUnoil(
+ OfficeSettings.getDefault().getOfficeDirectory().getPath());
+
+ if (unoilPath == null)
+ return;
+
+ File unoilFile = new File(unoilPath + File.separator + "unoil.jar");
+ JarFileSystem jfs = new JarFileSystem();
+ try {
+ jfs.setJarFile(unoilFile);
+ }
+ catch (IOException ioe) {
+ return;
+ }
+ catch (PropertyVetoException pve) {
+ return;
+ }
+
+ FileSystem result;
+ try {
+ result =
+ Repository.getDefault().findFileSystem(jfs.getSystemName());
+ if(result != null)
+ Repository.getDefault().removeFileSystem(result);
+ }
+ catch(Exception exp) {
+ }
+ }
+
+ private static void warnBeforeMount() {
+ OfficeSettings settings = OfficeSettings.getDefault();
+
+ if (settings.getWarnBeforeMount() == false)
+ return;
+
+ String message = "The Office Scripting Framework support jar file " +
+ "is not mounted, so Office scripts will not compile. NetBeans " +
+ "is going to mount this jar file automatically.";
+
+ String prompt = "Show this message in future.";
+
+ NagDialog warning = NagDialog.createInformationDialog(
+ message, prompt, true);
+
+ if (warning.getState() == false) {
+ settings.setWarnBeforeMount(false);
+ }
+ }
+}
diff --git a/scripting/java/org/openoffice/netbeans/modules/office/utils/ManifestParser.java b/scripting/java/org/openoffice/netbeans/modules/office/utils/ManifestParser.java
new file mode 100644
index 000000000000..b15d4b270027
--- /dev/null
+++ b/scripting/java/org/openoffice/netbeans/modules/office/utils/ManifestParser.java
@@ -0,0 +1,97 @@
+/*************************************************************************
+ *
+ * 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.utils;
+
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.io.IOException;
+import java.io.File;
+
+import org.w3c.dom.Document;
+import org.xml.sax.InputSource;
+import org.xml.sax.SAXException;
+import org.xml.sax.SAXParseException;
+
+import org.openide.xml.XMLUtil;
+
+import com.sun.star.script.framework.container.XMLParser;
+import org.openoffice.netbeans.modules.office.options.OfficeSettings;
+import org.openoffice.idesupport.OfficeInstallation;
+
+public class ManifestParser implements XMLParser {
+
+ private static ManifestParser parser = null;
+
+ private ManifestParser() {
+ }
+
+ public static ManifestParser getManifestParser() {
+ if (parser == null) {
+ synchronized(ManifestParser.class) {
+ if (parser == null)
+ parser = new ManifestParser();
+ }
+ }
+ return parser;
+ }
+
+ public Document parse(InputStream inputStream) {
+ InputSource is;
+ Document result = null;
+
+ try {
+ OfficeInstallation oi = OfficeSettings.getDefault().getOfficeDirectory();
+ String id = oi.getURL("share/dtd/officedocument/1_0/");
+
+ is = new InputSource(inputStream);
+ is.setSystemId(id);
+
+ result = XMLUtil.parse(is, false, false, null, null);
+ }
+ catch (IOException ioe) {
+ System.out.println("IO Error parsing stream.");
+ return null;
+ }
+ catch (SAXParseException spe) {
+ System.out.println("Sax Error parsing stream: " + spe.getMessage());
+ System.out.println("\tPublicId: " + spe.getPublicId());
+ System.out.println("\tSystemId: " + spe.getSystemId());
+ return null;
+ }
+ catch (SAXException se) {
+ System.out.println("Sax Error parsing stream: " + se.getMessage());
+ return null;
+ }
+
+ return result;
+ }
+
+ public void write(Document doc, OutputStream out) throws IOException {
+ XMLUtil.write(doc, out, "");
+ }
+}
diff --git a/scripting/java/org/openoffice/netbeans/modules/office/utils/NagDialog.java b/scripting/java/org/openoffice/netbeans/modules/office/utils/NagDialog.java
new file mode 100644
index 000000000000..05bd8ee966a4
--- /dev/null
+++ b/scripting/java/org/openoffice/netbeans/modules/office/utils/NagDialog.java
@@ -0,0 +1,127 @@
+/*************************************************************************
+ *
+ * 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.utils;
+
+import java.awt.BorderLayout;
+import java.awt.Dimension;
+
+import javax.swing.JPanel;
+import javax.swing.JOptionPane;
+import javax.swing.JCheckBox;
+import javax.swing.border.EmptyBorder;
+
+import org.openide.TopManager;
+import org.openide.NotifyDescriptor;
+
+public class NagDialog {
+
+ private NotifyDescriptor descriptor;
+ private JPanel panel;
+ private JCheckBox checkbox;
+
+ private NagDialog(String message, String prompt, boolean initialState,
+ int type) {
+ initUI(message, prompt, initialState, type);
+ }
+
+ public static NagDialog createInformationDialog(
+ String message, String prompt, boolean initialState) {
+ NagDialog result = new NagDialog(
+ message, prompt, initialState, JOptionPane.INFORMATION_MESSAGE);
+
+ result.setDescriptor(new NotifyDescriptor.Message(result.getPanel(),
+ NotifyDescriptor.PLAIN_MESSAGE));
+
+ return result;
+ }
+
+ public static NagDialog createConfirmationDialog(
+ String message, String prompt, boolean initialState) {
+ NagDialog result = new NagDialog(
+ message, prompt, initialState, JOptionPane.QUESTION_MESSAGE);
+
+ result.setDescriptor(new NotifyDescriptor.Confirmation(
+ result.getPanel(), NotifyDescriptor.OK_CANCEL_OPTION,
+ NotifyDescriptor.PLAIN_MESSAGE));
+
+ return result;
+ }
+
+ public boolean show() {
+ TopManager.getDefault().notify(descriptor);
+
+ if (descriptor.getValue() == NotifyDescriptor.OK_OPTION)
+ return true;
+ else
+ return false;
+ }
+
+ public boolean getState() {
+ return checkbox.isSelected();
+ }
+
+ private JPanel getPanel() {
+ return this.panel;
+ }
+
+ private void setDescriptor(NotifyDescriptor descriptor) {
+ this.descriptor = descriptor;
+ }
+
+ private void initUI(String message, String prompt, boolean initialState,
+ int type) {
+
+ this.panel = new JPanel();
+ JOptionPane optionPane = new JOptionPane(message, type, 0, null,
+ new Object[0], null)
+ {
+ public int getMaxCharactersPerLineCount() {
+ return 100;
+ }
+ };
+ optionPane.setUI(new javax.swing.plaf.basic.BasicOptionPaneUI() {
+ public Dimension getMinimumOptionPaneSize() {
+ if (minimumSize == null) {
+ return new Dimension(MinimumWidth, 50);
+ }
+ return new Dimension(minimumSize.width, 50);
+ }
+ });
+ optionPane.setWantsInput(false);
+
+ JPanel checkPanel = new JPanel();
+ checkbox = new JCheckBox(prompt, initialState);
+ checkPanel.setLayout(new BorderLayout());
+ checkPanel.setBorder(new EmptyBorder(0, 20, 0, 0));
+ checkPanel.add(checkbox, BorderLayout.WEST);
+
+ this.panel.setLayout(new BorderLayout());
+ this.panel.add(optionPane, BorderLayout.CENTER);
+ this.panel.add(checkPanel, BorderLayout.SOUTH);
+ }
+}
diff --git a/scripting/java/org/openoffice/netbeans/modules/office/utils/OfficeModule.java b/scripting/java/org/openoffice/netbeans/modules/office/utils/OfficeModule.java
new file mode 100644
index 000000000000..8cf16eb08a82
--- /dev/null
+++ b/scripting/java/org/openoffice/netbeans/modules/office/utils/OfficeModule.java
@@ -0,0 +1,68 @@
+/*************************************************************************
+ *
+ * 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.utils;
+
+import org.openide.TopManager;
+import org.openide.WizardDescriptor;
+import org.openide.NotifyDescriptor;
+import org.openide.modules.ModuleInstall;
+
+import com.sun.star.script.framework.container.XMLParserFactory;
+import org.openoffice.idesupport.OfficeInstallation;
+import org.openoffice.netbeans.modules.office.wizard.InstallationPathDescriptor;
+import org.openoffice.netbeans.modules.office.options.OfficeSettings;
+
+public class OfficeModule extends ModuleInstall {
+
+ private static final long serialVersionUID = -8499324854301243852L;
+
+ public void installed () {
+ WizardDescriptor wiz = new InstallationPathDescriptor();
+ TopManager.getDefault().createDialog(wiz).show();
+
+ if(wiz.getValue() == NotifyDescriptor.OK_OPTION) {
+ OfficeInstallation oi = (OfficeInstallation)
+ wiz.getProperty(InstallationPathDescriptor.PROP_INSTALLPATH);
+
+ OfficeSettings settings = OfficeSettings.getDefault();
+ settings.setOfficeDirectory(oi);
+ }
+ FrameworkJarChecker.mountDependencies();
+ XMLParserFactory.setParser(ManifestParser.getManifestParser());
+ }
+
+ public void restored () {
+ FrameworkJarChecker.mountDependencies();
+ XMLParserFactory.setParser(ManifestParser.getManifestParser());
+ }
+
+ public boolean closing () {
+ FrameworkJarChecker.unmountDependencies();
+ return true;
+ }
+}
diff --git a/scripting/java/org/openoffice/netbeans/modules/office/utils/PackageRemover.java b/scripting/java/org/openoffice/netbeans/modules/office/utils/PackageRemover.java
new file mode 100644
index 000000000000..07c2c939372f
--- /dev/null
+++ b/scripting/java/org/openoffice/netbeans/modules/office/utils/PackageRemover.java
@@ -0,0 +1,106 @@
+/*************************************************************************
+ *
+ * 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.utils;
+
+import java.io.File;
+import java.io.FileReader;
+import java.io.FileWriter;
+import java.io.BufferedReader;
+import java.io.BufferedWriter;
+import java.io.IOException;
+
+import org.openoffice.idesupport.zip.ParcelZipper;
+
+public class PackageRemover {
+ private PackageRemover() {
+ }
+
+ public static void removeDeclaration(File source) throws IOException {
+ File tmp = new File(source.getAbsolutePath() + ".tmp");
+
+ BufferedReader in = new BufferedReader(new FileReader(source));
+ BufferedWriter out = new BufferedWriter(new FileWriter(tmp));
+
+ try {
+ String line;
+ while ((line = in.readLine()) != null) {
+ if (line.startsWith("package")) {
+ String newDeclaration = evaluate(line);
+ if (newDeclaration != null) {
+ out.write(newDeclaration, 0, newDeclaration.length());
+ out.newLine();
+ }
+ }
+ else {
+ out.write(line, 0, line.length());
+ out.newLine();
+ }
+ }
+ }
+ finally {
+ if (in != null) {
+ in.close();
+ }
+ if (out != null) {
+ out.close();
+ }
+ }
+
+ if (source.delete() == false) {
+ tmp.delete();
+ throw new IOException("Could not overwrite " + source);
+ }
+ else {
+ tmp.renameTo(source);
+ }
+ }
+
+ public static String evaluate(String line) {
+
+ int idx = line.indexOf(ParcelZipper.CONTENTS_DIRNAME);
+ if (idx == -1)
+ return line;
+
+ idx = idx + ParcelZipper.CONTENTS_DIRNAME.length();
+ if (line.charAt(idx) == '.')
+ return "package " + line.substring(idx + 1);;
+
+ return null;
+ }
+
+ public static void main(String[] args) {
+ File source = new File(args[0]);
+
+ try {
+ removeDeclaration(source);
+ }
+ catch (IOException ioe) {
+ ioe.printStackTrace();
+ }
+ }
+}
diff --git a/scripting/java/org/openoffice/netbeans/modules/office/utils/ZipMounter.java b/scripting/java/org/openoffice/netbeans/modules/office/utils/ZipMounter.java
new file mode 100644
index 000000000000..8616bfaefdb2
--- /dev/null
+++ b/scripting/java/org/openoffice/netbeans/modules/office/utils/ZipMounter.java
@@ -0,0 +1,92 @@
+/*************************************************************************
+ *
+ * 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.utils;
+
+import java.io.*;
+import java.util.zip.*;
+import java.beans.PropertyVetoException;
+
+import org.openide.filesystems.FileSystem;
+import org.openide.filesystems.Repository;
+
+import org.openoffice.netbeans.modules.office.filesystem.OpenOfficeDocFileSystem;
+
+public class ZipMounter
+{
+ private static ZipMounter mounter = null;
+
+ private ZipMounter() {
+ }
+
+ public static ZipMounter getZipMounter() {
+ if (mounter == null) {
+ synchronized(ZipMounter.class) {
+ if (mounter == null)
+ mounter = new ZipMounter();
+ }
+ }
+ return mounter;
+ }
+
+ public void mountZipFile(File zipfile)
+ throws IOException, PropertyVetoException
+ {
+ if (zipfile != null) {
+ addDocumentToRepository(zipfile, true);
+ }
+ }
+
+ private FileSystem addDocumentToRepository(File rootFile, boolean writeable)
+ throws IOException, PropertyVetoException
+ {
+ Repository repo = Repository.getDefault();
+ OpenOfficeDocFileSystem oofs;
+ oofs = (OpenOfficeDocFileSystem)getMountedDocument(rootFile);
+ if(oofs != null)
+ repo.removeFileSystem(oofs);
+ oofs = new OpenOfficeDocFileSystem();
+ oofs.setDocument(rootFile);
+ repo.addFileSystem(oofs);
+ return oofs;
+ }
+
+ /** @return FileSystem which has given jar file as its root or
+ * null if no such file system could be found in repository */
+ private FileSystem getMountedDocument(File rootFile)
+ {
+ if (rootFile == null)
+ return null;
+ FileSystem oofs = null;
+ try {
+ oofs = Repository.getDefault().findFileSystem(
+ OpenOfficeDocFileSystem.computeSystemName(rootFile));
+ } catch(Exception exp) {
+ }
+ return oofs;
+ }
+}