Description
Attempts to parse a string to an address. The parser is not perfect and works best on US addresses. Most likely other address formats can be parsed with the USAddressParser class by providing different constraints in the builder. This method is here for convenience in working with US addresses.
Parameters
- address The address to be parsed.
Return Values
Returns the parsed address, as a Address object.
Change Log
Version |
Description |
6.0.59a |
Available for professional and enterprise editions. |
import com.screenscraper.util.parsing.address.Address;
String addressRaw = // some address
DataRecord dr = new DataRecord();
try
{
Address address = sutil.parseUSAddress( addressRaw );
log.debug( "Street: " + address.getStreet() );
log.debug( "Suite or Apartment: " + address.getSuiteOrApartment() );
log.debug( "City: " + address.getCity() );
log.debug( "State: " + address.getState() );
log.debug( "Zip: " + address.getZipCode() );
// if all of these four are blank then save only the raw address
// else save what we can
if(
sutil.isNullOrEmptyString( address.getStreet() )
&&
sutil.isNullOrEmptyString( address.getState() )
&&
sutil.isNullOrEmptyString( address.getCity() )
&&
sutil.isNullOrEmptyString( address.getZipCode() )
)
{
dr.put( "ADDRESS", addressRaw );
}
else
{
dr.put( "ADDRESS", address.getStreet() );
dr.put( "ADDRESS2", address.getSuiteOrApartment() );
dr.put( "STATE", address.getState() );
dr.put( "CITY", address.getCity() );
dr.put( "ZIP", address.getZipCode() );
}
session.setv( "DR_ADDRESS", dr );
}
catch( Exception e )
{
// If there was a parsing error, notify so it can be dealt with
log.warn( "Exception parsing address: " + e.getMessage() );
}