-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbuildtld_templates.groovy
67 lines (62 loc) · 2.49 KB
/
buildtld_templates.groovy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
/**
* Extracts the parameter documentation from Facelets templates (for the format, see e.g. formRow.xhtml) and
* prints out XML to be used in a TLD file (e.g. flexive.tld).
*
* @author Daniel Lichtenberger (daniel.lichtenberger@flexive.com), UCS - unique computing solutions gmbh (http://www.ucs.at)
* @version $Rev$
*/
if (!args || args.length != 1) {
println "Usage: buildtld_templates <taglib.xml>\n"
return
}
// load XML, skip DTD (because the facelets-dtd cannot be retrieved from the given URL)
final File taglibFile = new File(args[0])
final String taglibXml = taglibFile.text.replace("\r\n", "").replace("\n", "").replaceAll("<!DOCTYPE[^>]*>", "")
final def xmlOut = new StringWriter()
final def xml = new groovy.xml.MarkupBuilder(xmlOut)
new XmlSlurper(false, false).parseText(taglibXml).tag.list().each { it ->
final String tag = it."tag-name".toString()
final String source = it."source".toString()
boolean inParams = false // in Parameters: block
boolean inDescription = false // in Description: block
final def tagDescription = new StringBuffer()
xml.tag {
name(tag)
"body-content"("JSP")
if (!source.isEmpty()) {
// template component, source = source file name relative to the taglib file
new File(taglibFile.getParent() + File.separator + source).eachLine { String line ->
if (line.startsWith("Description:")) {
inDescription = true
return
}
if (line.startsWith("Parameters:")) {
description(tagDescription.toString())
inParams = true
inDescription = false
return
}
if (line.contains("ui:composition")) {
inParams = false
return
}
if (inDescription) {
tagDescription.append(line).append(" ")
}
if (inParams) {
//println line
def matcher = line =~ /\s*([a-zA-Z]+)\s+[-=]\s*(.*)/
if (matcher.matches()) {
attribute {
name(matcher.group(1))
required(false)
rtexprvalue(false)
description(matcher.group(2))
}
}
}
}
}
}
}
println xmlOut