diff options
7 files changed, 191 insertions, 130 deletions
diff --git a/scripting/java/org/openoffice/idesupport/CommandLineTools.java b/scripting/java/org/openoffice/idesupport/CommandLineTools.java index 2b33ef03ee5c..51da687f2038 100644 --- a/scripting/java/org/openoffice/idesupport/CommandLineTools.java +++ b/scripting/java/org/openoffice/idesupport/CommandLineTools.java @@ -2,9 +2,9 @@ * * $RCSfile: CommandLineTools.java,v $ * - * $Revision: 1.3 $ + * $Revision: 1.4 $ * - * last change: $Author: toconnor $ $Date: 2003-02-26 17:14:09 $ + * last change: $Author: toconnor $ $Date: 2003-03-12 18:26:28 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -95,11 +95,13 @@ public class CommandLineTools { } private void printUsage() { + System.out.println("java " + getClass().getName() + " -h " + + "prints this message"); System.out.println("java " + getClass().getName() + " -d " + "<script parcel zip file> " + "<destination document or directory>"); System.out.println("java " + getClass().getName() + " -g " + - "[parcel root directory] [options]"); + "[parcel root directory] [options] [script names]"); System.out.println("options:"); System.out.println("\t[-l language[=supported extension 1[" + File.pathSeparator + "supported extension 2]]]"); diff --git a/scripting/java/org/openoffice/idesupport/OfficeDocument.java b/scripting/java/org/openoffice/idesupport/OfficeDocument.java index c7caa81fc64a..9a372097a1a0 100644 --- a/scripting/java/org/openoffice/idesupport/OfficeDocument.java +++ b/scripting/java/org/openoffice/idesupport/OfficeDocument.java @@ -2,9 +2,9 @@ * * $RCSfile: OfficeDocument.java,v $ * - * $Revision: 1.5 $ + * $Revision: 1.6 $ * - * last change: $Author: toconnor $ $Date: 2003-01-30 16:22:15 $ + * last change: $Author: toconnor $ $Date: 2003-03-12 18:26:28 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -76,7 +76,8 @@ public class OfficeDocument public static final String PARCEL_PREFIX_DIR = ParcelZipper.PARCEL_PREFIX_DIR; - public static final String[] OFFICE_EXTENSIONS = {".sxc" , ".sxw"}; + public static final String[] OFFICE_EXTENSIONS = + {".sxc" , ".sxw", ".sxi", ".sxd"}; public static final String OFFICE_PRODUCT_NAME = "OpenOffice.org"; private File file = null; diff --git a/scripting/java/org/openoffice/idesupport/SVersionRCFile.java b/scripting/java/org/openoffice/idesupport/SVersionRCFile.java index ea2a8a454af7..7f4e810faf4a 100644 --- a/scripting/java/org/openoffice/idesupport/SVersionRCFile.java +++ b/scripting/java/org/openoffice/idesupport/SVersionRCFile.java @@ -2,9 +2,9 @@ *
* $RCSfile: SVersionRCFile.java,v $
*
- * $Revision: 1.8 $
+ * $Revision: 1.9 $
*
- * last change: $Author: toconnor $ $Date: 2003-02-20 12:04:18 $
+ * last change: $Author: toconnor $ $Date: 2003-03-12 18:26:28 $
*
* The Contents of this file are made available subject to the terms of
* either of the following licenses
@@ -147,18 +147,20 @@ public class SVersionRCFile { long l = sversionrc.lastModified();
if (l > lastModified) {
- BufferedReader br;
+ BufferedReader br = null;
try {
br = new BufferedReader(new FileReader(sversionrc));
+ load(br);
+ lastModified = l;
}
catch (FileNotFoundException fnfe) {
throw new IOException(fnfe.getMessage());
}
-
- load(br);
- br.close();
- lastModified = l;
+ finally {
+ if (br != null)
+ br.close();
+ }
}
return versions.elements();
}
diff --git a/scripting/java/org/openoffice/idesupport/xml/Manifest.java b/scripting/java/org/openoffice/idesupport/xml/Manifest.java index c9a08660684a..90c4cdfae29f 100644 --- a/scripting/java/org/openoffice/idesupport/xml/Manifest.java +++ b/scripting/java/org/openoffice/idesupport/xml/Manifest.java @@ -2,9 +2,9 @@ * * $RCSfile: Manifest.java,v $ * - * $Revision: 1.5 $ + * $Revision: 1.6 $ * - * last change: $Author: toconnor $ $Date: 2003-02-04 13:37:47 $ + * last change: $Author: toconnor $ $Date: 2003-03-12 18:26:29 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -154,11 +154,18 @@ public class Manifest { public InputStream getInputStream() throws IOException { InputStream result = null; + ByteArrayOutputStream out = null; - ByteArrayOutputStream out = new ByteArrayOutputStream(); - write(out); - result = new ByteArrayInputStream(out.toByteArray()); - // result = replaceNewlines(out.toByteArray()); + try { + out = new ByteArrayOutputStream(); + write(out); + result = new ByteArrayInputStream(out.toByteArray()); + // result = replaceNewlines(out.toByteArray()); + } + finally { + if (out != null) + out.close(); + } return result; } diff --git a/scripting/java/org/openoffice/idesupport/zip/ParcelZipper.java b/scripting/java/org/openoffice/idesupport/zip/ParcelZipper.java index 5e2f25a3a2d5..255bf13c6831 100644 --- a/scripting/java/org/openoffice/idesupport/zip/ParcelZipper.java +++ b/scripting/java/org/openoffice/idesupport/zip/ParcelZipper.java @@ -2,9 +2,9 @@ * * $RCSfile: ParcelZipper.java,v $ * - * $Revision: 1.7 $ + * $Revision: 1.8 $ * - * last change: $Author: toconnor $ $Date: 2003-02-20 12:03:27 $ + * last change: $Author: toconnor $ $Date: 2003-03-12 18:26:30 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -136,27 +136,31 @@ public class ParcelZipper tmppath = realpath + ".tmp"; File tmpfile = new File(tmppath); + ZipOutputStream out = null; try { if (tmpfile.exists() == true) tmpfile.delete(); - ZipOutputStream out = - new ZipOutputStream(new FileOutputStream(tmpfile)); + out = new ZipOutputStream(new FileOutputStream(tmpfile)); File[] children = basedir.listFiles(); for (int i = 0; i < children.length; i++) addFileToParcel(children[i], "", out, filter); - - out.close(); } catch (IOException ioe) { + out.close(); tmpfile.delete(); throw ioe; } + finally { + if (out != null) + out.close(); + } if (targetfile.exists() == true) targetfile.delete(); tmpfile.renameTo(targetfile); + return targetfile.getAbsolutePath(); } @@ -183,11 +187,17 @@ public class ParcelZipper byte[] bytes = new byte[1024]; int len; - FileInputStream fis = new FileInputStream(root); - while ((len = fis.read(bytes)) != -1) - out.write(bytes, 0, len); + FileInputStream fis = null; + try { + fis = new FileInputStream(root); + while ((len = fis.read(bytes)) != -1) + out.write(bytes, 0, len); + } + finally { + if (fis != null) fis.close(); + } out.closeEntry(); } } @@ -231,28 +241,25 @@ public class ParcelZipper private boolean isDocumentOverwriteNeeded(File parcel, File document) throws IOException { - ZipFile documentZip; + ZipFile documentZip = null; boolean result = false; try { documentZip = new ZipFile(document); - } - catch (IOException ioe) { - return false; - } - - String name = - PARCEL_PREFIX_DIR + getParcelLanguage(parcel) + - "/" + getParcelDirFromParcelZip(parcel.getName()) + - "/" + PARCEL_DESCRIPTOR_XML; - if (documentZip.getEntry(name) != null) - result = true; + String name = + PARCEL_PREFIX_DIR + getParcelLanguage(parcel) + + "/" + getParcelDirFromParcelZip(parcel.getName()) + + "/" + PARCEL_DESCRIPTOR_XML; - try { - documentZip.close(); + if (documentZip.getEntry(name) != null) + result = true; } catch (IOException ioe) { + return false; + } + finally { + if (documentZip != null) documentZip.close(); } return result; @@ -277,7 +284,7 @@ public class ParcelZipper private String unzipToDirectory(File parcel, File targetDirectory) throws IOException { - ZipInputStream in; + ZipInputStream in = null; File parcelDir = new File(targetDirectory, getParcelLanguage(parcel) + File.separator + getParcelDirFromParcelZip(parcel.getName())); @@ -289,33 +296,41 @@ public class ParcelZipper } } - in = new ZipInputStream(new FileInputStream(parcel)); - - File outFile; - ZipEntry inEntry = in.getNextEntry(); - byte[] bytes = new byte[1024]; - int len; + try { + in = new ZipInputStream(new FileInputStream(parcel)); - while (inEntry != null) { - outFile = new File(parcelDir, inEntry.getName()); - if (inEntry.isDirectory()) { - //System.err.println("Creating directory: " + outFile.getAbsolutePath()); - outFile.mkdir(); - } - else { - if (outFile.getParentFile().exists() != true) - outFile.getParentFile().mkdirs(); + File outFile; + ZipEntry inEntry = in.getNextEntry(); + byte[] bytes = new byte[1024]; + int len; - FileOutputStream out = new FileOutputStream(outFile); - // System.out.println("Writing file: " + outFile.getAbsolutePath()); - while ((len = in.read(bytes)) != -1) - out.write(bytes, 0, len); - out.close(); + while (inEntry != null) { + outFile = new File(parcelDir, inEntry.getName()); + if (inEntry.isDirectory()) { + outFile.mkdir(); + } + else { + if (outFile.getParentFile().exists() != true) + outFile.getParentFile().mkdirs(); + + FileOutputStream out = null; + try { + out = new FileOutputStream(outFile); + + while ((len = in.read(bytes)) != -1) + out.write(bytes, 0, len); + } + finally { + if (out != null) out.close(); + } + } + inEntry = in.getNextEntry(); } - - inEntry = in.getNextEntry(); } - in.close(); + finally { + if (in != null) in.close(); + } + return parcelDir.getAbsolutePath(); } @@ -335,8 +350,9 @@ public class ParcelZipper private String unzipToZip(File parcel, File targetDocument) throws IOException { - ZipInputStream documentStream, parcelStream; - ZipOutputStream outStream; + ZipInputStream documentStream = null; + ZipInputStream parcelStream = null; + ZipOutputStream outStream = null; Manifest manifest; String language = getParcelLanguage(parcel); @@ -352,23 +368,25 @@ public class ParcelZipper manifest = addParcelToManifest(targetDocument, parcel); - documentStream = - new ZipInputStream(new FileInputStream(targetDocument)); - parcelStream = new ZipInputStream(new FileInputStream(parcel)); - outStream = new ZipOutputStream(new FileOutputStream(tmpfile)); - try { + documentStream = + new ZipInputStream(new FileInputStream(targetDocument)); + parcelStream = new ZipInputStream(new FileInputStream(parcel)); + outStream = new ZipOutputStream(new FileOutputStream(tmpfile)); + copyParcelToZip(parcelStream, outStream, PARCEL_PREFIX_DIR + language + "/" + getParcelDirFromParcelZip(parcel.getName())); copyDocumentToZip(documentStream, outStream, manifest); - documentStream.close(); - parcelStream.close(); - outStream.close(); } catch (IOException ioe) { tmpfile.delete(); throw ioe; } + finally { + if (documentStream != null) documentStream.close(); + if (parcelStream != null) parcelStream.close(); + if (outStream != null) outStream.close(); + } if (targetDocument.delete() == false) { tmpfile.delete(); @@ -419,9 +437,16 @@ public class ParcelZipper if(inEntry.getName().equals("META-INF/manifest.xml") && manifest != null) { - InputStream manifestStream = manifest.getInputStream(); - while ((len = manifestStream.read(bytes)) != -1) - out.write(bytes, 0, len); + InputStream manifestStream = null; + try { + manifestStream = manifest.getInputStream(); + while ((len = manifestStream.read(bytes)) != -1) + out.write(bytes, 0, len); + } + finally { + if (manifestStream != null) + manifestStream.close(); + } } else if (inEntry.isDirectory() == false) { while ((len = in.read(bytes)) != -1) @@ -435,8 +460,8 @@ public class ParcelZipper public String removeParcel(File document, String parcelName) throws IOException { - ZipInputStream documentStream; - ZipOutputStream outStream; + ZipInputStream documentStream = null; + ZipOutputStream outStream = null; Manifest manifest = null; if (!parcelName.startsWith(PARCEL_PREFIX_DIR)) @@ -446,15 +471,15 @@ public class ParcelZipper // first write contents of document to tmpfile File tmpfile = new File(document.getAbsolutePath() + ".tmp"); - documentStream = new ZipInputStream(new FileInputStream(document)); - outStream = new ZipOutputStream(new FileOutputStream(tmpfile)); - try { ZipEntry outEntry; ZipEntry inEntry; byte[] bytes = new byte[1024]; int len; + documentStream = new ZipInputStream(new FileInputStream(document)); + outStream = new ZipOutputStream(new FileOutputStream(tmpfile)); + while ((inEntry = documentStream.getNextEntry()) != null) { if(inEntry.getName().startsWith(parcelName)) @@ -465,9 +490,16 @@ public class ParcelZipper if(inEntry.getName().equals("META-INF/manifest.xml") && manifest != null) { - InputStream manifestStream = manifest.getInputStream(); - while ((len = manifestStream.read(bytes)) != -1) - outStream.write(bytes, 0, len); + InputStream manifestStream = null; + try { + manifestStream = manifest.getInputStream(); + while ((len = manifestStream.read(bytes)) != -1) + outStream.write(bytes, 0, len); + } + finally { + if (manifestStream != null) + manifestStream.close(); + } } else if (inEntry.isDirectory() == false) { while ((len = documentStream.read(bytes)) != -1) @@ -482,8 +514,11 @@ public class ParcelZipper throw ioe; } finally { - documentStream.close(); - outStream.close(); + if (documentStream != null) + documentStream.close(); + + if (outStream != null) + outStream.close(); } if (document.delete() == false) { @@ -497,31 +532,25 @@ public class ParcelZipper } private Manifest getManifestFromDocument(File document) { - ZipFile documentZip; + ZipFile documentZip = null; Manifest result = null; try { documentZip = new ZipFile(document); + ZipEntry original = documentZip.getEntry("META-INF/manifest.xml"); + if (original != null) { + result = new Manifest(documentZip.getInputStream(original)); + } } catch (IOException ioe) { - return null; + result = null; } - - ZipEntry original = documentZip.getEntry("META-INF/manifest.xml"); - if (original != null) { + finally { try { - result = - new Manifest(documentZip.getInputStream(original)); + if (documentZip != null) + documentZip.close(); } - catch (IOException ioe) { - result = null; - } - } - - try { - documentZip.close(); - } - catch (IOException ioe) { + catch (IOException ioe) {} } return result; @@ -530,7 +559,7 @@ public class ParcelZipper private Manifest addParcelToManifest(File document, File parcel) throws IOException { - ZipFile parcelZip; + ZipFile parcelZip = null; Manifest result = null; result = getManifestFromDocument(document); @@ -541,24 +570,25 @@ public class ParcelZipper try { parcelZip = new ZipFile(parcel); - } - catch (IOException ioe) { - return null; - } - String prefix = PARCEL_PREFIX_DIR + language + "/" + - getParcelDirFromParcelZip(parcel.getName()) + "/"; + String prefix = PARCEL_PREFIX_DIR + language + "/" + + getParcelDirFromParcelZip(parcel.getName()) + "/"; - Enumeration entries = parcelZip.entries(); - while (entries.hasMoreElements()) { - ZipEntry entry = (ZipEntry)entries.nextElement(); - result.add(prefix + entry.getName()); - } - - try { - parcelZip.close(); + Enumeration entries = parcelZip.entries(); + while (entries.hasMoreElements()) { + ZipEntry entry = (ZipEntry)entries.nextElement(); + result.add(prefix + entry.getName()); + } } catch (IOException ioe) { + return null; + } + finally { + try { + if (parcelZip != null) + parcelZip.close(); + } + catch (IOException ioe) {} } return result; @@ -576,14 +606,28 @@ public class ParcelZipper } public String getParcelLanguage(File file) throws IOException { - ZipFile zf = new ZipFile(file); - ZipEntry ze = zf.getEntry(PARCEL_DESCRIPTOR_XML); + ZipFile zf = null; + ZipEntry ze = null; + InputStream is = null; + ParcelDescriptor pd; + + try { + zf = new ZipFile(file); + ze = zf.getEntry(PARCEL_DESCRIPTOR_XML); - if (ze == null) - throw new IOException("Could not find Parcel Descriptor in parcel"); + if (ze == null) + throw new IOException("Could not find Parcel Descriptor in parcel"); - InputStream is = zf.getInputStream(ze); - ParcelDescriptor pd = new ParcelDescriptor(is); + is = zf.getInputStream(ze); + pd = new ParcelDescriptor(is); + } + finally { + if (zf != null) + zf.close(); + + if (is != null) + is.close(); + } return pd.getLanguage().toLowerCase(); } diff --git a/scripting/java/org/openoffice/netbeans/modules/office/actions/DeployParcelAction.java b/scripting/java/org/openoffice/netbeans/modules/office/actions/DeployParcelAction.java index dc6ef00bce4c..cad2529fdcc4 100644 --- a/scripting/java/org/openoffice/netbeans/modules/office/actions/DeployParcelAction.java +++ b/scripting/java/org/openoffice/netbeans/modules/office/actions/DeployParcelAction.java @@ -2,9 +2,9 @@ * * $RCSfile: DeployParcelAction.java,v $ * - * $Revision: 1.6 $ + * $Revision: 1.7 $ * - * last change: $Author: toconnor $ $Date: 2003-02-20 12:01:53 $ + * last change: $Author: toconnor $ $Date: 2003-03-12 18:26:31 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -257,6 +257,7 @@ public class DeployParcelAction extends CookieAction implements Presenter.Popup if (file.isDirectory() || file.getName().endsWith(".sxw") || file.getName().endsWith(".sxc") || + file.getName().endsWith(".sxd") || file.getName().endsWith(".sxi")) return true; return false; diff --git a/scripting/java/org/openoffice/netbeans/modules/office/wizard/JavaScriptIterator.java b/scripting/java/org/openoffice/netbeans/modules/office/wizard/JavaScriptIterator.java index c6b95d6069d1..094acf052635 100644 --- a/scripting/java/org/openoffice/netbeans/modules/office/wizard/JavaScriptIterator.java +++ b/scripting/java/org/openoffice/netbeans/modules/office/wizard/JavaScriptIterator.java @@ -2,9 +2,9 @@ * * $RCSfile: JavaScriptIterator.java,v $ * - * $Revision: 1.1 $ + * $Revision: 1.2 $ * - * last change: $Author: toconnor $ $Date: 2003-01-16 17:51:44 $ + * last change: $Author: toconnor $ $Date: 2003-03-12 18:26:31 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -163,6 +163,10 @@ public class JavaScriptIterator implements TemplateWizard.Iterator { if (tmp.getExt().equals("java")) { try { PackageRemover.removeDeclaration(FileUtil.toFile(tmp)); + + // IssueZilla 11986 - rename the FileObject + // so the JavaNode is resynchronized + tmp.rename(tmp.lock(), tmp.getName(), tmp.getExt()); } catch (IOException ioe) { NotifyDescriptor d = new NotifyDescriptor.Message( |