IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Java Discussion :

Type MIME d'un fichier


Sujet :

Java

  1. #1
    Membre du Club
    Étudiant
    Inscrit en
    Mai 2004
    Messages
    110
    Détails du profil
    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Mai 2004
    Messages : 110
    Points : 50
    Points
    50
    Par défaut Type MIME d'un fichier
    Bonjour,

    Après quelques recherches sur le forum et dans la FAQ où une méthode est donné, j'aimerais savoir comment vous feriez pour connaitre le type MIME d'un fichier.

    J'ai justement utilisé cette méthode, mais pour un fichier audio MP3, cela me renvoie 'unknow' au lieu de "audio/mp3".

    Auriez-vous une solution à ce problème ?

    Merci d'avance

  2. #2
    Membre actif Avatar de tnodev
    Profil pro
    SSSSS
    Inscrit en
    Mai 2005
    Messages
    182
    Détails du profil
    Informations personnelles :
    Âge : 52
    Localisation : France, Hauts de Seine (Île de France)

    Informations professionnelles :
    Activité : SSSSS

    Informations forums :
    Inscription : Mai 2005
    Messages : 182
    Points : 231
    Points
    231
    Par défaut
    salut,

    J'ai créé un type enum avec les mime-type associé à leur content type, si cela peut-t'être utile...

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
    273
    274
    275
    276
    277
    278
    279
    280
    281
    282
    283
    284
    285
    286
    287
    288
    289
    290
    291
    292
    293
    294
    295
    296
    297
    298
    299
    300
    301
    302
    303
    304
    305
    306
    307
    308
    309
    310
    311
    312
    313
    314
    315
    316
    317
    318
    319
    320
    321
    322
    323
    324
    325
    326
    327
    328
    329
    330
    331
    332
    333
    334
    335
    336
    337
    338
    339
    340
    341
    342
    343
    344
    345
    346
    347
    348
    349
    350
    351
    352
    353
    354
    355
    356
    357
    358
    359
    360
    361
    362
    363
    364
    365
    366
    367
    368
    369
    370
    371
     
    /**
     * Les différents Mime-Type (couple extension/content type).
     * L'extension sans le point.
     * TODO A COMPLETER
     * @author Thomas Noirez
     *
     */
    public enum MimeType {
    	_123 ("application/vnd.lotus-1-2-3"),
    	_3dm ("x-world/x-3dmf"),
    	_3dmf ("x-world/x-3dmf"),
    	_3gp ("video/3gp"),
    	_3gpp ("audio/3gp"),
    	aab ("application/x-authorware-bin"),
    	aam ("application/x-authorware-map"),
    	aas ("application/x-authorware-map"),
    	adr ("application/x-msaddr"),
    	afl ("video/animaflex"),
    	ai ("application/postscript"),
    	aif ("audio/x-aiff"),
    	aifc ("audio/x-aiff"),
    	aiff ("audio/x-aiff"),
    	alt ("application/x-up-alert"),
    	aos ("application/x-nokia-9000-communicator-add-on-software"),
    	arj ("application/x-arj"),
    	asc ("text/plain"),
    	asd ("application/astound"),
    	asf ("video/x-ms-asf"),
    	asn ("application/astound"),
    	asp ("application/x-asap"),
    	asx ("video/x-ms-asf"),
    	asz ("application/astound"),
    	au ("audio/basic"),
    	avi ("video/avi"),
    	axs ("application/olescript"),
    	bas ("text/plain"),
    	bat ("text/plain"),
    	bcpio ("application/x-bcpio"),
    	bin ("application/octet-stream"),
    	bmp ("image/bmp"),
    	cacert ("application/x-x509-ca-cert"),
    	ccs ("text/ccs"),
    	cdf ("application/x-netcdf"),
    	cdr ("application/x-cdr"),
    	cer ("application/x-x509-ca-cert"),
    	chat ("application/x-chat"),
    	che ("application/x-up-cacheop"),
    	cht ("audio/x-dspeech"),
    	_class ("application/octet-stream"),
    	clp ("image/x-clp"),
    	cmd ("text/plain"),
    	cmx ("image/x-cmx"),
    	cnc ("application/x-cnc"),
    	cod ("image/cis-cod"),
    	coda ("application/x-coda"),
    	com ("application/octet-stream"),
    	con ("application/x-connector"),
    	cpi ("image/cpi"),
    	cpio ("application/x-cpio"),
    	csh ("application/x-csh"),
    	csm ("application/x-cu-seeme"),
    	css ("text/css"),
    	csv ("text/comma-separated-values"),
    	cu ("application/x-cu-seeme"),
    	cut ("image/x-halo-cut"),
    	dbf ("application/octet-stream"),
    	dcr ("application/x-director"),
    	dig ("multipart/mixed"),
    	dir ("application/x-director"),
    	doc ("application/msword"),
    	dsf ("image/x-mgx-dsf"),
    	dss ("text/dss"),
    	dst ("application/tajima"),
    	dus ("audio/x-dspeech"),
    	dvi ("application/x-dvi"),
    	dwf ("drawing/x-dwf"),
    	dwg ("image/vnd"),
    	dxf ("image/vnd"),
    	dxr ("application/x-director"),
    	ebk ("application/x-expandedbook"),
    	ecert ("application/x-x509-email-cert"),
    	email ("application/x-x509-email-cert"),
    	emf ("image/x-emf"),
    	eps ("application/postscript"),
    	erf ("application/x-hsp-erf"),
    	es ("audio/echospeech"),
    	etf ("image/x-etf"),
    	etx ("text/x-setext"),
    	evy ("application/envoy"),
    	exe ("application/x-msdownload"),
    	fh4 ("image/x-freehand"),
    	fh5 ("image/x-freehand"),
    	fhc ("image/x-freehand"),
    	fif ("image/fif"),
    	fml ("application/fml"),
    	fpx ("image/x-fpx"),
    	frl ("application/freeloader"),
    	fs ("application/X-FSRecipe"),
    	gif ("image/gif"),
    	gsd ("audio/gsm"),
    	gsm ("audio/gsm"),
    	gtar ("application/x-gtar"),
    	gvi ("?"),
    	gvp ("?"),
    	gz ("application/gzip"),
    	hdf ("application/x-hdf"),
    	hdml ("text/x-hdml"),
    	hqx ("application/mac-binhex40"),
    	htm ("text/html"),
    	html ("text/html"),
    	ica ("application/x-ica"),
    	ief ("image/ief"),
    	ins ("application/x-NET-Install"),
    	ips ("application/ips"),
    	ipx ("application/x-ipix"),
    	ivr ("i-world/i-vrml"),
    	jad ("text/vnd.sun.j2me.app-descriptor"),
    	jar ("application/java-archive"),
    	jardiff ("application/x-java-archive-diff"),
    	java ("text/x-java-source"),
    	jnlp ("application/x-java-jnlp-file"),
    	jp2 ("image/jp2"),
    	jpe ("image/jpeg"),
    	jpeg ("image/jpeg"),
    	jpg ("image/jpeg"),
    	jps ("image/x-jps"),
    	js ("application/x-javascript"),
    	latex ("application/x-latex"),
    	lha ("application/octet-stream"),
    	lit ("application/lit"),
    	lsp ("text/lsp"),
    	lwp ("application/x-wordpro"),
    	lzh ("application/octet-stream"),
    	lzx ("application/octet-stream"),
    	m3u ("audio/x-mpegurl"),
    	man ("application/x-troff-man"),
    	map ("application/x-httpd-imap"),
    	mbd ("application/mbedlet"),
    	mcf ("image/vasa"),
    	mdb ("application/mdb"),
    	me ("application/x-troff-me"),
    	mfp ("application/mirage"),
    	mid ("audio/x-midi"),
    	midi ("audio/x-midi"),
    	mif ("application/x-mif"),
    	mol ("chemical/x-mdl-molfile"),
    	mov ("video/quicktime"),
    	movie ("video/x-sgi-movie"),
    	mp2 ("audio/x-mpeg"),
    	mp3 ("audio/mpeg"),
    	mpe ("video/mpeg"),
    	mpeg ("video/mpeg"),
    	mpg ("video/mpeg"),
    	mpire ("application/x-mpire"),
    	mpl ("application/x-mpire"),
    	mpp ("application/vnd.ms-project"),
    	ms ("application/x-troff-ms"),
    	msi ("application/msi"),
    	msm ("application/msm"),
    	n2p ("application/n2p"),
    	nc ("application/x-netcdf"),
    	npx ("application/x-netfpx"),
    	nsc ("application/x-nschat"),
    	oda ("application/oda"),
    	ofml ("application/fml"),
    	page ("application/x-coda"),
    	pbd ("application/vnd.powerbuilder6"),
    	pbm ("image/x-portable-bitmap"),
    	pdb ("chemical/x-pdb"),
    	pdf ("application/pdf"),
    	pfr ("application/font-tdpfr"),
    	pgm ("image/x-portable-graymap"),
    	pgp ("application/x-pgp-plugin"),
    	pgr ("text/parsnegar-document"),
    	php ("application/x-httpd-php"),
    	php3 ("application/x-httpd-php3"),
    	php4 ("application/x-httpd-php"),
    	pls ("application/pls"),
    	png ("image/png"),
    	pnm ("image/x-portable-anymap"),
    	pot ("application/mspowerpoint"),
    	ppm ("image/x-portable-pixmap"),
    	pps ("application/mspowerpoint"),
    	ppt ("application/mspowerpoint"),
    	ppz ("application/mspowerpoint"),
    	pqf ("application/x-cprplayer"),
    	pqi ("application/cprplayer"),
    	ps ("application/postscript"),
    	psr ("application/datawindow"),
    	ptlk ("application/listenup"),
    	push ("multipart/x-mixed-replace"),
    	qd3 ("x-world/x-3dmf"),
    	qd3d ("x-world/x-3dmf"),
    	qrt ("application/quest"),
    	qt ("video/quicktime"),
    	qti ("image/x-quicktime"),
    	qtl ("application/x-quicktimeplayer"),
    	ra ("audio/x-pn-realaudio"),
    	ram ("audio/x-pn-realaudio"),
    	ras ("image/x-cmu-raster"),
    	rgb ("image/x-rgb"),
    	rip ("image/rip"),
    	rm ("audio/x-pn-realaudio"),
    	rmf ("audio/rmf"),
    	rng ("application/ringing-tones"),
    	roff ("application/x-troff"),
    	rpm ("audio/x-pn-realaudio-plugin"),
    	rrf ("application/x-InstallFromTheWeb"),
    	rss ("application/rss+xml"),
    	rtc ("application/rtc"),
    	rtf ("application/rtf"),
    	rtx ("text/richtext"),
    	sca ("application/x-supercard"),
    	scert ("application/x-x509-server-cert"),
    	scr ("application/octet-stream"),
    	seq ("application/octet-stream-bin"),
    	ser ("application/x-java-serialized-object"),
    	sh ("application/x-sh"),
    	shar ("application/x-shar"),
    	shtml ("text/x-server-parsed-html"),
    	shw ("application/presentations"),
    	sit ("application/x-stuffit"),
    	sjf ("application/octet-stream"),
    	smi ("application/smil"),
    	smil ("application/smil"),
    	sml ("application/smil"),
    	smp ("application/studiom"),
    	snd ("audio/basic"),
    	spc ("text/x-speech"),
    	spl ("application/futuresplash"),
    	spr ("application/x-sprite"),
    	sprite ("application/x-sprite"),
    	sql ("text/plain"),
    	src ("application/x-wais-source"),
    	ssi ("text/x-server-parsed-html"),
    	stk ("application/hstu"),
    	stream ("audio/x-qt-stream"),
    	sv4cpio ("application/x-sv4cpio"),
    	sv4crc ("application/x-sv4crc"),
    	svf ("image/vnd"),
    	svh ("image/svh"),
    	svr ("x-world/x-svr"),
    	swa ("application/x-director"),
    	swf ("application/x-shockwave-flash"),
    	t ("application/x-troff"),
    	talk ("application/talker"),
    	tar ("application/x-tar"),
    	tbk ("application/toolbook"),
    	tcl ("application/x-tcl"),
    	tex ("application/x-tex"),
    	texi ("application/x-texinfo"),
    	texinfo ("application/x-texinfo"),
    	text ("text/plain"),
    	tgz ("application/gzip"),
    	tif ("image/tiff"),
    	tiff ("image/tiff"),
    	tlk ("application/x-tlk"),
    	tmv ("application/x-Parable-Thing"),
    	torrent ("application/x-bittorrent"),
    	tr ("application/x-troff"),
    	troff ("application/x-troff"),
    	tsi ("audio/tsplayer"),
    	tsp ("application/dsptype"),
    	tsq ("application/timestamp-query"),
    	tsr ("application/timestamp-reply"),
    	tsv ("text/tab-separated-values"),
    	txt ("text/plain"),
    	u98 ("urdu/urdu98"),
    	ucert ("application/x-x509-user-cert"),
    	uin ("application/x-icq"),
    	usercert ("application/x-x509-user-cert"),
    	usr ("application/x-x509-user-cert"),
    	ustar ("application/x-ustar"),
    	vbd ("application/activexdocument"),
    	vcd ("application/x-cdlink"),
    	vcf ("text/x-vcard"),
    	vew ("application/groupwise"),
    	vgm ("video/x-videogram"),
    	vgp ("video/x-videogram-plugin"),
    	vgx ("video/x-videogram"),
    	viv ("video/vnd.vivo"),
    	vivo ("video/vnd.vivo"),
    	vmd ("application/vocaltec-media-desc"),
    	vmf ("application/vocaltec-media-file"),
    	vmi ("application/x-dreamcast-vms-info"),
    	vms ("application/x-dreamcast-vms"),
    	vox ("audio/voxware"),
    	vpa ("application/vpa"),
    	vqe ("audio/x-twinvq-plugin"),
    	vqf ("audio/x-twinvq"),
    	vql ("audio/x-twinvq"),
    	vrt ("x-world/x-vrt"),
    	vts ("workbook/formulaone"),
    	vtts ("workbook/formulaone"),
    	w60 ("application/wordperfect6.0"),
    	w61 ("application/wordperfect6.1"),
    	waf ("plugin/wanimate"),
    	wan ("plugin/wanimate"),
    	wav ("audio/wav"),
    	wax ("audio/x-ms-wax"),
    	wbmp ("image/vnd.wap.wbmp"),
    	wi ("image/wavelet"),
    	wid ("application/x-DemoShield"),
    	wis ("application/x-InstallShield"),
    	wlt ("application/x-mswallet"),
    	wm ("video/x-ms-wm"),
    	wma ("audio/x-ms-wma"),
    	wmd ("application/x-ms-wmd"),
    	wmf ("image/x-wmf"),
    	wml ("x-world/x-vrml"),
    	wmlc ("application/vnd.wap.wmlc"),
    	wmls ("text/vnd.wap.wmlscript"),
    	wmlsc ("application/vnd.wap.wmlscriptc"),
    	wmv ("video/x-ms-wmv"),
    	wmx ("video/x-ms-wmx"),
    	wmz ("application/x-ms-wmz"),
    	wp ("application/wordperfect"),
    	wp5 ("application/wordperfect"),
    	wpd ("application/wordperfect5.1"),
    	wri ("application/write"),
    	wrl ("x-world/x-vrml"),
    	wrz ("x-world/x-vrml"),
    	wtx ("audio/wtx"),
    	wvx ("video/x-ms-wvx"),
    	xbm ("image/x-xbitmap"),
    	xdr ("video/x-videogram"),
    	xif ("image/vnd.xiff"),
    	xla ("application/vnd.ms-excel"),
    	xlc ("application/vnd.ms-excel"),
    	xlm ("application/vnd.ms-excel"),
    	xls ("application/vnd.ms-excel"),
    	xlt ("application/vnd.ms-excel"),
    	xlw ("application/vnd.ms-excel"),
    	xml ("application/xml"),
    	xpm ("image/x-xpixmap"),
    	xwd ("image/x-xwindowdump"),
    	z ("application/x-compress"),
    	zip ("application/x-zip-compressed"),
    	zpa ("application/pcphoto"),
    	UNKNOWN ("text/unknown");
     
    	private String _value;
     
    	/**
             * @param value
             */
    	private MimeType(String value) {
    		_value = value;
    	}
     
    	/**
             * @return the value
             */
    	public final String getValue() {
    		return _value;
    	}
     
    	/**
             * Récup du content type en foncion de l'extension.
             * @param value l'extension sans le point maj. ou min.
             * @return SI null ou pas trouve alors [text/unknown] sinon le content-type
             */
    	public static String toContentType(final String value) {
    		EnumConversion<MimeType> ec = new EnumConversion<MimeType>(MimeType.class);
    		ec.setDefaultValue(UNKNOWN);
    		ec.setRemoveUnderscore(true);
     
    		return ec.getEnum(value).getValue();
    	}
    }

  3. #3
    Membre du Club
    Étudiant
    Inscrit en
    Mai 2004
    Messages
    110
    Détails du profil
    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Mai 2004
    Messages : 110
    Points : 50
    Points
    50
    Par défaut
    yes !! merci je vais regarder ca !!

  4. #4
    Expert éminent sénior
    Avatar de sinok
    Profil pro
    Inscrit en
    Août 2004
    Messages
    8 765
    Détails du profil
    Informations personnelles :
    Âge : 44
    Localisation : France, Paris (Île de France)

    Informations forums :
    Inscription : Août 2004
    Messages : 8 765
    Points : 12 977
    Points
    12 977
    Par défaut
    Bah en java c'ets pas évident, y'a pas de librairies pur qui soit réellement douée pour ça.

    Tu as le java activation framework qui fonctionne un peu mieux que la version contenue dans la FAQ et JMimeMagic qui sais déterminer encore plus de types mime mais qui est Buggé (renvoie un OutOfMemoryError sur certains fichiers).

    Le plus safe pour moi serait de récupérer une librairie native telle que libsharedmime et de faire les bindings avec JNI et de fournir la version compilée pour chaque OS

  5. #5
    Membre du Club
    Étudiant
    Inscrit en
    Mai 2004
    Messages
    110
    Détails du profil
    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Mai 2004
    Messages : 110
    Points : 50
    Points
    50
    Par défaut
    Citation Envoyé par tnodev
    salut,

    J'ai créé un type enum avec les mime-type associé à leur content type, si cela peut-t'être utile...

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
    273
    274
    275
    276
    277
    278
    279
    280
    281
    282
    283
    284
    285
    286
    287
    288
    289
    290
    291
    292
    293
    294
    295
    296
    297
    298
    299
    300
    301
    302
    303
    304
    305
    306
    307
    308
    309
    310
    311
    312
    313
    314
    315
    316
    317
    318
    319
    320
    321
    322
    323
    324
    325
    326
    327
    328
    329
    330
    331
    332
    333
    334
    335
    336
    337
    338
    339
    340
    341
    342
    343
    344
    345
    346
    347
    348
    349
    350
    351
    352
    353
    354
    355
    356
    357
    358
    359
    360
    361
    362
    363
    364
    365
    366
    367
    368
    369
    370
    371
     
    /**
     * Les différents Mime-Type (couple extension/content type).
     * L'extension sans le point.
     * TODO A COMPLETER
     * @author Thomas Noirez
     *
     */
    public enum MimeType {
    	_123 ("application/vnd.lotus-1-2-3"),
    	_3dm ("x-world/x-3dmf"),
    	_3dmf ("x-world/x-3dmf"),
    	_3gp ("video/3gp"),
    	_3gpp ("audio/3gp"),
    	aab ("application/x-authorware-bin"),
    	aam ("application/x-authorware-map"),
    	aas ("application/x-authorware-map"),
    	adr ("application/x-msaddr"),
    	afl ("video/animaflex"),
    	ai ("application/postscript"),
    	aif ("audio/x-aiff"),
    	aifc ("audio/x-aiff"),
    	aiff ("audio/x-aiff"),
    	alt ("application/x-up-alert"),
    	aos ("application/x-nokia-9000-communicator-add-on-software"),
    	arj ("application/x-arj"),
    	asc ("text/plain"),
    	asd ("application/astound"),
    	asf ("video/x-ms-asf"),
    	asn ("application/astound"),
    	asp ("application/x-asap"),
    	asx ("video/x-ms-asf"),
    	asz ("application/astound"),
    	au ("audio/basic"),
    	avi ("video/avi"),
    	axs ("application/olescript"),
    	bas ("text/plain"),
    	bat ("text/plain"),
    	bcpio ("application/x-bcpio"),
    	bin ("application/octet-stream"),
    	bmp ("image/bmp"),
    	cacert ("application/x-x509-ca-cert"),
    	ccs ("text/ccs"),
    	cdf ("application/x-netcdf"),
    	cdr ("application/x-cdr"),
    	cer ("application/x-x509-ca-cert"),
    	chat ("application/x-chat"),
    	che ("application/x-up-cacheop"),
    	cht ("audio/x-dspeech"),
    	_class ("application/octet-stream"),
    	clp ("image/x-clp"),
    	cmd ("text/plain"),
    	cmx ("image/x-cmx"),
    	cnc ("application/x-cnc"),
    	cod ("image/cis-cod"),
    	coda ("application/x-coda"),
    	com ("application/octet-stream"),
    	con ("application/x-connector"),
    	cpi ("image/cpi"),
    	cpio ("application/x-cpio"),
    	csh ("application/x-csh"),
    	csm ("application/x-cu-seeme"),
    	css ("text/css"),
    	csv ("text/comma-separated-values"),
    	cu ("application/x-cu-seeme"),
    	cut ("image/x-halo-cut"),
    	dbf ("application/octet-stream"),
    	dcr ("application/x-director"),
    	dig ("multipart/mixed"),
    	dir ("application/x-director"),
    	doc ("application/msword"),
    	dsf ("image/x-mgx-dsf"),
    	dss ("text/dss"),
    	dst ("application/tajima"),
    	dus ("audio/x-dspeech"),
    	dvi ("application/x-dvi"),
    	dwf ("drawing/x-dwf"),
    	dwg ("image/vnd"),
    	dxf ("image/vnd"),
    	dxr ("application/x-director"),
    	ebk ("application/x-expandedbook"),
    	ecert ("application/x-x509-email-cert"),
    	email ("application/x-x509-email-cert"),
    	emf ("image/x-emf"),
    	eps ("application/postscript"),
    	erf ("application/x-hsp-erf"),
    	es ("audio/echospeech"),
    	etf ("image/x-etf"),
    	etx ("text/x-setext"),
    	evy ("application/envoy"),
    	exe ("application/x-msdownload"),
    	fh4 ("image/x-freehand"),
    	fh5 ("image/x-freehand"),
    	fhc ("image/x-freehand"),
    	fif ("image/fif"),
    	fml ("application/fml"),
    	fpx ("image/x-fpx"),
    	frl ("application/freeloader"),
    	fs ("application/X-FSRecipe"),
    	gif ("image/gif"),
    	gsd ("audio/gsm"),
    	gsm ("audio/gsm"),
    	gtar ("application/x-gtar"),
    	gvi ("?"),
    	gvp ("?"),
    	gz ("application/gzip"),
    	hdf ("application/x-hdf"),
    	hdml ("text/x-hdml"),
    	hqx ("application/mac-binhex40"),
    	htm ("text/html"),
    	html ("text/html"),
    	ica ("application/x-ica"),
    	ief ("image/ief"),
    	ins ("application/x-NET-Install"),
    	ips ("application/ips"),
    	ipx ("application/x-ipix"),
    	ivr ("i-world/i-vrml"),
    	jad ("text/vnd.sun.j2me.app-descriptor"),
    	jar ("application/java-archive"),
    	jardiff ("application/x-java-archive-diff"),
    	java ("text/x-java-source"),
    	jnlp ("application/x-java-jnlp-file"),
    	jp2 ("image/jp2"),
    	jpe ("image/jpeg"),
    	jpeg ("image/jpeg"),
    	jpg ("image/jpeg"),
    	jps ("image/x-jps"),
    	js ("application/x-javascript"),
    	latex ("application/x-latex"),
    	lha ("application/octet-stream"),
    	lit ("application/lit"),
    	lsp ("text/lsp"),
    	lwp ("application/x-wordpro"),
    	lzh ("application/octet-stream"),
    	lzx ("application/octet-stream"),
    	m3u ("audio/x-mpegurl"),
    	man ("application/x-troff-man"),
    	map ("application/x-httpd-imap"),
    	mbd ("application/mbedlet"),
    	mcf ("image/vasa"),
    	mdb ("application/mdb"),
    	me ("application/x-troff-me"),
    	mfp ("application/mirage"),
    	mid ("audio/x-midi"),
    	midi ("audio/x-midi"),
    	mif ("application/x-mif"),
    	mol ("chemical/x-mdl-molfile"),
    	mov ("video/quicktime"),
    	movie ("video/x-sgi-movie"),
    	mp2 ("audio/x-mpeg"),
    	mp3 ("audio/mpeg"),
    	mpe ("video/mpeg"),
    	mpeg ("video/mpeg"),
    	mpg ("video/mpeg"),
    	mpire ("application/x-mpire"),
    	mpl ("application/x-mpire"),
    	mpp ("application/vnd.ms-project"),
    	ms ("application/x-troff-ms"),
    	msi ("application/msi"),
    	msm ("application/msm"),
    	n2p ("application/n2p"),
    	nc ("application/x-netcdf"),
    	npx ("application/x-netfpx"),
    	nsc ("application/x-nschat"),
    	oda ("application/oda"),
    	ofml ("application/fml"),
    	page ("application/x-coda"),
    	pbd ("application/vnd.powerbuilder6"),
    	pbm ("image/x-portable-bitmap"),
    	pdb ("chemical/x-pdb"),
    	pdf ("application/pdf"),
    	pfr ("application/font-tdpfr"),
    	pgm ("image/x-portable-graymap"),
    	pgp ("application/x-pgp-plugin"),
    	pgr ("text/parsnegar-document"),
    	php ("application/x-httpd-php"),
    	php3 ("application/x-httpd-php3"),
    	php4 ("application/x-httpd-php"),
    	pls ("application/pls"),
    	png ("image/png"),
    	pnm ("image/x-portable-anymap"),
    	pot ("application/mspowerpoint"),
    	ppm ("image/x-portable-pixmap"),
    	pps ("application/mspowerpoint"),
    	ppt ("application/mspowerpoint"),
    	ppz ("application/mspowerpoint"),
    	pqf ("application/x-cprplayer"),
    	pqi ("application/cprplayer"),
    	ps ("application/postscript"),
    	psr ("application/datawindow"),
    	ptlk ("application/listenup"),
    	push ("multipart/x-mixed-replace"),
    	qd3 ("x-world/x-3dmf"),
    	qd3d ("x-world/x-3dmf"),
    	qrt ("application/quest"),
    	qt ("video/quicktime"),
    	qti ("image/x-quicktime"),
    	qtl ("application/x-quicktimeplayer"),
    	ra ("audio/x-pn-realaudio"),
    	ram ("audio/x-pn-realaudio"),
    	ras ("image/x-cmu-raster"),
    	rgb ("image/x-rgb"),
    	rip ("image/rip"),
    	rm ("audio/x-pn-realaudio"),
    	rmf ("audio/rmf"),
    	rng ("application/ringing-tones"),
    	roff ("application/x-troff"),
    	rpm ("audio/x-pn-realaudio-plugin"),
    	rrf ("application/x-InstallFromTheWeb"),
    	rss ("application/rss+xml"),
    	rtc ("application/rtc"),
    	rtf ("application/rtf"),
    	rtx ("text/richtext"),
    	sca ("application/x-supercard"),
    	scert ("application/x-x509-server-cert"),
    	scr ("application/octet-stream"),
    	seq ("application/octet-stream-bin"),
    	ser ("application/x-java-serialized-object"),
    	sh ("application/x-sh"),
    	shar ("application/x-shar"),
    	shtml ("text/x-server-parsed-html"),
    	shw ("application/presentations"),
    	sit ("application/x-stuffit"),
    	sjf ("application/octet-stream"),
    	smi ("application/smil"),
    	smil ("application/smil"),
    	sml ("application/smil"),
    	smp ("application/studiom"),
    	snd ("audio/basic"),
    	spc ("text/x-speech"),
    	spl ("application/futuresplash"),
    	spr ("application/x-sprite"),
    	sprite ("application/x-sprite"),
    	sql ("text/plain"),
    	src ("application/x-wais-source"),
    	ssi ("text/x-server-parsed-html"),
    	stk ("application/hstu"),
    	stream ("audio/x-qt-stream"),
    	sv4cpio ("application/x-sv4cpio"),
    	sv4crc ("application/x-sv4crc"),
    	svf ("image/vnd"),
    	svh ("image/svh"),
    	svr ("x-world/x-svr"),
    	swa ("application/x-director"),
    	swf ("application/x-shockwave-flash"),
    	t ("application/x-troff"),
    	talk ("application/talker"),
    	tar ("application/x-tar"),
    	tbk ("application/toolbook"),
    	tcl ("application/x-tcl"),
    	tex ("application/x-tex"),
    	texi ("application/x-texinfo"),
    	texinfo ("application/x-texinfo"),
    	text ("text/plain"),
    	tgz ("application/gzip"),
    	tif ("image/tiff"),
    	tiff ("image/tiff"),
    	tlk ("application/x-tlk"),
    	tmv ("application/x-Parable-Thing"),
    	torrent ("application/x-bittorrent"),
    	tr ("application/x-troff"),
    	troff ("application/x-troff"),
    	tsi ("audio/tsplayer"),
    	tsp ("application/dsptype"),
    	tsq ("application/timestamp-query"),
    	tsr ("application/timestamp-reply"),
    	tsv ("text/tab-separated-values"),
    	txt ("text/plain"),
    	u98 ("urdu/urdu98"),
    	ucert ("application/x-x509-user-cert"),
    	uin ("application/x-icq"),
    	usercert ("application/x-x509-user-cert"),
    	usr ("application/x-x509-user-cert"),
    	ustar ("application/x-ustar"),
    	vbd ("application/activexdocument"),
    	vcd ("application/x-cdlink"),
    	vcf ("text/x-vcard"),
    	vew ("application/groupwise"),
    	vgm ("video/x-videogram"),
    	vgp ("video/x-videogram-plugin"),
    	vgx ("video/x-videogram"),
    	viv ("video/vnd.vivo"),
    	vivo ("video/vnd.vivo"),
    	vmd ("application/vocaltec-media-desc"),
    	vmf ("application/vocaltec-media-file"),
    	vmi ("application/x-dreamcast-vms-info"),
    	vms ("application/x-dreamcast-vms"),
    	vox ("audio/voxware"),
    	vpa ("application/vpa"),
    	vqe ("audio/x-twinvq-plugin"),
    	vqf ("audio/x-twinvq"),
    	vql ("audio/x-twinvq"),
    	vrt ("x-world/x-vrt"),
    	vts ("workbook/formulaone"),
    	vtts ("workbook/formulaone"),
    	w60 ("application/wordperfect6.0"),
    	w61 ("application/wordperfect6.1"),
    	waf ("plugin/wanimate"),
    	wan ("plugin/wanimate"),
    	wav ("audio/wav"),
    	wax ("audio/x-ms-wax"),
    	wbmp ("image/vnd.wap.wbmp"),
    	wi ("image/wavelet"),
    	wid ("application/x-DemoShield"),
    	wis ("application/x-InstallShield"),
    	wlt ("application/x-mswallet"),
    	wm ("video/x-ms-wm"),
    	wma ("audio/x-ms-wma"),
    	wmd ("application/x-ms-wmd"),
    	wmf ("image/x-wmf"),
    	wml ("x-world/x-vrml"),
    	wmlc ("application/vnd.wap.wmlc"),
    	wmls ("text/vnd.wap.wmlscript"),
    	wmlsc ("application/vnd.wap.wmlscriptc"),
    	wmv ("video/x-ms-wmv"),
    	wmx ("video/x-ms-wmx"),
    	wmz ("application/x-ms-wmz"),
    	wp ("application/wordperfect"),
    	wp5 ("application/wordperfect"),
    	wpd ("application/wordperfect5.1"),
    	wri ("application/write"),
    	wrl ("x-world/x-vrml"),
    	wrz ("x-world/x-vrml"),
    	wtx ("audio/wtx"),
    	wvx ("video/x-ms-wvx"),
    	xbm ("image/x-xbitmap"),
    	xdr ("video/x-videogram"),
    	xif ("image/vnd.xiff"),
    	xla ("application/vnd.ms-excel"),
    	xlc ("application/vnd.ms-excel"),
    	xlm ("application/vnd.ms-excel"),
    	xls ("application/vnd.ms-excel"),
    	xlt ("application/vnd.ms-excel"),
    	xlw ("application/vnd.ms-excel"),
    	xml ("application/xml"),
    	xpm ("image/x-xpixmap"),
    	xwd ("image/x-xwindowdump"),
    	z ("application/x-compress"),
    	zip ("application/x-zip-compressed"),
    	zpa ("application/pcphoto"),
    	UNKNOWN ("text/unknown");
     
    	private String _value;
     
    	/**
             * @param value
             */
    	private MimeType(String value) {
    		_value = value;
    	}
     
    	/**
             * @return the value
             */
    	public final String getValue() {
    		return _value;
    	}
     
    	/**
             * Récup du content type en foncion de l'extension.
             * @param value l'extension sans le point maj. ou min.
             * @return SI null ou pas trouve alors [text/unknown] sinon le content-type
             */
    	public static String toContentType(final String value) {
    		EnumConversion<MimeType> ec = new EnumConversion<MimeType>(MimeType.class);
    		ec.setDefaultValue(UNKNOWN);
    		ec.setRemoveUnderscore(true);
     
    		return ec.getEnum(value).getValue();
    	}
    }
    Et heu à quoi ca correspond "EnumConversion"
    Merci !!

  6. #6
    Expert éminent sénior
    Avatar de sinok
    Profil pro
    Inscrit en
    Août 2004
    Messages
    8 765
    Détails du profil
    Informations personnelles :
    Âge : 44
    Localisation : France, Paris (Île de France)

    Informations forums :
    Inscription : Août 2004
    Messages : 8 765
    Points : 12 977
    Points
    12 977
    Par défaut
    Cette classe permet juste d'associer un tyme mime à l'extension d'un fichier.

  7. #7
    Membre actif Avatar de tnodev
    Profil pro
    SSSSS
    Inscrit en
    Mai 2005
    Messages
    182
    Détails du profil
    Informations personnelles :
    Âge : 52
    Localisation : France, Hauts de Seine (Île de France)

    Informations professionnelles :
    Activité : SSSSS

    Informations forums :
    Inscription : Mai 2005
    Messages : 182
    Points : 231
    Points
    231
    Par défaut
    Oups...

    Classe de conversion String/enum afin de mieux gérer les cas tordus...
    Nécessite le StringUtils de common-lang

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
     
    package arc.common.enu;
     
    import org.apache.commons.lang.StringUtils;
     
     
    /**
     * Classe de conversion String/enum.
     * @author Thomas Noirez
     *
     */
    public class EnumConversion <E extends Enum> {
     
    	private Class<E> _enumType;
     
    	private E _defaultValue = null;
     
    	private boolean _removeUnderscore = false;
    	/**
             * @param enumType
             */
    	public EnumConversion(final Class<E> enumType) {
    		super();
    		_enumType = enumType;
    	}
     
    	/**
             * @param value la valeur string de l'enum
             * @return l'enum si il existe sinon null
             */
    	public E getEnum(final String value) {
    		if (value == null) {
    			return getDefaultValue();
    		}
    		try {
    			for (int i = 0; i < _enumType.getEnumConstants().length; i++) {
    				if (value.compareToIgnoreCase(getStringValue(_enumType.getEnumConstants()[i])) == 0) {
    					return _enumType.getEnumConstants()[i];
    				}
    			}
    			return getDefaultValue();
    		} catch (Exception e) {
    			return getDefaultValue();
    		}
    	}
     
    	private String getStringValue(E enumValue) {
    		if (_removeUnderscore) {
    			return StringUtils.remove(enumValue.toString(), '_');
    		} else {
    			return enumValue.toString();
    		}
    	}
     
    	/**
             * @param removeUnderscore removeUnderscore à définir.
             */
    	public final void setRemoveUnderscore(boolean removeUnderscore) {
    		_removeUnderscore = removeUnderscore;
    	}
     
    	/**
             * @return Renvoie default.
             */
    	private final E getDefaultValue() {
    		return _defaultValue;
    	}
     
    	/**
             * @param default1 default à définir.
             */
    	public final void setDefaultValue(E default1) {
    		_defaultValue = default1;
    	}
    }

  8. #8
    Membre du Club
    Étudiant
    Inscrit en
    Mai 2004
    Messages
    110
    Détails du profil
    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Mai 2004
    Messages : 110
    Points : 50
    Points
    50
    Par défaut
    Merci !

    Sinon j'ai regardé plusieurs librairies dont une qui me parait pas mal : jmimeinfo.
    Je vais voir lors de test plus poussé ...

    Merci à tous

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. récuperer le type mime à partir du fichier
    Par isma92 dans le forum Langage
    Réponses: 3
    Dernier message: 09/02/2007, 11h28
  2. Fiabiliser la détection du type Mime d'un fichier
    Par SegmentationFault dans le forum Langage
    Réponses: 20
    Dernier message: 19/12/2006, 18h49
  3. [FTP] Connaitre le type mime d'un fichier
    Par jak0 dans le forum Langage
    Réponses: 15
    Dernier message: 18/07/2006, 11h32
  4. Type Mime d'un fichier
    Par partyboy dans le forum Général JavaScript
    Réponses: 2
    Dernier message: 26/04/2006, 10h04
  5. [struts] déterminer le type Mime d'un fichier
    Par k4eve dans le forum Struts 1
    Réponses: 4
    Dernier message: 14/06/2004, 10h28

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo