-
Notifications
You must be signed in to change notification settings - Fork 16
Usage IS24 XML
The class org.openestate.io.is24_xml.Is24XmlUtils
provides a static createDocument()
function to read XML data in IS24-XML format from a java.io.File
, java.io.InputStream
, java.lang.String
or org.w3c.dom.Document
into a org.openestate.io.is24_xml.Is24XmlDocument
.
import java.io.File;
import javax.xml.bind.JAXBElement;
import org.openestate.io.is24_xml.Is24XmlDocument;
import org.openestate.io.is24_xml.Is24XmlUtils;
import org.openestate.io.is24_xml.xml.ImmobilieBaseTyp;
import org.openestate.io.is24_xml.xml.ImmobilienTransferTyp;
import org.openestate.io.is24_xml.xml.VirtuelleImmobilieBaseTyp;
public class Is24XmlReadingExample {
public static void main(String[] args) throws Exception {
if (args.length < 1) {
System.err.println("No file was specified!");
System.exit(1);
}
// read file into a Is24XmlDocument
Is24XmlDocument doc = Is24XmlUtils.createDocument(new File(args[0]));
// convert Is24XmlDocument into a Java object
ImmobilienTransferTyp transfer = doc.toObject();
// now we can access the XML content through ordinary Java objects
if (transfer.getAnbieter() != null) {
// process objects
for (JAXBElement<? extends ImmobilieBaseTyp> i : transfer.getAnbieter().getImmobilie()) {
ImmobilieBaseTyp obj = i.getValue();
// get object nr
String objectNr = obj.getAnbieterObjektID();
// get object title
String objectTitle = obj.getUeberschrift();
// print object information to console
System.out.println("found object " +
"'" + objectNr + "': " + objectTitle);
}
// process virtual objects
for (JAXBElement<? extends VirtuelleImmobilieBaseTyp> i : transfer.getAnbieter().getVirtuelleImmobilie()) {
VirtuelleImmobilieBaseTyp obj = i.getValue();
// get object nr
String objectNr = obj.getAnbieterObjektID();
// get object title
String objectTitle = obj.getUeberschrift();
// print object information to console
System.out.println("found virtual object " +
"'" + objectNr + "': " + objectTitle);
}
}
}
}
See a full example at Is24XmlReadingExample.java
.
The class org.openestate.io.is24_xml.xml.ImmobilienTransferTyp
is equivalent to a <IS24ImmobilienTransfer>
root element in a IS24-XML document. For example the following code creates a IS24-XML document programmatically:
import com.thedeanda.lorem.Lorem;
import com.thedeanda.lorem.LoremIpsum;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.net.URI;
import org.apache.commons.lang3.RandomStringUtils;
import org.apache.commons.lang3.RandomUtils;
import org.openestate.io.is24_xml.Is24XmlUtils;
import org.openestate.io.is24_xml.xml.AktionsTyp;
import org.openestate.io.is24_xml.xml.AusstattungsqualitaetsTyp;
import org.openestate.io.is24_xml.xml.BauphaseTyp;
import org.openestate.io.is24_xml.xml.EnergieausweistypTyp;
import org.openestate.io.is24_xml.xml.GenehmigungTyp;
import org.openestate.io.is24_xml.xml.HausKategorienTyp;
import org.openestate.io.is24_xml.xml.HausKauf;
import org.openestate.io.is24_xml.xml.HausMiete;
import org.openestate.io.is24_xml.xml.HeizungsartTyp;
import org.openestate.io.is24_xml.xml.ISOLaenderCodeTyp;
import org.openestate.io.is24_xml.xml.ImmobilieBaseTyp;
import org.openestate.io.is24_xml.xml.ImmobilienTransferTyp;
import org.openestate.io.is24_xml.xml.MMAnhangArtenTyp;
import org.openestate.io.is24_xml.xml.MultimediaAnhangTyp;
import org.openestate.io.is24_xml.xml.ObjectFactory;
import org.openestate.io.is24_xml.xml.ObjektZustandTyp;
import org.openestate.io.is24_xml.xml.StatusTyp;
import org.openestate.io.is24_xml.xml.StellplatzKategorieTyp;
import org.openestate.io.is24_xml.xml.WaehrungTyp;
public class Is24XmlWritingExample {
private final static ObjectFactory FACTORY = Is24XmlUtils.getFactory();
private final static Lorem RANDOMIZER = new LoremIpsum();
public static void main(String[] args) {
// create a ImmobilienTransferTyp object with some example data
// this object corresponds to the <IS24ImmobilienTransfer> root element in XML
ImmobilienTransferTyp transfer = FACTORY.createImmobilienTransferTyp();
transfer.setEmailBeiFehler(RANDOMIZER.getEmail());
transfer.setErstellerSoftware(RANDOMIZER.getName());
transfer.setErstellerSoftwareVersion(RandomStringUtils.randomNumeric(2));
transfer.setAnbieter(createAnbieter());
// now make something useful with the object
}
/**
* Create an {@link ImmobilienTransferTyp.Anbieter} with some example data.
*
* @return created example object
*/
private static ImmobilienTransferTyp.Anbieter createAnbieter() {
// create an example agency
ImmobilienTransferTyp.Anbieter anbieter = FACTORY.createImmobilienTransferTypAnbieter();
anbieter.setScoutKundenID(RandomStringUtils.randomAlphanumeric(2, 5));
// add some real estates to the agency
int hausKaufCount = RandomUtils.nextInt(1, 5);
for (int i = 0; i < hausKaufCount; i++) {
anbieter.getImmobilie().add(createImmobilieHausKauf());
}
int hausMieteCount = RandomUtils.nextInt(1, 5);
for (int i = 0; i < hausMieteCount; i++) {
anbieter.getImmobilie().add(createImmobilieHausMiete());
}
return anbieter;
}
/**
* Create an {@link HausKauf} with some example data.
*
* @return created example object
*/
private static HausKauf createImmobilieHausKauf() {
// create an example real estate
HausKauf.Type obj = FACTORY.createHausKaufType();
initImmobilie(obj);
obj.setAlsFerienwohnungGeeignet(RandomUtils.nextBoolean());
obj.setAnzahlBadezimmer(RandomUtils.nextLong(1, 5));
obj.setAnzahlGaragenStellplaetze(RandomUtils.nextLong(0, 3));
obj.setAnzahlSchlafzimmer(RandomUtils.nextLong(1, 5));
obj.setAusstattungsqualitaet(randomValue(AusstattungsqualitaetsTyp.values()));
obj.setBarrierefrei(RandomUtils.nextBoolean());
obj.setBaujahr(RandomUtils.nextLong(1900, 2010));
obj.setBauphase(randomValue(BauphaseTyp.values()));
obj.setDenkmalschutzobjekt(RandomUtils.nextBoolean());
obj.setEtagenzahl(RandomUtils.nextLong(1, 10));
obj.setFreiAb(RANDOMIZER.getWords(3, 10));
obj.setGaesteWC(RandomUtils.nextBoolean());
obj.setGrundstuecksFlaeche(BigDecimal.valueOf(RandomUtils.nextDouble(100, 1500)));
obj.setHausKategorie(randomValue(HausKategorienTyp.values()));
obj.setHeizungsart(randomValue(HeizungsartTyp.values()));
obj.setJahrLetzteModernisierung(RandomUtils.nextLong(1980, 2000));
obj.setKeller(RandomUtils.nextBoolean());
obj.setMitEinliegerwohnung(RandomUtils.nextBoolean());
obj.setNutzflaeche(BigDecimal.valueOf(RandomUtils.nextDouble(100, 1000)));
obj.setObjektzustand(randomValue(ObjektZustandTyp.values()));
obj.setParkplatz(randomValue(StellplatzKategorieTyp.values()));
obj.setRollstuhlgerecht(RandomUtils.nextBoolean());
obj.setVermietet(RandomUtils.nextBoolean());
obj.setWohnflaeche(BigDecimal.valueOf(RandomUtils.nextDouble(50, 500)));
obj.setZimmer(BigDecimal.valueOf(RandomUtils.nextDouble(1, 10)));
obj.setBefeuerungsArt(FACTORY.createBefeuerungsArtTyp());
obj.getBefeuerungsArt().setOel(
FACTORY.createBefeuerungsArtTypOel(RandomUtils.nextBoolean()));
obj.getBefeuerungsArt().setGas(
FACTORY.createBefeuerungsArtTypGas(RandomUtils.nextBoolean()));
obj.setEnergieausweis(FACTORY.createEnergieausweisTyp());
obj.getEnergieausweis().setEnergieausweistyp(randomValue(EnergieausweistypTyp.values()));
obj.getEnergieausweis().setEnergieverbrauchskennwert(BigDecimal.valueOf(RandomUtils.nextDouble(50, 500)));
obj.getEnergieausweis().setWarmwasserEnthalten(RandomUtils.nextBoolean());
obj.setKaufpreise(FACTORY.createVermarktungWohnKaufTyp());
obj.getKaufpreise().setKaufpreis(BigDecimal.valueOf(RandomUtils.nextDouble(100000, 9999999)));
obj.getKaufpreise().setMieteinnahmenProMonat(BigDecimal.valueOf(RandomUtils.nextDouble(5000, 50000)));
obj.getKaufpreise().setStellplatzKaufpreis(BigDecimal.valueOf(RandomUtils.nextDouble(1000, 10000)));
obj.getKaufpreise().setWohngeld(BigDecimal.valueOf(RandomUtils.nextDouble(500, 5000)));
return FACTORY.createHausKauf(obj);
}
/**
* Create an {@link HausMiete} with some example data.
*
* @return created example object
*/
private static HausMiete createImmobilieHausMiete() {
// create an example real estate
HausMiete.Type obj = FACTORY.createHausMieteType();
initImmobilie(obj);
obj.setAnzahlBadezimmer(RandomUtils.nextLong(1, 5));
obj.setAnzahlGaragenStellplaetze(RandomUtils.nextLong(0, 3));
obj.setAnzahlSchlafzimmer(RandomUtils.nextLong(1, 5));
obj.setAusstattungsqualitaet(randomValue(AusstattungsqualitaetsTyp.values()));
obj.setBarrierefrei(RandomUtils.nextBoolean());
obj.setBaujahr(RandomUtils.nextLong(1900, 2010));
obj.setBetreutesWohnen(RandomUtils.nextBoolean());
obj.setEinbaukueche(RandomUtils.nextBoolean());
obj.setEtagenzahl(RandomUtils.nextLong(1, 10));
obj.setFreiAb(RANDOMIZER.getWords(3, 10));
obj.setGaesteWC(RandomUtils.nextBoolean());
obj.setGrundstuecksFlaeche(BigDecimal.valueOf(RandomUtils.nextDouble(100, 1500)));
obj.setHausKategorie(randomValue(HausKategorienTyp.values()));
obj.setHaustiere(randomValue(GenehmigungTyp.values()));
obj.setHeizungsart(randomValue(HeizungsartTyp.values()));
obj.setJahrLetzteModernisierung(RandomUtils.nextLong(1980, 2000));
obj.setKeller(RandomUtils.nextBoolean());
obj.setNutzflaeche(BigDecimal.valueOf(RandomUtils.nextDouble(150, 500)));
obj.setObjektzustand(randomValue(ObjektZustandTyp.values()));
obj.setParkplatz(randomValue(StellplatzKategorieTyp.values()));
obj.setRollstuhlgerecht(RandomUtils.nextBoolean());
obj.setWohnflaeche(BigDecimal.valueOf(RandomUtils.nextDouble(50, 300)));
obj.setZimmer(BigDecimal.valueOf(RandomUtils.nextDouble(1, 5)));
obj.setBefeuerungsArt(FACTORY.createBefeuerungsArtTyp());
obj.getBefeuerungsArt().setErdwaerme(
FACTORY.createBefeuerungsArtTypErdwaerme(RandomUtils.nextBoolean()));
obj.getBefeuerungsArt().setPelletheizung(
FACTORY.createBefeuerungsArtTypPelletheizung(RandomUtils.nextBoolean()));
obj.setEnergieausweis(FACTORY.createEnergieausweisTyp());
obj.getEnergieausweis().setEnergieausweistyp(randomValue(EnergieausweistypTyp.values()));
obj.getEnergieausweis().setEnergieverbrauchskennwert(BigDecimal.valueOf(RandomUtils.nextDouble(50, 500)));
obj.getEnergieausweis().setWarmwasserEnthalten(RandomUtils.nextBoolean());
obj.setMietpreise(FACTORY.createVermarktungWohnMieteTyp());
obj.getMietpreise().setHeizkosten(BigDecimal.valueOf(RandomUtils.nextDouble(100, 500)));
obj.getMietpreise().setHeizkostenInWarmmieteEnthalten(RandomUtils.nextBoolean());
obj.getMietpreise().setKaltmiete(BigDecimal.valueOf(RandomUtils.nextDouble(150, 1500)));
obj.getMietpreise().setKaution(RANDOMIZER.getWords(3, 10));
obj.getMietpreise().setNebenkosten(BigDecimal.valueOf(RandomUtils.nextDouble(50, 500)));
obj.getMietpreise().setStellplatzMiete(BigDecimal.valueOf(RandomUtils.nextDouble(50, 500)));
obj.getMietpreise().setWarmmiete(BigDecimal.valueOf(RandomUtils.nextDouble(250, 2500)));
return FACTORY.createHausMiete(obj);
}
/**
* Init common values of a property.
*
* @param immobilie property object
*/
private static void initImmobilie(ImmobilieBaseTyp immobilie) {
immobilie.setAdressdruck(RandomUtils.nextBoolean());
immobilie.setAktiveGruppen(RANDOMIZER.getWords(1, 5));
immobilie.setAnbieterObjektID(RandomStringUtils.randomNumeric(2, 5));
immobilie.setAusstattung(RANDOMIZER.getWords(5, 50));
immobilie.setGruppierungsID(RandomUtils.nextLong(1, 9999));
immobilie.setImportmodus(AktionsTyp.AKTUALISIEREN);
immobilie.setLage(RANDOMIZER.getWords(5, 50));
immobilie.setObjektbeschreibung(RANDOMIZER.getWords(5, 50));
immobilie.setProvision(RANDOMIZER.getWords(1, 10));
immobilie.setProvisionshinweis(RANDOMIZER.getWords(5, 50));
immobilie.setProvisionspflichtig(RandomUtils.nextBoolean());
immobilie.setScoutObjektID(BigInteger.valueOf(RandomUtils.nextInt(1, 1000)));
immobilie.setSonstigeAngaben(RANDOMIZER.getWords(5, 50));
immobilie.setStatusHP(randomValue(StatusTyp.values()));
immobilie.setStatusIS24(randomValue(StatusTyp.values()));
immobilie.setStatusVBM(randomValue(StatusTyp.values()));
immobilie.setUeberschrift(RANDOMIZER.getWords(1, 5));
immobilie.setWaehrung(randomValue(WaehrungTyp.values()));
immobilie.setAdresse(FACTORY.createImmobilienAdresseTyp());
immobilie.getAdresse().setHausnummer(RandomStringUtils.randomNumeric(1, 4));
immobilie.getAdresse().setInternationaleRegion(RANDOMIZER.getStateFull());
immobilie.getAdresse().setLaenderkennzeichen(randomValue(ISOLaenderCodeTyp.values()));
immobilie.getAdresse().setOrt(RANDOMIZER.getCity());
immobilie.getAdresse().setPostleitzahl(RANDOMIZER.getZipCode());
immobilie.getAdresse().setStrasse(RANDOMIZER.getWords(1, 5));
immobilie.setApiSuchfelder(FACTORY.createImmobilieBaseTypApiSuchfelder(FACTORY.createApiSuchfelderTyp()));
immobilie.getApiSuchfelder().getValue().setApiSuchfeld1(FACTORY.createApiSuchfelderTypApiSuchfeld1("value1"));
immobilie.getApiSuchfelder().getValue().setApiSuchfeld2(FACTORY.createApiSuchfelderTypApiSuchfeld2("value2"));
immobilie.getApiSuchfelder().getValue().setApiSuchfeld3(FACTORY.createApiSuchfelderTypApiSuchfeld3("value3"));
immobilie.setKontaktperson(FACTORY.createKontaktAdresseTyp());
immobilie.getKontaktperson().setAnrede(RANDOMIZER.getWords(1));
immobilie.getKontaktperson().setEMail(RANDOMIZER.getEmail());
immobilie.getKontaktperson().setHausnummer(RandomStringUtils.randomNumeric(1, 4));
immobilie.getKontaktperson().setLaenderkennzeichen(randomValue(ISOLaenderCodeTyp.values()));
immobilie.getKontaktperson().setMobiltelefon(RANDOMIZER.getPhone());
immobilie.getKontaktperson().setNachname(RANDOMIZER.getLastName());
immobilie.getKontaktperson().setOrt(RANDOMIZER.getCity());
immobilie.getKontaktperson().setPostleitzahl(RANDOMIZER.getZipCode());
immobilie.getKontaktperson().setStrasse(RANDOMIZER.getWords(1, 5));
immobilie.getKontaktperson().setTelefax(RANDOMIZER.getPhone());
immobilie.getKontaktperson().setTelefon(RANDOMIZER.getPhone());
immobilie.getKontaktperson().setVorname(RANDOMIZER.getFirstName());
try {
immobilie.getKontaktperson().setHomepage(new URI("https://www.example.com"));
} catch (Exception ex) {
}
immobilie.setManuelleGeoCodierung(FACTORY.createManuellGeoCodingTyp());
immobilie.getManuelleGeoCodierung().setTermsRegion(RANDOMIZER.getStateFull());
immobilie.getManuelleGeoCodierung().setTermsStadt(RANDOMIZER.getCity());
immobilie.getManuelleGeoCodierung().setTermsStadtTeil(RANDOMIZER.getWords(1, 3));
int attachmentCount = RandomUtils.nextInt(3, 10);
for (int i = 0; i < attachmentCount; i++) {
MultimediaAnhangTyp attachment = FACTORY.createMultimediaAnhangTyp();
attachment.setAnhangArt(randomValue(MMAnhangArtenTyp.values()));
attachment.setDateiname("attachment-" + i + ".jpg");
attachment.setDateityp("jpg");
attachment.setTitel(RANDOMIZER.getWords(2, 10));
immobilie.getMultimediaAnhang().add(attachment);
}
}
/**
* Get a random value from an array.
*
* @param values array containing values to select from
* @param <T> type of contained values
* @return randomly selected value
*/
private static <T> T randomValue(T[] values) {
return (values != null && values.length > 0) ?
values[RandomUtils.nextInt(0, values.length)] :
null;
}
}
See a full example at Is24XmlWritingExample.java
.
After a org.openestate.io.is24_xml.xml.ImmobilienTransferTyp
object was created, it can be converted into a org.openestate.io.is24_xml.Is24XmlDocument
with the static newDocument()
function.
The class org.openestate.io.is24_xml.Is24XmlDocument
provides a toXml()
function, that finally writes the contents of the ImmobilienTransferTyp
object as XML into a java.io.File
, java.io.OutputStream
or java.io.Writer
.
import java.io.File;
import java.io.OutputStream;
import java.io.Writer;
import org.openestate.io.is24_xml.Is24XmlDocument;
import org.openestate.io.is24_xml.xml.ImmobilienTransferTyp;
public class Is24XmlWritingExample {
private final static boolean PRETTY_PRINT = true;
/**
* Convert a {@link ImmobilienTransferTyp} to XML and write it into a {@link File}.
*
* @param transfer Java object representing the XML root element
* @param file the file, where the document is written to
* @throws Exception if the document can't be written
*/
private static void write(ImmobilienTransferTyp transfer, File file) throws Exception {
Is24XmlDocument
.newDocument(transfer)
.toXml(file, PRETTY_PRINT);
}
/**
* Convert a {@link ImmobilienTransferTyp} to XML and write it into an {@link OutputStream}.
*
* @param transfer Java object representing the XML root element
* @param output the stream, where the document is written to
* @throws Exception if the document can't be written
*/
private static void write(ImmobilienTransferTyp transfer, OutputStream output) throws Exception {
Is24XmlDocument
.newDocument(transfer)
.toXml(output, PRETTY_PRINT);
}
/**
* Convert a {@link ImmobilienTransferTyp} to XML and write it into a {@link Writer}.
*
* @param transfer Java object representing the XML root element
* @param output the writer, where the document is written to
* @throws Exception if the document can't be written
*/
private static void write(ImmobilienTransferTyp transfer, Writer output) throws Exception {
Is24XmlDocument
.newDocument(transfer)
.toXml(output, PRETTY_PRINT);
}
/**
* Convert a {@link ImmobilienTransferTyp} to XML and print the results to the console.
*
* @param transfer Java object representing the XML root element
* @throws Exception if the document can't be written
*/
private static void writeToConsole(ImmobilienTransferTyp transfer) throws Exception {
System.out.println(
Is24XmlDocument
.newDocument(transfer)
.toXmlString(PRETTY_PRINT)
);
}
}
See a full example at Is24XmlWritingExample.java
.