1 40 package org.dspace.content; 41 42 import java.sql.SQLException ; 43 44 import org.dspace.core.Context; 45 import org.dspace.storage.rdbms.DatabaseManager; 46 import org.dspace.storage.rdbms.TableRowIterator; 47 48 57 public class FormatIdentifier 58 { 59 68 public static BitstreamFormat guessFormat(Context context, 69 Bitstream bitstream) throws SQLException 70 { 71 String filename = bitstream.getName().toLowerCase(); 74 75 if (filename == null) 77 { 78 return null; 79 } 80 81 String extension = filename; 84 int lastDot = filename.lastIndexOf('.'); 85 86 if (lastDot != -1) 87 { 88 extension = filename.substring(lastDot + 1); 89 } 90 91 if (extension.equals("")) 95 { 96 return null; 97 } 98 99 TableRowIterator tri = DatabaseManager.query(context, 101 "SELECT bitstreamformatregistry.* FROM bitstreamformatregistry, " + 102 "fileextension WHERE fileextension.extension LIKE ? " + 103 "AND bitstreamformatregistry.bitstream_format_id=" + 104 "fileextension.bitstream_format_id", 105 extension); 106 107 BitstreamFormat retFormat = null; 108 if (tri.hasNext()) 109 { 110 retFormat = new BitstreamFormat(context, tri.next()); 112 } 113 else 114 { 115 retFormat = null; 116 } 117 tri.close(); 119 return retFormat; 120 } 121 } 122 | Popular Tags |