groovyでstruts-config.xmlをhtml変換
struts-config.xmlの内容のうち、特にaction-mappingsについてはチェックする機会が多い。もうちょっと見やすくならないかな、ということで、htmlに変換してみた。(xslt使うのが本来のやり方なのかもしれないけれども、そこはGroovy中毒患者。)
import groovy.xml.MarkupBuilder
import org.custommonkey.xmlunit.*
final xmlSlurper = new XmlSlurper()
def config = xmlSlurper.parseText(new File(args[0]).text.replaceFirst(/<!DOCTYPE(?ms)[^>]+>/, ""))
def actions = config."action-mappings".action
def html = new MarkupBuilder()
html.html() {
head{
link(
rel:"stylesheet",
type:"text/css",
href:"style.css",
)
style{
def i = 0
actions.@path*.toString().collect{ it.split("/")[1] }.unique().each{
yieldUnescaped """
.${it}{
background-color: #${(1..6).collect{("A".."F")[(int)(Math.random()*6)]}.join("")};
}
"""
}
}
}
body{
table{
caption("action-mappings")
thead{
tr{
th("path")
th("type")
th("forward")
th("scope")
}
}
tbody{
actions.each{ action ->
tr(class:"${action.@path.toString().split("/")[1]}"){
td(action.@path)
td(action.@type)
td(style:"text-align:left;"){
ul{
action.forward.each{
li(it.@name)
}
}
}
td(action.@scope)
}
}
}
}
}
}
これに、適当なcssファイルを付け加えてみる。
table {
width:90%;
border-top:3px solid #e5eff8;
border-right:1px solid #e5eff8;
margin:1em auto;
border-collapse:collapse;
}
table caption{
font-size: 150%;
font-weight: bold;
border :2px solid gray;
text-valign: middle;
}
td {
color:#5B4167;
border-bottom:1px solid #e5eff8;
border-left:1px solid #e5eff8;
padding:.3em 1em;
text-align:center;
}
thead th {
background:#f4f9fe;
text-align:center;
font:bold 1.2em/2em "Century Gothic","Trebuchet MS",Arial,Helvetica,sans-serif;
color:#66a3d3;
}
いい加減、struts 1.Xなプロジェクト、抜けたい。でも現在保守作業中なので当分抜けられないんだろうな。



ディスカッション
コメント一覧
まだ、コメントがありません