harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From telli...@apache.org
Subject svn commit: r494047 - in /harmony/enhanced/classlib/trunk: depends/files/ make/ modules/luni/src/main/java/org/apache/harmony/luni/internal/net/www/ modules/luni/src/test/java/tests/api/java/net/
Date Mon, 08 Jan 2007 12:46:21 GMT
Author: tellison
Date: Mon Jan  8 04:46:20 2007
New Revision: 494047

URL: http://svn.apache.org/viewvc?view=rev&rev=494047
Log:
Fix for URLConnection#getFileNameMap() which should look for a file located via a user defined
property
otherwise load a set of defaults from lib/content-types.properties under java home.

Added:
    harmony/enhanced/classlib/trunk/depends/files/content-types.properties   (with props)
Modified:
    harmony/enhanced/classlib/trunk/make/build-java.xml
    harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/internal/net/www/MimeTable.java
    harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/net/URLConnectionTest.java

Added: harmony/enhanced/classlib/trunk/depends/files/content-types.properties
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/depends/files/content-types.properties?view=auto&rev=494047
==============================================================================
--- harmony/enhanced/classlib/trunk/depends/files/content-types.properties (added)
+++ harmony/enhanced/classlib/trunk/depends/files/content-types.properties Mon Jan  8 04:46:20
2007
@@ -0,0 +1,179 @@
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+# 
+#     http://www.apache.org/licenses/LICENSE-2.0
+# 
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+#
+#   MIME-types properties file.
+#
+
+#
+# All these MIME types were taken from the Apache httpd mime.types file
+# which can be found here:
+# http://svn.apache.org/viewvc/httpd/httpd/branches/1.3.x/conf/mime.types?revision=106443&view=markup
+#
+
+ai=application/postscript
+aif=audio/x-aiff
+aifc=audio/x-aiff
+aiff=audio/x-aiff
+asc=text/plain
+atom=application/atom+xml
+au=audio/basic
+avi=video/x-msvideo
+bcpio=application/x-bcpio
+bin=application/octet-stream
+bmp=image/bmp
+cdf=application/x-netcdf
+cgm=image/cgm
+class=application/octet-stream
+cpio=application/x-cpio
+cpt=application/mac-compactpro
+csh=application/x-csh
+css=text/css
+dcr=application/x-director
+dir=application/x-director
+djv=image/vnd.djvu
+djvu=image/vnd.djvu
+dll=application/octet-stream
+dmg=application/octet-stream
+dms=application/octet-stream
+doc=application/msword
+dtd=application/xml-dtd
+dvi=application/x-dvi
+dxr=application/x-director
+eps=application/postscript
+etx=text/x-setext
+exe=application/octet-stream
+ez=application/andrew-inset
+gif=image/gif
+gram=application/srgs
+grxml=application/srgs+xml
+gtar=application/x-gtar
+hdf=application/x-hdf
+hqx=application/mac-binhex40
+htm=text/html
+html=text/html
+ice=x-conference/x-cooltalk
+ico=image/x-icon
+ics=text/calendar
+ief=image/ief
+ifb=text/calendar
+iges=model/iges
+igs=model/iges
+jpe=image/jpeg
+jpeg=image/jpeg
+jpg=image/jpeg
+js=application/x-javascript
+kar=audio/midi
+latex=application/x-latex
+lha=application/octet-stream
+lzh=application/octet-stream
+m3u=audio/x-mpegurl
+m4u=video/vnd.mpegurl
+man=application/x-troff-man
+mathml=application/mathml+xml
+me=application/x-troff-me
+mesh=model/mesh
+mid=audio/midi
+midi=audio/midi
+mif=application/vnd.mif
+mov=video/quicktime
+movie=video/x-sgi-movie
+mp2=audio/mpeg
+mp3=audio/mpeg
+mpe=video/mpeg
+mpeg=video/mpeg
+mpg=video/mpeg
+mpga=audio/mpeg
+ms=application/x-troff-ms
+msh=model/mesh
+mxu=video/vnd.mpegurl
+nc=application/x-netcdf
+oda=application/oda
+ogg=application/ogg
+pbm=image/x-portable-bitmap
+pdb=chemical/x-pdb
+pdf=application/pdf
+pgm=image/x-portable-graymap
+pgn=application/x-chess-pgn
+png=image/png
+pnm=image/x-portable-anymap
+ppm=image/x-portable-pixmap
+ppt=application/vnd.ms-powerpoint
+ps=application/postscript
+qt=video/quicktime
+ra=audio/x-pn-realaudio
+ram=audio/x-pn-realaudio
+ras=image/x-cmu-raster
+rdf=application/rdf+xml
+rgb=image/x-rgb
+rm=application/vnd.rn-realmedia
+roff=application/x-troff
+rtf=text/rtf
+rtx=text/richtext
+sgm=text/sgml
+sgml=text/sgml
+sh=application/x-sh
+shar=application/x-shar
+silo=model/mesh
+sit=application/x-stuffit
+skd=application/x-koan
+skm=application/x-koan
+skp=application/x-koan
+skt=application/x-koan
+smi=application/smil
+smil=application/smil
+snd=audio/basic
+so=application/octet-stream
+spl=application/x-futuresplash
+src=application/x-wais-source
+sv4cpio=application/x-sv4cpio
+sv4crc=application/x-sv4crc
+svg=image/svg+xml
+swf=application/x-shockwave-flash
+t=application/x-troff
+tar=application/x-tar
+tcl=application/x-tcl
+tex=application/x-tex
+texi=application/x-texinfo
+texinfo=application/x-texinfo
+tif=image/tiff
+tiff=image/tiff
+tr=application/x-troff
+tsv=text/tab-separated-values
+txt=text/plain
+ustar=application/x-ustar
+vcd=application/x-cdlink
+vrml=model/vrml
+vxml=application/voicexml+xml
+wav=audio/x-wav
+wbmp=image/vnd.wap.wbmp
+wbxml=application/vnd.wap.wbxml
+wml=text/vnd.wap.wml
+wmlc=application/vnd.wap.wmlc
+wmls=text/vnd.wap.wmlscript
+wmlsc=application/vnd.wap.wmlscriptc
+wrl=model/vrml
+xbm=image/x-xbitmap
+xht=application/xhtml+xml
+xhtml=application/xhtml+xml
+xls=application/vnd.ms-excel
+xml=application/xml
+xpm=image/x-xpixmap
+xsl=application/xml
+xslt=application/xslt+xml
+xul=application/vnd.mozilla.xul+xml
+xwd=image/x-xwindowdump
+xyz=chemical/x-xyz
+zip=application/zip

Propchange: harmony/enhanced/classlib/trunk/depends/files/content-types.properties
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: harmony/enhanced/classlib/trunk/make/build-java.xml
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/make/build-java.xml?view=diff&rev=494047&r1=494046&r2=494047
==============================================================================
--- harmony/enhanced/classlib/trunk/make/build-java.xml (original)
+++ harmony/enhanced/classlib/trunk/make/build-java.xml Mon Jan  8 04:46:20 2007
@@ -234,6 +234,12 @@
         </copy>
 
         <!-- Copy across the support files -->
+        <copy todir="${hy.jdk}/jre/lib">
+            <fileset dir="${depends.files}">
+                <include name="content-types.properties" />
+            </fileset>
+        </copy>
+
         <copy todir="${hy.jdk}/jre/lib/boot">
             <fileset dir="${depends.files}">
                 <include name="bootclasspath.properties" />

Modified: harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/internal/net/www/MimeTable.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/internal/net/www/MimeTable.java?view=diff&rev=494047&r1=494046&r2=494047
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/internal/net/www/MimeTable.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/internal/net/www/MimeTable.java
Mon Jan  8 04:46:20 2007
@@ -17,6 +17,8 @@
 
 package org.apache.harmony.luni.internal.net.www;
 
+import java.io.File;
+import java.io.FileInputStream;
 import java.io.IOException;
 import java.io.InputStream;
 import java.net.FileNameMap;
@@ -27,11 +29,10 @@
 /**
  * Instances of this class map file extensions to MIME content types based on a
  * default MIME table.
- * <p>
+ * 
  * The default values can be overridden by modifying the contents of the file
- * "types.properties".
+ * "content-types.properties".
  */
