aboutsummaryrefslogtreecommitdiff
path: root/libjava/scripts/MakeDefaultMimeTypes.java
blob: 49b67d675bd653c2d652b5e6cae31d7f34809c0e (plain)
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
/* Copyright (C) 2000  Free Software Foundation

   This file is part of libgcj.

This software is copyrighted work licensed under the terms of the
Libgcj License.  Please consult the file "LIBGCJ_LICENSE" for
details.  */

import gnu.gcj.io.MimeTypes;
import java.io.IOException;
import java.io.FileNotFoundException;
import java.util.Hashtable;
import java.util.Enumeration;
import java.util.NoSuchElementException;

public class MakeDefaultMimeTypes
{
  private static void fatal (String message)
  {
    System.err.println ("MakeDefaultMimeTypes Error: " + message);
    System.exit (-1);
  }
  
  public static void main (String[] args)
  {
    Hashtable mime_table = new Hashtable ();
    
    if (args.length != 1)
      fatal ("missing mime type filename");

    try {
      MimeTypes.fillFromFile (mime_table, args[0]);
    } catch (FileNotFoundException ex) {
      fatal ("can't open " + args[0]);
    } catch (IOException ex) {
      fatal ("error reading " + args[0]);
    }

    System.out.println ("// Do not edit this file!  Create a new version with MakeDefaultMimeTypes.\
\
/* Copyright (C) 2000  Free Software Foundation\
\
   This file is part of libgcj.\
\
This software is copyrighted work licensed under the terms of the\
Libgcj License.  Please consult the file \"LIBGCJ_LICENSE\" for\
details.  */\
\
package gnu.gcj.io; \
\
public class DefaultMimeTypes\
{\
  public static final String[] types = {");

    Enumeration keys = mime_table.keys();
    Enumeration values = mime_table.elements();
    
    // Prepend first element with open bracket
    StringBuffer result = new StringBuffer("");
    
    try
      {
	result.append("      \"" 
		      + keys.nextElement().toString() 
		      + "\",\t\"" 
		      + values.nextElement().toString()
		      + "\"\n");
      }
    catch (NoSuchElementException ex)
      {
      }
    
    // Prepend subsequent elements with ", "
    try
      {
	while (true)
	  result.append("    , \"" 
			+ keys.nextElement().toString() 
			+ "\",\t\"" 
			+ values.nextElement().toString()
			+ "\"\n");
      }
    catch (NoSuchElementException ex)
      {
      }
    
    // Append last element with closing bracket
    result.append("  };\
}\
");
    System.out.println(result);
  }
}