Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
S
SPB_Exchange_Repo
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Amelin Konstantin
SPB_Exchange_Repo
Commits
0abb089c
Commit
0abb089c
authored
Oct 22, 2018
by
Amelin Konstantin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
split debug and main behavior. Add trait Logger
parent
3474fac9
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
80 additions
and
58 deletions
+80
-58
src/main/scala/Main.scala
+3
-3
src/main/scala/templates/RepoTemplate.scala
+1
-1
src/main/scala/templates/Template.scala
+7
-54
src/main/scala/templates/logger.scala
+69
-0
No files found.
src/main/scala/Main.scala
View file @
0abb089c
...
...
@@ -5,13 +5,13 @@ import templates._
object
Main
extends
App
{
implicit
def
templateFactory
(
source
:
Node
)
:
Template
=
{
implicit
def
templateFactory
(
source
:
Node
)
:
Template
with
Logger
=
{
(
source
\
"trade"
).
head
.
child
.
filter
{
case
v
:
Elem
=>
true
case
_
=>
false
}(
1
).
label
match
{
case
"repo"
=>
new
RepoTemplate
(
source
)
case
"repo"
=>
new
RepoTemplate
(
source
)
with
DebugLogger
case
v
=>
throw
new
Exception
(
"Undefined trade type"
)
}
}
...
...
@@ -22,7 +22,7 @@ object Main extends App {
val
outputXml
=
XML
.
loadString
(
p
.
format
(
template
.
render
))
//val outputXml = template.template
//
template.log()
template
.
log
()
Try
{
...
...
src/main/scala/templates/RepoTemplate.scala
View file @
0abb089c
...
...
@@ -3,7 +3,7 @@ package templates
import
scala.util.Try
import
scala.xml.Node
final
class
RepoTemplate
(
source
:
Node
)
extends
TradeTemplate
(
source
)
{
class
RepoTemplate
(
source
:
Node
)
extends
TradeTemplate
(
source
)
{
protected
[
this
]
def
templateTrade
:
Node
=
{
<
fpml
:
trade>
<fpml:tradeHeader>
...
...
src/main/scala/templates/Template.scala
View file @
0abb089c
package
templates
import
scala.collection.mutable
import
scala.util.
{
Success
,
Try
}
import
scala.xml.transform.
{
RewriteRule
,
RuleTransformer
}
import
scala.xml._
abstract
class
Template
(
protected
[
this
]
val
source
:
Node
)
{
protected
[
this
]
val
msgNotFound
=
"Not found"
private
[
this
]
val
data
=
{
val
m
:
mutable.LinkedHashMap
[
Int
,
mutable.Queue
[(
String
,
String
,
mutable.LinkedHashMap
[
Int
,
(
String
,
String
)])]]
=
mutable
.
LinkedHashMap
()
val
items
=
source
\\
"_"
for
(
i
<-
items
)
{
if
(
i
.
attributes
.
nonEmpty
||
(
i
.
child
.
length
==
1
))
{
val
idx
=
i
.
hashCode
val
attr
:
mutable.LinkedHashMap
[
Int
,
(
String
,
String
)]
=
if
(
i
.
attributes
.
nonEmpty
)
mutable
.
LinkedHashMap
()
else
null
val
text
=
if
(
i
.
child
.
nonEmpty
&&
!
i
.
child
.
head
.
text
.
contains
(
"\n"
))
i
.
child
.
head
.
text
else
null
m
.
get
(
idx
)
match
{
case
None
=>
m
(
idx
)
=
mutable
.
Queue
((
s
"tag: ${i.label}"
,
text
,
attr
))
case
_
=>
m
(
idx
).
enqueue
((
s
"tag: ${i.label}"
,
text
,
attr
))
}
if
(
i
.
attributes
.
nonEmpty
)
{
for
(
a
<-
i
.
attributes
)
{
m
(
idx
).
last
.
_3
(
a
.
value
.
hashCode
)
=
(
a
.
key
,
a
.
value
.
text
)
}
}
}
protected
[
this
]
def
get
(
content
:
Try
[
Node
],
attr
:
String
=
null
)
:
Text
=
content
match
{
case
Success
(
v
)
if
attr
!=
null
=>
v
.
attribute
(
attr
)
match
{
case
None
=>
Text
(
msgNotFound
)
case
o
=>
Text
(
o
.
get
.
text
)
}
m
}
protected
[
this
]
def
get
(
content
:
Try
[
Node
],
attr
:
String
=
null
)
:
Text
=
content
match
{
case
Success
(
v
)
=>
var
res
=
Text
(
v
.
text
)
if
(
attr
!=
null
)
v
.
attribute
(
attr
)
match
{
case
None
=>
res
=
Text
(
msgNotFound
)
case
o
=>
data
(
v
.
hashCode
).
head
.
_3
-=
o
.
get
.
hashCode
res
=
Text
(
o
.
get
.
text
)
}
else
if
(
data
(
v
.
hashCode
).
nonEmpty
)
{
if
(
data
(
v
.
hashCode
).
head
.
_3
!=
null
)
{
val
e
=
data
(
v
.
hashCode
).
head
.
copy
(
_2
=
null
)
data
(
v
.
hashCode
).
enqueue
(
e
)
}
data
(
v
.
hashCode
).
dequeue
()
}
res
case
_
=>
Text
(
msgNotFound
)
case
Success
(
v
)
=>
Text
(
v
.
text
)
case
_
=>
Text
(
msgNotFound
)
}
def
template
:
Node
...
...
@@ -87,12 +42,10 @@ abstract class Template(protected[this] val source: Node) {
rt2
.
transform
(
rt1
.
transform
(
template
)).
head
}
def
log
()
:
Unit
=
data
.
foreach
(
e
=>
println
(
e
.
_2
))
}
object
Template
{
def
apply
(
source
:
Node
)(
implicit
templateFactory
:
Node
=>
Template
)
:
Template
=
templateFactory
(
source
)
def
apply
(
source
:
Node
)(
implicit
templateFactory
:
Node
=>
Template
with
Logger
)
:
Template
with
Logger
=
templateFactory
(
source
)
}
src/main/scala/templates/logger.scala
0 → 100644
View file @
0abb089c
package
templates
import
scala.collection.mutable
import
scala.util.
{
Success
,
Try
}
import
scala.xml.
{
Node
,
Text
}
trait
Logger
{
this:
Template
=>
def
log
()
:
Unit
=
()
}
trait
DebugLogger
extends
Logger
{
this:
Template
=>
private
[
this
]
val
data
=
{
val
m
:
mutable.LinkedHashMap
[
Int
,
mutable.Queue
[(
String
,
String
,
mutable.LinkedHashMap
[
Int
,
(
String
,
String
)])]]
=
mutable
.
LinkedHashMap
()
val
items
=
source
\\
"_"
for
(
i
<-
items
)
{
if
(
i
.
attributes
.
nonEmpty
||
(
i
.
child
.
length
==
1
))
{
val
idx
=
i
.
hashCode
val
attr
:
mutable.LinkedHashMap
[
Int
,
(
String
,
String
)]
=
if
(
i
.
attributes
.
nonEmpty
)
mutable
.
LinkedHashMap
()
else
null
val
text
=
if
(
i
.
child
.
nonEmpty
&&
!
i
.
child
.
head
.
text
.
contains
(
"\n"
))
i
.
child
.
head
.
text
else
null
m
.
get
(
idx
)
match
{
case
None
=>
m
(
idx
)
=
mutable
.
Queue
((
s
"tag: ${i.label}"
,
text
,
attr
))
case
_
=>
m
(
idx
).
enqueue
((
s
"tag: ${i.label}"
,
text
,
attr
))
}
if
(
i
.
attributes
.
nonEmpty
)
{
for
(
a
<-
i
.
attributes
)
{
m
(
idx
).
last
.
_3
(
a
.
value
.
hashCode
)
=
(
a
.
key
,
a
.
value
.
text
)
}
}
}
}
m
}
override
protected
[
this
]
def
get
(
content
:
Try
[
Node
],
attr
:
String
=
null
)
:
Text
=
content
match
{
case
Success
(
v
)
=>
var
res
=
Text
(
v
.
text
)
if
(
attr
!=
null
)
v
.
attribute
(
attr
)
match
{
case
None
=>
res
=
Text
(
msgNotFound
)
case
o
=>
data
(
v
.
hashCode
).
head
.
_3
-=
o
.
get
.
hashCode
res
=
Text
(
o
.
get
.
text
)
}
else
if
(
data
(
v
.
hashCode
).
nonEmpty
)
{
if
(
data
(
v
.
hashCode
).
head
.
_3
!=
null
)
{
val
e
=
data
(
v
.
hashCode
).
head
.
copy
(
_2
=
null
)
data
(
v
.
hashCode
).
enqueue
(
e
)
}
data
(
v
.
hashCode
).
dequeue
()
}
res
case
_
=>
Text
(
msgNotFound
)
}
override
def
log
()
:
Unit
=
data
.
foreach
(
e
=>
println
(
e
.
_2
))
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment