Changeset 2914


Ignore:
Timestamp:
Nov 15, 2006, 8:38:30 AM (16 years ago)
Author:
Nicklas Nordborg
Message:

Download servlet now sets a MIME type by checking the registered file extensions if no MIME type
is set on a file.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/core/net/sf/basedb/core/MimeType.java

    r2898 r2914  
    130130   
    131131  /**
     132    Get the MIME type of a given file name or extension. This method will check
     133    all registered MIME types even if the logged in user doesn't have read permission.
     134    @param dc The DbControl to use for database access
     135    @param name The file name or extension, if a dot exists in the name only
     136      the last part will be used for MIME type lookup
     137    @param defaultMimeType A default MIME type to return if none is found
     138    @return A MIME type or null
     139    @throws BaseException If there is an error
     140    @since 2.2
     141   */
     142  public static String getMimeType(DbControl dc, String name, String defaultMimeType)
     143    throws BaseException
     144  {
     145    int dot = name.lastIndexOf('.');
     146    String mimeType = defaultMimeType;
     147
     148    String extension = dot >= 0 ? name.substring(dot + 1) : name;
     149    org.hibernate.Session session = dc.getHibernateSession();
     150    org.hibernate.Query query = HibernateUtil.getPredefinedQuery(session, "GET_MIME_TYPE_FROM_EXTENSION");
     151    /*
     152      SELECT mt
     153      FROM mimetype mt
     154      WHERE mt.extension = :extension
     155    */
     156    query.setString("extension", extension);
     157    MimeTypeData mt = HibernateUtil.loadData(MimeTypeData.class, query);
     158    if (mt != null) mimeType = mt.getName();
     159    return mimeType;
     160  }
     161 
     162  /**
    132163    Creates a new mimetype item from the given data.
    133164
Note: See TracChangeset for help on using the changeset viewer.