diff options
author | Robert Antoni Buj i Gelonch <robert.buj@gmail.com> | 2014-09-25 19:41:12 +0200 |
---|---|---|
committer | David Tardon <dtardon@redhat.com> | 2014-10-02 15:25:29 +0200 |
commit | 6f42a714399f4d0c46dad95c7c11bcd513c27eaa (patch) | |
tree | b5ea97f0171124e8232fe909e86ac0a087e8a3d0 /scripting/java/org | |
parent | 36d24bced0ea5fcbbd380b15e9d1a813fbef32cf (diff) |
scripting: Format_java_code.sh initial run
Conflicts:
scripting/java/com/sun/star/script/framework/io/UCBStreamHandler.java
Change-Id: I09b94d8c96dfbaf498bd93a0088feb80a9e4afb6
Diffstat (limited to 'scripting/java/org')
63 files changed, 1108 insertions, 1068 deletions
diff --git a/scripting/java/org/openoffice/idesupport/CommandLineTools.java b/scripting/java/org/openoffice/idesupport/CommandLineTools.java index c47e2457c121..8fa9269ca361 100644 --- a/scripting/java/org/openoffice/idesupport/CommandLineTools.java +++ b/scripting/java/org/openoffice/idesupport/CommandLineTools.java @@ -43,28 +43,25 @@ public class CommandLineTools { // Get the URL for the Office DTD directory and pass it to the // XMLParserFactory so that Office xml files can be parsed - if (officePath == null) - { + if (officePath == null) { try { SVersionRCFile sv = SVersionRCFile.createInstance(); - if (sv.getDefaultVersion() != null) - { + + if (sv.getDefaultVersion() != null) { officePath = sv.getDefaultVersion().getPath(); } - } - catch (IOException ioe) { + } catch (IOException ioe) { System.err.println("Error getting Office directory"); } } - if (officePath == null) - { + if (officePath == null) { driver.fatalUsage("Error: Office Installation path not set"); } File officeDir = new File(officePath); - if (!officeDir.exists() || !officeDir.isDirectory()) - { + + if (!officeDir.exists() || !officeDir.isDirectory()) { driver.fatalUsage( "Error: Office Installation path not valid: " + officePath); } @@ -78,8 +75,7 @@ public class CommandLineTools { else { try { command.execute(); - } - catch (Exception e) { + } catch (Exception e) { driver.fatal("Error: " + e.getMessage()); } } @@ -91,17 +87,17 @@ public class CommandLineTools { private void printUsage() { System.out.println("java " + getClass().getName() + " -h " + - "prints this message"); + "prints this message"); System.out.println("java " + getClass().getName() + - " [-o Path to Office Installation] " + - "-d <script parcel zip file> " + - "<destination document or directory>"); + " [-o Path to Office Installation] " + + "-d <script parcel zip file> " + + "<destination document or directory>"); System.out.println("java " + getClass().getName() + - " [-o Path to Office Installation] " + - "-g [parcel root directory] [options] [script names]"); + " [-o Path to Office Installation] " + + "-g [parcel root directory] [options] [script names]"); System.out.println("options:"); System.out.println("\t[-l language[=supported extension 1[" + - File.pathSeparator + "supported extension 2]]]"); + File.pathSeparator + "supported extension 2]]]"); System.out.println("\t[-p name=value]"); System.out.println("\t[-v]"); } @@ -121,8 +117,7 @@ public class CommandLineTools { if (args.length < 1) { return null; - } - else if (args[0].equals("-h")) { + } else if (args[0].equals("-h")) { return new Command() { public void execute() { printUsage(); @@ -132,24 +127,24 @@ public class CommandLineTools { int i = 0; - if(args[0].equals("-o")) { - officePath = args[i+1]; + if (args[0].equals("-o")) { + officePath = args[i + 1]; i += 2; } - if(args[i].equals("-d")) { + if (args[i].equals("-d")) { if ((args.length - i) != 3) return null; else - return new DeployCommand(args[i+1], args[i+2]); - } - else if(args[i].equals("-g")) { + return new DeployCommand(args[i + 1], args[i + 2]); + } else if (args[i].equals("-g")) { if ((args.length - i) == 1) return new GenerateCommand(System.getProperty("user.dir")); GenerateCommand command; i++; + if (!args[i].startsWith("-")) command = new GenerateCommand(args[i++]); else @@ -158,19 +153,18 @@ public class CommandLineTools { for (; i < args.length; i++) { if (args[i].equals("-l")) { command.setLanguage(args[++i]); - } - else if (args[i].equals("-p")) { + } else if (args[i].equals("-p")) { command.addProperty(args[++i]); - } - else if (args[i].equals("-v")) { + } else if (args[i].equals("-v")) { command.setVerbose(); - } - else { + } else { command.addScript(args[i]); } } + return command; } + return null; } @@ -207,13 +201,13 @@ public class CommandLineTools { extensions = new String[tokenizer.countTokens()]; int i = 0; - while(tokenizer.hasMoreTokens()) + while (tokenizer.hasMoreTokens()) extensions[i++] = (String)tokenizer.nextToken(); - } - else { + } else { extensions = new String[1]; extensions[0] = ext; } + this.finder = new ExtensionFinder(this.language, extensions); } } @@ -244,6 +238,7 @@ public class CommandLineTools { public void addScript(ScriptEntry entry) { if (scripts == null) scripts = new ArrayList(3); + scripts.add(entry); } @@ -251,15 +246,14 @@ public class CommandLineTools { if (!basedir.isDirectory()) { throw new Exception(basedir.getName() + " is not a directory"); - } - else if (!contents.exists()) { + } else if (!contents.exists()) { throw new Exception(basedir.getName() + - " does not contain a Contents directory"); + " does not contain a Contents directory"); } if (language == null && !parcelxml.exists()) { throw new Exception(parcelxml.getName() + " not found and language " + - "not specified"); + "not specified"); } if (language != null && parcelxml.exists()) { @@ -271,8 +265,8 @@ public class CommandLineTools { if (!desclang.equals(language.toLowerCase())) throw new Exception(parcelxml.getName() + " already exists, " + - "and has a different language attribute: " + - desc.getLanguage()); + "and has a different language attribute: " + + desc.getLanguage()); } if (language != null && scripts == null) { @@ -282,6 +276,7 @@ public class CommandLineTools { log("Searching for " + language + " scripts"); ScriptEntry[] entries = finder.findMethods(contents); + for (int i = 0; i < entries.length; i++) { addScript(entries[i]); log("Found: " + entries[i].getLogicalName()); @@ -293,7 +288,9 @@ public class CommandLineTools { throw new Exception("No valid scripts found"); ParcelDescriptor desc = new ParcelDescriptor(parcelxml, language); - desc.setScriptEntries((ScriptEntry[])scripts.toArray(new ScriptEntry[scripts.size()])); + desc.setScriptEntries((ScriptEntry[])scripts.toArray(new + ScriptEntry[scripts.size()])); + if (properties.size() != 0) { Enumeration enumer = properties.keys(); @@ -305,15 +302,16 @@ public class CommandLineTools { desc.setLanguageProperty(name, value); } } + desc.write(); - } - else { + } else { if (!parcelxml.exists()) throw new Exception("No valid scripts found"); } contents = new File(contents.getAbsolutePath()); - String name = ParcelZipper.getParcelZipper().zipParcel(contents, AllFilesFilter.getInstance()); + String name = ParcelZipper.getParcelZipper().zipParcel(contents, + AllFilesFilter.getInstance()); System.out.println(name + " generated"); } @@ -335,7 +333,7 @@ public class CommandLineTools { public void execute() throws Exception { ParcelZipper.getParcelZipper().deployParcel(source, target); System.out.println(source.getName() + - " successfully deployed to " + target.getAbsolutePath()); + " successfully deployed to " + target.getAbsolutePath()); } } } diff --git a/scripting/java/org/openoffice/idesupport/ExtensionFinder.java b/scripting/java/org/openoffice/idesupport/ExtensionFinder.java index 0fa051c5af67..48b80fd77eec 100644 --- a/scripting/java/org/openoffice/idesupport/ExtensionFinder.java +++ b/scripting/java/org/openoffice/idesupport/ExtensionFinder.java @@ -44,6 +44,7 @@ public class ExtensionFinder implements MethodFinder { return empty; parcelName = basedir.getName(); + if (parcelName.equals(ParcelZipper.CONTENTS_DIRNAME)) parcelName = basedir.getParentFile().getName(); @@ -51,10 +52,12 @@ public class ExtensionFinder implements MethodFinder { if (files.size() != 0) return files.toArray(empty); + return empty; } - private void findFiles(ArrayList<ScriptEntry> list, File basedir, String parcelName) { + private void findFiles(ArrayList<ScriptEntry> list, File basedir, + String parcelName) { File[] children = basedir.listFiles(); File f; @@ -67,7 +70,7 @@ public class ExtensionFinder implements MethodFinder { for (int j = 0; j < extensions.length; j++) { if (f.getName().endsWith(extensions[j])) { ScriptEntry entry = new ScriptEntry(language, - f.getName(), parcelName); + f.getName(), parcelName); list.add(entry); break; } diff --git a/scripting/java/org/openoffice/idesupport/JavaFinder.java b/scripting/java/org/openoffice/idesupport/JavaFinder.java index 98043d2198e8..e9385fd3c57e 100644 --- a/scripting/java/org/openoffice/idesupport/JavaFinder.java +++ b/scripting/java/org/openoffice/idesupport/JavaFinder.java @@ -65,10 +65,12 @@ public class JavaFinder implements MethodFinder { return empty; parcelName = basedir.getName(); + if (parcelName.equals(ParcelZipper.CONTENTS_DIRNAME)) parcelName = basedir.getParentFile().getName(); String[] classNames = findClassNames(basedir); + if (classNames != null && classNames.length != 0) { ClassLoader classloader; @@ -78,40 +80,32 @@ public class JavaFinder implements MethodFinder { else classloader = getClassLoader(); - for (int i = 0; i < classNames.length; i++) - { - try - { + for (int i = 0; i < classNames.length; i++) { + try { Class clazz = classloader.loadClass(classNames[i]); Method[] methods = clazz.getDeclaredMethods(); - for (int k = 0; k < methods.length; k++) - { - if (Modifier.isPublic(methods[k].getModifiers())) - { + + for (int k = 0; k < methods.length; k++) { + if (Modifier.isPublic(methods[k].getModifiers())) { Class[] params = methods[k].getParameterTypes(); - if(params.length > 0) - { - if(params[0].getName().equals(FIRST_PARAM)) - { + + if (params.length > 0) { + if (params[0].getName().equals(FIRST_PARAM)) { ScriptEntry entry = new ScriptEntry(classNames[i] + "." + - methods[k].getName(), parcelName); + methods[k].getName(), parcelName); result.add(entry); } } } } - } - catch (ClassNotFoundException e) - { + } catch (ClassNotFoundException e) { System.err.println("Caught ClassNotFoundException loading: " - + classNames[i]); + + classNames[i]); continue; - } - catch (NoClassDefFoundError nc) - { + } catch (NoClassDefFoundError nc) { System.err.println("Caught NoClassDefFoundErr loading: " + - classNames[i]); + classNames[i]); continue; } } @@ -119,6 +113,7 @@ public class JavaFinder implements MethodFinder { if (result.size() != 0) return result.toArray(empty); + return empty; } @@ -133,8 +128,7 @@ public class JavaFinder implements MethodFinder { if (s != null) urls.add(new URL(s)); - } - catch (MalformedURLException mue) { + } catch (MalformedURLException mue) { } } @@ -146,7 +140,8 @@ public class JavaFinder implements MethodFinder { files.add(basedir); try { - Iterator<OfficeInstallation> offices = SVersionRCFile.createInstance().getVersions(); + Iterator<OfficeInstallation> offices = + SVersionRCFile.createInstance().getVersions(); while (offices.hasNext()) { OfficeInstallation oi = offices.next(); @@ -157,14 +152,14 @@ public class JavaFinder implements MethodFinder { break; } } - } - catch (IOException ioe) { + } catch (IOException ioe) { return null; } URL[] urls = new URL[files.size()]; String urlpath; File f; + for (int i = 0; i < urls.length; i++) { try { f = files.get(i); @@ -172,8 +167,7 @@ public class JavaFinder implements MethodFinder { if (urlpath != null) urls[i] = new URL(urlpath); - } - catch (MalformedURLException mue) { + } catch (MalformedURLException mue) { // do nothing, go on to next file } } @@ -191,36 +185,36 @@ public class JavaFinder implements MethodFinder { else if (children[i].getName().endsWith(suffix)) result.add(children[i]); } + return result; } - private String[] findClassNames(File basedir) - { + private String[] findClassNames(File basedir) { ArrayList<File> classFiles = findFiles(basedir, CLASS_SUFFIX); - if(classFiles == null || classFiles.size() == 0) + + if (classFiles == null || classFiles.size() == 0) return null; ArrayList<File> javaFiles = findFiles(basedir, JAVA_SUFFIX); - if(javaFiles == null || javaFiles.size() == 0) + + if (javaFiles == null || javaFiles.size() == 0) return null; ArrayList<String> result = new ArrayList<String>(); - for (int i = 0; i < classFiles.size(); i++) - { + + for (int i = 0; i < classFiles.size(); i++) { File classFile = classFiles.get(i); String className = classFile.getName(); className = className.substring(0, className.lastIndexOf(CLASS_SUFFIX)); boolean finished = false; - for (int j = 0; j < javaFiles.size() && !finished; j++) - { + for (int j = 0; j < javaFiles.size() && !finished; j++) { File javaFile = javaFiles.get(j); String javaName = javaFile.getName(); javaName = javaName.substring(0, javaName.lastIndexOf(JAVA_SUFFIX)); - if (javaName.equals(className)) - { + if (javaName.equals(className)) { String path = classFile.getAbsolutePath(); path = path.substring(basedir.getAbsolutePath().length() + 1); path = path.replace(File.separatorChar, '.'); @@ -232,6 +226,7 @@ public class JavaFinder implements MethodFinder { } } } + return result.toArray(new String[result.size()]); } } diff --git a/scripting/java/org/openoffice/idesupport/LocalOffice.java b/scripting/java/org/openoffice/idesupport/LocalOffice.java index ad6e4ad8302b..f6d0814e0199 100644 --- a/scripting/java/org/openoffice/idesupport/LocalOffice.java +++ b/scripting/java/org/openoffice/idesupport/LocalOffice.java @@ -28,8 +28,7 @@ import java.net.ConnectException; * office has to be started with options appropriate for establishing * local connection. */ -public class LocalOffice -{ +public class LocalOffice { /** @@ -40,15 +39,13 @@ public class LocalOffice * @param port is a communication port. */ protected void connect(String officePath, int port) - throws ConnectException - { + throws ConnectException { } /** * Closes the connection to the running office. */ - public void disconnect() - { + public void disconnect() { } /** @@ -56,7 +53,6 @@ public class LocalOffice * * @param uri is an identifier of storage has to be refreshed. */ - public void refreshStorage(String uri) - { + public void refreshStorage(String uri) { } } diff --git a/scripting/java/org/openoffice/idesupport/OfficeDocument.java b/scripting/java/org/openoffice/idesupport/OfficeDocument.java index 764501f01695..abad0ebbdd77 100644 --- a/scripting/java/org/openoffice/idesupport/OfficeDocument.java +++ b/scripting/java/org/openoffice/idesupport/OfficeDocument.java @@ -29,23 +29,22 @@ import java.util.zip.ZipFile; import org.openoffice.idesupport.zip.ParcelZipper; -public class OfficeDocument -{ +public class OfficeDocument { public static final String PARCEL_PREFIX_DIR = ParcelZipper.PARCEL_PREFIX_DIR; public static final String[] OFFICE_EXTENSIONS = - {".sxc" , ".sxw", ".sxi", ".sxd"}; + {".sxc" , ".sxw", ".sxi", ".sxd"}; public static final String OFFICE_PRODUCT_NAME = "OpenOffice.org"; private File file = null; - public OfficeDocument(File file) throws IllegalArgumentException - { + public OfficeDocument(File file) throws IllegalArgumentException { if (!file.exists() || file.isDirectory() || !isOfficeFile(file)) { throw new IllegalArgumentException("This is not a valid " + - OFFICE_PRODUCT_NAME + " document."); + OFFICE_PRODUCT_NAME + " document."); } + this.file = file; } @@ -53,6 +52,7 @@ public class OfficeDocument for (int i = 0; i < OFFICE_EXTENSIONS.length; i++) if (file.getName().endsWith(OFFICE_EXTENSIONS[i])) return true; + return false; } @@ -61,15 +61,13 @@ public class OfficeDocument ArrayList<String> parcels = new ArrayList<String>(); ZipFile zp = null; - try - { + try { zp = new ZipFile(this.file); - for (Enumeration enumer = zp.entries(); enumer.hasMoreElements(); ) - { + for (Enumeration enumer = zp.entries(); enumer.hasMoreElements();) { ZipEntry ze = (ZipEntry)enumer.nextElement(); - if (ze.getName().endsWith(ParcelZipper.PARCEL_DESCRIPTOR_XML)) - { + + if (ze.getName().endsWith(ParcelZipper.PARCEL_DESCRIPTOR_XML)) { String tmp = ze.getName(); int end = tmp.lastIndexOf('/'); tmp = tmp.substring(0, end); @@ -78,19 +76,15 @@ public class OfficeDocument parcels.add(parcelName); } } - } - catch(ZipException ze) { + } catch (ZipException ze) { ze.printStackTrace(); - } - catch(IOException ioe) { + } catch (IOException ioe) { ioe.printStackTrace(); - } - finally { + } finally { if (zp != null) { try { zp.close(); - } - catch (IOException asdf) { + } catch (IOException asdf) { } } } @@ -102,11 +96,11 @@ public class OfficeDocument try { ParcelZipper.getParcelZipper().removeParcel(file, parcelName); - } - catch (IOException ioe) { + } catch (IOException ioe) { ioe.printStackTrace(); return false; } + return true; } } diff --git a/scripting/java/org/openoffice/idesupport/OfficeInstallation.java b/scripting/java/org/openoffice/idesupport/OfficeInstallation.java index 586d3a2d47ef..fdc89c9d12a1 100644 --- a/scripting/java/org/openoffice/idesupport/OfficeInstallation.java +++ b/scripting/java/org/openoffice/idesupport/OfficeInstallation.java @@ -46,8 +46,7 @@ public class OfficeInstallation implements java.io.Serializable { path = path.replace('/', File.separatorChar); this.path = path; - } - else { + } else { this.path = path; if (System.getProperty("os.name").startsWith("Windows")) diff --git a/scripting/java/org/openoffice/idesupport/SVersionRCFile.java b/scripting/java/org/openoffice/idesupport/SVersionRCFile.java index a258983da7dd..4e754e347c75 100644 --- a/scripting/java/org/openoffice/idesupport/SVersionRCFile.java +++ b/scripting/java/org/openoffice/idesupport/SVersionRCFile.java @@ -32,14 +32,14 @@ public class SVersionRCFile { private static final String DEFAULT_NAME = System.getProperty("os.name").startsWith("Windows") ? - System.getProperty("user.home") + File.separator + - "Application Data" + File.separator + "sversion.ini" : - System.getProperty("user.home") + File.separator + - ".sversionrc"; + System.getProperty("user.home") + File.separator + + "Application Data" + File.separator + "sversion.ini" : + System.getProperty("user.home") + File.separator + + ".sversionrc"; public static final String FILE_URL_PREFIX = System.getProperty("os.name").startsWith("Windows") ? - "file:///" : "file://"; + "file:///" : "file://"; @@ -55,7 +55,8 @@ public class SVersionRCFile { /* Make sure this is in LowerCase !!!!! */ private static final String SCRIPTF = "scriptf"; - private static final HashMap<String, SVersionRCFile> files = new HashMap<String, SVersionRCFile>(3); + private static final HashMap<String, SVersionRCFile> files = new + HashMap<String, SVersionRCFile>(3); private File sversionrc = null; private OfficeInstallation defaultversion = null; @@ -72,13 +73,13 @@ public class SVersionRCFile { } public static SVersionRCFile createInstance() { - return(createInstance(DEFAULT_NAME)); + return (createInstance(DEFAULT_NAME)); } private static SVersionRCFile createInstance(String name) { SVersionRCFile result = null; - synchronized(SVersionRCFile.class) { + synchronized (SVersionRCFile.class) { result = files.get(name); if (result == null) { @@ -86,6 +87,7 @@ public class SVersionRCFile { files.put(name, result); } } + return result; } @@ -108,15 +110,14 @@ public class SVersionRCFile { br = new BufferedReader(new FileReader(sversionrc)); load(br); lastModified = l; - } - catch (FileNotFoundException fnfe) { + } catch (FileNotFoundException fnfe) { throw new IOException(fnfe.getMessage()); - } - finally { + } finally { if (br != null) br.close(); } } + return versions.iterator(); } @@ -124,10 +125,10 @@ public class SVersionRCFile { String s; while ((s = br.readLine()) != null && - !(s.equals(VERSIONS_LINE))) {} + !(s.equals(VERSIONS_LINE))) {} while ((s = br.readLine()) != null && - s.length() != 0) { + s.length() != 0) { StringTokenizer tokens = new StringTokenizer(s, "="); int count = tokens.countTokens(); @@ -137,6 +138,7 @@ public class SVersionRCFile { String name = tokens.nextToken(); String path = tokens.nextToken(); OfficeInstallation oi = new OfficeInstallation(name, path); + if (oi.supportsFramework()) { versions.add(oi); defaultversion = oi; @@ -152,8 +154,7 @@ public class SVersionRCFile { try { path = f.getCanonicalPath(); - } - catch (IOException ioe) { + } catch (IOException ioe) { return null; } @@ -169,33 +170,33 @@ public class SVersionRCFile { return buf.toString(); } - public static String getPathForUnoil(String officeInstall) - { + public static String getPathForUnoil(String officeInstall) { File unopkgdir = new File(officeInstall, UNOPACKAGEDIR); - if(!unopkgdir.exists()) - { + + if (!unopkgdir.exists()) { return null; } + File scriptf = null; String[] listunopkg = unopkgdir.list(); int size = listunopkg.length; - for(int i=0; i<size; i++) - { - if (listunopkg[i].toLowerCase().indexOf(SCRIPTF)>-1) - { + + for (int i = 0; i < size; i++) { + if (listunopkg[i].toLowerCase().indexOf(SCRIPTF) > -1) { scriptf = new File(unopkgdir, listunopkg[i]); } } - if(scriptf != null) - { + + if (scriptf != null) { File unoil = new File(scriptf, UNOILJAR); - if(unoil.exists()) - { + + if (unoil.exists()) { String path = unoil.getParent(); path = path.substring(path.indexOf(UNOPACKAGEDIR)); return officeInstall + path; } } + return null; } @@ -208,10 +209,10 @@ public class SVersionRCFile { ov = new SVersionRCFile(args[0]); Iterator<OfficeInstallation> enumer; + try { enumer = ov.getVersions(); - } - catch (IOException ioe) { + } catch (IOException ioe) { System.err.println("Error getting versions: " + ioe.getMessage()); return; } @@ -219,7 +220,7 @@ public class SVersionRCFile { while (enumer.hasNext()) { OfficeInstallation oi = enumer.next(); System.out.println("Name: " + oi.getName() + ", Path: " + oi.getPath() + - ", URL: " + oi.getURL()); + ", URL: " + oi.getURL()); } } } diff --git a/scripting/java/org/openoffice/idesupport/filter/BinaryOnlyFilter.java b/scripting/java/org/openoffice/idesupport/filter/BinaryOnlyFilter.java index a78ef0e11191..95436158bc6f 100644 --- a/scripting/java/org/openoffice/idesupport/filter/BinaryOnlyFilter.java +++ b/scripting/java/org/openoffice/idesupport/filter/BinaryOnlyFilter.java @@ -33,6 +33,7 @@ public class BinaryOnlyFilter implements FileFilter { for (int i = 0; i < EXTENSIONS.length; i++) if (name.endsWith(EXTENSIONS[i])) return true; + return false; } diff --git a/scripting/java/org/openoffice/idesupport/filter/ExceptParcelFilter.java b/scripting/java/org/openoffice/idesupport/filter/ExceptParcelFilter.java index 792c9d42a26d..178d449fd8ee 100644 --- a/scripting/java/org/openoffice/idesupport/filter/ExceptParcelFilter.java +++ b/scripting/java/org/openoffice/idesupport/filter/ExceptParcelFilter.java @@ -26,8 +26,7 @@ public class ExceptParcelFilter implements FileFilter { private ExceptParcelFilter() { } - public void setParcelToRemove(String parcelName) - { + public void setParcelToRemove(String parcelName) { ExceptParcelFilter.parcelName = parcelName; } @@ -37,6 +36,7 @@ public class ExceptParcelFilter implements FileFilter { public boolean validate(String name) { if (name.startsWith(ExceptParcelFilter.parcelName)) return true; + return false; } diff --git a/scripting/java/org/openoffice/idesupport/localoffice/LocalOfficeImpl.java b/scripting/java/org/openoffice/idesupport/localoffice/LocalOfficeImpl.java index 35a995819b83..3051b72bbfdd 100644 --- a/scripting/java/org/openoffice/idesupport/localoffice/LocalOfficeImpl.java +++ b/scripting/java/org/openoffice/idesupport/localoffice/LocalOfficeImpl.java @@ -40,8 +40,7 @@ import org.openoffice.idesupport.LocalOffice; * with options appropriate for establishing local connection. */ public final class LocalOfficeImpl - extends LocalOffice -{ + extends LocalOffice { private final static String STORAGE_MRG_SINGLETON = "/singletons/drafts.com.sun.star.script.framework.storage.theScriptStorageManager"; @@ -57,8 +56,7 @@ public final class LocalOfficeImpl */ @Override protected void connect(String officePath, int port) - throws ConnectException - { + throws ConnectException { try { bootstrap(port); } catch (java.lang.Exception ex) { @@ -72,35 +70,36 @@ public final class LocalOfficeImpl * @param uri is an identifier of storage has to be refreshed. */ @Override - public void refreshStorage(String uri) - { + public void refreshStorage(String uri) { try { Object object = null; object = mComponentContext.getValueByName(STORAGE_MRG_SINGLETON); XScriptStorageManager storageMgr; storageMgr = UnoRuntime.queryInterface( - XScriptStorageManager.class, object); + XScriptStorageManager.class, object); storageMgr.refreshScriptStorage(uri); } catch (java.lang.Exception ex) { -System.out.println("*** LocalOfficeImpl.refreshStorage: FAILED " + ex.getMessage()); -System.out.println("*** LocalOfficeImpl.refreshStorage: FAILED " + ex.getClass().getName()); + System.out.println("*** LocalOfficeImpl.refreshStorage: FAILED " + + ex.getMessage()); + System.out.println("*** LocalOfficeImpl.refreshStorage: FAILED " + + ex.getClass().getName()); } -System.out.println("*** LocalOfficeImpl.refreshStorage: DONE"); + + System.out.println("*** LocalOfficeImpl.refreshStorage: DONE"); } /** * Closes the connection to the running office. */ @Override - public void disconnect() - { -/* - if(mComponentFactory != null) { - XComponent comp = (XComponent)UnoRuntime.queryInterface( - XComponent.class, mComponentFactory); - comp.dispose(); - } -*/ + public void disconnect() { + /* + if(mComponentFactory != null) { + XComponent comp = (XComponent)UnoRuntime.queryInterface( + XComponent.class, mComponentFactory); + comp.dispose(); + } + */ } /** @@ -112,22 +111,21 @@ System.out.println("*** LocalOfficeImpl.refreshStorage: DONE"); * @param port is a communication port. */ private void bootstrap(int port) - throws java.lang.Exception - { + throws java.lang.Exception { Object object; mComponentContext = Bootstrap.createInitialComponentContext(null); XUnoUrlResolver urlresolver = UnoUrlResolver.create(mComponentContext); object = urlresolver.resolve( - "uno:socket,host=localhost,port=" + - port + - ";urp;StarOffice.ServiceManager"); + "uno:socket,host=localhost,port=" + + port + + ";urp;StarOffice.ServiceManager"); mComponentFactory = UnoRuntime.queryInterface( - XMultiComponentFactory.class, object); + XMultiComponentFactory.class, object); XPropertySet factoryProps; factoryProps = UnoRuntime.queryInterface( - XPropertySet.class, mComponentFactory); + XPropertySet.class, mComponentFactory); object = factoryProps.getPropertyValue("DefaultContext"); mComponentContext = UnoRuntime.queryInterface( - XComponentContext.class, object); + XComponentContext.class, object); } } diff --git a/scripting/java/org/openoffice/idesupport/ui/ConfigurePanel.java b/scripting/java/org/openoffice/idesupport/ui/ConfigurePanel.java index 72d98823864b..4098dca61f0e 100644 --- a/scripting/java/org/openoffice/idesupport/ui/ConfigurePanel.java +++ b/scripting/java/org/openoffice/idesupport/ui/ConfigurePanel.java @@ -53,7 +53,7 @@ public class ConfigurePanel extends JPanel { "Choose What to Export as Scripts"; public ConfigurePanel(String basedir, ArrayList<String> classpath, - ParcelDescriptor descriptor) { + ParcelDescriptor descriptor) { this.basedir = new File(basedir); this.classpath = classpath; @@ -62,17 +62,17 @@ public class ConfigurePanel extends JPanel { } public ConfigurePanel(String basedir, ArrayList<String> classpath) - throws IOException { + throws IOException { this.basedir = new File(basedir); this.classpath = classpath; this.descriptor = new ParcelDescriptor(new File(this.basedir, - ParcelZipper.PARCEL_DESCRIPTOR_XML)); + ParcelZipper.PARCEL_DESCRIPTOR_XML)); initUI(); } public void reload(String basedir, ArrayList<String> classpath, - ParcelDescriptor descriptor) { + ParcelDescriptor descriptor) { if (basedir != null) this.basedir = new File(basedir); @@ -85,12 +85,12 @@ public class ConfigurePanel extends JPanel { } methodPanel.reload(this.basedir, this.classpath, - descriptor.getLanguage()); + descriptor.getLanguage()); scriptPanel.reload(descriptor.getScriptEntries()); } public void reload(String basedir, ArrayList<String> classpath) - throws IOException { + throws IOException { if (basedir != null) this.basedir = new File(basedir); @@ -99,10 +99,10 @@ public class ConfigurePanel extends JPanel { this.classpath = classpath; this.descriptor = new ParcelDescriptor(new File(this.basedir, - ParcelZipper.PARCEL_DESCRIPTOR_XML)); + ParcelZipper.PARCEL_DESCRIPTOR_XML)); methodPanel.reload(this.basedir, this.classpath, - descriptor.getLanguage()); + descriptor.getLanguage()); scriptPanel.reload(descriptor.getScriptEntries()); } @@ -163,16 +163,17 @@ public class ConfigurePanel extends JPanel { private JPanel initMethodButtons() { JPanel panel = new JPanel(); panel.setLayout(new GridBagLayout()); - ImageIcon icon = new ImageIcon(getClass().getResource("/org/openoffice/idesupport/ui/add.gif")); + ImageIcon icon = new ImageIcon( + getClass().getResource("/org/openoffice/idesupport/ui/add.gif")); JButton addButton = new JButton("Add", icon); addButton.setHorizontalTextPosition(AbstractButton.LEFT); addButton.addActionListener( - new ActionListener() { - public void actionPerformed(ActionEvent e) { - scriptPanel.addScriptEntries(methodPanel.getSelectedEntries()); - } + new ActionListener() { + public void actionPerformed(ActionEvent e) { + scriptPanel.addScriptEntries(methodPanel.getSelectedEntries()); } + } ); GridBagConstraints gbc = new java.awt.GridBagConstraints(); @@ -199,19 +200,19 @@ public class ConfigurePanel extends JPanel { JButton removeAllButton = new JButton("Remove All"); removeButton.addActionListener( - new ActionListener() { - public void actionPerformed(ActionEvent e) { - scriptPanel.removeSelectedRows(); - } + new ActionListener() { + public void actionPerformed(ActionEvent e) { + scriptPanel.removeSelectedRows(); } + } ); removeAllButton.addActionListener( - new ActionListener() { - public void actionPerformed(ActionEvent e) { - scriptPanel.removeAllRows(); - } + new ActionListener() { + public void actionPerformed(ActionEvent e) { + scriptPanel.removeAllRows(); } + } ); panel.add(removeButton); diff --git a/scripting/java/org/openoffice/idesupport/ui/ScriptPanel.java b/scripting/java/org/openoffice/idesupport/ui/ScriptPanel.java index a6969cdd89ef..c25b5fb04660 100644 --- a/scripting/java/org/openoffice/idesupport/ui/ScriptPanel.java +++ b/scripting/java/org/openoffice/idesupport/ui/ScriptPanel.java @@ -56,8 +56,7 @@ public class ScriptPanel extends JPanel { try { entry = (ScriptEntry) entries[i].clone(); - } - catch (CloneNotSupportedException cnse) { + } catch (CloneNotSupportedException cnse) { entry = new ScriptEntry(entries[i].getLanguage(), entries[i].getLanguageName(), entries[i].getLocation()); @@ -108,8 +107,10 @@ public class ScriptPanel extends JPanel { private void tableFocusLost() { TableCellEditor editor = table.getCellEditor(); + if (editor != null) { Object value = editor.getCellEditorValue(); + if (value != null) model.setValueAt(value, table.getEditingRow(), table.getEditingColumn()); @@ -118,16 +119,19 @@ public class ScriptPanel extends JPanel { private class ScriptTableModel extends AbstractTableModel { final String[] columnNames = {"Exported Method", - "Script Name"}; + "Script Name" + }; private ArrayList<ScriptEntry> scripts; private int nextRow; public ScriptTableModel(ScriptEntry[] entries) { scripts = new ArrayList<ScriptEntry>(entries.length + 11); + for (int i = 0; i < entries.length; i++) { scripts.add(entries[i]); } + nextRow = entries.length; } diff --git a/scripting/java/org/openoffice/idesupport/xml/Manifest.java b/scripting/java/org/openoffice/idesupport/xml/Manifest.java index 263de3d97b29..492df63b75ea 100644 --- a/scripting/java/org/openoffice/idesupport/xml/Manifest.java +++ b/scripting/java/org/openoffice/idesupport/xml/Manifest.java @@ -53,14 +53,13 @@ public class Manifest { try { root = (Element) - document.getElementsByTagName("manifest:manifest").item(0); + document.getElementsByTagName("manifest:manifest").item(0); el = document.createElement("manifest:file-entry"); el.setAttribute("manifest:media-type", type); el.setAttribute("manifest:full-path", entry); root.appendChild(el); - } - catch (Exception e) { + } catch (Exception e) { System.err.println("Error adding entry: " + e.getMessage()); } } @@ -78,25 +77,28 @@ public class Manifest { try { root = (Element) - document.getElementsByTagName("manifest:manifest").item(0); + document.getElementsByTagName("manifest:manifest").item(0); NodeList nl = root.getElementsByTagName("manifest:file-entry"); + if (nl == null || (len = nl.getLength()) == 0) return; ArrayList<Element> list = new ArrayList<Element>(); + for (int i = 0; i < len; i++) { el = (Element)nl.item(i); + if (el.getAttribute("manifest:full-path").startsWith(entry)) { list.add(el); } } Iterator iter = list.iterator(); + while (iter.hasNext()) root.removeChild((Element)iter.next()); - } - catch (Exception e) { + } catch (Exception e) { System.err.println("Error removing entry: " + e.getMessage()); } } @@ -109,8 +111,7 @@ public class Manifest { out = new ByteArrayOutputStream(); write(out); result = new ByteArrayInputStream(out.toByteArray()); - } - finally { + } finally { if (out != null) out.close(); } diff --git a/scripting/java/org/openoffice/idesupport/zip/ParcelZipper.java b/scripting/java/org/openoffice/idesupport/zip/ParcelZipper.java index 9fd7f5da00fd..3c8d797f220c 100644 --- a/scripting/java/org/openoffice/idesupport/zip/ParcelZipper.java +++ b/scripting/java/org/openoffice/idesupport/zip/ParcelZipper.java @@ -24,8 +24,7 @@ import org.openoffice.idesupport.filter.FileFilter; import org.openoffice.idesupport.filter.BinaryOnlyFilter; import org.openoffice.idesupport.xml.Manifest; -public class ParcelZipper -{ +public class ParcelZipper { public static final String PARCEL_PREFIX_DIR = "Scripts/"; private static final String PARCEL_EXTENSION = "sxp"; public static final String CONTENTS_DIRNAME = "Contents"; @@ -42,6 +41,7 @@ public class ParcelZipper public static synchronized ParcelZipper getParcelZipper() { if (zipper == null) zipper = new ParcelZipper(); + return zipper; } @@ -52,7 +52,7 @@ public class ParcelZipper public String removeParcel(File document, String parcelName) - throws IOException { + throws IOException { ZipInputStream documentStream = null; ZipOutputStream outStream = null; @@ -60,6 +60,7 @@ public class ParcelZipper if (!parcelName.startsWith(PARCEL_PREFIX_DIR)) parcelName = PARCEL_PREFIX_DIR + parcelName; + manifest = removeParcelFromManifest(document, parcelName); // first write contents of document to tmpfile @@ -76,38 +77,36 @@ public class ParcelZipper while ((inEntry = documentStream.getNextEntry()) != null) { - if(inEntry.getName().startsWith(parcelName)) + if (inEntry.getName().startsWith(parcelName)) continue; outEntry = new ZipEntry(inEntry); outStream.putNextEntry(outEntry); - if(inEntry.getName().equals("META-INF/manifest.xml") && - manifest != null) { + if (inEntry.getName().equals("META-INF/manifest.xml") && + manifest != null) { InputStream manifestStream = null; + try { manifestStream = manifest.getInputStream(); + while ((len = manifestStream.read(bytes)) != -1) outStream.write(bytes, 0, len); - } - finally { + } finally { if (manifestStream != null) manifestStream.close(); } - } - else if (!inEntry.isDirectory()) { + } else if (!inEntry.isDirectory()) { while ((len = documentStream.read(bytes)) != -1) outStream.write(bytes, 0, len); } outStream.closeEntry(); } - } - catch (IOException ioe) { + } catch (IOException ioe) { tmpfile.delete(); throw ioe; - } - finally { + } finally { if (documentStream != null) documentStream.close(); @@ -118,8 +117,7 @@ public class ParcelZipper if (!document.delete()) { tmpfile.delete(); throw new IOException("Could not overwrite " + document); - } - else + } else tmpfile.renameTo(document); return document.getAbsolutePath(); @@ -132,18 +130,16 @@ public class ParcelZipper 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) { - } - finally { + } catch (IOException ioe) { + } finally { try { if (documentZip != null) documentZip.close(); - } - catch (IOException ioe) {} + } catch (IOException ioe) {} } return result; @@ -153,6 +149,7 @@ public class ParcelZipper Manifest result = null; result = getManifestFromDocument(document); + if (result == null) return null; diff --git a/scripting/java/org/openoffice/netbeans/editor/JavaKit.java b/scripting/java/org/openoffice/netbeans/editor/JavaKit.java index 3f622927ed83..1a3b6abddd17 100644 --- a/scripting/java/org/openoffice/netbeans/editor/JavaKit.java +++ b/scripting/java/org/openoffice/netbeans/editor/JavaKit.java @@ -57,10 +57,10 @@ public class JavaKit extends ExtKit { public static final String JAVA_MIME_TYPE = "text/x-java"; // NOI18N - static final long serialVersionUID =-5445829962533684922L; + static final long serialVersionUID = -5445829962533684922L; static { - Settings.addInitializer( new JavaSettingsInitializer( JavaKit.class ) ); + Settings.addInitializer(new JavaSettingsInitializer(JavaKit.class)); Settings.reset(); URL skeleton = null, body = null; @@ -73,8 +73,8 @@ public class JavaKit extends ExtKit { new URLAccessor(body)); JCBaseFinder finder = new JCBaseFinder(); - finder.append( provider ); - JavaCompletion.setFinder( finder ); + finder.append(provider); + JavaCompletion.setFinder(finder); } } @@ -110,7 +110,7 @@ public class JavaKit extends ExtKit { protected void initDocument(BaseDocument doc) { doc.addLayer(new JavaDrawLayerFactory.JavaLayer(), - JavaDrawLayerFactory.JAVA_LAYER_VISIBILITY); + JavaDrawLayerFactory.JAVA_LAYER_VISIBILITY); doc.addDocumentListener(new JavaDrawLayerFactory.LParenWatcher()); } @@ -131,8 +131,7 @@ public class JavaKit extends ExtKit { /** Not implemented */ public void append(byte[] buffer, int off, int len) - throws IOException - { + throws IOException { throw new IllegalArgumentException("read only!"); } @@ -150,6 +149,7 @@ public class JavaKit extends ExtKit { */ public void read(byte[] buffer, int off, int len) throws IOException { InputStream str = getStream(actOff); + while (len > 0) { int count = str.read(buffer, off, len); streamOff += count; @@ -162,7 +162,7 @@ public class JavaKit extends ExtKit { * @param requestWrite if true, file is opened for read/write */ public void open(boolean requestWrite) throws IOException { - if(requestWrite) + if (requestWrite) throw new IllegalArgumentException("read only!"); } @@ -181,7 +181,7 @@ public class JavaKit extends ExtKit { * at which the next read or write occurs. */ public long getFilePointer() throws IOException { - return actOff; + return actOff; } /** Clears the file and sets the offset to 0 */ @@ -206,7 +206,7 @@ public class JavaKit extends ExtKit { stream = null; } - if(stream == null) { + if (stream == null) { stream = url.openStream(); streamOff = 0; } @@ -214,6 +214,7 @@ public class JavaKit extends ExtKit { while (streamOff < off) { long len = stream.skip(off - streamOff); streamOff += (int)len; + if (len == 0) throw new IOException("EOF"); } diff --git a/scripting/java/org/openoffice/netbeans/editor/NetBeansSourceView.java b/scripting/java/org/openoffice/netbeans/editor/NetBeansSourceView.java index b4b2bd8d4fa3..19388fd8f82f 100644 --- a/scripting/java/org/openoffice/netbeans/editor/NetBeansSourceView.java +++ b/scripting/java/org/openoffice/netbeans/editor/NetBeansSourceView.java @@ -49,25 +49,24 @@ public class NetBeansSourceView extends JPanel try { Class kitClass = Class.forName( - NetBeansSourceView.class.getPackage().getName() + ".JavaKit"); + NetBeansSourceView.class.getPackage().getName() + ".JavaKit"); JEditorPane.registerEditorKitForContentType( "text/x-java", kitClass.getName(), kitClass.getClassLoader()); - } - catch( ClassNotFoundException exc ) { + } catch (ClassNotFoundException exc) { } } private class MyLocalizer implements LocaleSupport.Localizer { private ResourceBundle bundle; - public MyLocalizer( String bundleName ) { - bundle = ResourceBundle.getBundle( bundleName ); + public MyLocalizer(String bundleName) { + bundle = ResourceBundle.getBundle(bundleName); } // Localizer - public String getString( String key ) { - return bundle.getString( key ); + public String getString(String key) { + return bundle.getString(key); } } @@ -102,10 +101,10 @@ public class NetBeansSourceView extends JPanel } java.net.URL url = null; + try { url = f.toURL(); - } - catch (java.net.MalformedURLException mue) { + } catch (java.net.MalformedURLException mue) { System.err.println("Invalid file"); System.exit(-1); } @@ -120,11 +119,11 @@ public class NetBeansSourceView extends JPanel } // Code grabbed from NetBeans editor module - public void scrollToLine(int line) - { + public void scrollToLine(int line) { BaseDocument doc = Utilities.getDocument(pane); int pos = -1; + if (doc != null) { // Obtain the offset where to jump pos = Utilities.getRowStartFromLineOffset(doc, line); @@ -132,11 +131,11 @@ public class NetBeansSourceView extends JPanel if (pos != -1) { Caret caret = pane.getCaret(); + if (caret instanceof BaseCaret) { // support extended scroll mode BaseCaret bCaret = (BaseCaret)caret; bCaret.setDot(pos, bCaret, EditorUI.SCROLL_FIND); - } - else { + } else { caret.setDot(pos); } } @@ -151,16 +150,14 @@ public class NetBeansSourceView extends JPanel so we don't get a storm of DocumentEvents during loading */ pane.getDocument().removeDocumentListener(this); - if (!isModified) - { + if (!isModified) { pane.setText(model.getText()); } // scroll to current position of the model try { scrollToLine(model.getCurrentPosition()); - } - catch (Exception e) { + } catch (Exception e) { // couldn't scroll to line, do nothing } diff --git a/scripting/java/org/openoffice/netbeans/modules/office/actions/BuildParcelAction.java b/scripting/java/org/openoffice/netbeans/modules/office/actions/BuildParcelAction.java index db68ba7f874a..9aa998cfe77a 100644 --- a/scripting/java/org/openoffice/netbeans/modules/office/actions/BuildParcelAction.java +++ b/scripting/java/org/openoffice/netbeans/modules/office/actions/BuildParcelAction.java @@ -50,7 +50,7 @@ public class BuildParcelAction extends BuildAllAction { if (task.isSuccessful()) { ParcelFolderCookie cookie = (ParcelFolderCookie) - activatedNodes[i].getCookie(ParcelFolderCookie.class); + activatedNodes[i].getCookie(ParcelFolderCookie.class); if (cookie != null) cookie.generate(); diff --git a/scripting/java/org/openoffice/netbeans/modules/office/actions/ConfigureParcelAction.java b/scripting/java/org/openoffice/netbeans/modules/office/actions/ConfigureParcelAction.java index 0e4005828c9c..fa64996ced70 100644 --- a/scripting/java/org/openoffice/netbeans/modules/office/actions/ConfigureParcelAction.java +++ b/scripting/java/org/openoffice/netbeans/modules/office/actions/ConfigureParcelAction.java @@ -43,15 +43,15 @@ public class ConfigureParcelAction extends CookieAction { return HelpCtx.DEFAULT_HELP; } - protected void performAction(final Node[] activatedNodes) - { + 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); + 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 index 015c15cfb54b..6f9f48b02489 100644 --- a/scripting/java/org/openoffice/netbeans/modules/office/actions/DeployParcelAction.java +++ b/scripting/java/org/openoffice/netbeans/modules/office/actions/DeployParcelAction.java @@ -51,16 +51,17 @@ 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 { +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 () { + public String getName() { return DEPLOY_LABEL; } - public HelpCtx getHelpCtx () { + public HelpCtx getHelpCtx() { return HelpCtx.DEFAULT_HELP; } @@ -79,12 +80,13 @@ public class DeployParcelAction extends CookieAction implements Presenter.Popup (ParcelCookie)nodes[0].getCookie(ParcelCookie.class); File target = new File(oi.getPath(File.separator + label + - File.separator + "Scripts")); + File.separator + "Scripts")); File langdir = new File(target, parcelCookie.getLanguage()); if (!langdir.exists()) { boolean response = askIfCreateDirectory(langdir); + if (!response) { return; } @@ -110,8 +112,10 @@ public class DeployParcelAction extends CookieAction implements Presenter.Popup item.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { File target = getTargetFile(); + if (target == null) return; + deploy(target); } }); @@ -120,15 +124,15 @@ public class DeployParcelAction extends CookieAction implements Presenter.Popup return menu; } - protected int mode () { + protected int mode() { return MODE_ONE; } - protected Class[] cookieClasses () { + protected Class[] cookieClasses() { return new Class[] { ParcelCookie.class }; } - protected void performAction (Node[] activatedNodes) { + protected void performAction(Node[] activatedNodes) { // do nothing, should not happen } @@ -150,7 +154,7 @@ public class DeployParcelAction extends CookieAction implements Presenter.Popup private boolean askIfCreateDirectory(File directory) { String message = directory.getAbsolutePath() + " does not exist. " + - "Do you want to create it now?"; + "Do you want to create it now?"; NotifyDescriptor d = new NotifyDescriptor.Confirmation( message, NotifyDescriptor.OK_CANCEL_OPTION); @@ -160,10 +164,10 @@ public class DeployParcelAction extends CookieAction implements Presenter.Popup return false; boolean result; + try { result = directory.mkdirs(); - } - catch (SecurityException se) { + } catch (SecurityException se) { result = false; } @@ -173,6 +177,7 @@ public class DeployParcelAction extends CookieAction implements Presenter.Popup tmp, NotifyDescriptor.ERROR_MESSAGE); TopManager.getDefault().notify(d2); } + return result; } @@ -185,14 +190,14 @@ public class DeployParcelAction extends CookieAction implements Presenter.Popup 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."; + "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()) { NagDialog warning = NagDialog.createInformationDialog( - message, "Show this message in future", true); + message, "Show this message in future", true); warning.show(); @@ -216,6 +221,7 @@ public class DeployParcelAction extends CookieAction implements Presenter.Popup file.getName().endsWith(".sxd") || file.getName().endsWith(".sxi")) return true; + return false; } @@ -229,6 +235,7 @@ public class DeployParcelAction extends CookieAction implements Presenter.Popup 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 index 7fa5fa7e0292..8b22e93ef9c4 100644 --- a/scripting/java/org/openoffice/netbeans/modules/office/actions/MountDocumentAction.java +++ b/scripting/java/org/openoffice/netbeans/modules/office/actions/MountDocumentAction.java @@ -26,41 +26,33 @@ import org.openide.util.actions.CookieAction; /** * @version 1.0 */ -public class MountDocumentAction extends CookieAction -{ - public String getName() - { +public class MountDocumentAction extends CookieAction { + public String getName() { return "Mount Document"; //NOI18N } - public HelpCtx getHelpCtx() - { + public HelpCtx getHelpCtx() { return HelpCtx.DEFAULT_HELP; } - protected int mode() - { + protected int mode() { // enable duplication for as many qualifying nodes as are selected: return CookieAction.MODE_ALL; } - protected java.lang.Class[] cookieClasses() - { + 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) - { + 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 index c579dacc2e53..01395dc3fb7d 100644 --- a/scripting/java/org/openoffice/netbeans/modules/office/actions/MountParcelAction.java +++ b/scripting/java/org/openoffice/netbeans/modules/office/actions/MountParcelAction.java @@ -26,40 +26,32 @@ import org.openide.util.actions.CookieAction; /** * @version 1.0 */ -public class MountParcelAction extends CookieAction -{ - public String getName() - { +public class MountParcelAction extends CookieAction { + public String getName() { return "Mount Parcel"; //NOI18N } - public HelpCtx getHelpCtx() - { + public HelpCtx getHelpCtx() { return HelpCtx.DEFAULT_HELP; } - protected int mode() - { + protected int mode() { // enable duplication for as many qualifying nodes as are selected: return CookieAction.MODE_ALL; } - protected java.lang.Class[] cookieClasses() - { + 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) - { + 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 index 04ac91f3e741..df57575020f4 100644 --- a/scripting/java/org/openoffice/netbeans/modules/office/actions/OfficeDocumentCookie.java +++ b/scripting/java/org/openoffice/netbeans/modules/office/actions/OfficeDocumentCookie.java @@ -22,8 +22,7 @@ import java.util.Enumeration; import javax.swing.event.ChangeListener; import org.openide.nodes.Node; -public interface OfficeDocumentCookie extends Node.Cookie -{ +public interface OfficeDocumentCookie extends Node.Cookie { void mount(); Enumeration getParcels(); void removeParcel(String name); diff --git a/scripting/java/org/openoffice/netbeans/modules/office/actions/OfficeDocumentSupport.java b/scripting/java/org/openoffice/netbeans/modules/office/actions/OfficeDocumentSupport.java index 0237872185bf..c77fc63a7cbc 100644 --- a/scripting/java/org/openoffice/netbeans/modules/office/actions/OfficeDocumentSupport.java +++ b/scripting/java/org/openoffice/netbeans/modules/office/actions/OfficeDocumentSupport.java @@ -44,8 +44,8 @@ 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 -{ +public class OfficeDocumentSupport implements OfficeDocumentCookie, OpenCookie, + FileChangeListener { protected OfficeDocumentDataObject dataObj; private boolean isMounted = false; private OfficeDocument document; @@ -54,12 +54,13 @@ public class OfficeDocumentSupport implements OfficeDocumentCookie, OpenCookie, public OfficeDocumentSupport(OfficeDocumentDataObject dataObj) { this.dataObj = dataObj; FileObject fo = dataObj.getPrimaryFile(); + try { this.document = new OfficeDocument(FileUtil.toFile(fo)); - } - catch (Exception e) { + } catch (Exception e) { e.printStackTrace(); } + fo.addFileChangeListener(this); } @@ -69,26 +70,24 @@ public class OfficeDocumentSupport implements OfficeDocumentCookie, OpenCookie, try { ZipMounter.getZipMounter().mountZipFile(file); isMounted = true; - } - catch (IOException ioe) { + } catch (IOException ioe) { ErrorManager.getDefault().notify(ioe); - } - catch (PropertyVetoException pve) { + } catch (PropertyVetoException pve) { ErrorManager.getDefault().notify(pve); } } - public void open () { + public void open() { File file = FileUtil.toFile(dataObj.getPrimaryFile()); OfficeSettings settings = OfficeSettings.getDefault(); File soffice = new File(settings.getOfficeDirectory().getPath( - File.separator + "soffice")); + File.separator + "soffice")); try { - Process p = Runtime.getRuntime ().exec (new String[] { - soffice.getAbsolutePath(), file.getAbsolutePath () - }); + Process p = Runtime.getRuntime().exec(new String[] { + soffice.getAbsolutePath(), file.getAbsolutePath() + }); } catch (IOException ioe) { ErrorManager.getDefault().notify(ioe); } diff --git a/scripting/java/org/openoffice/netbeans/modules/office/actions/ParcelCookie.java b/scripting/java/org/openoffice/netbeans/modules/office/actions/ParcelCookie.java index 1e4f701234bd..1c782ae6bf22 100644 --- a/scripting/java/org/openoffice/netbeans/modules/office/actions/ParcelCookie.java +++ b/scripting/java/org/openoffice/netbeans/modules/office/actions/ParcelCookie.java @@ -21,8 +21,7 @@ package org.openoffice.netbeans.modules.office.actions; import java.io.File; import org.openide.nodes.Node; -public interface ParcelCookie extends Node.Cookie -{ +public interface ParcelCookie extends Node.Cookie { File getFile(); String getLanguage(); diff --git a/scripting/java/org/openoffice/netbeans/modules/office/actions/ParcelDescriptorEditorSupport.java b/scripting/java/org/openoffice/netbeans/modules/office/actions/ParcelDescriptorEditorSupport.java index 00402b93409d..c4378ceff24d 100644 --- a/scripting/java/org/openoffice/netbeans/modules/office/actions/ParcelDescriptorEditorSupport.java +++ b/scripting/java/org/openoffice/netbeans/modules/office/actions/ParcelDescriptorEditorSupport.java @@ -32,7 +32,8 @@ import org.openoffice.netbeans.modules.office.loader.ParcelDescriptorDataObject; /** Support for editing a data object as text. */ // Replace OpenCookie with EditCookie or maybe ViewCookie as desired: -public class ParcelDescriptorEditorSupport extends DataEditorSupport implements EditorCookie, OpenCookie, CloseCookie, PrintCookie { +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 @@ -51,12 +52,15 @@ public class ParcelDescriptorEditorSupport extends DataEditorSupport implements 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; } @@ -66,11 +70,13 @@ public class ParcelDescriptorEditorSupport extends DataEditorSupport implements 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(); } @@ -111,7 +117,8 @@ public class ParcelDescriptorEditorSupport extends DataEditorSupport implements * @throws IOException if the lock could not be taken */ protected FileLock takeLock() throws IOException { - return ((ParcelDescriptorDataObject)getDataObject()).getPrimaryEntry().takeLock(); + return ((ParcelDescriptorDataObject) + getDataObject()).getPrimaryEntry().takeLock(); } /** Find the editor support this environment represents. @@ -120,7 +127,8 @@ public class ParcelDescriptorEditorSupport extends DataEditorSupport implements * @return the editor support */ public CloneableOpenSupport findCloneableOpenSupport() { - return (ParcelDescriptorEditorSupport)getDataObject().getCookie(ParcelDescriptorEditorSupport.class); + 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 index 21091196b0e8..0e7e4226d657 100644 --- a/scripting/java/org/openoffice/netbeans/modules/office/actions/ParcelDescriptorParserCookie.java +++ b/scripting/java/org/openoffice/netbeans/modules/office/actions/ParcelDescriptorParserCookie.java @@ -22,8 +22,7 @@ import org.w3c.dom.NodeList; import javax.swing.event.ChangeListener; import org.openide.nodes.Node; -public interface ParcelDescriptorParserCookie extends Node.Cookie -{ +public interface ParcelDescriptorParserCookie extends Node.Cookie { // should return a NodeList of org.w3c.dom.Element NodeList getScriptElements(); diff --git a/scripting/java/org/openoffice/netbeans/modules/office/actions/ParcelDescriptorParserSupport.java b/scripting/java/org/openoffice/netbeans/modules/office/actions/ParcelDescriptorParserSupport.java index 7d71560bce59..f3f105679677 100644 --- a/scripting/java/org/openoffice/netbeans/modules/office/actions/ParcelDescriptorParserSupport.java +++ b/scripting/java/org/openoffice/netbeans/modules/office/actions/ParcelDescriptorParserSupport.java @@ -32,50 +32,45 @@ import org.openide.filesystems.*; import org.openide.xml.XMLUtil; public class ParcelDescriptorParserSupport - implements ParcelDescriptorParserCookie, FileChangeListener -{ + implements ParcelDescriptorParserCookie, FileChangeListener { private FileObject fo; private Document document; private Set listeners; - public ParcelDescriptorParserSupport(FileObject fo) - { + public ParcelDescriptorParserSupport(FileObject fo) { this.fo = fo; fo.addFileChangeListener(this); } - private synchronized void parseFile() - { + private synchronized void parseFile() { File file = FileUtil.toFile(fo); InputSource is; try { is = new InputSource(new FileInputStream(file)); - } - catch (FileNotFoundException fnfe) { + } 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) { + } catch (IOException ioe) { System.out.println("IO Error parsing file: " + file.getName()); - } - catch (SAXException se) { + } catch (SAXException se) { System.out.println("Sax Error parsing file: " + file.getName()); } } - public synchronized NodeList getScriptElements() - { + public synchronized NodeList getScriptElements() { if (document == null) parseFile(); if (document != null) return document.getElementsByTagName("script"); + return null; } diff --git a/scripting/java/org/openoffice/netbeans/modules/office/actions/ParcelFolderCookie.java b/scripting/java/org/openoffice/netbeans/modules/office/actions/ParcelFolderCookie.java index 778bd208b570..6a17ee13ab31 100644 --- a/scripting/java/org/openoffice/netbeans/modules/office/actions/ParcelFolderCookie.java +++ b/scripting/java/org/openoffice/netbeans/modules/office/actions/ParcelFolderCookie.java @@ -20,8 +20,7 @@ package org.openoffice.netbeans.modules.office.actions; import org.openide.nodes.Node; -public interface ParcelFolderCookie extends Node.Cookie -{ +public interface ParcelFolderCookie extends Node.Cookie { void generate(); boolean configure(); diff --git a/scripting/java/org/openoffice/netbeans/modules/office/actions/ParcelFolderSupport.java b/scripting/java/org/openoffice/netbeans/modules/office/actions/ParcelFolderSupport.java index bf310bc8b2c0..ce0ac563b0a5 100644 --- a/scripting/java/org/openoffice/netbeans/modules/office/actions/ParcelFolderSupport.java +++ b/scripting/java/org/openoffice/netbeans/modules/office/actions/ParcelFolderSupport.java @@ -58,8 +58,7 @@ import org.openoffice.idesupport.zip.ParcelZipper; import org.openoffice.idesupport.filter.FileFilter; import org.openoffice.idesupport.ui.ConfigurePanel; -public class ParcelFolderSupport implements ParcelFolderCookie -{ +public class ParcelFolderSupport implements ParcelFolderCookie { protected ParcelFolder parcelFolder; private ConfigurePanel configuror = null; @@ -72,8 +71,7 @@ public class ParcelFolderSupport implements ParcelFolderCookie if (descriptor == null) { return ""; - } - else { + } else { return descriptor.getLanguage(); } } @@ -83,8 +81,7 @@ public class ParcelFolderSupport implements ParcelFolderCookie if (descriptor == null) { return ""; - } - else { + } else { return descriptor.getLanguageProperty("classpath"); } } @@ -97,8 +94,7 @@ public class ParcelFolderSupport implements ParcelFolderCookie try { descriptor.write(); - } - catch (IOException ioe) { + } catch (IOException ioe) { ErrorManager.getDefault().notify(ioe); } } @@ -108,7 +104,7 @@ public class ParcelFolderSupport implements ParcelFolderCookie FileObject primary = parcelFolder.getPrimaryFile(); File contents = FileUtil.toFile( - primary.getFileObject(ParcelZipper.CONTENTS_DIRNAME)); + primary.getFileObject(ParcelZipper.CONTENTS_DIRNAME)); return ParcelDescriptor.getParcelDescriptor(contents); } @@ -128,32 +124,32 @@ public class ParcelFolderSupport implements ParcelFolderCookie // 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); + parcelBase.getName() + "." + ParcelZipper.PARCEL_EXTENSION); boolean proceed = configure(); + if (!proceed) { return; } final OutputWriter out = ParcelSupport.getOutputWindowWriter(parcelDir.getName() + " (generating)"); + try { out.println("Generating: " + parcelDir.getName(), null); - ParcelZipper.getParcelZipper().zipParcel(contentsDir, targetfile, node.getFileFilter()); + 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) - { + } catch (IOException ioe) { + out.println("GENERATION FAILED: reason: " + ioe.getClass().getName() + ": " + + ioe.getMessage()); + } finally { + if (out != null) { out.close(); } } @@ -164,33 +160,32 @@ public class ParcelFolderSupport implements ParcelFolderCookie FileObject primary = parcelFolder.getPrimaryFile(); File contents = FileUtil.toFile( - primary.getFileObject(ParcelZipper.CONTENTS_DIRNAME)); + primary.getFileObject(ParcelZipper.CONTENTS_DIRNAME)); ArrayList<String> classpath = getConfigureClasspath(); classpath.add(contents.getAbsolutePath()); try { ParcelDescriptor descriptor = getParcelDescriptor(); + if (descriptor == null) { descriptor = ParcelDescriptor.createParcelDescriptor(contents); } if (configuror == null) { configuror = new ConfigurePanel(contents.getAbsolutePath(), - classpath, descriptor); - } - else { + classpath, descriptor); + } else { configuror.reload(contents.getAbsolutePath(), classpath, - descriptor); + descriptor); } - } - catch (IOException ioe) { + } catch (IOException ioe) { ErrorManager.getDefault().notify(ioe); return false; } DialogDescriptor dd = new DialogDescriptor(configuror, - ConfigurePanel.DIALOG_TITLE); + ConfigurePanel.DIALOG_TITLE); Dialog dialog = TopManager.getDefault().createDialog(dd); dialog.show(); @@ -199,14 +194,13 @@ public class ParcelFolderSupport implements ParcelFolderCookie try { ParcelDescriptor descriptor = configuror.getConfiguration(); descriptor.write(); - } - catch (Exception e) { + } catch (Exception e) { ErrorManager.getDefault().notify(e); } - } - else { + } else { return false; } + return true; } @@ -214,30 +208,30 @@ public class ParcelFolderSupport implements ParcelFolderCookie ArrayList<String> result = new ArrayList<String>(); String classpath = NbClassPath.createRepositoryPath().getClassPath(); - if ( System.getProperty( "os.name" ).startsWith( "Windows" ) ) - { + + 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(); + 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()) + 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.separator + "program" + File.separator + "classes")); File[] jarfiles = classesDir.listFiles(); for (int i = 0; i < jarfiles.length; i++) diff --git a/scripting/java/org/openoffice/netbeans/modules/office/actions/ParcelSupport.java b/scripting/java/org/openoffice/netbeans/modules/office/actions/ParcelSupport.java index ab05d89d687d..381be44ccadb 100644 --- a/scripting/java/org/openoffice/netbeans/modules/office/actions/ParcelSupport.java +++ b/scripting/java/org/openoffice/netbeans/modules/office/actions/ParcelSupport.java @@ -44,8 +44,7 @@ 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 -{ +public class ParcelSupport implements ParcelCookie { private FileObject fo; private ParcelZipper zipper = ParcelZipper.getParcelZipper(); private String language = null; @@ -62,26 +61,23 @@ public class ParcelSupport implements ParcelCookie if (language == null) { try { language = zipper.getParcelLanguage(getFile()); - } - catch (IOException ioe) { + } catch (IOException ioe) { return null; } } + return language; } - public void mount() - { + public void mount() { File parcel = FileUtil.toFile(fo); if (parcel != null) { try { ZipMounter.getZipMounter().mountZipFile(parcel); - } - catch (IOException ioe) { + } catch (IOException ioe) { ErrorManager.getDefault().notify(ioe); - } - catch (PropertyVetoException pve) { + } catch (PropertyVetoException pve) { ErrorManager.getDefault().notify(pve); } } @@ -93,12 +89,12 @@ public class ParcelSupport implements ParcelCookie 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."; + "Office, please close it before continuing. Click OK to " + + "continue deployment."; if (settings.getWarnBeforeDocDeploy()) { NagDialog warning = NagDialog.createConfirmationDialog( - message, "Show this message in future", true); + message, "Show this message in future", true); boolean result = warning.show(); @@ -117,36 +113,35 @@ public class ParcelSupport implements ParcelCookie if (!zipper.isOverwriteNeeded(source, target)) if (!promptForOverwrite(source, target)) return false; - } - catch (IOException ioe) { - out.println("DEPLOYMENT FAILED: reason: " + - ioe.getClass().getName() + ": "+ ioe.getMessage()); - 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); + "\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) + } catch (IOException ioe) { + out.println("DEPLOYMENT FAILED: reason: " + + ioe.getClass().getName() + ": " + ioe.getMessage()); + return false; + } finally { + if (out != null) out.close(); } + return true; } @@ -156,19 +151,20 @@ public class ParcelSupport implements ParcelCookie io.setOutputVisible(true); OutputWriter out = io.getOut(); + try { out.reset(); - } - catch( IOException e) { + } 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?"; + "to this target. Do you wish to overwrite it?"; NotifyDescriptor d = new NotifyDescriptor.Confirmation( message, NotifyDescriptor.OK_CANCEL_OPTION); diff --git a/scripting/java/org/openoffice/netbeans/modules/office/filesystem/OpenOfficeDocFileSystem.java b/scripting/java/org/openoffice/netbeans/modules/office/filesystem/OpenOfficeDocFileSystem.java index e86f5e03ae3c..6081445d258a 100644 --- a/scripting/java/org/openoffice/netbeans/modules/office/filesystem/OpenOfficeDocFileSystem.java +++ b/scripting/java/org/openoffice/netbeans/modules/office/filesystem/OpenOfficeDocFileSystem.java @@ -42,8 +42,7 @@ import org.openide.util.NbBundle; * OpenOffice.org Document filesystem. */ public class OpenOfficeDocFileSystem - extends AbstractFileSystem -{ + extends AbstractFileSystem { public static final String SCRIPTS_ROOT = "Scripts"; // must be a folder public static final String SEPARATOR = "/"; // zip file separator @@ -74,6 +73,7 @@ public class OpenOfficeDocFileSystem static { // Identify the type of OS String osname = System.getProperty("os.name"); + if (osname.startsWith("Mac OS")) osType = OS_MACOS; else if (osname.startsWith("Windows")) @@ -85,8 +85,7 @@ public class OpenOfficeDocFileSystem /** * Default constructor. Initializes new OpenOffice filesystem. */ - public OpenOfficeDocFileSystem() - { + public OpenOfficeDocFileSystem() { // Create the filesystem cache cache = new HashMap(); @@ -116,8 +115,7 @@ public class OpenOfficeDocFileSystem /** * Constructor. Initializes new OpenOffice filesystem with FS capability. */ - public OpenOfficeDocFileSystem(FileSystemCapability cap) - { + public OpenOfficeDocFileSystem(FileSystemCapability cap) { this(); setCapability(cap); } @@ -127,8 +125,7 @@ public class OpenOfficeDocFileSystem * NOTE: The scope is not a part of the signature so it is impossible * to mount the same archive more than once. */ - public static String computeSystemName(File file) - { + public static String computeSystemName(File file) { return OpenOfficeDocFileSystem.class.getName() + "[" + file + "]"; } @@ -137,21 +134,19 @@ public class OpenOfficeDocFileSystem /** * Provides the 'human readable' name of the instance of the filesystem. */ - public String getDisplayName() - { + public String getDisplayName() { if (!isValid()) return NbBundle.getMessage(OpenOfficeDocFileSystem.class, - "LAB_invalid_file_system", ((docFile != null)? docFile.toString(): "")); + "LAB_invalid_file_system", ((docFile != null) ? docFile.toString() : "")); else return NbBundle.getMessage(OpenOfficeDocFileSystem.class, - "LAB_valid_file_system", docFile.toString()); + "LAB_valid_file_system", docFile.toString()); } /** * Retrieves the 'document' property. */ - public File getDocument() - { + public File getDocument() { return docFile; } @@ -162,39 +157,45 @@ public class OpenOfficeDocFileSystem // of the root file object) should cause everything using this filesystem // to refresh. The system name must change and refreshRoot should be used // to ensure that everything is correctly updated. + public synchronized void setDocument(File file) - throws java.beans.PropertyVetoException, java.io.IOException - { -System.out.println("OpenOfficeDocFileSystem.setDocument: file=\"" + file.toString() + "\""); - if(!file.exists() || !file.isFile()) { + throws java.beans.PropertyVetoException, java.io.IOException { + System.out.println("OpenOfficeDocFileSystem.setDocument: file=\"" + + file.toString() + "\""); + + if (!file.exists() || !file.isFile()) { IOException ioe = new IOException( file.toString() + " does not exist"); ErrorManager.getDefault().annotate(ioe, NbBundle.getMessage( - OpenOfficeDocFileSystem.class, "EXC_root_dir_does_not_exist", - file.toString())); + OpenOfficeDocFileSystem.class, "EXC_root_dir_does_not_exist", + file.toString())); throw ioe; } + // update the document try { - updateDocument(); - } catch(IOException ioe) { + updateDocument(); + } catch (IOException ioe) { // cannot save all!!! -System.out.println("*** OpenOfficeDocFileSystem.setDocument:"); -System.out.println(" file: " + ((docFile != null)? docFile.toString(): "")); -System.out.println(" exception: " + ioe.getMessage()); + System.out.println("*** OpenOfficeDocFileSystem.setDocument:"); + System.out.println(" file: " + ((docFile != null) ? docFile.toString() : + "")); + System.out.println(" exception: " + ioe.getMessage()); } + // new document type verification!!! closeDocument(); + // open a new document try { openDocument(file); firePropertyChange(PROP_ROOT, null, refreshRoot()); setRefreshTime(REFRESH_TIME); - } catch(IOException ioe) { + } catch (IOException ioe) { // cannot open a new document!!! -System.out.println("*** OpenOfficeDocFileSystem.setDocument:"); -System.out.println(" file: " + ((file != null)? file.toString(): "")); -System.out.println(" exception: " + ioe.getMessage()); + System.out.println("*** OpenOfficeDocFileSystem.setDocument:"); + System.out.println(" file: " + ((file != null) ? file.toString() : "")); + System.out.println(" exception: " + ioe.getMessage()); } } @@ -203,8 +204,7 @@ System.out.println(" exception: " + ioe.getMessage()); * NOTE: The portion of the mounted document available to the user is * always editable. */ - public boolean isReadOnly() - { + public boolean isReadOnly() { return false; } @@ -213,8 +213,7 @@ System.out.println(" exception: " + ioe.getMessage()); * NOTE: The portion of the mounted document available to the user is * always editable. */ - public void setReadOnly(boolean flag) - { + public void setReadOnly(boolean flag) { // sorry! it is not supported. } @@ -224,8 +223,7 @@ System.out.println(" exception: " + ioe.getMessage()); * Participates in the environment configuration. * This is how you can affect the classpath for execution, compilation, etc. */ - public void prepareEnvironment(FileSystem.Environment environment) - { + public void prepareEnvironment(FileSystem.Environment environment) { // BUG: the compiller cannot access files within the OpenOffice document. //environment.addClassPath(docFile.toString()); } @@ -266,7 +264,7 @@ System.out.println(" exception: " + ioe.getMessage()); // The actions should typically be CookieActions looking for DataObject // cookies, where the object's primary file is on this type of filesystem. public SystemAction[] getActions() { -// ------>>>> UPDATE OPENOFFICE DOCUMENT <<<<------ + // ------>>>> UPDATE OPENOFFICE DOCUMENT <<<<------ return new SystemAction[] { SystemAction.get(SomeAction.class), null, // separator @@ -283,17 +281,18 @@ System.out.println(" exception: " + ioe.getMessage()); * to avoid retaining resources for too long etc. Filesystems should maintain correct * semantics regardless of whether and when this method is called. */ - public void removeNotify() - { + public void removeNotify() { setRefreshTime(REFRESH_OFF); // disable refresh + // update the document try { - updateDocument(); - } catch(IOException ioe) { + updateDocument(); + } catch (IOException ioe) { // cannot save all!!! -System.out.println("*** OpenOfficeDocFileSystem.removeNotify:"); -System.out.println(" exception: " + ioe.getMessage()); + System.out.println("*** OpenOfficeDocFileSystem.removeNotify:"); + System.out.println(" exception: " + ioe.getMessage()); } + closeDocument(); super.removeNotify(); } @@ -302,9 +301,8 @@ System.out.println(" exception: " + ioe.getMessage()); * Opens (mounts) an OpenOffice document. */ private void openDocument(File file) - throws IOException, PropertyVetoException - { - synchronized(cache) { + throws IOException, PropertyVetoException { + synchronized (cache) { setSystemName(computeSystemName(file)); docFile = file; zipFile = new ZipFile(docFile); @@ -316,19 +314,19 @@ System.out.println(" exception: " + ioe.getMessage()); /* * Closes the document and cleans up the cache. */ - private void closeDocument() - { - synchronized(cache) { + private void closeDocument() { + synchronized (cache) { // if a document mounted - close it - if(docFile != null) { + if (docFile != null) { // close the document archive - if(zipFile != null) { + if (zipFile != null) { try { zipFile.close(); - } catch(IOException ioe) { + } catch (IOException ioe) { // sorry! we can do nothing about it. } } + zipFile = null; // clean up cache scanDocument(new CleanStrategy()); @@ -341,21 +339,24 @@ System.out.println(" exception: " + ioe.getMessage()); /* * Creates a document cache. */ - private void cacheDocument(Enumeration entries, Strategy editables) - { + private void cacheDocument(Enumeration entries, Strategy editables) { Entry cacheEntry; ZipEntry archEntry; - synchronized(cache) { + + synchronized (cache) { cache.clear(); // root folder cacheEntry = new ReadWriteEntry(null); cache.put(cacheEntry.getName(), cacheEntry); + // the rest of items - while(entries.hasMoreElements()) { + while (entries.hasMoreElements()) { archEntry = (ZipEntry)entries.nextElement(); cacheEntry = new Entry(archEntry); - if(editables.evaluate(cacheEntry)) + + if (editables.evaluate(cacheEntry)) cacheEntry = new ReadWriteEntry(archEntry); + cache.put(cacheEntry.getName(), cacheEntry); } } // synchronized @@ -365,44 +366,51 @@ System.out.println(" exception: " + ioe.getMessage()); * Updates the document. */ private void updateDocument() - throws IOException - { - if(docFile == null) + throws IOException { + if (docFile == null) return; - synchronized(cache) { + + synchronized (cache) { ModifiedStrategy modifiedStrategy = new ModifiedStrategy(); scanDocument(modifiedStrategy); - if(isModified || modifiedStrategy.isModified()) - { + + if (isModified || modifiedStrategy.isModified()) { File tmpFile = null; + try { // create updated document tmpFile = File.createTempFile( - TMP_FILE_PREF, TMP_FILE_SUFX, docFile.getParentFile()); + TMP_FILE_PREF, TMP_FILE_SUFX, docFile.getParentFile()); saveDocument(tmpFile); - } catch(IOException ioe) { - if(tmpFile != null) + } catch (IOException ioe) { + if (tmpFile != null) tmpFile.delete(); + throw ioe; } + // close the document archive - if(zipFile != null) { + if (zipFile != null) { try { zipFile.close(); - } catch(IOException ioe) { + } catch (IOException ioe) { } } + zipFile = null; // create the document and backup File newFile = new File(docFile.getParentFile() + File.separator + - "~" + docFile.getName()); - if(newFile.exists()) + "~" + docFile.getName()); + + if (newFile.exists()) newFile.delete(); // delete old backup + docFile.renameTo(newFile); tmpFile.renameTo(docFile); // open the document archive zipFile = new ZipFile(docFile); } + isModified = false; } // synchronized } @@ -411,9 +419,8 @@ System.out.println(" exception: " + ioe.getMessage()); * Saves the document in a new archive. */ private void saveDocument(File file) - throws IOException - { - synchronized(cache) { + throws IOException { + synchronized (cache) { SaveStrategy saver = new SaveStrategy(file); scanDocument(saver); saver.close(); @@ -423,11 +430,11 @@ System.out.println(" exception: " + ioe.getMessage()); /* * Provides each individual entry in the cached document to an apraiser. */ - private void scanDocument(Strategy strategy) - { - synchronized(cache) { + private void scanDocument(Strategy strategy) { + synchronized (cache) { Iterator itr = cache.values().iterator(); - while(itr.hasNext()) { + + while (itr.hasNext()) { strategy.evaluate((Entry)itr.next()); } } // synchronized @@ -437,25 +444,29 @@ System.out.println(" exception: " + ioe.getMessage()); * Retrieves or creates a file. */ private Entry getFileEntry(String name) - throws IOException - { + throws IOException { Entry cEntry = null; - synchronized(cache) { + + synchronized (cache) { cEntry = (Entry)cache.get(name); - if(cEntry == null) { + + if (cEntry == null) { // create a new file ZipEntry zEntry = new ZipEntry(name); zEntry.setTime(new Date().getTime()); cEntry = new Entry(zEntry); - if(!editableStrategy.evaluate(cEntry)) { + + if (!editableStrategy.evaluate(cEntry)) { throw new IOException( "cannot create/edit readonly file"); // I18N } + cEntry = new ReadWriteEntry(zEntry); cache.put(cEntry.getName(), cEntry); isModified = true; } } // synchronized + return cEntry; } @@ -463,12 +474,13 @@ System.out.println(" exception: " + ioe.getMessage()); * Retrieves or creates a folder. */ private Entry getFolderEntry(String name) - throws IOException - { + throws IOException { Entry cEntry = null; - synchronized(cache) { + + synchronized (cache) { cEntry = (Entry)cache.get(name); - if(cEntry == null) { + + if (cEntry == null) { // create a new folder ZipEntry zEntry = new ZipEntry(name + SEPARATOR); zEntry.setMethod(ZipEntry.STORED); @@ -477,19 +489,22 @@ System.out.println(" exception: " + ioe.getMessage()); zEntry.setCrc(crc.getValue()); zEntry.setTime(new Date().getTime()); cEntry = new Entry(zEntry); - if(!editableStrategy.evaluate(cEntry)) { + + if (!editableStrategy.evaluate(cEntry)) { throw new IOException( "cannot create folder"); // I18N } + cEntry = new ReadWriteEntry(zEntry); cEntry.getOutputStream(); // sets up modified flag cache.put(cEntry.getName(), cEntry); isModified = true; } else { - if(!cEntry.isFolder()) + if (!cEntry.isFolder()) cEntry = null; } } // synchronized + return cEntry; } @@ -502,20 +517,23 @@ System.out.println(" exception: " + ioe.getMessage()); * the rest of the code. * WORKAROUND: we have to strip leading '/' if it is in the name. */ - private static String zipName(String name) - { - String zname = ((name.startsWith(File.separator))? - name.substring(File.separator.length()): name); - switch(osType) { + private static String zipName(String name) { + String zname = ((name.startsWith(File.separator)) ? + name.substring(File.separator.length()) : name); + + switch (osType) { case OS_MACOS: zname = zname.replace(':', '/'); // ':' by '/' break; + case OS_WINDOWS: zname = zname.replace((char)0x5c, '/'); // '\' by '/' break; + default: break; } + return zname; } @@ -526,14 +544,15 @@ System.out.println(" exception: " + ioe.getMessage()); * not affect the file's presence or name. */ private class InfoImpl - implements Info - { + implements Info { public boolean folder(String name) { - synchronized(cache) { + synchronized (cache) { String zname = zipName(name); Entry entry = (Entry)cache.get(zname); - if(entry != null) + + if (entry != null) return entry.isFolder(); + // logical zip file entry childrenStrategy.setParent(zname); scanDocument(childrenStrategy); @@ -542,14 +561,14 @@ System.out.println(" exception: " + ioe.getMessage()); } public Date lastModified(String name) { - synchronized(cache) { + synchronized (cache) { Entry entry = (Entry)cache.get(zipName(name)); - return new Date((entry != null)? entry.getTime(): 0L); + return new Date((entry != null) ? entry.getTime() : 0L); } } public boolean readOnly(String name) { - synchronized(cache) { + synchronized (cache) { Entry entry = (Entry)cache.get(zipName(name)); return entry && entry.isReadOnly(); } @@ -564,24 +583,22 @@ System.out.println(" exception: " + ioe.getMessage()); } public long size(String name) { - synchronized(cache) { + synchronized (cache) { Entry entry = (Entry)cache.get(zipName(name)); - return (entry != null)? entry.getSize(): 0; + return (entry != null) ? entry.getSize() : 0; } // synchronized } public InputStream inputStream(String name) - throws FileNotFoundException - { - synchronized(cache) { + throws FileNotFoundException { + synchronized (cache) { Entry entry = (Entry)cache.get(zipName(name)); - return (entry != null)? entry.getInputStream(): null; + return (entry != null) ? entry.getInputStream() : null; } // synchronized } public OutputStream outputStream(String name) - throws IOException - { + throws IOException { return getFileEntry(zipName(name)).getOutputStream(); } @@ -589,19 +606,18 @@ System.out.println(" exception: " + ioe.getMessage()); // This only means that you should define how the file should be locked // to the outside world--perhaps it does not need to be. public void lock(String name) - throws IOException - { -/* - File file = getFile(name); - if (file.exists() == true && file.canWrite() == false) { - IOException ioe = new IOException("file " + file + - " could not be locked"); - ErrorManager.getDefault().annotate(ioe, NbBundle.getMessage( - OpenOfficeDocFileSystem.class, "EXC_file_could_not_be_locked", - file.getName(), getDisplayName(), file.getPath())); - throw ioe; - } -*/ + throws IOException { + /* + File file = getFile(name); + if (file.exists() == true && file.canWrite() == false) { + IOException ioe = new IOException("file " + file + + " could not be locked"); + ErrorManager.getDefault().annotate(ioe, NbBundle.getMessage( + OpenOfficeDocFileSystem.class, "EXC_file_could_not_be_locked", + file.getName(), getDisplayName(), file.getPath())); + throw ioe; + } + */ } public void unlock(String name) { @@ -620,80 +636,90 @@ System.out.println(" exception: " + ioe.getMessage()); * Operations that change the available files. */ private class ChangeImpl - implements Change - { + implements Change { public void createFolder(String name) - throws IOException - { - synchronized(cache) { + throws IOException { + synchronized (cache) { String zname = zipName(name); - if(cache.get(zname) != null) { + + if (cache.get(zname) != null) { throw new IOException( "cannot create new folder: " + name); // I18N } + getFolderEntry(zname); } // synchronized } public void createData(String name) - throws IOException - { - synchronized(cache) { + throws IOException { + synchronized (cache) { String zname = zipName(name); - if(cache.get(zname) != null) { + + if (cache.get(zname) != null) { throw new IOException( "cannot create new data: " + name); // I18N } + OutputStream os = getFileEntry(zname).getOutputStream(); os.close(); } // synchronized } public void rename(String oldName, String newName) - throws IOException - { + throws IOException { String oname = zipName(oldName); String nname = zipName(newName); - if((oname.length() == 0) || (nname.length() == 0)) { + + if ((oname.length() == 0) || (nname.length() == 0)) { throw new IOException( "cannot move or rename the root folder"); // I18N } - synchronized(cache) { - if(cache.get(nname) != null) { + + synchronized (cache) { + if (cache.get(nname) != null) { throw new IOException( "target file/folder " + newName + " exists"); // I18N } + Entry entry = (Entry)cache.get(oname); - if(entry == null) { + + if (entry == null) { throw new IOException( "there is no such a file/folder " + oldName); // I18N } - if(entry.isReadOnly()) { + + if (entry.isReadOnly()) { throw new IOException( "file/folder " + oldName + " is readonly"); // I18N } + entry.rename(nname); - if(!editableStrategy.evaluate(entry)) { + + if (!editableStrategy.evaluate(entry)) { entry.rename(oname); throw new IOException( "cannot create file/folder"); // I18N } + cache.remove(oname); cache.put(entry.getName(), entry); } // synchronized } public void delete(String name) - throws IOException - { + throws IOException { String zname = zipName(name); - if(zname.length() == 0) { + + if (zname.length() == 0) { throw new IOException( "cannot delete the root folder"); // I18N } - synchronized(cache) { + + synchronized (cache) { Entry entry = (Entry)cache.remove(zname); - if(entry != null) { + + if (entry != null) { // BUG: this is the design bug. Cache has to // remember that the entry was removed. isModified = true; @@ -707,17 +733,17 @@ System.out.println(" exception: " + ioe.getMessage()); * Operation which provides the directory structure. */ private class ListImpl - implements List - { - public String[] children(String name) - { + implements List { + public String[] children(String name) { String[] children = null; - synchronized(cache) { + + synchronized (cache) { String zname = zipName(name); Entry entry = (Entry)cache.get(zname); - if(entry != null) { + + if (entry != null) { // real zip file entry - if(entry.isFolder()) { + if (entry.isFolder()) { childrenStrategy.setParent(entry.getName()); } } else { @@ -725,9 +751,11 @@ System.out.println(" exception: " + ioe.getMessage()); // (portion of the path of a real zip file entry) childrenStrategy.setParent(zname); } + scanDocument(childrenStrategy); children = childrenStrategy.getChildren(); } // synchronize + return children; } @@ -781,8 +809,7 @@ System.out.println(" exception: " + ioe.getMessage()); /* ----------------------------------------------------------- * This interface hides an action will be performed on an entry. */ - private interface Strategy - { + private interface Strategy { boolean evaluate(Entry entry); } @@ -790,17 +817,14 @@ System.out.println(" exception: " + ioe.getMessage()); * Recognizes editable (read-write) entires */ private class EditableStrategy - implements Strategy - { + implements Strategy { private String scope; - public EditableStrategy(String scope) - { + public EditableStrategy(String scope) { this.scope = scope; } - public boolean evaluate(Entry entry) - { + public boolean evaluate(Entry entry) { // recognizes all entries in a subtree of the // 'scope' as editable entries return entry && entry.getName().startsWith(scope); @@ -811,55 +835,58 @@ System.out.println(" exception: " + ioe.getMessage()); * Recognizes and accumulates immediate children of the parent. */ private class ChildrenStrategy - implements Strategy - { + implements Strategy { private String parent; private Collection children = new HashSet(); - public void setParent(String name) - { - parent = (name.length() > 0)? (name + SEPARATOR): ""; - if(children == null) + public void setParent(String name) { + parent = (name.length() > 0) ? (name + SEPARATOR) : ""; + + if (children == null) children = (java.util.List)new LinkedList(); + children.clear(); } - public boolean evaluate(Entry entry) - { + public boolean evaluate(Entry entry) { // do not accept "children" of a file // ignore "read only" part of the filesystem - if(!entry.isReadOnly()) { + if (!entry.isReadOnly()) { // identify a child - if( (entry.getName().length() > 0) && - (entry.getName().startsWith(parent))) - { + if ((entry.getName().length() > 0) && + (entry.getName().startsWith(parent))) { // identify an immediate child String child = entry.getName(); - if(parent.length() > 0) { + + if (parent.length() > 0) { child = entry.getName().substring(parent.length()); } + int idx = child.indexOf(SEPARATOR); - if(idx > 0) // more path elements ahead + + if (idx > 0) // more path elements ahead child = child.substring(0, idx); + return children.add(child); } } + return false; } - public int countChildren() - { + public int countChildren() { return children.size(); } - public String[] getChildren() - { + public String[] getChildren() { String[] chn = new String[children.size()]; Iterator itr = children.iterator(); int idx = 0; - while(itr.hasNext()) { + + while (itr.hasNext()) { chn[idx++] = (String)itr.next(); } + return chn; } } @@ -868,18 +895,15 @@ System.out.println(" exception: " + ioe.getMessage()); * Recognizes cache entries which have to be save into new archive. */ private class ModifiedStrategy - implements Strategy - { + implements Strategy { private boolean modified; - public boolean evaluate(Entry entry) - { + public boolean evaluate(Entry entry) { modified |= entry.isModified(); return entry.isModified(); } - public boolean isModified() - { + public boolean isModified() { return modified; } } @@ -888,35 +912,33 @@ System.out.println(" exception: " + ioe.getMessage()); * Saves each entry in the filesystem cache. */ private class SaveStrategy - implements Strategy - { + implements Strategy { ZipOutputStream docos; IOException ioexp; public SaveStrategy(File newdoc) - throws IOException - { + throws IOException { docos = new ZipOutputStream(new FileOutputStream(newdoc)); ioexp = null; // success by default } - public boolean evaluate(Entry entry) - { - if(entry.getName().length() == 0) + public boolean evaluate(Entry entry) { + if (entry.getName().length() == 0) return false; + try { entry.save(docos); - } catch(IOException ioe) { - if(ioexp == null) + } catch (IOException ioe) { + if (ioexp == null) ioexp = ioe; } + return true; } public void close() - throws IOException - { - if(docos != null) { + throws IOException { + if (docos != null) { try { docos.close(); } catch (IOException ioe) { @@ -924,7 +946,8 @@ System.out.println(" exception: " + ioe.getMessage()); } finally { docos = null; } - if(ioexp != null) { + + if (ioexp != null) { throw ioexp; } } @@ -935,15 +958,14 @@ System.out.println(" exception: " + ioe.getMessage()); * Cleans each entiry in the filesystem cache. */ private class CleanStrategy - implements Strategy - { - public boolean evaluate(Entry entry) - { + implements Strategy { + public boolean evaluate(Entry entry) { try { entry.clean(); - } catch(java.lang.Exception exp) { + } catch (java.lang.Exception exp) { // sorry! can do nothing about it. } + return true; } } @@ -951,25 +973,24 @@ System.out.println(" exception: " + ioe.getMessage()); /* ----------------------------------------------------------- * ReadOnly cache entry */ - private class Entry - { + private class Entry { private String name; private boolean folder; private long size; private long time; private File node; // data files only - public Entry(ZipEntry entry) - { - if(entry != null) { + public Entry(ZipEntry entry) { + if (entry != null) { name = entry.getName(); folder = entry.isDirectory(); size = entry.getSize(); time = entry.getTime(); + // removes tail file separator from a folder name - if(folder && name.endsWith(SEPARATOR)) { + if (folder && name.endsWith(SEPARATOR)) { name = name.substring( - 0, name.length() - SEPARATOR.length()); + 0, name.length() - SEPARATOR.length()); } } else { // 'null' is special cace of root folder @@ -980,65 +1001,56 @@ System.out.println(" exception: " + ioe.getMessage()); } } - public boolean isReadOnly() - { + public boolean isReadOnly() { return true; } - public boolean isFolder() - { + public boolean isFolder() { return folder; } - public boolean isModified() - { + public boolean isModified() { return false; } - public String getName() - { + public String getName() { return name; } - public long getSize() - { + public long getSize() { return size; } - public long getTime() - { + public long getTime() { // adjust last modified time to the java.io.File - return (time >= 0)? time: 0; + return (time >= 0) ? time : 0; } public InputStream getInputStream() - throws FileNotFoundException - { + throws FileNotFoundException { return !isFolder() ? new FileInputStream(getFile()) : null; } public OutputStream getOutputStream() - throws IOException - { + throws IOException { return null; } public void rename(String name) - throws IOException - { + throws IOException { // BUG: this is the design bug. Cache has to manage such kind // of operation in order to keep the data integrity. this.name = name; } public void save(ZipOutputStream arch) - throws IOException - { + throws IOException { InputStream is = null; ZipEntry entry = new ZipEntry( - getName() + ((isFolder())? SEPARATOR: "")); + getName() + ((isFolder()) ? SEPARATOR : "")); + try { - if(isFolder()) { + if (isFolder()) { // folder entry.setMethod(ZipEntry.STORED); entry.setSize(0); @@ -1048,55 +1060,56 @@ System.out.println(" exception: " + ioe.getMessage()); arch.putNextEntry(entry); } else { // file - if(!isModified()) + if (!isModified()) entry.setTime(getTime()); else entry.setTime(node.lastModified()); + arch.putNextEntry(entry); is = getInputStream(); FileUtil.copy(is, arch); } } finally { // close streams - if(is != null) { + if (is != null) { try { is.close(); - } catch(java.io.IOException ioe) { + } catch (java.io.IOException ioe) { // sorry! can do nothing about it. } } - if(arch != null) + + if (arch != null) arch.closeEntry(); } } public void clean() - throws IOException - { - if(node != null) + throws IOException { + if (node != null) node.delete(); } - public String toString() - { + public String toString() { return ( - ((isReadOnly())? "RO ": "RW ") + - ((isFolder())? "D": "F") + - " \"" + getName() + "\""); + ((isReadOnly()) ? "RO " : "RW ") + + ((isFolder()) ? "D" : "F") + + " \"" + getName() + "\""); } /* package */ File getFile() - throws FileNotFoundException - { - if(node == null) { + throws FileNotFoundException { + if (node == null) { try { node = File.createTempFile(TMP_FILE_PREF, TMP_FILE_SUFX); - // copy the file from archive to the cache - OutputStream nos = null; - InputStream zis = null; + // copy the file from archive to the cache + OutputStream nos = null; + InputStream zis = null; + try { ZipEntry entry = zipFile.getEntry(getName()); - if(entry != null) { + + if (entry != null) { // copy existing file to the cache zis = zipFile.getInputStream(entry); nos = new FileOutputStream(node); @@ -1104,28 +1117,31 @@ System.out.println(" exception: " + ioe.getMessage()); } } finally { // close streams - if(nos != null) { + if (nos != null) { try { nos.close(); - } catch(java.io.IOException ioe) { + } catch (java.io.IOException ioe) { } } - if(zis != null) { + + if (zis != null) { try { zis.close(); - } catch(java.io.IOException ioe) { + } catch (java.io.IOException ioe) { } } } - } catch(java.lang.Exception exp) { + } catch (java.lang.Exception exp) { // delete cache file - if(node != null) + if (node != null) node.delete(); + node = null; throw new FileNotFoundException( "cannot access file: " + getName()); // I18N } } + return node; } @@ -1135,36 +1151,30 @@ System.out.println(" exception: " + ioe.getMessage()); * ReadWrite cache entry */ private class ReadWriteEntry - extends Entry - { + extends Entry { private boolean modified; // 'null' is special cace of root folder - public ReadWriteEntry(ZipEntry entry) - { + public ReadWriteEntry(ZipEntry entry) { super(entry); } - public boolean isReadOnly() - { + public boolean isReadOnly() { return false; } - public boolean isModified() - { + public boolean isModified() { return modified; } public void rename(String name) - throws IOException - { + throws IOException { modified = true; super.rename(name); } public OutputStream getOutputStream() - throws IOException - { + throws IOException { modified = true; return !isFolder() ? new FileOutputStream(getFile()) : null; } diff --git a/scripting/java/org/openoffice/netbeans/modules/office/filesystem/OpenOfficeDocFileSystemBeanInfo.java b/scripting/java/org/openoffice/netbeans/modules/office/filesystem/OpenOfficeDocFileSystemBeanInfo.java index 4e4b8fb54404..ad3d18e154db 100644 --- a/scripting/java/org/openoffice/netbeans/modules/office/filesystem/OpenOfficeDocFileSystemBeanInfo.java +++ b/scripting/java/org/openoffice/netbeans/modules/office/filesystem/OpenOfficeDocFileSystemBeanInfo.java @@ -31,8 +31,7 @@ import org.openide.util.Utilities; * Description of the OpenOffice.org Document filesystem. */ public class OpenOfficeDocFileSystemBeanInfo - extends SimpleBeanInfo -{ + extends SimpleBeanInfo { private static String ICONLOCATION = "org/openoffice/netbeans/modules/office/resources"; private static String COLORICON16NAME = @@ -43,49 +42,47 @@ public class OpenOfficeDocFileSystemBeanInfo /** * Retrieves an additional bean information. */ - public BeanInfo[] getAdditionalBeanInfo() - { + public BeanInfo[] getAdditionalBeanInfo() { try { return new BeanInfo[] { - Introspector.getBeanInfo(FileSystem.class) - }; + Introspector.getBeanInfo(FileSystem.class) + }; } catch (IntrospectionException ie) { ErrorManager.getDefault().notify(ie); return null; } } -/* - // If you have a visual dialog to customize configuration of the - // filesystem: - public BeanDescriptor getBeanDescriptor() - { - return new BeanDescriptor(OpenOfficeDocFileSystem.class, - OpenOfficeDocFileSystemCustomizer.class); - } -*/ + /* + // If you have a visual dialog to customize configuration of the + // filesystem: + public BeanDescriptor getBeanDescriptor() + { + return new BeanDescriptor(OpenOfficeDocFileSystem.class, + OpenOfficeDocFileSystemCustomizer.class); + } + */ /** * Retrieves bean property descriptors. */ - public PropertyDescriptor[] getPropertyDescriptors() - { + public PropertyDescriptor[] getPropertyDescriptors() { try { // Included only to make it a writable property (it is read-only // in FileSystem): PropertyDescriptor readOnly = new PropertyDescriptor( "readOnly", OpenOfficeDocFileSystem.class); readOnly.setDisplayName(NbBundle.getMessage( - OpenOfficeDocFileSystemBeanInfo.class, "PROP_readOnly")); + OpenOfficeDocFileSystemBeanInfo.class, "PROP_readOnly")); readOnly.setShortDescription(NbBundle.getMessage( - OpenOfficeDocFileSystemBeanInfo.class, "HINT_readOnly")); + OpenOfficeDocFileSystemBeanInfo.class, "HINT_readOnly")); // This could be whatever properties you use to configure the // filesystem: PropertyDescriptor document = new PropertyDescriptor( "Document", OpenOfficeDocFileSystem.class); document.setDisplayName(NbBundle.getMessage( - OpenOfficeDocFileSystemBeanInfo.class, "PROP_document")); + OpenOfficeDocFileSystemBeanInfo.class, "PROP_document")); document.setShortDescription(NbBundle.getMessage( - OpenOfficeDocFileSystemBeanInfo.class, "HINT_document")); + OpenOfficeDocFileSystemBeanInfo.class, "HINT_document")); // Request to the property editor that it be permitted only to // choose directories: document.setValue("directories", Boolean.FALSE); // NOI18N @@ -101,9 +98,8 @@ public class OpenOfficeDocFileSystemBeanInfo /** * Retrieves an icon by the icon type. */ - public Image getIcon(int type) - { - if((type == BeanInfo.ICON_COLOR_16x16) || + public Image getIcon(int type) { + if ((type == BeanInfo.ICON_COLOR_16x16) || (type == BeanInfo.ICON_MONO_16x16)) { return Utilities.loadImage(COLORICON16NAME); } else { diff --git a/scripting/java/org/openoffice/netbeans/modules/office/loader/OfficeDocumentDataLoader.java b/scripting/java/org/openoffice/netbeans/modules/office/loader/OfficeDocumentDataLoader.java index d47481ec39d5..268c6054b2bb 100644 --- a/scripting/java/org/openoffice/netbeans/modules/office/loader/OfficeDocumentDataLoader.java +++ b/scripting/java/org/openoffice/netbeans/modules/office/loader/OfficeDocumentDataLoader.java @@ -59,6 +59,7 @@ public class OfficeDocumentDataLoader extends UniFileLoader { protected FileObject findPrimaryFile(FileObject fo) { ExtensionList extensions = getExtensions(); + if (!extensions.isRegistered(fo)) return null; @@ -67,32 +68,32 @@ public class OfficeDocumentDataLoader extends UniFileLoader { try { jarFs.setJarFile(document); - } - catch (IOException e) { + } catch (IOException e) { return null; - } - catch (Exception e) { + } catch (Exception e) { return null; } + return fo; } protected SystemAction[] defaultActions() { return new SystemAction[] { - SystemAction.get(OpenAction.class), - null, - SystemAction.get(CutAction.class), - SystemAction.get(CopyAction.class), - SystemAction.get(PasteAction.class), - null, - SystemAction.get(DeleteAction.class), - SystemAction.get(RenameAction.class), - null, - SystemAction.get(PropertiesAction.class), - }; + SystemAction.get(OpenAction.class), + null, + SystemAction.get(CutAction.class), + SystemAction.get(CopyAction.class), + SystemAction.get(PasteAction.class), + null, + SystemAction.get(DeleteAction.class), + SystemAction.get(RenameAction.class), + null, + SystemAction.get(PropertiesAction.class), + }; } - protected MultiDataObject createMultiObject(FileObject primaryFile) throws DataObjectExistsException, IOException { + protected MultiDataObject createMultiObject(FileObject primaryFile) throws + DataObjectExistsException, IOException { return new OfficeDocumentDataObject(primaryFile, this); } } diff --git a/scripting/java/org/openoffice/netbeans/modules/office/loader/OfficeDocumentDataNode.java b/scripting/java/org/openoffice/netbeans/modules/office/loader/OfficeDocumentDataNode.java index 91f393e5d176..32d438f1f3c2 100644 --- a/scripting/java/org/openoffice/netbeans/modules/office/loader/OfficeDocumentDataNode.java +++ b/scripting/java/org/openoffice/netbeans/modules/office/loader/OfficeDocumentDataNode.java @@ -36,7 +36,7 @@ public class OfficeDocumentDataNode extends DataNode { public OfficeDocumentDataNode(OfficeDocumentDataObject obj) { this(obj, new OfficeDocumentChildren((OfficeDocumentCookie) - obj.getCookie(OfficeDocumentCookie.class))); + obj.getCookie(OfficeDocumentCookie.class))); } public OfficeDocumentDataNode(OfficeDocumentDataObject obj, Children ch) { @@ -55,27 +55,32 @@ public class OfficeDocumentDataNode extends DataNode { if (copies != null) { for (int i = 0; i < copies.length; i++) { if (copies[i] instanceof ParcelDataNode) { - File source = FileUtil.toFile(((ParcelDataNode)copies[i]).getDataObject().getPrimaryFile()); + File source = FileUtil.toFile(((ParcelDataNode) + copies[i]).getDataObject().getPrimaryFile()); File target = FileUtil.toFile(getDataObject().getPrimaryFile()); if (source.exists() && source.canRead() && target.exists() && target.canWrite()) { - ls.add(new ParcelDataNode.ParcelPasteType((ParcelDataNode)copies[i], target, false)); + ls.add(new ParcelDataNode.ParcelPasteType((ParcelDataNode)copies[i], target, + false)); } } } } Node[] moves = NodeTransfer.nodes(t, NodeTransfer.MOVE); + if (moves != null) { for (int i = 0; i < moves.length; i++) { if (moves[i] instanceof ParcelDataNode) { - File source = FileUtil.toFile(((ParcelDataNode)moves[i]).getDataObject().getPrimaryFile()); + File source = FileUtil.toFile(((ParcelDataNode) + moves[i]).getDataObject().getPrimaryFile()); File target = FileUtil.toFile(getDataObject().getPrimaryFile()); if (source.exists() && source.canRead() && target.exists() && target.canWrite()) { - ls.add(new ParcelDataNode.ParcelPasteType((ParcelDataNode)moves[i], target, true)); + ls.add(new ParcelDataNode.ParcelPasteType((ParcelDataNode)moves[i], target, + true)); } } } diff --git a/scripting/java/org/openoffice/netbeans/modules/office/loader/OfficeDocumentDataObject.java b/scripting/java/org/openoffice/netbeans/modules/office/loader/OfficeDocumentDataObject.java index 23f5fd6e22ea..742b7d882968 100644 --- a/scripting/java/org/openoffice/netbeans/modules/office/loader/OfficeDocumentDataObject.java +++ b/scripting/java/org/openoffice/netbeans/modules/office/loader/OfficeDocumentDataObject.java @@ -29,7 +29,8 @@ import org.openoffice.netbeans.modules.office.actions.*; public class OfficeDocumentDataObject extends MultiDataObject { - public OfficeDocumentDataObject(FileObject pf, OfficeDocumentDataLoader loader) throws DataObjectExistsException { + public OfficeDocumentDataObject(FileObject pf, + OfficeDocumentDataLoader loader) throws DataObjectExistsException { super(pf, loader); init(); } diff --git a/scripting/java/org/openoffice/netbeans/modules/office/loader/ParcelContentsFolder.java b/scripting/java/org/openoffice/netbeans/modules/office/loader/ParcelContentsFolder.java index 53fa63199517..9243df8c7341 100644 --- a/scripting/java/org/openoffice/netbeans/modules/office/loader/ParcelContentsFolder.java +++ b/scripting/java/org/openoffice/netbeans/modules/office/loader/ParcelContentsFolder.java @@ -41,8 +41,9 @@ import org.openoffice.netbeans.modules.office.actions.ParcelFolderCookie; import org.openoffice.netbeans.modules.office.utils.PackageRemover; public class ParcelContentsFolder extends DataFolder { - public ParcelContentsFolder(FileObject pf, ParcelContentsFolderDataLoader loader) - throws DataObjectExistsException { + public ParcelContentsFolder(FileObject pf, + ParcelContentsFolderDataLoader loader) + throws DataObjectExistsException { super(pf, loader); } @@ -59,11 +60,11 @@ public class ParcelContentsFolder extends DataFolder { DataFolder contents = (DataFolder)getDataObject(); ParcelFolderCookie cookie = (ParcelFolderCookie)contents.getFolder(). - getCookie(ParcelFolderCookie.class); + getCookie(ParcelFolderCookie.class); String language = cookie.getLanguage(); ParcelContentsFolder.createEmptyScript(contents, - language); + language); } }; return newtypes; @@ -76,11 +77,9 @@ public class ParcelContentsFolder extends DataFolder { if (language.toLowerCase().equals("java")) { sourceFile += ".java"; - } - else if (language.toLowerCase().equals("beanshell")) { + } else if (language.toLowerCase().equals("beanshell")) { sourceFile += ".bsh"; - } - else { + } else { NotifyDescriptor d = new NotifyDescriptor.Message( "Language not defined for this Parcel Folder"); TopManager.getDefault().notify(d); @@ -89,36 +88,37 @@ public class ParcelContentsFolder extends DataFolder { FileSystem fs = Repository.getDefault().getDefaultFileSystem(); DataObject result = null; + try { DataObject dObj = DataObject.find(fs.findResource(sourceFile)); result = dObj.createFromTemplate(parent); - } - catch (IOException ioe) { + } catch (IOException ioe) { ErrorManager.getDefault().notify(ioe); } FileObject fo = result.getPrimaryFile(); + if (fo.getExt().equals("java")) { FileLock lock = null; + try { PackageRemover.removeDeclaration(FileUtil.toFile(fo)); // IssueZilla 11986 - rename the FileObject // so the JavaNode is resynchronized lock = fo.lock(); + if (lock != null) { fo.rename(lock, fo.getName(), fo.getExt()); } - } - catch (IOException ioe) { + } catch (IOException ioe) { NotifyDescriptor d = new NotifyDescriptor.Message( - "Error removing package declaration from file: " + - fo.getNameExt() + - ". You should manually remove this declaration " + - "before building the Parcel Recipe"); + "Error removing package declaration from file: " + + fo.getNameExt() + + ". You should manually remove this declaration " + + "before building the Parcel Recipe"); TopManager.getDefault().notify(d); - } - finally { + } finally { if (lock != null) { lock.releaseLock(); } diff --git a/scripting/java/org/openoffice/netbeans/modules/office/loader/ParcelContentsFolderDataLoader.java b/scripting/java/org/openoffice/netbeans/modules/office/loader/ParcelContentsFolderDataLoader.java index 4406f3f903c8..4943a4f5d75e 100644 --- a/scripting/java/org/openoffice/netbeans/modules/office/loader/ParcelContentsFolderDataLoader.java +++ b/scripting/java/org/openoffice/netbeans/modules/office/loader/ParcelContentsFolderDataLoader.java @@ -55,19 +55,20 @@ public class ParcelContentsFolderDataLoader extends UniFileLoader { protected SystemAction[] defaultActions() { return new SystemAction[] { - SystemAction.get(PasteAction.class), - SystemAction.get(NewAction.class), - // null, - // SystemAction.get(PropertiesAction.class), - }; + SystemAction.get(PasteAction.class), + SystemAction.get(NewAction.class), + // null, + // SystemAction.get(PropertiesAction.class), + }; } protected MultiDataObject createMultiObject(FileObject primaryFile) - throws DataObjectExistsException { + throws DataObjectExistsException { return new ParcelContentsFolder(primaryFile, this); } - protected MultiDataObject.Entry createPrimaryEntry(MultiDataObject obj, FileObject primaryFile) { + protected MultiDataObject.Entry createPrimaryEntry(MultiDataObject obj, + FileObject primaryFile) { return new FileEntry.Folder(obj, primaryFile); } } diff --git a/scripting/java/org/openoffice/netbeans/modules/office/loader/ParcelDataLoader.java b/scripting/java/org/openoffice/netbeans/modules/office/loader/ParcelDataLoader.java index 14e968668f71..86e86742c43e 100644 --- a/scripting/java/org/openoffice/netbeans/modules/office/loader/ParcelDataLoader.java +++ b/scripting/java/org/openoffice/netbeans/modules/office/loader/ParcelDataLoader.java @@ -57,19 +57,20 @@ public class ParcelDataLoader extends UniFileLoader { protected SystemAction[] defaultActions() { return new SystemAction[] { - SystemAction.get(DeployParcelAction.class), - null, - SystemAction.get(CutAction.class), - SystemAction.get(CopyAction.class), - null, - SystemAction.get(DeleteAction.class), - SystemAction.get(RenameAction.class), - null, - SystemAction.get(PropertiesAction.class), - }; + SystemAction.get(DeployParcelAction.class), + null, + SystemAction.get(CutAction.class), + SystemAction.get(CopyAction.class), + null, + SystemAction.get(DeleteAction.class), + SystemAction.get(RenameAction.class), + null, + SystemAction.get(PropertiesAction.class), + }; } - protected MultiDataObject createMultiObject(FileObject primaryFile) throws DataObjectExistsException, IOException { + protected MultiDataObject createMultiObject(FileObject primaryFile) throws + DataObjectExistsException, IOException { return new ParcelDataObject(primaryFile, this); } } diff --git a/scripting/java/org/openoffice/netbeans/modules/office/loader/ParcelDataNode.java b/scripting/java/org/openoffice/netbeans/modules/office/loader/ParcelDataNode.java index 5865f32c2803..cb51b982e7c4 100644 --- a/scripting/java/org/openoffice/netbeans/modules/office/loader/ParcelDataNode.java +++ b/scripting/java/org/openoffice/netbeans/modules/office/loader/ParcelDataNode.java @@ -55,7 +55,7 @@ public class ParcelDataNode extends DataNode { boolean isCut = false; public ParcelPasteType(ParcelDataNode sourceParcel, - File targetDocument, boolean isCut) { + File targetDocument, boolean isCut) { this.sourceParcel = sourceParcel; this.targetDocument = targetDocument; this.isCut = isCut; @@ -68,13 +68,13 @@ public class ParcelDataNode extends DataNode { if (isCut) { FileObject fo = sourceParcel.getDataObject().getPrimaryFile(); + try { fo.delete(); - } - catch (IOException ioe) {} + } catch (IOException ioe) {} + return ExTransferable.EMPTY; - } - else { + } else { return null; } } diff --git a/scripting/java/org/openoffice/netbeans/modules/office/loader/ParcelDataObject.java b/scripting/java/org/openoffice/netbeans/modules/office/loader/ParcelDataObject.java index 83833d06b480..0c9cf1720ca3 100644 --- a/scripting/java/org/openoffice/netbeans/modules/office/loader/ParcelDataObject.java +++ b/scripting/java/org/openoffice/netbeans/modules/office/loader/ParcelDataObject.java @@ -31,7 +31,8 @@ import org.openoffice.netbeans.modules.office.actions.*; */ public class ParcelDataObject extends MultiDataObject { - public ParcelDataObject(FileObject pf, ParcelDataLoader loader) throws DataObjectExistsException { + public ParcelDataObject(FileObject pf, + ParcelDataLoader loader) throws DataObjectExistsException { super(pf, loader); init(); } diff --git a/scripting/java/org/openoffice/netbeans/modules/office/loader/ParcelDescriptorDataLoader.java b/scripting/java/org/openoffice/netbeans/modules/office/loader/ParcelDescriptorDataLoader.java index 8f6083ae00d8..58b94c91031c 100644 --- a/scripting/java/org/openoffice/netbeans/modules/office/loader/ParcelDescriptorDataLoader.java +++ b/scripting/java/org/openoffice/netbeans/modules/office/loader/ParcelDescriptorDataLoader.java @@ -53,20 +53,21 @@ public class ParcelDescriptorDataLoader extends UniFileLoader { protected SystemAction[] defaultActions() { return new SystemAction[] { - SystemAction.get(OpenAction.class), - null, - SystemAction.get(CutAction.class), - SystemAction.get(CopyAction.class), - SystemAction.get(PasteAction.class), - null, - SystemAction.get(DeleteAction.class), - SystemAction.get(RenameAction.class), - null, - SystemAction.get(PropertiesAction.class), - }; + SystemAction.get(OpenAction.class), + null, + SystemAction.get(CutAction.class), + SystemAction.get(CopyAction.class), + SystemAction.get(PasteAction.class), + null, + SystemAction.get(DeleteAction.class), + SystemAction.get(RenameAction.class), + null, + SystemAction.get(PropertiesAction.class), + }; } - protected MultiDataObject createMultiObject(FileObject primaryFile) throws DataObjectExistsException, IOException { + protected MultiDataObject createMultiObject(FileObject primaryFile) throws + DataObjectExistsException, IOException { return new ParcelDescriptorDataObject(primaryFile, this); } } diff --git a/scripting/java/org/openoffice/netbeans/modules/office/loader/ParcelDescriptorDataObject.java b/scripting/java/org/openoffice/netbeans/modules/office/loader/ParcelDescriptorDataObject.java index c344830b1c27..f72735cfc2ad 100644 --- a/scripting/java/org/openoffice/netbeans/modules/office/loader/ParcelDescriptorDataObject.java +++ b/scripting/java/org/openoffice/netbeans/modules/office/loader/ParcelDescriptorDataObject.java @@ -34,18 +34,21 @@ public class ParcelDescriptorDataObject extends MultiDataObject { private boolean canParse = false; - public ParcelDescriptorDataObject(FileObject pf, ParcelDescriptorDataLoader loader) throws DataObjectExistsException { + public ParcelDescriptorDataObject(FileObject pf, + ParcelDescriptorDataLoader loader) throws DataObjectExistsException { super(pf, loader); init(); } private void init() { FileObject fo = getPrimaryFile(); + if (FileUtil.toFile(fo) != null) canParse = true; CookieSet cookies = getCookieSet(); cookies.add(new ParcelDescriptorEditorSupport(this)); + if (canParse) cookies.add(new ParcelDescriptorParserSupport(getPrimaryFile())); } diff --git a/scripting/java/org/openoffice/netbeans/modules/office/loader/ParcelFolder.java b/scripting/java/org/openoffice/netbeans/modules/office/loader/ParcelFolder.java index cb03c0c8f35d..a9f04564794f 100644 --- a/scripting/java/org/openoffice/netbeans/modules/office/loader/ParcelFolder.java +++ b/scripting/java/org/openoffice/netbeans/modules/office/loader/ParcelFolder.java @@ -47,7 +47,7 @@ public class ParcelFolder extends DataFolder { public static final String LANGUAGE_ATTRIBUTE = "language"; public ParcelFolder(FileObject pf, ParcelFolderDataLoader loader) - throws DataObjectExistsException { + throws DataObjectExistsException { super(pf, loader); CookieSet cookies = getCookieSet(); cookies.add(new ParcelFolderSupport(this)); @@ -74,10 +74,12 @@ public class ParcelFolder extends DataFolder { super(pf.createNodeChildren(dataFilter)); location = (File)pf.getPrimaryFile().getAttribute(LOCATION); + if (location == null) location = FileUtil.toFile(pf.getPrimaryFile()); String name = (String)pf.getPrimaryFile().getAttribute(FILTER); + if (name == null) filter = DEFAULT_FILTER; else { @@ -91,10 +93,10 @@ public class ParcelFolder extends DataFolder { ParcelFolderCookie cookie = (ParcelFolderCookie)pf.getCookie(ParcelFolderCookie.class); String s = cookie.getClasspath(); + if (s != null) { classpath = s; - } - else { + } else { classpath = "."; cookie.setClasspath(classpath); } @@ -111,6 +113,7 @@ public class ParcelFolder extends DataFolder { public String getLanguage() { if (language == null) language = (String)getPrimaryFile().getAttribute(LANGUAGE); + return language; } @@ -121,6 +124,7 @@ public class ParcelFolder extends DataFolder { sheet = super.createSheet(); props = sheet.get(Sheet.PROPERTIES); + if (props == null) { props = Sheet.createPropertiesSet(); sheet.put(props); @@ -139,24 +143,24 @@ public class ParcelFolder extends DataFolder { } private Node.Property createLocationProperty() { - Node.Property prop = - new PropertySupport.ReadWrite(LOCATION, File.class, - "Location", "Output location of Parcel Zip File") { - public void setValue(Object obj) { - if (obj instanceof File) { - location = (File)obj; - try { - getPrimaryFile().setAttribute(LOCATION, location); - } - catch (IOException ioe) { - } + Node.Property prop = + new PropertySupport.ReadWrite(LOCATION, File.class, + "Location", "Output location of Parcel Zip File") { + public void setValue(Object obj) { + if (obj instanceof File) { + location = (File)obj; + + try { + getPrimaryFile().setAttribute(LOCATION, location); + } catch (IOException ioe) { } } + } - public Object getValue() { - return location; - } - }; + public Object getValue() { + return location; + } + }; prop.setValue("files", Boolean.FALSE); return prop; } @@ -165,114 +169,114 @@ public class ParcelFolder extends DataFolder { private Node.Property createLanguageProperty() { Node.Property prop = - new PropertySupport.ReadWrite(LANGUAGE, String.class, - "Parcel Language", "Language of scripts in this Parcel") { - public void setValue(Object obj) { - if (obj instanceof String) { - language = (String)obj; - - try { - getPrimaryFile().setAttribute(LANGUAGE, language); - } - catch (IOException ioe) { - } + new PropertySupport.ReadWrite(LANGUAGE, String.class, + "Parcel Language", "Language of scripts in this Parcel") { + public void setValue(Object obj) { + if (obj instanceof String) { + language = (String)obj; + + try { + getPrimaryFile().setAttribute(LANGUAGE, language); + } catch (IOException ioe) { } } + } - public Object getValue() { - if (language == null) - language = (String)getPrimaryFile().getAttribute(LANGUAGE); - return language; - } + public Object getValue() { + if (language == null) + language = (String)getPrimaryFile().getAttribute(LANGUAGE); - public PropertyEditor getPropertyEditor() { - return new PropertyEditorSupport() { - public String[] getTags() { - return languages; - } - - public void setAsText(String text) { - for (int i = 0; i < languages.length; i++) - if (text.equals(languages[i])) - this.setValue(languages[i]); - } - - public String getAsText() { - return (String)this.getValue(); - } - }; - } - }; + return language; + } + + public PropertyEditor getPropertyEditor() { + return new PropertyEditorSupport() { + public String[] getTags() { + return languages; + } + + public void setAsText(String text) { + for (int i = 0; i < languages.length; i++) + if (text.equals(languages[i])) + this.setValue(languages[i]); + } + + public String getAsText() { + return (String)this.getValue(); + } + }; + } + }; return prop; } private FileFilter[] availableFilters = new FileFilter[] { - BinaryOnlyFilter.getInstance(), AllFilesFilter.getInstance()}; + BinaryOnlyFilter.getInstance(), AllFilesFilter.getInstance() + }; private Node.Property createFilterProperty() { Node.Property prop = - new PropertySupport.ReadWrite(FILTER, String.class, - "File Filter", "Files to be included in Parcel") { - public void setValue(Object obj) { - if (obj instanceof FileFilter) { - filter = (FileFilter)obj; - - try { - getPrimaryFile().setAttribute(FILTER, filter.toString()); - } - catch (IOException ioe) { - } + new PropertySupport.ReadWrite(FILTER, String.class, + "File Filter", "Files to be included in Parcel") { + public void setValue(Object obj) { + if (obj instanceof FileFilter) { + filter = (FileFilter)obj; + + try { + getPrimaryFile().setAttribute(FILTER, filter.toString()); + } catch (IOException ioe) { } } + } - public Object getValue() { - return filter; - } + public Object getValue() { + return filter; + } - public PropertyEditor getPropertyEditor() { - return new PropertyEditorSupport() { - public String[] getTags() { - String[] tags = new String[availableFilters.length]; + public PropertyEditor getPropertyEditor() { + return new PropertyEditorSupport() { + public String[] getTags() { + String[] tags = new String[availableFilters.length]; - for (int i = 0; i < availableFilters.length; i++) - tags[i] = availableFilters[i].toString(); + for (int i = 0; i < availableFilters.length; i++) + tags[i] = availableFilters[i].toString(); - return tags; - } + return tags; + } - public void setAsText(String text) { - for (int i = 0; i < availableFilters.length; i++) - if (text.equals(availableFilters[i].toString())) - this.setValue(availableFilters[i]); - } + public void setAsText(String text) { + for (int i = 0; i < availableFilters.length; i++) + if (text.equals(availableFilters[i].toString())) + this.setValue(availableFilters[i]); + } - public String getAsText() { - return this.getValue().toString(); - } - }; - } - }; + public String getAsText() { + return this.getValue().toString(); + } + }; + } + }; return prop; } private Node.Property createClasspathProperty() { - Node.Property prop = - new PropertySupport.ReadWrite(CLASSPATH, String.class, - "Classpath", "Classpath property for scripts in this parcel") { - public void setValue(Object obj) { - if (obj instanceof String) { - classpath = (String)obj; - - ParcelFolderCookie cookie = (ParcelFolderCookie) - getDataObject().getCookie(ParcelFolderCookie.class); - cookie.setClasspath(classpath); - } + Node.Property prop = + new PropertySupport.ReadWrite(CLASSPATH, String.class, + "Classpath", "Classpath property for scripts in this parcel") { + public void setValue(Object obj) { + if (obj instanceof String) { + classpath = (String)obj; + + ParcelFolderCookie cookie = (ParcelFolderCookie) + getDataObject().getCookie(ParcelFolderCookie.class); + cookie.setClasspath(classpath); } + } - public Object getValue() { - return classpath; - } - }; + public Object getValue() { + return classpath; + } + }; return prop; } } @@ -280,8 +284,10 @@ public class ParcelFolder extends DataFolder { private class ParcelFolderFilter implements DataFilter { public boolean acceptDataObject(DataObject dobj) { String name = dobj.getPrimaryFile().getNameExt(); + if (name.equals(ParcelZipper.PARCEL_DESCRIPTOR_XML)) return false; + return true; } } diff --git a/scripting/java/org/openoffice/netbeans/modules/office/loader/ParcelFolderDataLoader.java b/scripting/java/org/openoffice/netbeans/modules/office/loader/ParcelFolderDataLoader.java index df60b27561c1..965d11b18ce7 100644 --- a/scripting/java/org/openoffice/netbeans/modules/office/loader/ParcelFolderDataLoader.java +++ b/scripting/java/org/openoffice/netbeans/modules/office/loader/ParcelFolderDataLoader.java @@ -56,10 +56,13 @@ public class ParcelFolderDataLoader extends UniFileLoader { return null; FileObject contents = fo.getFileObject(ParcelZipper.CONTENTS_DIRNAME); + if (contents == null) return null; - FileObject descriptor = contents.getFileObject(ParcelZipper.PARCEL_DESCRIPTOR_XML); + FileObject descriptor = contents.getFileObject( + ParcelZipper.PARCEL_DESCRIPTOR_XML); + if (descriptor == null) return null; @@ -68,25 +71,27 @@ public class ParcelFolderDataLoader extends UniFileLoader { protected SystemAction[] defaultActions() { return new SystemAction[] { - SystemAction.get(CompileParcelAction.class), - SystemAction.get(BuildParcelAction.class), - SystemAction.get(ConfigureParcelAction.class), - null, - SystemAction.get(CutAction.class), - SystemAction.get(CopyAction.class), - null, - SystemAction.get(DeleteAction.class), - SystemAction.get(RenameAction.class), - null, - SystemAction.get(PropertiesAction.class), - }; + SystemAction.get(CompileParcelAction.class), + SystemAction.get(BuildParcelAction.class), + SystemAction.get(ConfigureParcelAction.class), + null, + SystemAction.get(CutAction.class), + SystemAction.get(CopyAction.class), + null, + SystemAction.get(DeleteAction.class), + SystemAction.get(RenameAction.class), + null, + SystemAction.get(PropertiesAction.class), + }; } - protected MultiDataObject createMultiObject(FileObject primaryFile) throws DataObjectExistsException, IOException { + protected MultiDataObject createMultiObject(FileObject primaryFile) throws + DataObjectExistsException, IOException { return new ParcelFolder(primaryFile, this); } - protected MultiDataObject.Entry createPrimaryEntry(MultiDataObject obj, FileObject primaryFile) { + protected MultiDataObject.Entry createPrimaryEntry(MultiDataObject obj, + FileObject primaryFile) { return new FileEntry.Folder(obj, primaryFile); } } diff --git a/scripting/java/org/openoffice/netbeans/modules/office/nodes/OfficeDocumentChildren.java b/scripting/java/org/openoffice/netbeans/modules/office/nodes/OfficeDocumentChildren.java index 01710f9bcaac..b5e939bc2811 100644 --- a/scripting/java/org/openoffice/netbeans/modules/office/nodes/OfficeDocumentChildren.java +++ b/scripting/java/org/openoffice/netbeans/modules/office/nodes/OfficeDocumentChildren.java @@ -48,16 +48,19 @@ public class OfficeDocumentChildren extends Children.Keys } Enumeration parcels = document.getParcels(); + if (!parcels.hasMoreElements()) { setKeys(Collections.EMPTY_SET); return; } ArrayList keys = new ArrayList(); + while (parcels.hasMoreElements()) { String parcel = (String)parcels.nextElement(); keys.add(parcel); } + setKeys(keys); } @@ -101,8 +104,8 @@ public class OfficeDocumentChildren extends Children.Keys protected SystemAction[] createActions() { return new SystemAction[] { - SystemAction.get(DeleteAction.class), - }; + SystemAction.get(DeleteAction.class), + }; } public HelpCtx getHelpCtx() { @@ -116,12 +119,12 @@ public class OfficeDocumentChildren extends Children.Keys public void destroy() throws IOException { OfficeSettings settings = OfficeSettings.getDefault(); String message = "If you already have this document open in " + - "Office, please close it before continuing. Click OK to " + - "delete this parcel."; + "Office, please close it before continuing. Click OK to " + + "delete this parcel."; if (settings.getWarnBeforeParcelDelete()) { NagDialog warning = NagDialog.createConfirmationDialog( - message, "Show this message in future", true); + message, "Show this message in future", true); boolean result = warning.show(); @@ -131,6 +134,7 @@ public class OfficeDocumentChildren extends Children.Keys if (!result) return; } + super.destroy(); document.removeParcel(name); } diff --git a/scripting/java/org/openoffice/netbeans/modules/office/nodes/ParcelDescriptorChildren.java b/scripting/java/org/openoffice/netbeans/modules/office/nodes/ParcelDescriptorChildren.java index e8f6ef9003a7..52312ea03574 100644 --- a/scripting/java/org/openoffice/netbeans/modules/office/nodes/ParcelDescriptorChildren.java +++ b/scripting/java/org/openoffice/netbeans/modules/office/nodes/ParcelDescriptorChildren.java @@ -31,7 +31,8 @@ import org.openoffice.netbeans.modules.office.actions.ParcelDescriptorParserCook /** List of children of a containing node. * Remember to document what your permitted keys are! */ -public class ParcelDescriptorChildren extends Children.Keys implements ChangeListener { +public class ParcelDescriptorChildren extends Children.Keys implements + ChangeListener { private ParcelDescriptorParserCookie parserCookie = null; @@ -51,8 +52,10 @@ public class ParcelDescriptorChildren extends Children.Keys implements ChangeLis } ArrayList keys = new ArrayList(len); + for (int i = 0; i < len; i++) keys.add(nl.item(i)); + setKeys(keys); } diff --git a/scripting/java/org/openoffice/netbeans/modules/office/nodes/ScriptNode.java b/scripting/java/org/openoffice/netbeans/modules/office/nodes/ScriptNode.java index 91b4d97cb68f..861a4a4f1909 100644 --- a/scripting/java/org/openoffice/netbeans/modules/office/nodes/ScriptNode.java +++ b/scripting/java/org/openoffice/netbeans/modules/office/nodes/ScriptNode.java @@ -54,10 +54,10 @@ public class ScriptNode extends AbstractNode { protected SystemAction[] createActions() { return new SystemAction[] { - SystemAction.get(ToolsAction.class), - null, - SystemAction.get(PropertiesAction.class), - }; + SystemAction.get(ToolsAction.class), + null, + SystemAction.get(PropertiesAction.class), + }; } public HelpCtx getHelpCtx() { @@ -75,12 +75,14 @@ public class ScriptNode extends AbstractNode { protected Sheet createSheet() { Sheet sheet = super.createSheet(); Sheet.Set props = sheet.get(Sheet.PROPERTIES); + if (props == null) { props = Sheet.createPropertiesSet(); sheet.put(props); } org.openide.nodes.Node.Property prop = null; + if ((prop = getStringProperty(LOGICAL_NAME)) != null) props.put(prop); @@ -92,7 +94,8 @@ public class ScriptNode extends AbstractNode { private org.openide.nodes.Node.Property getStringProperty(String name) { NodeList nl = element.getElementsByTagName(name); - if(nl.getLength() != 1) + + if (nl.getLength() != 1) return null; Element nameElement = (Element)nl.item(0); @@ -107,7 +110,7 @@ public class ScriptNode extends AbstractNode { public StringProperty(ScriptNode sn, String name, String value) { super(value, String.class, name, - "The name of the java language method for this script"); + "The name of the java language method for this script"); this.sn = sn; this.name = name; this.value = value; diff --git a/scripting/java/org/openoffice/netbeans/modules/office/options/OfficeSettings.java b/scripting/java/org/openoffice/netbeans/modules/office/options/OfficeSettings.java index a56cdfa97779..1caa8835b4f8 100644 --- a/scripting/java/org/openoffice/netbeans/modules/office/options/OfficeSettings.java +++ b/scripting/java/org/openoffice/netbeans/modules/office/options/OfficeSettings.java @@ -60,8 +60,7 @@ public class OfficeSettings extends SystemOption { setOfficeDirectory(oi); return; } - } - catch (IOException ioe) { + } catch (IOException ioe) { } } } diff --git a/scripting/java/org/openoffice/netbeans/modules/office/options/OfficeSettingsBeanInfo.java b/scripting/java/org/openoffice/netbeans/modules/office/options/OfficeSettingsBeanInfo.java index 63a386986896..a811ab855fd5 100644 --- a/scripting/java/org/openoffice/netbeans/modules/office/options/OfficeSettingsBeanInfo.java +++ b/scripting/java/org/openoffice/netbeans/modules/office/options/OfficeSettingsBeanInfo.java @@ -39,54 +39,53 @@ public class OfficeSettingsBeanInfo extends SimpleBeanInfo { try { PropertyDescriptor[] props = new PropertyDescriptor[] { new PropertyDescriptor(OfficeSettings.OFFICE_DIRECTORY, - OfficeSettings.class, - "get" + OfficeSettings.OFFICE_DIRECTORY, - "set" + OfficeSettings.OFFICE_DIRECTORY), + OfficeSettings.class, + "get" + OfficeSettings.OFFICE_DIRECTORY, + "set" + OfficeSettings.OFFICE_DIRECTORY), new PropertyDescriptor(OfficeSettings.WARN_BEFORE_DOC_DEPLOY, - OfficeSettings.class, - "get" + OfficeSettings.WARN_BEFORE_DOC_DEPLOY, - "set" + OfficeSettings.WARN_BEFORE_DOC_DEPLOY), + OfficeSettings.class, + "get" + OfficeSettings.WARN_BEFORE_DOC_DEPLOY, + "set" + OfficeSettings.WARN_BEFORE_DOC_DEPLOY), new PropertyDescriptor(OfficeSettings.WARN_BEFORE_PARCEL_DELETE, - OfficeSettings.class, - "get" + OfficeSettings.WARN_BEFORE_PARCEL_DELETE, - "set" + OfficeSettings.WARN_BEFORE_PARCEL_DELETE), + OfficeSettings.class, + "get" + OfficeSettings.WARN_BEFORE_PARCEL_DELETE, + "set" + OfficeSettings.WARN_BEFORE_PARCEL_DELETE), new PropertyDescriptor(OfficeSettings.WARN_AFTER_DIR_DEPLOY, - OfficeSettings.class, - "get" + OfficeSettings.WARN_AFTER_DIR_DEPLOY, - "set" + OfficeSettings.WARN_AFTER_DIR_DEPLOY), + OfficeSettings.class, + "get" + OfficeSettings.WARN_AFTER_DIR_DEPLOY, + "set" + OfficeSettings.WARN_AFTER_DIR_DEPLOY), new PropertyDescriptor(OfficeSettings.WARN_BEFORE_MOUNT, - OfficeSettings.class, - "get" + OfficeSettings.WARN_BEFORE_MOUNT, - "set" + OfficeSettings.WARN_BEFORE_MOUNT) + OfficeSettings.class, + "get" + OfficeSettings.WARN_BEFORE_MOUNT, + "set" + OfficeSettings.WARN_BEFORE_MOUNT) }; props[0].setDisplayName(NbBundle.getMessage( - OfficeSettingsBeanInfo.class, "PROP_OfficeDirectory")); + OfficeSettingsBeanInfo.class, "PROP_OfficeDirectory")); props[0].setShortDescription(NbBundle.getMessage( - OfficeSettingsBeanInfo.class, "HINT_OfficeDirectory")); + OfficeSettingsBeanInfo.class, "HINT_OfficeDirectory")); props[0].setPropertyEditorClass(OfficeDirectoryEditor.class); props[1].setDisplayName(NbBundle.getMessage( - OfficeSettingsBeanInfo.class, "PROP_WarnBeforeDocDeploy")); + OfficeSettingsBeanInfo.class, "PROP_WarnBeforeDocDeploy")); props[1].setShortDescription(NbBundle.getMessage( - OfficeSettingsBeanInfo.class, "HINT_WarnBeforeDocDeploy")); + OfficeSettingsBeanInfo.class, "HINT_WarnBeforeDocDeploy")); props[1].setHidden(true); props[2].setDisplayName(NbBundle.getMessage( - OfficeSettingsBeanInfo.class, "PROP_WarnAfterDirDeploy")); + OfficeSettingsBeanInfo.class, "PROP_WarnAfterDirDeploy")); props[2].setShortDescription(NbBundle.getMessage( - OfficeSettingsBeanInfo.class, "HINT_WarnAfterDirDeploy")); + OfficeSettingsBeanInfo.class, "HINT_WarnAfterDirDeploy")); props[2].setHidden(true); props[3].setDisplayName(NbBundle.getMessage( - OfficeSettingsBeanInfo.class, "PROP_WarnBeforeMount")); + OfficeSettingsBeanInfo.class, "PROP_WarnBeforeMount")); props[3].setShortDescription(NbBundle.getMessage( - OfficeSettingsBeanInfo.class, "HINT_WarnBeforeMount")); + OfficeSettingsBeanInfo.class, "HINT_WarnBeforeMount")); props[3].setHidden(true); return props; - } - catch (IntrospectionException ie) { + } catch (IntrospectionException ie) { ErrorManager.getDefault().notify(ie); return null; } @@ -105,18 +104,18 @@ public class OfficeSettingsBeanInfo extends SimpleBeanInfo { private SelectPathPanel panel; - public String getAsText () { + public String getAsText() { return ((OfficeInstallation)getValue()).getPath(); } - public void setAsText (String path) { + public void setAsText(String path) { OfficeInstallation oi = new OfficeInstallation(path); if (!oi.supportsFramework()) throw new IllegalArgumentException(path + - " is not a valid Office install"); + " is not a valid Office install"); else - setValue (oi); + setValue(oi); } public Component getCustomEditor() { diff --git a/scripting/java/org/openoffice/netbeans/modules/office/utils/FrameworkJarChecker.java b/scripting/java/org/openoffice/netbeans/modules/office/utils/FrameworkJarChecker.java index b26b729455bf..9c6c33900383 100644 --- a/scripting/java/org/openoffice/netbeans/modules/office/utils/FrameworkJarChecker.java +++ b/scripting/java/org/openoffice/netbeans/modules/office/utils/FrameworkJarChecker.java @@ -33,46 +33,44 @@ public class FrameworkJarChecker { public static void mountDependencies() { String unoilPath = SVersionRCFile.getPathForUnoil( - OfficeSettings.getDefault().getOfficeDirectory().getPath()); + 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) { + } catch (IOException ioe) { return; - } - catch (PropertyVetoException pve) { + } catch (PropertyVetoException pve) { return; } FileSystem result; + try { result = Repository.getDefault().findFileSystem(jfs.getSystemName()); - } - catch(Exception exp) { + } catch (Exception exp) { result = null; - } - finally { + } finally { jfs.removeNotify(); } - if(result == null) { + if (result == null) { JarFileSystem newjfs = new JarFileSystem(); + try { newjfs.setJarFile(unoilFile); - } - catch (IOException ioe) { + } catch (IOException ioe) { return; - } - catch (PropertyVetoException pve) { + } catch (PropertyVetoException pve) { return; } + Repository.getDefault().addFileSystem(newjfs); newjfs.setHidden(true); } @@ -80,31 +78,31 @@ public class FrameworkJarChecker { public static void unmountDependencies() { String unoilPath = SVersionRCFile.getPathForUnoil( - OfficeSettings.getDefault().getOfficeDirectory().getPath()); + 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) { + } catch (IOException ioe) { return; - } - catch (PropertyVetoException pve) { + } catch (PropertyVetoException pve) { return; } FileSystem result; + try { result = Repository.getDefault().findFileSystem(jfs.getSystemName()); - if(result != null) + + if (result != null) Repository.getDefault().removeFileSystem(result); - } - catch(Exception exp) { + } catch (Exception exp) { } } @@ -115,13 +113,13 @@ public class FrameworkJarChecker { 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."; + "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); + message, prompt, true); if (!warning.getState()) { 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 index 1859ec60865e..67e6202c7789 100644 --- a/scripting/java/org/openoffice/netbeans/modules/office/utils/ManifestParser.java +++ b/scripting/java/org/openoffice/netbeans/modules/office/utils/ManifestParser.java @@ -45,6 +45,7 @@ public class ManifestParser implements XMLParser { if (parser == null) { parser = new ManifestParser(); } + return parser; } @@ -60,18 +61,15 @@ public class ManifestParser implements XMLParser { is.setSystemId(id); result = XMLUtil.parse(is, false, false, null, null); - } - catch (IOException ioe) { + } catch (IOException ioe) { System.out.println("IO Error parsing stream."); return null; - } - catch (SAXParseException spe) { + } 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) { + } catch (SAXException se) { System.out.println("Sax Error parsing stream: " + se.getMessage()); return null; } diff --git a/scripting/java/org/openoffice/netbeans/modules/office/utils/NagDialog.java b/scripting/java/org/openoffice/netbeans/modules/office/utils/NagDialog.java index c54833ba02bb..f6f9ee148e0e 100644 --- a/scripting/java/org/openoffice/netbeans/modules/office/utils/NagDialog.java +++ b/scripting/java/org/openoffice/netbeans/modules/office/utils/NagDialog.java @@ -36,7 +36,7 @@ public class NagDialog { private JCheckBox checkbox; private NagDialog(String message, String prompt, boolean initialState, - int type) { + int type) { initUI(message, prompt, initialState, type); } @@ -46,7 +46,7 @@ public class NagDialog { message, prompt, initialState, JOptionPane.INFORMATION_MESSAGE); result.setDescriptor(new NotifyDescriptor.Message(result.getPanel(), - NotifyDescriptor.PLAIN_MESSAGE)); + NotifyDescriptor.PLAIN_MESSAGE)); return result; } @@ -57,8 +57,8 @@ public class NagDialog { message, prompt, initialState, JOptionPane.QUESTION_MESSAGE); result.setDescriptor(new NotifyDescriptor.Confirmation( - result.getPanel(), NotifyDescriptor.OK_CANCEL_OPTION, - NotifyDescriptor.PLAIN_MESSAGE)); + result.getPanel(), NotifyDescriptor.OK_CANCEL_OPTION, + NotifyDescriptor.PLAIN_MESSAGE)); return result; } @@ -82,21 +82,21 @@ public class NagDialog { } private void initUI(String message, String prompt, boolean initialState, - int type) { + int type) { this.panel = new JPanel(); JOptionPane optionPane = new JOptionPane(message, type, 0, null, - new Object[0], null) - { - public int getMaxCharactersPerLineCount() { - return 100; - } - }; + 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); } }); diff --git a/scripting/java/org/openoffice/netbeans/modules/office/utils/OfficeModule.java b/scripting/java/org/openoffice/netbeans/modules/office/utils/OfficeModule.java index 305735cd4b86..a4d917e2552b 100644 --- a/scripting/java/org/openoffice/netbeans/modules/office/utils/OfficeModule.java +++ b/scripting/java/org/openoffice/netbeans/modules/office/utils/OfficeModule.java @@ -32,27 +32,28 @@ public class OfficeModule extends ModuleInstall { private static final long serialVersionUID = -8499324854301243852L; - public void installed () { + public void installed() { WizardDescriptor wiz = new InstallationPathDescriptor(); TopManager.getDefault().createDialog(wiz).show(); - if(wiz.getValue() == NotifyDescriptor.OK_OPTION) { + if (wiz.getValue() == NotifyDescriptor.OK_OPTION) { OfficeInstallation oi = (OfficeInstallation) - wiz.getProperty(InstallationPathDescriptor.PROP_INSTALLPATH); + wiz.getProperty(InstallationPathDescriptor.PROP_INSTALLPATH); OfficeSettings settings = OfficeSettings.getDefault(); settings.setOfficeDirectory(oi); } + FrameworkJarChecker.mountDependencies(); XMLParserFactory.setParser(ManifestParser.getManifestParser()); } - public void restored () { + public void restored() { FrameworkJarChecker.mountDependencies(); XMLParserFactory.setParser(ManifestParser.getManifestParser()); } - public boolean closing () { + 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 index 270b30fde9d9..f79368f6f495 100644 --- a/scripting/java/org/openoffice/netbeans/modules/office/utils/PackageRemover.java +++ b/scripting/java/org/openoffice/netbeans/modules/office/utils/PackageRemover.java @@ -39,24 +39,25 @@ public class PackageRemover { 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 { + } else { out.write(line, 0, line.length()); out.newLine(); } } - } - finally { + } finally { if (in != null) { in.close(); } + if (out != null) { out.close(); } @@ -65,8 +66,7 @@ public class PackageRemover { if (!source.delete()) { tmp.delete(); throw new IOException("Could not overwrite " + source); - } - else { + } else { tmp.renameTo(source); } } @@ -74,10 +74,12 @@ public class PackageRemover { 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);; @@ -89,8 +91,7 @@ public class PackageRemover { try { removeDeclaration(source); - } - catch (IOException ioe) { + } 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 index 7150ef81e541..4163ea1ea99f 100644 --- a/scripting/java/org/openoffice/netbeans/modules/office/utils/ZipMounter.java +++ b/scripting/java/org/openoffice/netbeans/modules/office/utils/ZipMounter.java @@ -27,8 +27,7 @@ import org.openide.filesystems.Repository; import org.openoffice.netbeans.modules.office.filesystem.OpenOfficeDocFileSystem; -public class ZipMounter -{ +public class ZipMounter { private static ZipMounter mounter = null; private ZipMounter() { @@ -37,25 +36,26 @@ public class ZipMounter public static synchronized ZipMounter getZipMounter() { if (mounter == null) mounter = new ZipMounter(); + return mounter; } public void mountZipFile(File zipfile) - throws IOException, PropertyVetoException - { + throws IOException, PropertyVetoException { if (zipfile != null) { addDocumentToRepository(zipfile, true); } } private FileSystem addDocumentToRepository(File rootFile, boolean writeable) - throws IOException, PropertyVetoException - { + throws IOException, PropertyVetoException { Repository repo = Repository.getDefault(); OpenOfficeDocFileSystem oofs; oofs = (OpenOfficeDocFileSystem)getMountedDocument(rootFile); - if(oofs != null) + + if (oofs != null) repo.removeFileSystem(oofs); + oofs = new OpenOfficeDocFileSystem(); oofs.setDocument(rootFile); repo.addFileSystem(oofs); @@ -64,16 +64,18 @@ public class ZipMounter /** @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) - { + private FileSystem getMountedDocument(File rootFile) { if (rootFile == null) return null; + FileSystem oofs = null; + try { oofs = Repository.getDefault().findFileSystem( - OpenOfficeDocFileSystem.computeSystemName(rootFile)); - } catch(Exception exp) { + OpenOfficeDocFileSystem.computeSystemName(rootFile)); + } catch (Exception exp) { } + return oofs; } } diff --git a/scripting/java/org/openoffice/netbeans/modules/office/wizard/InstallationPathDescriptor.java b/scripting/java/org/openoffice/netbeans/modules/office/wizard/InstallationPathDescriptor.java index 46147272eb83..f75873dade3f 100644 --- a/scripting/java/org/openoffice/netbeans/modules/office/wizard/InstallationPathDescriptor.java +++ b/scripting/java/org/openoffice/netbeans/modules/office/wizard/InstallationPathDescriptor.java @@ -56,7 +56,8 @@ public class InstallationPathDescriptor extends WizardDescriptor { protected void updateState() { super.updateState(); putProperty("WizardPanel_contentData", iterator.getSteps()); // NOI18N - putProperty("WizardPanel_contentSelectedIndex", Integer.valueOf(iterator.getIndex())); // NOI18N + putProperty("WizardPanel_contentSelectedIndex", + Integer.valueOf(iterator.getIndex())); // NOI18N } } diff --git a/scripting/java/org/openoffice/netbeans/modules/office/wizard/InstallationPathIterator.java b/scripting/java/org/openoffice/netbeans/modules/office/wizard/InstallationPathIterator.java index 918bcbdf0b49..fafd40165978 100644 --- a/scripting/java/org/openoffice/netbeans/modules/office/wizard/InstallationPathIterator.java +++ b/scripting/java/org/openoffice/netbeans/modules/office/wizard/InstallationPathIterator.java @@ -40,16 +40,16 @@ public class InstallationPathIterator implements WizardDescriptor.Iterator { protected WizardDescriptor.Panel[] createPanels() { return new WizardDescriptor.Panel[] { - new SelectPathPanel() - }; + new SelectPathPanel() + }; } // And the list of step names: protected String[] createSteps() { return new String[] { - "Select OpenOffice.org Installation" - }; + "Select OpenOffice.org Installation" + }; } // --- The rest probably does not need to be touched. --- @@ -66,6 +66,7 @@ public class InstallationPathIterator implements WizardDescriptor.Iterator { if (panels == null) { panels = createPanels(); } + return panels; } @@ -77,6 +78,7 @@ public class InstallationPathIterator implements WizardDescriptor.Iterator { if (steps == null) { steps = createSteps(); } + return steps; } @@ -87,7 +89,7 @@ public class InstallationPathIterator implements WizardDescriptor.Iterator { public String name() { return NbBundle.getMessage(InstallationPathIterator.class, "TITLE_x_of_y", - Integer.valueOf(index + 1), Integer.valueOf(getPanels().length)); + Integer.valueOf(index + 1), Integer.valueOf(getPanels().length)); } public boolean hasNext() { @@ -98,10 +100,12 @@ public class InstallationPathIterator implements WizardDescriptor.Iterator { } public void nextPanel() { if (!hasNext()) throw new NoSuchElementException(); + index++; } public void previousPanel() { if (!hasPrevious()) throw new NoSuchElementException(); + index--; } public WizardDescriptor.Panel current() { 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 8a326201301b..dd602ce1131d 100644 --- a/scripting/java/org/openoffice/netbeans/modules/office/wizard/JavaScriptIterator.java +++ b/scripting/java/org/openoffice/netbeans/modules/office/wizard/JavaScriptIterator.java @@ -58,17 +58,17 @@ public class JavaScriptIterator implements TemplateWizard.Iterator { protected WizardDescriptor.Panel[] createPanels() { return new WizardDescriptor.Panel[] { - // keep the default 2nd panel: - wiz.targetChooser(), - }; + // keep the default 2nd panel: + wiz.targetChooser(), + }; } // And the list of step names: protected String[] createSteps() { return new String[] { - null, - }; + null, + }; } private DataFolder checkTarget(DataFolder folder) { @@ -80,21 +80,23 @@ public class JavaScriptIterator implements TemplateWizard.Iterator { if (fs instanceof OpenOfficeDocFileSystem && fo.isRoot()) { FileObject scripts = fo.getFileObject(OpenOfficeDocFileSystem.SCRIPTS_ROOT); + if (scripts == null) scripts = fo.createFolder(OpenOfficeDocFileSystem.SCRIPTS_ROOT); FileObject javafolder = scripts.getFileObject("java"); + if (javafolder == null) javafolder = scripts.createFolder("java"); DataFolder subfolder = new DataFolder(javafolder); return subfolder; } - } - catch (IOException ioe) { + } catch (IOException ioe) { /* do nothing, we will just return the folder we were passed in */ } + return folder; } @@ -105,6 +107,7 @@ public class JavaScriptIterator implements TemplateWizard.Iterator { DataObject template = wiz.getTemplate(); DataObject result; + if (name == null) { // Default name. result = template.createFromTemplate(targetFolder); @@ -113,6 +116,7 @@ public class JavaScriptIterator implements TemplateWizard.Iterator { } FileObject tmp = result.getPrimaryFile(); + if (tmp.getExt().equals("java")) { try { PackageRemover.removeDeclaration(FileUtil.toFile(tmp)); @@ -120,13 +124,12 @@ public class JavaScriptIterator implements TemplateWizard.Iterator { // IssueZilla 11986 - rename the FileObject // so the JavaNode is resynchronized tmp.rename(tmp.lock(), tmp.getName(), tmp.getExt()); - } - catch (IOException ioe) { + } catch (IOException ioe) { NotifyDescriptor d = new NotifyDescriptor.Message( - "Error removing package declaration from file: " + - tmp.getNameExt() + - ". You should manually remove this declaration " + - "before building the Parcel Recipe"); + "Error removing package declaration from file: " + + tmp.getNameExt() + + ". You should manually remove this declaration " + + "before building the Parcel Recipe"); TopManager.getDefault().notify(d); } } @@ -150,18 +153,22 @@ public class JavaScriptIterator implements TemplateWizard.Iterator { panels = createPanels(); // Make sure list of steps is accurate. String[] steps = createSteps(); + for (int i = 0; i < panels.length; i++) { Component c = panels[i].getComponent(); + if (steps[i] == null) { // Default step name to component name of panel. // Mainly useful for getting the name of the target // chooser to appear in the list of steps. steps[i] = c.getName(); } + if (c instanceof JComponent) { // assume Swing components JComponent jc = (JComponent)c; // Step #. - jc.putClientProperty("WizardPanel_contentSelectedIndex", Integer.valueOf(i)); // NOI18N + jc.putClientProperty("WizardPanel_contentSelectedIndex", + Integer.valueOf(i)); // NOI18N // Step name (actually the whole list for reference). jc.putClientProperty("WizardPanel_contentData", steps); // NOI18N } @@ -189,10 +196,12 @@ public class JavaScriptIterator implements TemplateWizard.Iterator { } public void nextPanel() { if (!hasNext()) throw new NoSuchElementException(); + index++; } public void previousPanel() { if (!hasPrevious()) throw new NoSuchElementException(); + index--; } public WizardDescriptor.Panel current() { diff --git a/scripting/java/org/openoffice/netbeans/modules/office/wizard/ParcelContentsIterator.java b/scripting/java/org/openoffice/netbeans/modules/office/wizard/ParcelContentsIterator.java index 510a9adb638c..4135724d2010 100644 --- a/scripting/java/org/openoffice/netbeans/modules/office/wizard/ParcelContentsIterator.java +++ b/scripting/java/org/openoffice/netbeans/modules/office/wizard/ParcelContentsIterator.java @@ -62,17 +62,17 @@ public class ParcelContentsIterator implements TemplateWizard.Iterator { protected WizardDescriptor.Panel[] createPanels() { return new WizardDescriptor.Panel[] { - new ParcelPropertiesPanel(), - }; + new ParcelPropertiesPanel(), + }; } // And the list of step names: protected String[] createSteps() { return new String[] { - // null, - "Parcel Properties", - }; + // null, + "Parcel Properties", + }; } private DataFolder checkTarget(DataFolder folder) { @@ -84,21 +84,23 @@ public class ParcelContentsIterator implements TemplateWizard.Iterator { if (fs instanceof OpenOfficeDocFileSystem && fo.isRoot()) { FileObject scripts = fo.getFileObject(OpenOfficeDocFileSystem.SCRIPTS_ROOT); + if (scripts == null) scripts = fo.createFolder(OpenOfficeDocFileSystem.SCRIPTS_ROOT); FileObject javafolder = scripts.getFileObject("java"); + if (javafolder == null) javafolder = scripts.createFolder("java"); DataFolder subfolder = new DataFolder(javafolder); return subfolder; } - } - catch (IOException ioe) { + } catch (IOException ioe) { /* do nothing, we will just return the folder we were passed in */ } + return folder; } @@ -111,6 +113,7 @@ public class ParcelContentsIterator implements TemplateWizard.Iterator { DataObject template = wiz.getTemplate(); DataObject result; + if (name == null) { // Default name. result = template.createFromTemplate(targetFolder); @@ -152,18 +155,22 @@ public class ParcelContentsIterator implements TemplateWizard.Iterator { panels = createPanels(); // Make sure list of steps is accurate. String[] steps = createSteps(); + for (int i = 0; i < panels.length; i++) { Component c = panels[i].getComponent(); + if (steps[i] == null) { // Default step name to component name of panel. // Mainly useful for getting the name of the target // chooser to appear in the list of steps. steps[i] = c.getName(); } + if (c instanceof JComponent) { // assume Swing components JComponent jc = (JComponent)c; // Step #. - jc.putClientProperty("WizardPanel_contentSelectedIndex", Integer.valueOf(i)); // NOI18N + jc.putClientProperty("WizardPanel_contentSelectedIndex", + Integer.valueOf(i)); // NOI18N // Step name (actually the whole list for reference). jc.putClientProperty("WizardPanel_contentData", steps); // NOI18N } @@ -191,10 +198,12 @@ public class ParcelContentsIterator implements TemplateWizard.Iterator { } public void nextPanel() { if (!hasNext()) throw new NoSuchElementException(); + index++; } public void previousPanel() { if (!hasPrevious()) throw new NoSuchElementException(); + index--; } public WizardDescriptor.Panel current() { diff --git a/scripting/java/org/openoffice/netbeans/modules/office/wizard/ParcelPropertiesPanel.java b/scripting/java/org/openoffice/netbeans/modules/office/wizard/ParcelPropertiesPanel.java index e0355ed391c6..aaf3abd5a186 100644 --- a/scripting/java/org/openoffice/netbeans/modules/office/wizard/ParcelPropertiesPanel.java +++ b/scripting/java/org/openoffice/netbeans/modules/office/wizard/ParcelPropertiesPanel.java @@ -51,6 +51,7 @@ public class ParcelPropertiesPanel implements WizardDescriptor.FinishPanel { if (component == null) { component = new ParcelPropertiesVisualPanel(this); } + return component; } diff --git a/scripting/java/org/openoffice/netbeans/modules/office/wizard/ParcelPropertiesVisualPanel.java b/scripting/java/org/openoffice/netbeans/modules/office/wizard/ParcelPropertiesVisualPanel.java index bdb25bd02fb3..bf10d713e4c7 100644 --- a/scripting/java/org/openoffice/netbeans/modules/office/wizard/ParcelPropertiesVisualPanel.java +++ b/scripting/java/org/openoffice/netbeans/modules/office/wizard/ParcelPropertiesVisualPanel.java @@ -39,7 +39,8 @@ public class ParcelPropertiesVisualPanel extends javax.swing.JPanel { languagesComboBox.addItem("BeanShell"); // Provide a name in the title bar. - setName(NbBundle.getMessage(ParcelPropertiesVisualPanel.class, "TITLE_ParcelPropertiesVisualPanel")); + setName(NbBundle.getMessage(ParcelPropertiesVisualPanel.class, + "TITLE_ParcelPropertiesVisualPanel")); } /** This method is called from within the constructor to @@ -121,27 +122,33 @@ public class ParcelPropertiesVisualPanel extends javax.swing.JPanel { }//GEN-END:initComponents - private void recipeNameFocusGained(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_recipeNameFocusGained + private void recipeNameFocusGained(java.awt.event.FocusEvent + evt) {//GEN-FIRST:event_recipeNameFocusGained recipeName.selectAll(); }//GEN-LAST:event_recipeNameFocusGained - private void recipeNameFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_recipeNameFocusLost + private void recipeNameFocusLost(java.awt.event.FocusEvent + evt) {//GEN-FIRST:event_recipeNameFocusLost changeName(); }//GEN-LAST:event_recipeNameFocusLost - private void languagesComboBoxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_languagesComboBoxActionPerformed + private void languagesComboBoxActionPerformed(java.awt.event.ActionEvent + evt) {//GEN-FIRST:event_languagesComboBoxActionPerformed String language = (String)languagesComboBox.getSelectedItem(); panel.setLanguage(language); }//GEN-LAST:event_languagesComboBoxActionPerformed - private void recipeNameActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_recipeNameActionPerformed + private void recipeNameActionPerformed(java.awt.event.ActionEvent + evt) {//GEN-FIRST:event_recipeNameActionPerformed changeName(); }//GEN-LAST:event_recipeNameActionPerformed private void changeName() { String name = recipeName.getText().trim(); + if (name.length() == 0) name = null; + panel.setName(name); } diff --git a/scripting/java/org/openoffice/netbeans/modules/office/wizard/SelectPathPanel.java b/scripting/java/org/openoffice/netbeans/modules/office/wizard/SelectPathPanel.java index 66fb0a29821a..dfa434d75a35 100644 --- a/scripting/java/org/openoffice/netbeans/modules/office/wizard/SelectPathPanel.java +++ b/scripting/java/org/openoffice/netbeans/modules/office/wizard/SelectPathPanel.java @@ -36,7 +36,8 @@ import org.openoffice.idesupport.SVersionRCFile; /** A single panel descriptor for a wizard. * You probably want to make a wizard iterator to hold it. */ -public class SelectPathPanel implements WizardDescriptor.Panel /* .FinishPanel */ { +public class SelectPathPanel implements + WizardDescriptor.Panel { /* .FinishPanel */ /** The visual component that displays this panel. * If you need to access the component from this class, @@ -52,8 +53,7 @@ public class SelectPathPanel implements WizardDescriptor.Panel /* .FinishPanel * if (office == null) { try { office = SVersionRCFile.createInstance().getDefaultVersion(); - } - catch (java.io.IOException ioe) {} + } catch (java.io.IOException ioe) {} } } @@ -65,6 +65,7 @@ public class SelectPathPanel implements WizardDescriptor.Panel /* .FinishPanel * if (component == null) { component = new SelectPathVisualPanel(this); } + return component; } @@ -98,10 +99,13 @@ public class SelectPathPanel implements WizardDescriptor.Panel /* .FinishPanel * } protected final void fireChangeEvent() { Iterator it; + synchronized (listeners) { it = new HashSet(listeners).iterator(); } + ChangeEvent ev = new ChangeEvent(this); + while (it.hasNext()) { ((ChangeListener)it.next()).stateChanged(ev); } diff --git a/scripting/java/org/openoffice/netbeans/modules/office/wizard/SelectPathVisualPanel.java b/scripting/java/org/openoffice/netbeans/modules/office/wizard/SelectPathVisualPanel.java index 3853944e72fe..ca26a25bc150 100644 --- a/scripting/java/org/openoffice/netbeans/modules/office/wizard/SelectPathVisualPanel.java +++ b/scripting/java/org/openoffice/netbeans/modules/office/wizard/SelectPathVisualPanel.java @@ -52,8 +52,7 @@ public class SelectPathVisualPanel extends javax.swing.JPanel { OfficeInstallation oi = (OfficeInstallation)enumer.nextElement(); installationsComboBox.addItem(oi); } - } - catch (IOException ioe) { + } catch (IOException ioe) { installationsComboBox.addItem("<empty>"); } @@ -63,15 +62,16 @@ public class SelectPathVisualPanel extends javax.swing.JPanel { } installationsComboBox.addActionListener( - new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - installationsComboBoxActionPerformed(evt); - } + new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + installationsComboBoxActionPerformed(evt); } + } ); // Provide a name in the title bar. - setName(NbBundle.getMessage(SelectPathVisualPanel.class, "TITLE_SelectPathVisualPanel")); + setName(NbBundle.getMessage(SelectPathVisualPanel.class, + "TITLE_SelectPathVisualPanel")); } private void installationsComboBoxActionPerformed( @@ -155,7 +155,8 @@ public class SelectPathVisualPanel extends javax.swing.JPanel { }//GEN-END:initComponents - private void browseButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_browseButtonActionPerformed + private void browseButtonActionPerformed(java.awt.event.ActionEvent + evt) {//GEN-FIRST:event_browseButtonActionPerformed // Add your handling code here: File target = null; @@ -167,10 +168,10 @@ public class SelectPathVisualPanel extends javax.swing.JPanel { target = chooser.getSelectedFile(); String path; + try { path = target.getCanonicalPath(); - } - catch (IOException ioe) { + } catch (IOException ioe) { path = target.getAbsolutePath(); } |