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/openoffice/netbeans/modules/office/filesystem | |
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/openoffice/netbeans/modules/office/filesystem')
2 files changed, 298 insertions, 292 deletions
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 { |