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
|
#! /usr/bin/perl -w
# Written by Dirk Stöcker <openstreetmap@dstoecker.de>
# Public domain, no rights reserved.
use strict;
use LWP::Simple;
use encoding 'utf8';
my $item;
my $comment = 0;
# This is a simple conversion and in no way a complete XML parser
# but it works with a default Perl installation
# Print a header to write valid Java code. No line break,
# so that the input and output line numbers will match.
print "class trans_wms { void tr(String s){} void f() {";
my @lines;
if($ARGV[0] && $ARGV[0] =~ /^http:\/\//)
{
my $content = get($ARGV[0]);
die "Couldn't get $ARGV[0]" unless defined $content;
@lines = split("\r?\n", $content);
}
else
{
@lines = <>;
}
for my $line (@lines)
{
$line =~ s/\r//g;
chomp($line);
print "tr(\"\"); ";
if($line =~ /<name>(.*)<\/name>/)
{
my $val = $1;
$val =~ s/&/&/g;
print "tr(\"$val\"); /* $line */\n";
}
elsif($line =~ /^[ \t]*$/)
{
print "\n";
}
elsif($line =~ /<entry>/) # required or the gettext info texts get too large
{
print "public newEntry() {};\n";
}
else
{
print "/* $line */\n";
}
}
print "}}\n";
|