-
 public class MimeTable implements FileNameMap {
 
     public static final String UNKNOWN = "content/unknown"; //$NON-NLS-1$
@@ -43,44 +44,81 @@
 
     // Default mapping.
     static {
-        types.put("text", "text/plain"); //$NON-NLS-1$ //$NON-NLS-2$
-        types.put("txt", "text/plain"); //$NON-NLS-1$ //$NON-NLS-2$
-        types.put("htm", "text/html"); //$NON-NLS-1$ //$NON-NLS-2$
-        types.put("html", "text/html"); //$NON-NLS-1$ //$NON-NLS-2$
+        types.setProperty("text", "text/plain"); //$NON-NLS-1$ //$NON-NLS-2$
+        types.setProperty("txt", "text/plain"); //$NON-NLS-1$ //$NON-NLS-2$
+        types.setProperty("htm", "text/html"); //$NON-NLS-1$ //$NON-NLS-2$
+        types.setProperty("html", "text/html"); //$NON-NLS-1$ //$NON-NLS-2$
     }
 
     /**
      * Contructs a MIME table using the default values defined in this class.
-     * <p>
-     * It then augments this table by reading pairs of extensions and matching
-     * content types from the file "types.properties", which is represented in
-     * standard java.util.Properties.load(...) format.
+     * 
+     * It then augments this table by reading pairs of extensions and
+     * corresponding content types from the file "content-types.properties",
+     * which is represented in standard java.util.Properties.load(...) format.
      */
     public MimeTable() {
         InputStream str = AccessController
                 .doPrivileged(new PrivilegedAction<InputStream>() {
                     public InputStream run() {
-                        return MimeTable.this.getClass().getResourceAsStream(
-                                "types.properties"); //$NON-NLS-1$
+                        return getContentTypes();
                     }
                 });
 
-        try {
-            if (str != null) {
-                types.load(str);
+        if (str != null) {
+            try {
+                try {
+                    types.load(str);
+                } finally {
+                    str.close();
+                }
+            } catch (IOException ex) {
+                // Ignore
             }
-        } catch (IOException ex) {
-            // Ignored
         }
     }
 
     /**
+     * Answer an InputStream over an external properties file containing the
+     * MIME types.
+     * 
+     * Looks in the location specified in the user property, and then in the
+     * expected location.
+     * 
+     * @return the InputStream, or null if none.
+     */
+    private InputStream getContentTypes() {
+        // User override?
+        String userTable = System.getProperty("content.types.user.table"); //$NON-NLS-1$
+        if (userTable != null) {
+            try {
+                return new FileInputStream(userTable);
+            } catch (IOException e) {
+                // Ignore invalid values
+            }
+        }
+
+        // Standard location?
+        String javahome = System.getProperty("java.home"); //$NON-NLS-1$
+        File contentFile = new File(javahome, "lib" //$NON-NLS-1$
+                + File.separator + "content-types.properties"); //$NON-NLS-1$
+        try {
+            return new FileInputStream(contentFile);
+        } catch (IOException e) {
+            // Not found or can't read
+        }
+
+        return null;
+    }
+
+    /**
      * Determines the MIME type for the given filename.
      * 
-     * @return java.lang.String The mime type associated with the file's
-     *         extension or null if no mapping is known.
      * @param filename
-     *            java.lang.String The file whose extension will be mapped.
+     *            The file whose extension will be mapped.
+     * 
+     * @return The mime type associated with the file's extension or null if no
+     *         mapping is known.
      */
     public String getContentTypeFor(String filename) {
         if (filename.endsWith("/")) { //$NON-NLS-1$
@@ -96,7 +134,6 @@
         if (firstCharInExtension > filename.lastIndexOf('/')) {
             ext = filename.substring(firstCharInExtension, lastCharInExtension);
         }
-        return (String) types.get(ext.toLowerCase());
+        return types.getProperty(ext.toLowerCase());
     }
-
 }

Modified: harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/net/URLConnectionTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/net/URLConnectionTest.java?view=diff&rev=494047&r1=494046&r2=494047
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/net/URLConnectionTest.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/net/URLConnectionTest.java
Mon Jan  8 04:46:20 2007
@@ -224,14 +224,28 @@
 	 * @tests java.net.URLConnection#getFileNameMap()
 	 */
 	public void test_getFileNameMap() {
+        // Tests for the standard MIME types -- users may override these
+        // in their JRE
+        FileNameMap map = URLConnection.getFileNameMap();
+        
+        // These types are defaulted
+        assertEquals("text/html", map.getContentTypeFor("htm"));
+        assertEquals("text/html", map.getContentTypeFor("html"));
+        assertEquals("text/plain", map.getContentTypeFor("text"));
+        assertEquals("text/plain", map.getContentTypeFor("txt"));
+        
+        // These types come from the properties file
+        assertEquals("application/pdf", map.getContentTypeFor("pdf"));
+        assertEquals("application/zip", map.getContentTypeFor("zip"));
+        
 		URLConnection.setFileNameMap(new FileNameMap() {
 			public String getContentTypeFor(String fileName) {
 				return "Spam!";
 			}
 		});
 		try {
-			assertEquals("Incorrect FileNameMap returned", "Spam!", URLConnection.getFileNameMap()
-					.getContentTypeFor(null));
+			assertEquals("Incorrect FileNameMap returned", "Spam!",
+                    URLConnection.getFileNameMap().getContentTypeFor(null));
 		} finally {
 			// unset the map so other tests don't fail
 			URLConnection.setFileNameMap(null);



Mime
View raw message