Commit 9872178a by Amelin Konstantin

Rewrite render

parent 82523709
......@@ -6,12 +6,12 @@ import templates._
object Main extends App {
val p = new PrettyPrinter(140, 2)
val sourceXml = XML.loadFile("src/main/resources/nsd/Repo NSD bond.xml")
val sourceXml = XML.loadFile("src/main/resources/nsd/Repo NSD equity.xml")
val template = Template(sourceXml)
val outputXml = XML.loadString(p.format(template.template))
val outputXml = XML.loadString(p.format(template.render))
//val outputXml = template.template
template.log()
//template.log()
Try {
......
......@@ -162,11 +162,13 @@ final class RepoTemplate(source: Node) extends TradeTemplate(source) {
<fpmlext:assetReference href="RU0009109391" />
</fpmlext:collateral>
*/}
{/*
<rtsrep:deliveryDate>
<fpml:adjustableDate>
<fpml:unadjustedDate>{ get(Try { (source \ "trade" \ "repo" \ "spotLeg" \ "deliveryDate" \\ "unadjustedDate").head }) }</fpml:unadjustedDate>
</fpml:adjustableDate>
</rtsrep:deliveryDate>
*/}
</fpmlext:spotLeg>
<fpmlext:forwardLeg xsi:type="rtsrep:ForwardRepoTransactionLeg">
<fpml:buyerPartyReference href={ get(Try { (source \ "trade" \ "repo" \ "forwardLeg" \ "buyerPartyReference").head }, "href") } />
......@@ -180,11 +182,13 @@ final class RepoTemplate(source: Node) extends TradeTemplate(source) {
<fpml:currency>{ get(Try { (source \ "trade" \ "repo" \ "forwardLeg" \\ "currency").head }) }</fpml:currency>
<fpml:amount>{ get(Try { (source \ "trade" \ "repo" \ "forwardLeg" \\ "amount").head }) }</fpml:amount>
</fpml:settlementAmount>
{/*
<rtsrep:deliveryDate>
<fpml:adjustableDate>
<fpml:unadjustedDate>{ get(Try { (source \ "trade" \ "repo" \ "forwardLeg" \ "deliveryDate" \\ "unadjustedDate").head }) }</fpml:unadjustedDate>
</fpml:adjustableDate>
</rtsrep:deliveryDate>
*/}
</fpmlext:forwardLeg>
{ if (productType == Equity)
<fpml:equity id={ get(Try { (source \ "trade" \ "repo" \ "equity").head }, "id") }>
......
......@@ -66,15 +66,17 @@ abstract class Template(protected[this] val source: Node) {
def render: Node = {
val rule: RewriteRule = new RewriteRule {
override def transform(n: Node): NodeSeq = n match {
case v if v.attributes.nonEmpty && v.attributes.filter(_.value.text == msgNotFound).nonEmpty =>
NodeSeq.Empty
case v if v.child.length == 1 && v.child.head.text == msgNotFound =>
case v if v.text == msgNotFound =>
NodeSeq.Empty
case v: Elem if v.attributes.nonEmpty && v.attributes.value.text.contains(msgNotFound) =>
v.copy(attributes = v.attributes.filter(_.value.text != msgNotFound))
case _ => n
}
}
new RuleTransformer(rule).transform(template).head
val rt = new RuleTransformer(rule)
rt.transform(template).head
}
def log(): Unit = data.foreach(e => println(e._2))
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment