java equivalent of perl module Locale::SubCountry?

V

vturner

Perl has a nice module that converts state province codes for various
countries between a three-char code and the fully expanded name. For
example, Australia (country code "AU") is composed of several states or
provinces, kind of like states in the US. Two of the provinces are "QLD"
for "Queensland" and "NSW" for "New South Wales". I need something that
can take an input of "Queensland" and return "QLD" and vice-versa.

I'm working on a java interface to USPS's online shipping tool and they
expect a country code of "AU" and a State code of "QLD". However, the
person entering the information on the web site may choose to put in
"Australia" and "Queensland" for the country and state/province code,
respectively. I can probably use java.util.locale to go back and forth
between "AU" and "Australia", but I can't find an equivalent way to go back
and forth between "Queenslands" and "QLD".

Does any one know of a Java class/package like this?

some documentation on the perl module is described here:

http://www.cpan.org/modules/by-module/Locale/Locale-SubCountry-1.34.readme
 
S

Sudsy

vturner wrote:
Does any one know of a Java class/package like this?

I don't, but you could always pull down the ISO codes and write
something which uses a HashMap or similar construct to achieve
your goal.
 
V

vturner

Sudsy said:
vturner wrote:


I don't, but you could always pull down the ISO codes and write
something which uses a HashMap or similar construct to achieve
your goal.
Yeah, but the whole idea is to avoid having to reinvent the wheel. It's one
thing to maintain a mapping between 100 or so country codes and their
respective names, and another thing to keep track of all the province codes
within each country. There's multiple provinces in each Country and most
of them are pretty esoteric -- it would be very difficult to know if you've
caught everything.

I think what I might end up doing is just calling, from a Java program, a
perl script that invokes the perl module (using Runtime.exec() ) and just
pass back the info either via file or InputStream.
 
P

Paul Lutus

vturner said:
Yeah, but the whole idea is to avoid having to reinvent the wheel. It's
one thing to maintain a mapping between 100 or so country codes and their
respective names, and another thing to keep track of all the province
codes
within each country. There's multiple provinces in each Country and most
of them are pretty esoteric -- it would be very difficult to know if
you've caught everything.

So use the Perl database, dump its contents and create a Java version with
the same information.
I think what I might end up doing is just calling, from a Java program, a
perl script that invokes the perl module (using Runtime.exec() ) and just
pass back the info either via file or InputStream.

There really is no need for something like this. You may be able to read the
Perl files directly and glean the required information, and create a Java
class to handle this issue.
 
V

vturner

Paul said:
So use the Perl database, dump its contents and create a Java version with
the same information.


There really is no need for something like this. You may be able to read
the Perl files directly and glean the required information, and create a
Java class to handle this issue.
You know, that's not a bad idea. I don't know why I didn't think of that.
Just lazy, I guess. I looked at the perl module and it has XML entries
like:

<country>
<name>AUSTRALIA</name>
<code>AU</code>
<subcountry>
<name>New South Wales</name>
<code>NSW</code>
<category>state</category>
<FIPS>02</FIPS>
</subcountry>
<subcountry>
<name>Queensland</name>
<code>QLD</code>
<category>state</category>
<FIPS>04</FIPS>
</subcountry>
....
</country>

Seems kind of like a waste to do it and not share it though. Is there a
place like CPAN for Java where you can share code?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,048
Latest member
verona

Latest Threads

Top