adammurdoch 2003/02/23 23:24:59
Modified: vfs/src/java/org/apache/commons/vfs FileContent.java
FileObject.java Resources.properties
vfs/src/java/org/apache/commons/vfs/provider
AbstractFileObject.java DefaultFileContent.java
DelegateFileObject.java
vfs/src/java/org/apache/commons/vfs/provider/jar
JarFileObject.java
Log:
- FileContent changes:
- Added getAttributes() and getAttributeNames().
- Don't allow get/set last-modified time if the file is being written to.
- Don't allow get/set properties on files that don't exist.
- Allow get/set properties on files that are being read.
- Don't allow get certificates if the file is being written to.
- Replaced AbstractFileObject.doGetAttribute() with doGetAttributes().
- Fixed Javadocs.
Revision Changes Path
1.8 +32 -15
jakarta-commons-sandbox/vfs/src/java/org/apache/commons/vfs/FileContent.java
Index: FileContent.java
===================================================================
RCS file:
/home/cvs/jakarta-commons-sandbox/vfs/src/java/org/apache/commons/vfs/FileContent.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- FileContent.java 13 Feb 2003 04:28:45 -0000 1.7
+++ FileContent.java 24 Feb 2003 07:24:58 -0000 1.8
@@ -58,6 +58,7 @@
import java.io.InputStream;
import java.io.OutputStream;
import java.security.cert.Certificate;
+import java.util.Map;
/**
* Represents the data content of a file.
@@ -117,28 +118,42 @@
* The time to set the last-modified timestamp to.
*
* @throws FileSystemException
- * If the file is read-only, or is being read, or on error setting
- * the last-modified timestamp.
+ * If the file is read-only, or is being written to, or on error
+ * setting the last-modified timestamp.
*/
void setLastModifiedTime( long modTime ) throws FileSystemException;
/**
- * Gets the value of an attribute of the file's content.
+ * Returns a read-only map of this file's attributes.
+ *
+ * @throws FileSystemException
+ * If the file does not exist, or does not support attributes.
+ */
+ Map getAttributes() throws FileSystemException;
+
+ /**
+ * Lists the attributes of the file's content.
*
- * <p>TODO - change to <code>Map getAttributes()</code> instead?
+ * @return
+ * The names of the attributes. Never returns null;
*
- * <p>TODO - define the standard attribute names, and define which attrs
- * are guaranteed to be present.
+ * @throws FileSystemException
+ * If the file does not exist, or does not support attributes.
+ */
+ String[] getAttributeNames() throws FileSystemException;
+
+ /**
+ * Gets the value of an attribute of the file's content.
*
* @param attrName
- * The name of the attribute.
+ * The name of the attribute. Attribute names are case insensitive.
*
* @return
- * The value of the attribute.
+ * The value of the attribute, or null if the attribute value is
+ * unknown.
*
* @throws FileSystemException
- * If the file does not exist, or is being written, or if the
- * attribute is unknown.
+ * If the file does not exist, or does not support attributes.
*/
Object getAttribute( String attrName ) throws FileSystemException;
@@ -153,16 +168,18 @@
* The value of the attribute.
*
* @throws FileSystemException
- * If the file is read-only, or is being read, or if the attribute
- * is not supported, or on error setting the attribute.
+ * If the file does not exist, or is read-only, or does not support
+ * attributes, or on error setting the attribute.
*/
void setAttribute( String attrName, Object value )
throws FileSystemException;
/**
- * Retrives the certificates if any used to sign this file or folder.
- * This will return null if there is no certificates or the file system
- * does not support signing.
+ * Retrieves the certificates if any used to sign this file or folder.
+ *
+ * @return
+ * The certificates, or an empty array if there are no certificates or
+ * the file does not support signing.
*
* @throws FileSystemException
* If the file does not exist, or is being written.
1.18 +1 -1
jakarta-commons-sandbox/vfs/src/java/org/apache/commons/vfs/FileObject.java
Index: FileObject.java
===================================================================
RCS file:
/home/cvs/jakarta-commons-sandbox/vfs/src/java/org/apache/commons/vfs/FileObject.java,v
retrieving revision 1.17
retrieving revision 1.18
diff -u -r1.17 -r1.18
--- FileObject.java 23 Feb 2003 00:40:38 -0000 1.17
+++ FileObject.java 24 Feb 2003 07:24:58 -0000 1.18
@@ -336,7 +336,7 @@
* This file's content.
*
* @throws FileSystemException
- * If this file is a folder.
+ * On error getting this file's content.
*/
FileContent getContent() throws FileSystemException;
1.22 +11 -5
jakarta-commons-sandbox/vfs/src/java/org/apache/commons/vfs/Resources.properties
Index: Resources.properties
===================================================================
RCS file:
/home/cvs/jakarta-commons-sandbox/vfs/src/java/org/apache/commons/vfs/Resources.properties,v
retrieving revision 1.21
retrieving revision 1.22
diff -u -r1.21 -r1.22
--- Resources.properties 23 Feb 2003 00:40:38 -0000 1.21
+++ Resources.properties 24 Feb 2003 07:24:58 -0000 1.22
@@ -30,7 +30,7 @@
vfs.provider/get-url.error=Could not create URL for "{0}".
vfs.provider/close.error=Could not close "{0}".
vfs.provider/read.error=Could not read file "{0}".
-vfs.provider/read-not-readable.error=File "{0}" is not readable.
+vfs.provider/read-not-readable.error=File "{0}" is not readable.
vfs.provider/read-not-file.error=Could not read from "{0}" because it is a not a
file.
# DefaultFileContent
@@ -39,15 +39,20 @@
vfs.provider/get-size.error=Could not determine the size of file "{0}".
vfs.provider/read-in-use.error=Could not read file "{0}" because it is currently
being written to.
vfs.provider/write-in-use.error=Could not write to "{0}" because it is currently in
use.
+vfs.provider/get-last-modified-writing.error=Could not determine the last modified
timestamp of "{0}" because it is being written to.
vfs.provider/get-last-modified-no-exist.error=Could not determine the last modified
timestamp of "{0}" because it does not exist.
vfs.provider/get-last-modified.error=Could not determine the last modified
timestamp of "{0}".
+vfs.provider/set-last-modified-writing.error=Could not set the last modified
timestamp of "{0}" because it is being written to.
vfs.provider/set-last-modified-no-exist.error=Could not set the last modified
timestamp of "{0}" because it does not exist.
vfs.provider/set-last-modified.error=Could not set the last modified timestamp of
"{0}".
vfs.provider/get-certificates-no-exist.error=Could not retrieve the certificates of
"{0}" because it does not exist.
+vfs.provider/get-certificates-writing.error=Could not retrieve the certificates of
"{0}" because it is being written to.
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/get-attribute.error=Could not get attribute "{0}" of "{1}".
+vfs.provider/get-attributes-no-exist.error=Could not get attributes "{1}" because
it does not exist.
+vfs.provider/get-attributes.error=Could not get attributes "{1}".
+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}".
# AbstractFileSystemProvider
@@ -75,8 +80,9 @@
vfs.impl/unknown-scheme.error=Unknown scheme "{0}" in URI "{1}".
vfs.impl/find-rel-file.error=Could not find file with URI "{0}" because it is a
relative path, and no base URI was provided.
vfs.impl/multiple-providers-for-scheme.error=Multiple providers registered for URL
scheme "{0}".
-vfs.impl/unknown-provider.error=No file system provider is registered for URI
scheme "{0}".
-vfs.impl/no-local-file-provider.error=Could not find a file system provider which
can handle local files.
+vfs.impl/unknown-provider.error=No file provider is registered with URI scheme
"{0}" to handle file "{1}".
+vfs.impl/no-provider-for-file.error=Could not find a file provider that can handle
file "{0}".
+vfs.impl/no-local-file-provider.error=Could not find a file provider which can
handle local files.
vfs.impl/no-replicator.error=No file replicator configured.
vfs.impl/no-temp-file-store.error=No temporary file store configured.
vfs.impl/replicate-file.error=Could not replicate "{0}".
@@ -87,7 +93,7 @@
vfs.impl/find-config-file.error=Could not find VFS configuration resource "{0}".
vfs.impl/load-config.error=Could not load VFS configuration from "{0}".
vfs.impl/create-provider.error=Could not create file provider of class "{0}".
-vfs.impl/skipping-provider.warn=Skipping provider "{0}" because required class
"{0}" is not available.
+vfs.impl/skipping-provider.warn=Skipping provider "{0}" because required class
"{1}" is not available.
# VFSClassLoader
vfs.impl/pkg-sealing-unsealed=Trying to seal package "{0}" that exists as unsealed.
1.28 +17 -15
jakarta-commons-sandbox/vfs/src/java/org/apache/commons/vfs/provider/AbstractFileObject.java
Index: AbstractFileObject.java
===================================================================
RCS file:
/home/cvs/jakarta-commons-sandbox/vfs/src/java/org/apache/commons/vfs/provider/AbstractFileObject.java,v
retrieving revision 1.27
retrieving revision 1.28
diff -u -r1.27 -r1.28
--- AbstractFileObject.java 23 Feb 2003 00:40:38 -0000 1.27
+++ AbstractFileObject.java 24 Feb 2003 07:24:58 -0000 1.28
@@ -66,6 +66,8 @@
import java.security.cert.Certificate;
import java.util.ArrayList;
import java.util.List;
+import java.util.Map;
+import java.util.Collections;
import org.apache.commons.vfs.FileContent;
import org.apache.commons.vfs.FileName;
import org.apache.commons.vfs.FileObject;
@@ -139,7 +141,7 @@
/**
* Determines if this file can be read. Is only called if [EMAIL PROTECTED]
#doGetType}
- * does not return null.
+ * does not return [EMAIL PROTECTED] FileType#IMAGINARY}.
*
* This implementation always returns true.
*/
@@ -150,7 +152,7 @@
/**
* Determines if this file can be written to. Is only called if
- * [EMAIL PROTECTED] #doGetType} does not return null.
+ * [EMAIL PROTECTED] #doGetType} does not return [EMAIL PROTECTED]
FileType#IMAGINARY}.
*
* This implementation always returns true.
*/
@@ -169,7 +171,7 @@
/**
* Deletes the file. Is only called when:
* <ul>
- * <li>[EMAIL PROTECTED] #doGetType} does not return null.
+ * <li>[EMAIL PROTECTED] #doGetType} does not return [EMAIL PROTECTED]
FileType#IMAGINARY}.
* <li>[EMAIL PROTECTED] #doIsWriteable} returns true.
* <li>This file has no children, if a folder.
* </ul>
@@ -184,7 +186,7 @@
/**
* Creates this file as a folder. Is only called when:
* <ul>
- * <li>[EMAIL PROTECTED] #doGetType} returns null.
+ * <li>[EMAIL PROTECTED] #doGetType} returns [EMAIL PROTECTED]
FileType#IMAGINARY}.
* <li>The parent folder exists and is writeable, or this file is the
* root of the file system.
* </ul>
@@ -217,7 +219,7 @@
/**
* Returns the last modified time of this file. Is only called if
- * [EMAIL PROTECTED] #doGetType} does not return null.
+ * [EMAIL PROTECTED] #doGetType} does not return [EMAIL PROTECTED]
FileType#IMAGINARY}.
*
* This implementation throws an exception.
*/
@@ -228,7 +230,7 @@
/**
* Sets the last modified time of this file. Is only called if
- * [EMAIL PROTECTED] #doGetType} does not return null.
+ * [EMAIL PROTECTED] #doGetType} does not return [EMAIL PROTECTED]
FileType#IMAGINARY}.
*
* This implementation throws an exception.
*/
@@ -239,20 +241,20 @@
}
/**
- * Gets an attribute of this file. Is only called if [EMAIL PROTECTED]
#doGetType}
- * does not return null.
+ * Returns the attributes of this file. Is only called if [EMAIL PROTECTED]
#doGetType}
+ * does not return [EMAIL PROTECTED] FileType#IMAGINARY}.
*
- * This implementation always returns null.
+ * This implementation always returns an empty map.
*/
- protected Object doGetAttribute( final String attrName )
+ protected Map doGetAttributes()
throws Exception
{
- return null;
+ return Collections.EMPTY_MAP;
}
/**
* Sets an attribute of this file. Is only called if [EMAIL PROTECTED]
#doGetType}
- * does not return null.
+ * does not return [EMAIL PROTECTED] FileType#IMAGINARY}.
*
* This implementation throws an exception.
*/
@@ -264,7 +266,7 @@
/**
* Returns the certificates used to sign this file. Is only called if
- * [EMAIL PROTECTED] #doGetType} does not return null.
+ * [EMAIL PROTECTED] #doGetType} does not return [EMAIL PROTECTED]
FileType#IMAGINARY}.
*
* This implementation always returns null.
*/
@@ -296,8 +298,8 @@
* <ul>
* <li>[EMAIL PROTECTED] #doIsWriteable} returns true.
* <li>[EMAIL PROTECTED] #doGetType} returns [EMAIL PROTECTED] FileType#FILE},
or
- * [EMAIL PROTECTED] #doGetType} returns null, and the file's parent exists
- * and is a folder.
+ * [EMAIL PROTECTED] #doGetType} returns [EMAIL PROTECTED] FileType#IMAGINARY},
and the file's
+ * parent exists and is a folder.
* </ul>
*
* <p>It is guaranteed that there are no open stream (input or output) for
1.14 +72 -10
jakarta-commons-sandbox/vfs/src/java/org/apache/commons/vfs/provider/DefaultFileContent.java
Index: DefaultFileContent.java
===================================================================
RCS file:
/home/cvs/jakarta-commons-sandbox/vfs/src/java/org/apache/commons/vfs/provider/DefaultFileContent.java,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -r1.13 -r1.14
--- DefaultFileContent.java 23 Feb 2003 00:40:38 -0000 1.13
+++ DefaultFileContent.java 24 Feb 2003 07:24:58 -0000 1.14
@@ -60,6 +60,9 @@
import java.io.OutputStream;
import java.security.cert.Certificate;
import java.util.ArrayList;
+import java.util.Map;
+import java.util.Collections;
+import java.util.Set;
import org.apache.commons.vfs.FileContent;
import org.apache.commons.vfs.FileObject;
import org.apache.commons.vfs.FileSystemException;
@@ -83,6 +86,8 @@
private int state = STATE_NONE;
private final ArrayList instrs = new ArrayList();
private FileContentOutputStream outstr;
+ private Map attrs;
+ private Map roAttrs;
public DefaultFileContent( final AbstractFileObject file )
{
@@ -117,7 +122,7 @@
// Get the size
return file.doGetContentSize();
}
- catch ( Exception exc )
+ catch ( final Exception exc )
{
throw new FileSystemException( "vfs.provider/get-size.error", new
Object[]{file}, exc );
}
@@ -128,6 +133,10 @@
*/
public long getLastModifiedTime() throws FileSystemException
{
+ if ( state == STATE_WRITING )
+ {
+ throw new FileSystemException(
"vfs.provider/get-last-modified-writing.error", file );
+ }
if ( !file.getType().hasAttributes() )
{
throw new FileSystemException(
"vfs.provider/get-last-modified-no-exist.error", file );
@@ -145,8 +154,12 @@
/**
* Sets the last-modified timestamp.
*/
- public void setLastModifiedTime( long modTime ) throws FileSystemException
+ public void setLastModifiedTime( final long modTime ) throws FileSystemException
{
+ if ( state == STATE_WRITING )
+ {
+ throw new FileSystemException(
"vfs.provider/set-last-modified-writing.error", file );
+ }
if ( !file.getType().hasAttributes() )
{
throw new FileSystemException(
"vfs.provider/set-last-modified-no-exist.error", file );
@@ -162,19 +175,47 @@
}
/**
- * Gets the value of an attribute.
+ * Returns a read-only map of this file's attributes.
*/
- public Object getAttribute( final String attrName )
- throws FileSystemException
+ public Map getAttributes() throws FileSystemException
{
- try
+ if ( !file.getType().hasAttributes() )
{
- return file.doGetAttribute( attrName );
+ throw new FileSystemException(
"vfs.provider/get-attributes-no-exist.error", file );
}
- catch ( final Exception e )
+ if ( roAttrs == null )
{
- throw new FileSystemException( "vfs.provider/get-attribute.error", new
Object[]{attrName, file}, e );
+ try
+ {
+ attrs = file.doGetAttributes();
+ roAttrs = Collections.unmodifiableMap( attrs );
+ }
+ catch ( final Exception e )
+ {
+ throw new FileSystemException( "vfs.provider/get-attributes.error",
file, e );
+ }
}
+ return roAttrs;
+ }
+
+ /**
+ * Lists the attributes of this file.
+ */
+ public String[] getAttributeNames() throws FileSystemException
+ {
+ getAttributes();
+ final Set names = attrs.keySet();
+ return (String[])names.toArray( new String[ names.size() ] );
+ }
+
+ /**
+ * Gets the value of an attribute.
+ */
+ public Object getAttribute( final String attrName )
+ throws FileSystemException
+ {
+ getAttributes();
+ return attrs.get( attrName.toLowerCase() );
}
/**
@@ -183,6 +224,10 @@
public void setAttribute( final String attrName, final Object value )
throws FileSystemException
{
+ if ( !file.getType().hasAttributes() )
+ {
+ throw new FileSystemException(
"vfs.provider/set-attribute-no-exist.error", new Object[]{attrName, file} );
+ }
try
{
file.doSetAttribute( attrName, value );
@@ -191,6 +236,11 @@
{
throw new FileSystemException( "vfs.provider/set-attribute.error", new
Object[]{attrName, file}, e );
}
+
+ if ( attrs != null )
+ {
+ attrs.put( attrName, value );
+ }
}
/**
@@ -202,10 +252,22 @@
{
throw new FileSystemException(
"vfs.provider/get-certificates-no-exist.error", file );
}
+ if ( state == STATE_WRITING )
+ {
+ throw new FileSystemException(
"vfs.provider/get-certificates-writing.error", file );
+ }
try
{
- return file.doGetCertificates();
+ final Certificate[] certs = file.doGetCertificates();
+ if ( certs != null )
+ {
+ return certs;
+ }
+ else
+ {
+ return new Certificate[ 0 ];
+ }
}
catch ( final Exception e )
{
1.7 +9 -8
jakarta-commons-sandbox/vfs/src/java/org/apache/commons/vfs/provider/DelegateFileObject.java
Index: DelegateFileObject.java
===================================================================
RCS file:
/home/cvs/jakarta-commons-sandbox/vfs/src/java/org/apache/commons/vfs/provider/DelegateFileObject.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- DelegateFileObject.java 23 Feb 2003 00:40:38 -0000 1.6
+++ DelegateFileObject.java 24 Feb 2003 07:24:58 -0000 1.7
@@ -60,6 +60,7 @@
import java.security.cert.Certificate;
import java.util.HashSet;
import java.util.Set;
+import java.util.Map;
import org.apache.commons.vfs.FileChangeEvent;
import org.apache.commons.vfs.FileListener;
import org.apache.commons.vfs.FileName;
@@ -249,16 +250,16 @@
}
/**
- * Called from [EMAIL PROTECTED] DefaultFileContent#getAttribute}.
+ * Returns the attributes of this file.
*/
- protected Object doGetAttribute( final String attrName )
+ protected Map doGetAttributes()
throws Exception
{
- return file.getContent().getAttribute( attrName );
+ return file.getContent().getAttributes();
}
/**
- * Called from [EMAIL PROTECTED] DefaultFileContent#setAttribute}.
+ * Sets an attribute of this file.
*/
protected void doSetAttribute( final String atttrName,
final Object value )
@@ -268,7 +269,7 @@
}
/**
- * Called from [EMAIL PROTECTED] DefaultFileContent#getCertificates}.
+ * Returns the certificates of this file.
*/
protected Certificate[] doGetCertificates() throws Exception
{
@@ -276,7 +277,7 @@
}
/**
- * Called from [EMAIL PROTECTED] DefaultFileContent#getLastModifiedTime}.
+ * Returns the last-modified time of this file.
*/
protected long doGetLastModifiedTime() throws Exception
{
@@ -284,7 +285,7 @@
}
/**
- * Called from [EMAIL PROTECTED] DefaultFileContent#setLastModifiedTime}.
+ * Sets the last-modified time of this file.
*/
protected void doSetLastModifiedTime( final long modtime )
throws Exception
1.8 +23 -10
jakarta-commons-sandbox/vfs/src/java/org/apache/commons/vfs/provider/jar/JarFileObject.java
Index: JarFileObject.java
===================================================================
RCS file:
/home/cvs/jakarta-commons-sandbox/vfs/src/java/org/apache/commons/vfs/provider/jar/JarFileObject.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- JarFileObject.java 12 Feb 2003 07:56:15 -0000 1.7
+++ JarFileObject.java 24 Feb 2003 07:24:59 -0000 1.8
@@ -57,8 +57,10 @@
import java.io.IOException;
import java.security.cert.Certificate;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
import java.util.jar.Attributes;
-import java.util.jar.Attributes.Name;
import java.util.jar.JarEntry;
import java.util.jar.JarFile;
import java.util.jar.Manifest;
@@ -125,19 +127,30 @@
/**
* Returns the value of an attribute.
*/
- protected Object doGetAttribute( final String attrName )
+ protected Map doGetAttributes()
throws Exception
{
+ final Map attrs = new HashMap();
+
+ // Add the file system's attributes first
final JarFileSystem fs = (JarFileSystem)getFileSystem();
- final Attributes attr = getAttributes();
- final Name name = fs.lookupName( attrName );
- String value = attr.getValue( name );
- if ( value != null )
+ addAll( fs.getAttributes(), attrs );
+
+ // Add this file's attributes
+ addAll( getAttributes(), attrs );
+
+ return attrs;
+ }
+
+ /** Adds the source attributes to the destination map. */
+ private void addAll( final Attributes src, final Map dest )
+ {
+ for ( Iterator iterator = src.entrySet().iterator(); iterator.hasNext(); )
{
- return value;
+ final Map.Entry entry = (Map.Entry)iterator.next();
+ final String name = entry.getKey().toString().toLowerCase();
+ dest.put( name, entry.getValue() );
}
-
- return fs.getAttribute( name );
}
/**
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]