You are viewing a plain text version of this content. The canonical link for it is here.
Posted to scm@geronimo.apache.org by jd...@apache.org on 2003/08/29 14:50:29 UTC

cvs commit: incubator-geronimo/specs/activation/src/java/javax/activation FileDataSource.java FileTypeMap.java URLDataSource.java

jdillon     2003/08/29 05:50:29

  Modified:    specs/activation/src/java/javax/activation
                        FileDataSource.java FileTypeMap.java
                        URLDataSource.java
  Log:
   o Applied patch GERONIMO-37
  
  Revision  Changes    Path
  1.2       +38 -12    incubator-geronimo/specs/activation/src/java/javax/activation/FileDataSource.java
  
  Index: FileDataSource.java
  ===================================================================
  RCS file: /home/cvs/incubator-geronimo/specs/activation/src/java/javax/activation/FileDataSource.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- FileDataSource.java	16 Aug 2003 18:07:45 -0000	1.1
  +++ FileDataSource.java	29 Aug 2003 12:50:29 -0000	1.2
  @@ -63,6 +63,8 @@
   package javax.activation;
   
   import java.io.File;
  +import java.io.FileInputStream;
  +import java.io.FileOutputStream;
   import java.io.IOException;
   import java.io.InputStream;
   import java.io.OutputStream;
  @@ -74,42 +76,66 @@
    * @version $Revision$ $Date$
    */
   public class FileDataSource implements DataSource {
  +
       private File file;
  +    private FileTypeMap fileTypeMap;
   
  +    /**
  +     * Creates a FileDataSource from a File object
  +     */
       public FileDataSource(File file) {
           this.file = file;
       }
   
  +    /**
  +     * Creates a FileDataSource from the specified path name
  +     */
       public FileDataSource(String name) {
           this(new File(name));
       }
   
  +    /**
  +     * Return the InputStream obtained from the data source
  +     */
       public InputStream getInputStream() throws IOException {
  -        /*@todo implement*/
  -        return null;
  +        return new FileInputStream(file);
       }
   
  +    /**
  +     * Return the OutputStream obtained from the data source
  +     */
       public OutputStream getOutputStream() throws IOException {
  -        /*@todo implement*/
  -        return null;
  +        return new FileOutputStream(file);
       }
   
  +    /**
  +     * Returns the content type of the data source
  +     */
       public String getContentType() {
  -        /*@todo implement*/
  -        return null;
  +        if (fileTypeMap == null)
  +            return FileTypeMap.getDefaultFileTypeMap().getContentType(file);
  +
  +        return fileTypeMap.getContentType(file);
       }
   
  +    /**
  +     * Returns the name of the data source object
  +     */
       public String getName() {
  -        /*@todo implement*/
  -        return null;
  +        return file.getName();
       }
   
  +    /**
  +     * Returns the data source file
  +     */
       public File getFile() {
  -        /*@todo implement*/
  -        return null;
  +        return file;
       }
   
  +    /**
  +     * Sets the FileTypeMap associated with the data source
  +     */
       public void setFileTypeMap(FileTypeMap map) {
  -        /*@todo implement*/
  +        fileTypeMap = map;
       }
   }
  
  
  
  1.2       +15 -7     incubator-geronimo/specs/activation/src/java/javax/activation/FileTypeMap.java
  
  Index: FileTypeMap.java
  ===================================================================
  RCS file: /home/cvs/incubator-geronimo/specs/activation/src/java/javax/activation/FileTypeMap.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- FileTypeMap.java	16 Aug 2003 18:07:45 -0000	1.1
  +++ FileTypeMap.java	29 Aug 2003 12:50:29 -0000	1.2
  @@ -65,26 +65,34 @@
   import java.io.File;
   
   /**
  - *
  - *
  + * FileTypeMap is an abstract class that provides a data type interface for files.
    *
    * @version $Revision$ $Date$
    */
   public abstract class FileTypeMap {
  +	
  +	private static FileTypeMap defaultFileTypeMap;
  +
       public FileTypeMap() {
  -        /*@todo implement*/
       }
   
       public abstract String getContentType(File file);
   
       public abstract String getContentType(String filename);
   
  +	/**
  +	 * Sets the default FileTypeMap for the system
  +	 */
       public static void setDefaultFileTypeMap(FileTypeMap map) {
  -        /*@todo implement*/
  +        defaultFileTypeMap = map;
       }
   
  +	/**
  +	 * Returns the default FileTypeMap
  +	 */
       public static FileTypeMap getDefaultFileTypeMap() {
  -        /*@todo implement*/
  -        return null;
  +        if (defaultFileTypeMap==null)
  +        	return new MimetypesFileTypeMap();
  +        return defaultFileTypeMap;
       }
   }
  
  
  
  1.2       +46 -14    incubator-geronimo/specs/activation/src/java/javax/activation/URLDataSource.java
  
  Index: URLDataSource.java
  ===================================================================
  RCS file: /home/cvs/incubator-geronimo/specs/activation/src/java/javax/activation/URLDataSource.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- URLDataSource.java	16 Aug 2003 18:07:45 -0000	1.1
  +++ URLDataSource.java	29 Aug 2003 12:50:29 -0000	1.2
  @@ -66,40 +66,72 @@
   import java.io.InputStream;
   import java.io.OutputStream;
   import java.net.URL;
  +import java.net.URLConnection;
   
   /**
    *
  - *
  - *
    * @version $Revision$ $Date$
    */
   public class URLDataSource implements DataSource {
  +
  +    private URL url;
  +    private final static String DEFAULT_CONTENT_TYPE = "application/octet-stream";
  +
  +    /**
  +     * Creates a URLDataSource from a URL object
  +     */
       public URLDataSource(URL url) {
  -        /*@todo implement*/
  +        this.url = url;
       }
   
  +    /**
  +     * Returns the value of the URL content-type header field
  +     * 
  +     */
       public String getContentType() {
  -        /*@todo implement*/
  -        return null;
  +        URLConnection connection = null;
  +        try {
  +            connection = url.openConnection();
  +        } catch (IOException e) {
  +        }
  +        if (connection == null)
  +            return DEFAULT_CONTENT_TYPE;
  +
  +        return connection.getContentType();
  +
       }
   
  +    /**
  +     * Returns the file name of the URL object
  +     */
       public String getName() {
  -        /*@todo implement*/
  -        return null;
  +        return url.getFile();
       }
   
  +    /**
  +     * Returns an InputStream obtained from the data source
  +     */
       public InputStream getInputStream() throws IOException {
  -        /*@todo implement*/
  -        return null;
  +        return url.openStream();
       }
   
  +    /**
  +     * Returns an OutputStream obtained from the data source
  +     */
       public OutputStream getOutputStream() throws IOException {
  -        /*@todo implement*/
  -        return null;
  +
  +        URLConnection connection = url.openConnection();
  +        if (connection == null)
  +            return null;
  +
  +        connection.setDoOutput(true); //is it necessary?
  +        return connection.getOutputStream();
       }
   
  +    /**
  +     * Returns the URL of the data source
  +     */
       public URL getURL() {
  -        /*@todo implement*/
  -        return null;
  +        return url;
       }
   }