-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathweb-xml-merge.xsl
156 lines (138 loc) · 5.71 KB
/
web-xml-merge.xsl
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"
xmlns:j2ee="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<xsl:output indent="yes"/>
<xsl:preserve-space elements="*"/>
<xsl:param name="mergeXmlFile">C:/projects/GrouperI2MI_1-5-x/grouper-ui/temp/70.web.cas.filtered.xml</xsl:param>
<xsl:param name="mergeTagsXmlFile">C:\projects\GrouperI2MI_1-5-x\grouper-ui/web-xml-merge-tags.xml</xsl:param>
<xsl:variable name="mergeXml" select="document($mergeXmlFile)"/>
<xsl:variable name="mergeTagsXml" select="document($mergeTagsXmlFile)"/>
<xsl:variable name="docRoot" select="/web-app"/>
<xsl:template match="/">
<web-app xmlns:j2ee="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
version="2.4">
<xsl:comment>DO NOT EDIT THIS FILE. IT WILL BE OVERWRITTEN. CHANGE YOUR FILE specified by the build.properties value [additional.web.xml]. The contents of that file are merged into ${grouper-ui}/webapp/WEB-INF/web.core.xml</xsl:comment>
<xsl:choose>
<xsl:when test="not($mergeXmlFile) or starts-with($mergeXmlFile,'$')">
<xsl:copy-of select="$docRoot/*"/>
</xsl:when>
<xsl:otherwise>
<xsl:apply-templates select="/web-app"/>
</xsl:otherwise>
</xsl:choose>
</web-app>
</xsl:template>
<xsl:template match="web-app" >
<xsl:comment>In webapp</xsl:comment>
<xsl:for-each select="$mergeTagsXml/merge-tags/tag">
<xsl:call-template name="merge"/>
</xsl:for-each>
</xsl:template>
<xsl:template name="merge">
<xsl:choose>
<xsl:when test="./@type='single'">
<xsl:call-template name="singleType"/>
</xsl:when>
<xsl:when test="./@type='list'">
<xsl:call-template name="listType"/>
</xsl:when>
<xsl:otherwise>
<xsl:call-template name="sequenceType"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template name="singleType">
<!-- If tag appears it should only appear once. Don't overwrite-->
<xsl:variable name="tagname">
<xsl:value-of select="@name"/>
</xsl:variable>
<xsl:choose>
<xsl:when test="boolean($docRoot/*[name()=$tagname])">
<xsl:copy-of select="$docRoot/*[name()=$tagname]"/>
</xsl:when>
<xsl:otherwise>
<xsl:copy-of select="$mergeXml/web-app/*[name()=$tagname]"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template name="listType">
<!-- if exist in either file put list tags then put merge list items then existing
without duplicates -->
<xsl:variable name="key">
<xsl:value-of select="@key"/>
</xsl:variable>
<xsl:variable name="tagname">
<xsl:value-of select="@name"/>
</xsl:variable>
<xsl:if test="boolean($docRoot/*[name()=$tagname]) or boolean($mergeXml/web-app/*[name()=$tagname])">
<xsl:for-each select="./*[1]">
<xsl:copy>
<xsl:copy-of select="$mergeXml/web-app/*[name()=$tagname]/*[name()=$key]"/>
<xsl:for-each select="$docRoot/*[name()=$tagname]/*[name()=$key]">
<xsl:variable name="docText">
<xsl:value-of select="./child::text()"/>
</xsl:variable>
<xsl:if test="not($mergeXml/web-app/*[name()=$tagname]/*[name()=$key]/child::text()=$docText)">
<xsl:copy-of select="."/>
</xsl:if>
</xsl:for-each>
</xsl:copy>
</xsl:for-each>
</xsl:if>
</xsl:template>
<xsl:template name="sequenceType">
<xsl:comment>Processing <xsl:value-of select="@name"/></xsl:comment>
<xsl:variable name="key">
<xsl:value-of select="@key"/>
</xsl:variable>
<xsl:variable name="tagname">
<xsl:value-of select="@name"/>
</xsl:variable>
<xsl:for-each select="$mergeXml/web-app/*[name()=$tagname]">
<xsl:if test="./*[name()=$key] or $tagname != 'error-page'">
<xsl:comment>Inserting tag from merge file</xsl:comment>
<xsl:copy-of select="."/>
</xsl:if>
</xsl:for-each>
<xsl:for-each select="$docRoot/*[name()=$tagname]">
<xsl:choose>
<xsl:when test="$tagname='security-constraint'">
<xsl:variable name="curDocKey">
<xsl:value-of select="./web-resource-collection/url-pattern/child::text()"/>
</xsl:variable>
<xsl:variable name="mergeDocKey">
<xsl:value-of select="$mergeXml/web-app/security-constraint/web-resource-collection/url-pattern[child::text()=$curDocKey]/child::text()"/>
</xsl:variable>
<xsl:if test="not($curDocKey=$mergeDocKey)">
<xsl:comment>Inserting tag from base file. Merge file was <xsl:value-of select="$mergeXmlFile"/></xsl:comment>
<xsl:copy-of select="."/>
</xsl:if>
</xsl:when>
<xsl:when test="$tagname='filter-mapping'">
<xsl:comment>Inserting tag from base file. Merge file was <xsl:value-of select="$mergeXmlFile"/></xsl:comment>
<xsl:copy-of select="."/>
</xsl:when>
<xsl:otherwise>
<xsl:if test="./*[name()=$key]">
<xsl:variable name="curDocKey">
<xsl:value-of select="./*[name()=$key]"/>
</xsl:variable>
<xsl:variable name="mergeDocKey">
<xsl:value-of select="$mergeXml/web-app/*[name()=$tagname]/*[name()=$key and child::text()=$curDocKey]"/>
</xsl:variable>
<xsl:if test="$tagname='security-constraint'">
</xsl:if>
<!-- If tag with same key didn't exist in merge file, insert here -->
<xsl:if test="not(boolean($mergeXml/web-app/*[name()=$tagname]/*[name()=$key and child::text()=$curDocKey]))">
<xsl:comment>Inserting tag from base file. Merge file was <xsl:value-of select="$mergeXmlFile"/></xsl:comment>
<xsl:copy-of select="."/>
</xsl:if>
</xsl:if>
</xsl:otherwise>
</xsl:choose>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>