-
Notifications
You must be signed in to change notification settings - Fork 16
Usage ImmobiliareIT
The class org.openestate.io.immobiliare_it.ImmobiliareItUtils
provides a
static createDocument()
function to read XML data in immobiliare.it format
from a java.io.File
, java.io.InputStream
, java.lang.String
or
org.w3c.dom.Document
into a
org.openestate.io.immobiliare_it.ImmobiliareItDocument
.
import java.io.File;
import org.apache.commons.lang3.StringUtils;
import org.openestate.io.immobiliare_it.ImmobiliareItDocument;
import org.openestate.io.immobiliare_it.ImmobiliareItUtils;
import org.openestate.io.immobiliare_it.xml.Feed;
import org.openestate.io.immobiliare_it.xml.Feed.Properties.Property;
public static void main( String[] args )
{
if (args.length<1)
{
System.err.println( "No file was specified!" );
System.exit( 1 );
}
// read file into a ImmobiliareItDocument
ImmobiliareItDocument doc = ImmobiliareItUtils.createDocument( new File( args[0] ) );
// convert ImmobiliareItDocument into a Java object
Feed feed = doc.toObject();
// now we can access the XML content through ordinary Java objects
if (feed.getProperties()!=null)
{
for (Property object : feed.getProperties().getProperty())
{
// get object nr
String objectNr = StringUtils.trimToNull( object.getUniqueId() );
if (objectNr==null) objectNr = "???";
// get object description
String objectInfo = (object.getFeatures()!=null && !object.getFeatures().getDescription().isEmpty())?
StringUtils.trimToNull( object.getFeatures().getDescription().get( 0 ).getValue() ): null;
if (objectInfo==null) objectInfo = "???";
// print object informations to console
System.out.println( "> found object "
+ "'" + objectNr + "': " + objectInfo );
}
}
}
See a full example at ImmobiliareItReadingExample.java
.
The class org.openestate.io.immobiliare_it.xml.Feed
is equivalent to a
<feed>
root element in a immobiliare.it document. For example the following
code creates a immobiliare.it document programmatically:
import java.util.Calendar;
import java.util.Currency;
import org.apache.commons.lang3.RandomStringUtils;
import org.apache.commons.lang3.RandomUtils;
import org.apache.commons.lang3.StringUtils;
import org.openestate.io.immobiliare_it.ImmobiliareItDocument;
import org.openestate.io.immobiliare_it.ImmobiliareItUtils;
import org.openestate.io.immobiliare_it.xml.Box;
import org.openestate.io.immobiliare_it.xml.BusinessElement;
import org.openestate.io.immobiliare_it.xml.ClassEnergy;
import org.openestate.io.immobiliare_it.xml.Clazz;
import org.openestate.io.immobiliare_it.xml.Feed;
import org.openestate.io.immobiliare_it.xml.Feed.Properties.Property;
import org.openestate.io.immobiliare_it.xml.Floor;
import org.openestate.io.immobiliare_it.xml.Furniture;
import org.openestate.io.immobiliare_it.xml.Garden;
import org.openestate.io.immobiliare_it.xml.Heat;
import org.openestate.io.immobiliare_it.xml.Kitchen;
import org.openestate.io.immobiliare_it.xml.LocationStructure.Locality.Neighbourhood.LocationNeighbourhoodType;
import org.openestate.io.immobiliare_it.xml.Operation;
import org.openestate.io.immobiliare_it.xml.OwnershipType;
import org.openestate.io.immobiliare_it.xml.PictureExtended;
import org.openestate.io.immobiliare_it.xml.PictureProject;
import org.openestate.io.immobiliare_it.xml.PropertyType;
import org.openestate.io.immobiliare_it.xml.PropertyTypeBusiness;
import org.openestate.io.immobiliare_it.xml.PropertyTypeSimple;
import org.openestate.io.immobiliare_it.xml.Rental;
import org.openestate.io.immobiliare_it.xml.Status;
import org.openestate.io.immobiliare_it.xml.TerrainType;
import org.openestate.io.immobiliare_it.xml.VideoProject;
import org.openestate.io.immobiliare_it.xml.VideoType;
import org.openestate.io.immobiliare_it.xml.YesNoReady;
import org.openestate.io.immobiliare_it.xml.types.Category;
import org.openestate.io.immobiliare_it.xml.types.EnergyUnit;
import org.openestate.io.immobiliare_it.xml.types.LandSizeUnit;
import org.openestate.io.immobiliare_it.xml.types.SizeUnit;
public static void main( String[] args )
{
// create a Feed object with some example data
// this object corresponds to the <feed> root element in XML
Feed feed = ImmobiliareItUtils.getFactory().createFeed();
// append some example objects to the Feed object
feed.setProperties( ImmobiliareItUtils.getFactory().createFeedProperties() );
feed.getProperties().getProperty().add( createProperty() );
feed.getProperties().getProperty().add( createProperty() );
// now make something useful with the object
}
protected static Property createProperty()
{
// create an example real estate for rent
Property obj = ImmobiliareItUtils.getFactory().createFeedPropertiesProperty();
obj.setBuildingStatus( Status.ABITABILE );
obj.setCategory( Category.COMMERCIALE );
obj.setDateExpiration( Calendar.getInstance() );
obj.setDateUpdated( Calendar.getInstance() );
obj.setOperation( Operation.WRITE );
obj.setUniqueId( RandomStringUtils.randomAlphanumeric( 5 ) );
obj.setAgent( ImmobiliareItUtils.getFactory().createFeedPropertiesPropertyAgent() );
obj.getAgent().setEmail( "[email protected]" );
obj.getAgent().setOfficeName( "agency name" );
obj.setBlueprints( ImmobiliareItUtils.getFactory().createFeedPropertiesPropertyBlueprints() );
obj.getBlueprints().getBlueprint().add( createPictureExtended() );
obj.getBlueprints().getBlueprint().add( createPictureExtended() );
obj.getBlueprints().getBlueprint().add( createPictureExtended() );
obj.setBuilding( ImmobiliareItUtils.getFactory().createBuilding() );
obj.getBuilding().setCategory( Category.COMMERCIALE );
obj.getBuilding().setClazz( Clazz.SIGNORILE);
obj.getBuilding().setDetail( PropertyTypeBusiness.ALBERGO);
obj.getBuilding().setStatus( Status.DISCRETO );
obj.getBuilding().setType( PropertyType.BUNGALOW);
obj.setExtraFeatures( ImmobiliareItUtils.getFactory().createFeedPropertiesPropertyExtraFeatures() );
obj.getExtraFeatures().setAirConditioning( RandomUtils.nextInt( 0, 2 )==1 );
obj.getExtraFeatures().setBalcony( RandomUtils.nextInt( 0, 2 )==1);
obj.getExtraFeatures().setBathrooms( RandomUtils.nextLong( 1, 5 ) );
obj.getExtraFeatures().setBeamHeight( RandomUtils.nextLong( 1, 10 ) );
obj.getExtraFeatures().setBedrooms( RandomUtils.nextLong( 1, 5 ) );
obj.getExtraFeatures().setBuildYear( RandomUtils.nextInt( 1900, 2000 ) );
obj.getExtraFeatures().setDocDescription( "some descriptions" );
obj.getExtraFeatures().setDocSpecification( "some specifications" );
obj.getExtraFeatures().setElevator( RandomUtils.nextInt( 0, 2 )==1 );
obj.getExtraFeatures().setFloorplannerUrl( "http://floorplanner-url.it/" );
obj.getExtraFeatures().setFreeConditions( "free conditions" );
obj.getExtraFeatures().setFurniture( Furniture.PARZIALMENTE_ARREDATO );
obj.getExtraFeatures().setGarden( Garden.NESSUNO );
obj.getExtraFeatures().setHeating( Heat.AUTONOMO );
obj.getExtraFeatures().setKitchen( Kitchen.SEMI_ABITABILE );
obj.getExtraFeatures().setNet( RandomUtils.nextInt( 0, 2 )==1 );
obj.getExtraFeatures().setNumFloors( RandomUtils.nextLong( 1, 5 ) );
obj.getExtraFeatures().setOverheadCrane( YesNoReady.READY );
obj.getExtraFeatures().setReception( RandomUtils.nextInt( 0, 2 )==1 );
obj.getExtraFeatures().setRentContract( Rental.LIBERO );
obj.getExtraFeatures().setSecurityAlarm( RandomUtils.nextInt( 0, 2 )==1 );
obj.getExtraFeatures().setTerrace( RandomUtils.nextInt( 0, 2 )==1 );
obj.getExtraFeatures().setVirtualTour( "virtual tour" );
obj.getExtraFeatures().setAdditionalCosts( ImmobiliareItUtils.getFactory().createAdditionalCostsType() );
obj.getExtraFeatures().getAdditionalCosts().setCurrency( Currency.getInstance( "EUR" ) );
obj.getExtraFeatures().getAdditionalCosts().setValue( RandomUtils.nextLong( 0, 5000 ) );
obj.getExtraFeatures().setExternalArea( ImmobiliareItUtils.getFactory().createLandSizeType() );
obj.getExtraFeatures().getExternalArea().setUnit( LandSizeUnit.M2 );
obj.getExtraFeatures().getExternalArea().setValue( RandomUtils.nextLong( 50, 5000 ) );
obj.getExtraFeatures().setFloor( ImmobiliareItUtils.getFactory().createFloor() );
obj.getExtraFeatures().getFloor().setType( Floor.FloorType.INTERMEDIO );
obj.getExtraFeatures().getFloor().setValue( RandomUtils.nextLong( 0, 10 ) );
obj.getExtraFeatures().setGarage( ImmobiliareItUtils.getFactory().createBox() );
obj.getExtraFeatures().getGarage().setType( Box.BoxType.POSTO_AUTO );
obj.getExtraFeatures().getGarage().setValue( RandomUtils.nextLong( 0, 10 ) );
obj.getExtraFeatures().setOfficeSize( ImmobiliareItUtils.getFactory().createSizeType() );
obj.getExtraFeatures().getOfficeSize().setUnit( SizeUnit.M2 );
obj.getExtraFeatures().getOfficeSize().setValue( RandomUtils.nextLong( 5, 50 ) );
obj.setFeatures( ImmobiliareItUtils.getFactory().createFeedPropertiesPropertyFeatures() );
obj.getFeatures().setEnergyClass( ClassEnergy.D );
obj.getFeatures().setRooms( RandomUtils.nextInt( 1, 5 ) );
obj.getFeatures().setEnergyPerformance( ImmobiliareItUtils.getFactory().createClassEnergyPerformance() );
obj.getFeatures().getEnergyPerformance().setCertified( RandomUtils.nextInt( 0, 2 )==1 );
obj.getFeatures().getEnergyPerformance().setUnit( EnergyUnit.KWH_M2ANNO );
obj.getFeatures().getEnergyPerformance().setValue( "energy performance" );
obj.getFeatures().setPrice( ImmobiliareItUtils.getFactory().createPriceType() );
obj.getFeatures().getPrice().setCurrency( Currency.getInstance( "EUR" ) );
obj.getFeatures().getPrice().setReserved( RandomUtils.nextInt( 0, 2 )==1 );
obj.getFeatures().getPrice().setValue( RandomUtils.nextLong( 500, 5000000 ) );
obj.getFeatures().setSize( ImmobiliareItUtils.getFactory().createSizeType() );
obj.getFeatures().getSize().setUnit( SizeUnit.M2 );
obj.getFeatures().getSize().setValue( RandomUtils.nextLong( 50, 5000 ) );
obj.setLocation( ImmobiliareItUtils.getFactory().createLocationStructure() );
obj.getLocation().setAdministrativeArea( "administrative area" );
obj.getLocation().setCountryCode( "DE" );
obj.getLocation().setCity( ImmobiliareItUtils.getFactory().createLocationStructureCity() );
obj.getLocation().getCity().setCode( 0L );
obj.getLocation().getCity().setValue( "Berlin" );
obj.getLocation().setLocality( ImmobiliareItUtils.getFactory().createLocationStructureLocality() );
obj.getLocation().getLocality().setLatitude( RandomUtils.nextDouble( 0, 90 ) );
obj.getLocation().getLocality().setLongitude( RandomUtils.nextDouble( 0, 90 ) );
obj.getLocation().getLocality().setPostalCode( "13125" );
obj.getLocation().getLocality().setNeighbourhood( ImmobiliareItUtils.getFactory().createLocationStructureLocalityNeighbourhood() );
obj.getLocation().getLocality().getNeighbourhood().setId( 0L );
obj.getLocation().getLocality().getNeighbourhood().setType( LocationNeighbourhoodType.DISTRICT );
obj.getLocation().getLocality().getNeighbourhood().setValue( "about the neighbourhood" );
obj.getLocation().getLocality().setThoroughfare( ImmobiliareItUtils.getFactory().createLocationStructureLocalityThoroughfare() );
obj.getLocation().getLocality().getThoroughfare().setDisplay( RandomUtils.nextInt( 0, 2 )==1 );
obj.getLocation().getLocality().getThoroughfare().setValue( "about thoroughfare" );
obj.getLocation().setSubAdministrativeArea( ImmobiliareItUtils.getFactory().createLocationStructureSubAdministrativeArea() );
obj.getLocation().getSubAdministrativeArea().setCode( RandomStringUtils.randomAlphanumeric( 5 ) );
obj.getLocation().getSubAdministrativeArea().setValue( "Berlin" );
obj.setPictures( ImmobiliareItUtils.getFactory().createFeedPropertiesPropertyPictures() );
obj.getPictures().getPictureUrlAndPicture().add( createPicture() );
obj.getPictures().getPictureUrlAndPicture().add( createPicture() );
obj.getPictures().getPictureUrlAndPicture().add( createPicture() );
obj.setPropertyType( ImmobiliareItUtils.getFactory().createProptype() );
obj.getPropertyType().setBusinessType( ImmobiliareItUtils.getFactory().createBusinessElement() );
obj.getPropertyType().getBusinessType().setCategory( BusinessElement.BusinessElementCategory.IMMOBILE );
obj.getPropertyType().getBusinessType().setValue( PropertyTypeBusiness.ALTRO );
obj.getPropertyType().setTerrains( ImmobiliareItUtils.getFactory().createTerrains() );
obj.getPropertyType().getTerrains().getTerrain().add( TerrainType.SEMINATIVO );
obj.getPropertyType().setType( PropertyTypeSimple.CASA_INDIPENDENTE );
obj.setTransactionType( ImmobiliareItUtils.getFactory().createTransactionType() );
obj.getTransactionType().setAuction( RandomUtils.nextInt( 0, 2 )==1 );
obj.getTransactionType().setOwnership( OwnershipType.PARZIALE );
obj.getTransactionType().setValue( "notes about transaction" );
obj.setVideos( ImmobiliareItUtils.getFactory().createFeedPropertiesPropertyVideos() );
obj.getVideos().getVideo().add( createVideo() );
obj.getVideos().getVideo().add( createVideo() );
return obj;
}
protected static PictureProject createPicture()
{
PictureProject pic = ImmobiliareItUtils.getFactory().createPictureProject();
pic.setPosition( RandomUtils.nextLong( 0, 100 ) );
pic.setValue( "image-" + RandomUtils.nextInt( 0, 999 ) + ".jpg" );
return pic;
}
protected static PictureExtended createPictureExtended()
{
PictureExtended pic = ImmobiliareItUtils.getFactory().createPictureExtended();
pic.setPosition( RandomUtils.nextLong( 0, 100 ) );
pic.setValue( "image-" + RandomUtils.nextInt( 0, 999 ) + ".jpg" );
pic.setUrl( "http://mywebsite.org/" + pic.getValue() );
return pic;
}
protected static VideoProject createVideo()
{
VideoProject video = ImmobiliareItUtils.getFactory().createVideoProject();
video.setType( VideoType.LOCAL );
video.setValue( "video-" + RandomUtils.nextInt( 0, 999 ) + ".mp4" );
return video;
}
See a full example at ImmobiliareItWritingExample.java
.
After a org.openestate.io.immobiliare_it.xml.Feed
object was created, it can
be converted into a org.openestate.io.immobiliare_it.ImmobiliareItDocument
with the static newDocument()
function.
The class org.openestate.io.immobiliare_it.ImmobiliareItDocument
provides a
toXml()
function, that finally writes the contents of the Feed
object as XML
into a java.io.File
, java.io.OutputStream
or java.io.Writer
.
import java.io.File;
import org.openestate.io.immobiliare_it.ImmobiliareItDocument;
import org.openestate.io.immobiliare_it.xml.Feed;
protected static void write( Feed feed, File file )
{
try
{
ImmobiliareItDocument doc = ImmobiliareItDocument.newDocument( feed );
doc.toXml( file );
}
catch (Exception ex)
{
System.err.println( "Can't write document into a file!" );
System.err.println( "> " + ex.getLocalizedMessage(), ex );
System.exit( 1 );
}
}
See a full example at ImmobiliareItWritingExample.java
.