All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.scalaxal.example.TestReadWrite.scala Maven / Gradle / Ivy

There is a newer version: 1.1
Show newest version
package com.scalaxal.example

import com.scalaxal.io.{XalToXml, XalPrintWriter, XalFileReader}
import xml.PrettyPrinter
import com.scalaxal.xAL.{AddressLine, AddressLines, AddressDetails, XAL}

/**
 * Author: Ringo Wathelet
 * Date: 4/02/13 
 * Version: 1
 */

object TestReadWrite {
  def main(args: Array[String]) {
    test2
  }


  def test1() {
    println("....XAL TestReadWrite test1 start...\n")

    // create a xal object from an xml file
    val xal = new XalFileReader().getXalFromFile("./xal-files/XAL.XML")

    if (xal.isDefined) {
      // create a new AddressDetails with an specific AddressLine
      val newAddressDetails = AddressDetails(addressDetailsType =
        Some(new AddressLines(addressLines = (Seq.empty :+ new AddressLine(Some("a new address line"))))))

      // create a new xal object with the new AddressDetails
      val newXal = xal.get.copy(addressDetails = (xal.get.addressDetails :+ newAddressDetails))

      //          "./xal-files/scalaxal-XAL.XML"
//      new XalPrintWriter().write(Option(newXal), new PrettyPrinter(80, 3))

      // write the AddressDetails
//      xal.get.addressDetails.foreach(x =>
//        XalToXml.toXml(x).foreach(z => println(new PrettyPrinter(80, 3).format(z))))

      // write the AddressDetails
    xal.get.addressDetails.foreach(x => new XalPrintWriter().write(Some(x), new PrettyPrinter(80, 3)))
    }

    println("\n....XAL TestReadWrite test1 done...")
  }

  def test2() {

    println("....XAL TestReadWrite test2 start...\n")

    // create a xal object from an xml file
    val xal = new XalFileReader().getXalFromFile("./xal-files/XAL.XML")

    if (xal.isDefined) {

      // create a new AddressDetails
      val newAddressDetails = new AddressDetails(new AddressLines(new AddressLine("a new address line")))

      // create a new xal object with the new AddressDetails
      val newXal = xal.get addToAddressDetails newAddressDetails

      //          "./xal-files/scalaxal-XAL.XML"
      val writer = new XalPrintWriter()
      writer.write(Some(newXal), new PrettyPrinter(80, 3))
      writer.close()

      // write the AddressDetails
      //      xal.get.addressDetails.foreach(x =>
      //        XalToXml.toXml(x).foreach(z => println(new PrettyPrinter(80, 3).format(z))))

      // write the AddressDetails
 //     newAddressLines.addressLines.foreach(x => new XalPrintWriter().write(Option(x), new PrettyPrinter(80, 3)))
    }

    println("\n....XAL TestReadWrite test2 done...")

  }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy