-
Notifications
You must be signed in to change notification settings - Fork 2
/
adjust-conf-files.xsl
179 lines (155 loc) · 6.48 KB
/
adjust-conf-files.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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:exist="http://exist.sourceforge.net/NS/exist"
xmlns:log4j="http://jakarta.apache.org/log4j/"
xmlns:webapp="http://xmlns.jcp.org/xml/ns/javaee"
exclude-result-prefixes="xs exist log4j webapp"
version="2.0">
<!--
script for modifying eXist-db conf files
to the WeGA needs
-->
<xsl:param name="env"/>
<xsl:param name="context_path"/>
<xsl:param name="default_app_path"/>
<!-- needed servlets -->
<!-- wird das ResourceServlet wirklich benötigt? Ja, für Dashboard etc-->
<!-- 'org.exist.xmlrpc.RpcServlet' und 'JMXServlet' werden für Produktiv-Einsatz nicht benötigt -->
<xsl:variable name="production-servlets" as="xs:string+" select="(
'ResourceServlet',
'EXistServlet',
'XQueryServlet',
'XQueryURLRewrite'
)"/>
<!--
copy over DOCTYPE instructions
adopted from https://stackoverflow.com/questions/51432291/copy-entire-doctype-tag-from-input-document-using-xslt-2-0
-->
<xsl:template match="/">
<xsl:variable name="unparsed-text">
<xsl:value-of disable-output-escaping="yes"
select="unparsed-text(base-uri())"/>
</xsl:variable>
<xsl:if test="matches($unparsed-text, '.*?(\n?<!DOCTYPE\s.*?>).*')">
<xsl:value-of disable-output-escaping="yes"
select="replace(
$unparsed-text,
'.*?(\n?<!DOCTYPE\s.*?>).*',
'$1',
's')"/>
</xsl:if>
<xsl:apply-templates/>
</xsl:template>
<xsl:template match="node()|@*">
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
</xsl:copy>
</xsl:template>
<!--
+++++++++++++++++++++++++++++++++++++++++
$exist.home$/conf.xml
+++++++++++++++++++++++++++++++++++++++++
-->
<xsl:template match="@preserve-whitespace-mixed-content[parent::indexer]">
<xsl:attribute name="preserve-whitespace-mixed-content" select="'yes'"/>
</xsl:template>
<xsl:template match="@caching[parent::transformer]">
<xsl:attribute name="caching">
<xsl:choose>
<xsl:when test="$env eq 'production'">yes</xsl:when>
<xsl:otherwise>no</xsl:otherwise>
</xsl:choose>
</xsl:attribute>
</xsl:template>
<xsl:template match="@indent[parent::serializer]">
<xsl:attribute name="indent" select="'no'"/>
</xsl:template>
<!--
+++++++++++++++++++++++++++++++++++++++++
$exist.home$/webapp/WEB-INF/controller-config.xml
+++++++++++++++++++++++++++++++++++++++++
-->
<xsl:template match="exist:forward">
<xsl:if test="$env ne 'production' or @servlet = $production-servlets">
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
</xsl:copy>
</xsl:if>
</xsl:template>
<xsl:template match="exist:root">
<xsl:choose>
<xsl:when test="@pattern = '/apps'">
<xsl:copy>
<xsl:apply-templates select="@*"/>
</xsl:copy>
</xsl:when>
<xsl:when test="@pattern = '.*' and not($default_app_path)">
<xsl:copy>
<xsl:apply-templates select="@*"/>
</xsl:copy>
</xsl:when>
<xsl:when test="@pattern = '.*' and $default_app_path">
<root pattern=".*" path="{$default_app_path}" xmlns="http://exist.sourceforge.net/NS/exist"/>
</xsl:when>
</xsl:choose>
</xsl:template>
<!--
+++++++++++++++++++++++++++++++++++++++++
$exist.home$/tools/jetty/webapps/exist-webapp-context.xml
+++++++++++++++++++++++++++++++++++++++++
-->
<xsl:template match="Set[@name='contextPath' and $context_path]">
<xsl:copy>
<xsl:attribute name="name" select="'contextPath'"/>
<xsl:value-of select="$context_path"/>
</xsl:copy>
</xsl:template>
<!--
+++++++++++++++++++++++++++++++++++++++++
$exist.home$/webapp/WEB-INF/web.xml
+++++++++++++++++++++++++++++++++++++++++
-->
<xsl:template match="webapp:servlet[not(
webapp:servlet-name = $production-servlets
or $env = 'development'
or (webapp:servlet-name = 'RestXqServlet' and $env = 'restxq'))
]"/>
<xsl:template match="webapp:servlet-mapping[not(webapp:servlet-name = 'XQueryURLRewrite' or $env = 'development')]"/>
<!-- for the restxq-only experience we hijack the XQueryURLRewrite servlet-mapping (which defaults to '/*') -->
<xsl:template match="webapp:servlet-name[parent::webapp:servlet-mapping][$env = 'restxq']">
<xsl:copy>RestXqServlet</xsl:copy>
</xsl:template>
<xsl:template match="webapp:filter[$env ne 'development']"/>
<xsl:template match="webapp:filter-mapping[$env ne 'development']"/>
<xsl:template match="webapp:login-config[$env ne 'development']"/>
<xsl:template match="webapp:context-param[$env ne 'development']"/>
<xsl:template match="webapp:listener[$env ne 'development']"/>
<xsl:template match="webapp:init-param[webapp:param-name = 'hidden' and $env ne 'development']">
<!-- Deny direct access to the REST interface -->
<xsl:copy>
<xsl:element name="param-name" namespace="http://xmlns.jcp.org/xml/ns/javaee">
<xsl:text>hidden</xsl:text>
</xsl:element>
<xsl:element name="param-value" namespace="http://xmlns.jcp.org/xml/ns/javaee">
<xsl:text>true</xsl:text>
</xsl:element>
</xsl:copy>
</xsl:template>
<!--
+++++++++++++++++++++++++++++++++++++++++
$exist.home$/etc/jetty/jetty.xml
+++++++++++++++++++++++++++++++++++++++++
add ForwardedRequestCustomizer to the Jetty configuration
to properly process the X-Forward-For and related proxy headers
https://github.com/peterstadler/existdb-docker/issues/6
-->
<xsl:template match="New[@class='org.eclipse.jetty.server.HttpConfiguration']">
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
<Call name="addCustomizer">
<Arg><New class="org.eclipse.jetty.server.ForwardedRequestCustomizer"/></Arg>
</Call>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>