Created
April 8, 2010 19:47
-
-
Save cilquirm/360453 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env groovy | |
import groovy.util.*; | |
def webXml = new XmlSlurper().parse( arg[0] as File ) | |
def grabElements = { name, map, it -> | |
def objName = it."${name}-name".text() | |
map[ objName ] = [ 'className' : it."${name}-class".text() ] | |
map[ objName ][ 'params' ] = [ : ] as LinkedHashMap | |
it.'init-param'.each { it2 -> | |
map[ objName ][ 'params' ][ "${it2.'param-name'.text()}" ] = "${it2.'param-value'.text()}" | |
} | |
} | |
def filters = [:] | |
def servlets = [:] | |
webXml.filter.each( grabElements.curry( 'filter', filters ) ) | |
webXml.servlet.each( grabElements.curry( 'servlet', servlets ) ) | |
println "Map<String,String> params = null;" | |
webXml.'filter-mapping'.each { mapping -> | |
def filterName = mapping.'filter-name'.text() | |
currentFilter = filters[filterName] | |
if (!currentFilter['params'].isEmpty()) { | |
println "params = new HashMap<String,String>();" | |
currentFilter['params'].each { key, value -> | |
println "params.put(\"${key}\", \"${value}\");" | |
} | |
} | |
println "filter(\"${mapping.'url-pattern'.text()}\").through(${currentFilter['className']}.class);" | |
println "\n\n" | |
} | |
webXml.'servlet-mapping'.each { mapping -> | |
def filterName = mapping.'servlet-name'.text() | |
currentServlet = servlets[filterName] | |
if (!currentServlet['params'].isEmpty()) { | |
println "params = new HashMap<String,String>();" | |
currentServlet['params'].each { key, value -> | |
println "params.put(\"${key}\", \"${value}\");" | |
} | |
} | |
println "serve(\"${mapping.'url-pattern'.text()}\").with(${currentFilter['className']}.class);" | |
println "\n\n" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment