Source code

Download source archive ↓

upstream/piflow-bundle/src/main/scala/cn/piflow/bundle/xml/XmlSave.scala

1package cn.piflow.bundle.xml
2
3import cn.piflow._
4import cn.piflow.conf._
5import cn.piflow.conf.bean.PropertyDescriptor
6import cn.piflow.conf.util.{ImageUtil, MapUtil}
7import org.codehaus.jackson.map.ext.CoreXMLSerializers.XMLGregorianCalendarSerializer
8
9import scala.beans.BeanProperty
10
11class XmlSave extends ConfigurableStop{
12
13  val authorEmail: String = "xjzhu@cnic.cn"
14  val description: String = "Save data to xml file"
15  val inportList: List[String] = List(Port.DefaultPort)
16  val outportList: List[String] = List(Port.DefaultPort)
17
18  var xmlSavePath:String = _
19
20  def perform(in: JobInputStream, out: JobOutputStream, pec: JobContext): Unit = {
21    val xmlDF = in.read()
22
23    xmlDF.write.format("xml").save(xmlSavePath)
24  }
25
26  def initialize(ctx: ProcessContext): Unit = {
27
28  }
29
30  override def setProperties(map: Map[String, Any]): Unit = {
31    xmlSavePath = MapUtil.get(map,"xmlSavePath").asInstanceOf[String]
32  }
33
34  override def getPropertyDescriptor(): List[PropertyDescriptor] = {
35    var descriptor : List[PropertyDescriptor] = List()
36    val xmlSavePath = new PropertyDescriptor()
37      .name("xmlSavePath")
38      .displayName("XmlSavePath")
39      .description("xml file save path")
40      .defaultValue("")
41      .required(true)
42        .example("hdfs://192.168.3.138:8020/work/test/test.xml")
43    descriptor = xmlSavePath :: descriptor
44    descriptor
45  }
46
47  override def getIcon(): Array[Byte] = {
48    ImageUtil.getImage("icon/xml/XmlSave.png")
49  }
50
51  override def getGroup(): List[String] = {
52    List(StopGroup.XmlGroup)
53  }
54
55}