6 if ($ARGV[0] eq "-v") {
8 $i4jversion = shift @ARGV;
9 die("-v i4jversion must be an integer [probably 7 or 8]") unless $i4jversion =~ m/^\d+$/;
12 my $fileformats = $ARGV[0];
13 $fileformats = "../../src/jalview/io/FileFormat.java" unless $fileformats;
15 # default mimetype will be text/x-$shortname
16 # TODO: find an actual extension for mat, see JAL-Xxxxx for outstanding issues too
17 # TODO: look up standard mime type used for BLASTfmt matrices, etc
19 rnaml => "application/rnaml+xml",
20 biojson => "application/x-jalview-biojson+json",
21 jnet => "application/x-jalview-jnet+text",
22 features => "application/x-jalview-features+text",
23 scorematrix => "application/x-jalview-scorematrix+text",
24 pdb => "chemical/x-pdb",
25 mmcif => "chemical/x-cif",
26 mmcif2 => "chemical/x-mcif",
27 jalview => "application/x-jalview+xml+zip",
28 jvl => "application/x-jalview-jvl+text",
29 annotations => "application/x-jalview-annotations+text",
32 my @dontaddshortname = qw(features json);
33 my @dontaddextension = qw(html xml json jar mfa fastq);
34 my $add_associations = {
35 biojson => {shortname=>"biojson",name=>"BioJSON",extensions=>["biojson"]},
36 gff2 => {shortname=>"gff2",name=>"Generic Features Format v2",extensions=>["gff2"]},
37 gff3 => {shortname=>"gff3",name=>"Generic Features Format v3",extensions=>["gff3"]},
38 features => {shortname=>"features",name=>"Jalview Features",extensions=>["features","jvfeatures"]},
39 annotations => {shortname=>"annotations",name=>"Jalview Annotations",extensions=>["annotations","jvannotations"]},
40 mmcif2 => {shortname=>"mmcif2",name=>"mmCIF",extensions=>["mcif","mmcif"]},
41 jvl => {shortname=>"jvl",name=>"Jalview Version Locator",extensions=>["jvl"],iconfile=>"Jalview-Version-Locator"},
42 jnet => {shortname=>"jnet",name=>"JnetFile",extensions=>["concise","jnet"]},
43 scorematrix => {shortname=>"scorematrix",name=>"Substitution Matrix",extensions=>["mat"]},
45 my $add_extensions = {
48 my @put_first = qw(jalview jvl);
50 my $v = ($i4jversion >= 8)?$i4jversion:"";
51 my $i4jtemplatefile = "file_associations_template-install4j${v}.xml";
53 open(IT,"<$i4jtemplatefile") or dir("Could not open '$i4jtemplatefile' for reading");
60 my $i4jautofile = $i4jtemplatefile;
61 $i4jautofile =~ s/template/auto$1/;
63 open(IA,">$i4jautofile") or die ("Could not open '$i4jautofile' for writing");
65 open(IN, "<$fileformats") or die ("Could not open '$fileformats' for reading");
67 my $file_associations = {};
68 while(my $line = <IN>) {
70 $line =~ s/(^ | $)//g;
71 if ($line =~ m/^(\w+) ?\( ?"([^"]*)" ?, ?"([^"]*)" ?, ?(true|false) ?, ?(true|false) ?\)$/i) {
72 my $shortname = lc($1);
73 next if (grep($_ eq $shortname, @dontaddshortname));
76 $extensions =~ s/\s+//g;
77 my @possextensions = split(m/,/,$extensions);
79 my $addext = $add_extensions->{$shortname};
80 if (ref($addext) eq "ARRAY") {
81 push(@possextensions, @$addext);
83 for my $possext (@possextensions) {
84 next if grep($_ eq $possext, @extensions);
85 next if grep($_ eq $possext, @dontaddextension);
86 push(@extensions,$possext);
88 next unless scalar(@extensions);
89 $file_associations->{$shortname} = {
90 shortname => $shortname,
92 extensions => \@extensions
94 warn("Adding file association for $shortname\n");
99 my %all_associations = (%$file_associations, %$add_associations);
101 for my $shortname (@put_first, sort keys %all_associations) {
102 my $a = $all_associations{$shortname};
103 if (ref($a) ne "HASH") {
107 my $name = $a->{name};
108 my $extensions = $a->{extensions};
109 my $mimetype = $mimetypes->{$shortname};
110 $mimetype = "text/x-$shortname" unless $mimetype;
112 my $iconfile = $a->{iconfile};
113 $iconfile = "Jalview-File" unless $iconfile;
115 my @extensions = @$extensions;
116 #warn("LINE: $line\nFound extensions '".join("', '", @extensions)."' for $name Files ($shortname)'n");
118 my $i4jentry = $i4jtemplate;
120 $i4jentry =~ s/\$\$NAME\$\$/$name/g;
121 $i4jentry =~ s/\$\$SHORTNAME\$\$/$shortname/g;
122 $i4jentry =~ s/\$\$MIMETYPE\$\$/$mimetype/g;
123 $i4jentry =~ s/\$\$ICONFILE\$\$/$iconfile/g;
125 for my $ext (@extensions) {
126 my $i4jextentry = $i4jentry;
127 $i4jextentry =~ s/\$\$EXTENSION\$\$/$ext/g;
128 $i4jextentry =~ s/\$\$ID\$\$/$id/g;
131 print IA $i4jextentry;
134 delete $all_associations{$shortname};