summaryrefslogtreecommitdiffstats
path: root/scripting/java/org/openoffice/netbeans/modules/office/utils
diff options
context:
space:
mode:
authorTomas O'Connor <toconnor@openoffice.org>2002-11-12 13:31:11 +0000
committerTomas O'Connor <toconnor@openoffice.org>2002-11-12 13:31:11 +0000
commite75a5b278c89166503ec8a875655724adb2b05a3 (patch)
tree23f81328bc7edf89423d65e40351ffe64c35aecc /scripting/java/org/openoffice/netbeans/modules/office/utils
parentInitial checkin of org.openoffice.idesupport java package for shared (diff)
downloadcore-e75a5b278c89166503ec8a875655724adb2b05a3.tar.gz
core-e75a5b278c89166503ec8a875655724adb2b05a3.zip
Add Office Scripting in Java NetBeans module
Diffstat (limited to 'scripting/java/org/openoffice/netbeans/modules/office/utils')
-rw-r--r--scripting/java/org/openoffice/netbeans/modules/office/utils/FrameworkJarChecker.java113
-rw-r--r--scripting/java/org/openoffice/netbeans/modules/office/utils/ManifestParser.java70
-rw-r--r--scripting/java/org/openoffice/netbeans/modules/office/utils/NagDialog.java100
-rw-r--r--scripting/java/org/openoffice/netbeans/modules/office/utils/PackageRemover.java60
-rw-r--r--scripting/java/org/openoffice/netbeans/modules/office/utils/ZipMounter.java65
5 files changed, 408 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..afee822e9f4e
--- /dev/null
+++ b/scripting/java/org/openoffice/netbeans/modules/office/utils/FrameworkJarChecker.java
@@ -0,0 +1,113 @@
+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());
+
+ 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());
+
+ 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..41f069985604
--- /dev/null
+++ b/scripting/java/org/openoffice/netbeans/modules/office/utils/ManifestParser.java
@@ -0,0 +1,70 @@
+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 org.openoffice.netbeans.modules.office.options.OfficeSettings;
+import org.openoffice.idesupport.xml.XMLParser;
+
+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 {
+ is = new InputSource(inputStream);
+ is.setSystemId("file://" +
+ OfficeSettings.getDefault().getOfficeDirectory() +
+ File.separator + "share" +
+ File.separator + "dtd" +
+ File.separator + "officedocument" +
+ File.separator + "1_0" + File.separator);
+ 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..44ce96c1f202
--- /dev/null
+++ b/scripting/java/org/openoffice/netbeans/modules/office/utils/NagDialog.java
@@ -0,0 +1,100 @@
+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/PackageRemover.java b/scripting/java/org/openoffice/netbeans/modules/office/utils/PackageRemover.java
new file mode 100644
index 000000000000..f08ea7832268
--- /dev/null
+++ b/scripting/java/org/openoffice/netbeans/modules/office/utils/PackageRemover.java
@@ -0,0 +1,60 @@
+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));
+
+ String line;
+ while ((line = in.readLine()) != null) {
+ if (line.startsWith("package") && line.indexOf(ParcelZipper.CONTENTS_DIRNAME) != -1) {
+ // got package declaration, do not write it
+ continue;
+ }
+ else {
+ out.write(line, 0, line.length());
+ out.newLine();
+ }
+ }
+
+ while ((line = in.readLine()) != null) {
+ out.write(line, 0, line.length());
+ out.newLine();
+ }
+
+ in.close();
+ out.close();
+
+ if (source.delete() == false) {
+ tmp.delete();
+ throw new IOException("Could not overwrite " + source);
+ }
+ else
+ tmp.renameTo(source);
+ }
+
+ 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..a328bb765e18
--- /dev/null
+++ b/scripting/java/org/openoffice/netbeans/modules/office/utils/ZipMounter.java
@@ -0,0 +1,65 @@
+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;
+ }
+}