commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ima...@apache.org
Subject svn commit: r537943 - in /jakarta/commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs: FileContent.java Resources.properties provider/AbstractFileObject.java provider/DefaultFileContent.java
Date Mon, 14 May 2007 18:37:15 GMT
Author: imario
Date: Mon May 14 11:37:14 2007
New Revision: 537943

URL: http://svn.apache.org/viewvc?view=rev&rev=537943
Log:
VFS-149: Add FileContent.hasAttribute and removeAttribute - Thanks to Adam Heath for the patch!

Modified:
    jakarta/commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs/FileContent.java
    jakarta/commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs/Resources.properties
    jakarta/commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs/provider/AbstractFileObject.java
    jakarta/commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs/provider/DefaultFileContent.java

Modified: jakarta/commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs/FileContent.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs/FileContent.java?view=diff&rev=537943&r1=537942&r2=537943
==============================================================================
--- jakarta/commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs/FileContent.java
(original)
+++ jakarta/commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs/FileContent.java
Mon May 14 11:37:14 2007
@@ -76,6 +76,16 @@
     void setLastModifiedTime(long modTime) throws FileSystemException;
 
     /**
+     * Checks if an attribute of the file's content exists.
+     *
+     * @param attrName The name of the attribute.
+     * @throws FileSystemException If the file does not exist, or does not support
+     *                             attributes.
+     */
+    boolean hasAttribute(String attrName)
+        throws FileSystemException;
+
+    /**
      * Returns a read-only map of this file's attributes.
      *
      * @throws FileSystemException If the file does not exist, or does not support attributes.
@@ -110,6 +120,16 @@
      *                             attributes, or on error setting the attribute.
      */
     void setAttribute(String attrName, Object value)
+        throws FileSystemException;
+
+    /**
+     * Removes the value of an attribute of the file's content.
+     *
+     * @param attrName The name of the attribute.
+     * @throws FileSystemException If the file does not exist, or is read-only, or does not
support
+     *                             attributes, or on error removing the attribute.
+     */
+    void removeAttribute(String attrName)
         throws FileSystemException;
 
     /**

Modified: jakarta/commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs/Resources.properties
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs/Resources.properties?view=diff&rev=537943&r1=537942&r2=537943
==============================================================================
--- jakarta/commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs/Resources.properties
(original)
+++ jakarta/commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs/Resources.properties
Mon May 14 11:37:14 2007
@@ -29,6 +29,7 @@
 vfs.provider/get-last-modified-not-supported.error=This file type does not support retriving
last modified time.
 vfs.provider/set-last-modified-not-supported.error=This file type does not support setting
last modified time.
 vfs.provider/set-attribute-not-supported.error=This file type does not support setting attributes.
+vfs.provider/remove-attribute-not-supported.error=This file type does not support removing
attributes.
 vfs.provider/get-attribute-not-supported.error=This file type does not support getting attributes.
 vfs.provider/write-not-supported.error=This file type cannot be written to.
 vfs.provider/get-type.error=Could not determine the type of file "{0}".
@@ -82,10 +83,13 @@
 vfs.provider/get-certificates.error=Could not retrieve the certificates of "{0}".
 vfs.provider/close-instr.error=Could not close the input stream for file "{0}".
 vfs.provider/close-outstr.error=Could not close the output stream for file "{0}".
+vfs.provider/exists-attribute-no-exist.error=Could not check if attribute "{0}" of "{1}"
exists because attributes are not supported.
 vfs.provider/get-attributes-no-exist.error=Could not get attributes for file "{0}" because
it does not exist.
 vfs.provider/get-attributes.error=Could not get attributes "{0}".
 vfs.provider/set-attribute-no-exist.error=Could not set attribute "{0}" of "{1}" because
it does not exist.
 vfs.provider/set-attribute.error=Could not set attribute "{0}" of "{1}".
+vfs.provider/remove-attribute-no-exist.error=Could not check if attribute "{0}" of "{1}"
exists because attributes are not supported.
+vfs.provider/remove-attribute.error=Could not remove attribute "{0}" of "{1}".
 
 # AbstractFileSystemProvider
 vfs.provider/invalid-absolute-uri.error=Invalid absolute URI "{0}".

Modified: jakarta/commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs/provider/AbstractFileObject.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs/provider/AbstractFileObject.java?view=diff&rev=537943&r1=537942&r2=537943
==============================================================================
--- jakarta/commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs/provider/AbstractFileObject.java
(original)
+++ jakarta/commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs/provider/AbstractFileObject.java
Mon May 14 11:37:14 2007
@@ -302,6 +302,20 @@
     }
 
     /**
+     * Removes an attribute of this file.  Is only called if {@link #doGetType}
+     * does not return {@link FileType#IMAGINARY}.
+     * <p/>
+     * This implementation throws an exception.
+	 * @returns true if removing the attribute succeed. In this case we remove the attribute
from
+	 * our cache
+     */
+    protected void doRemoveAttribute(final String atttrName)
+        throws Exception
+    {
+        throw new FileSystemException("vfs.provider/remove-attribute-not-supported.error");
+    }
+
+    /**
      * Returns the certificates used to sign this file.  Is only called if
      * {@link #doGetType} does not return {@link FileType#IMAGINARY}.
      * <p/>

Modified: jakarta/commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs/provider/DefaultFileContent.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs/provider/DefaultFileContent.java?view=diff&rev=537943&r1=537942&r2=537943
==============================================================================
--- jakarta/commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs/provider/DefaultFileContent.java
(original)
+++ jakarta/commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs/provider/DefaultFileContent.java
Mon May 14 11:37:14 2007
@@ -197,6 +197,19 @@
         }
     }
 
+   /**
+     * Checks if an attribute exists.
+     */
+    public boolean hasAttribute(final String attrName) throws FileSystemException
+    {
+        if (!file.getType().hasAttributes())
+        {
+            throw new FileSystemException("vfs.provider/exists-attributes-no-exist.error",
file);
+        }
+        getAttributes();
+        return attrs.containsKey(attrName);
+    }
+
     /**
      * Returns a read-only map of this file's attributes.
      */
@@ -269,6 +282,31 @@
         if (attrs != null)
         {
             attrs.put(attrName, value);
+        }
+    }
+
+    /**
+     * Removes an attribute.
+     */
+    public void removeAttribute(final String attrName) throws FileSystemException
+    {
+        if (!file.getType().hasAttributes())
+        {
+            throw new FileSystemException("vfs.provider/remove-attribute-no-exist.error",
file);
+        }
+
+		try
+        {
+            file.doRemoveAttribute(attrName);
+        }
+        catch (final Exception e)
+        {
+            throw new FileSystemException("vfs.provider/remove-attribute.error", new Object[]{attrName,
file}, e);
+        }
+
+        if (attrs != null)
+        {
+            attrs.remove(attrName);
         }
     }
 



---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Mime
View raw message