-
Notifications
You must be signed in to change notification settings - Fork 4
/
urlrewritefilter.xml
247 lines (235 loc) · 9.12 KB
/
urlrewritefilter.xml
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
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
<project name="urlrewritefilter" default="urlrewritefilter.update"
basedir="./" xmlns:antcontrib="antlib:net.sf.antcontrib">
<property name="urlrewritefilter.version" value="4.0.3" />
<property name="urlrewritefilter.version" value="3.2.0" />
<target name="urlrewritefilter.servlet.install" depends="exists.urlrewrite.xml">
<property name="urlrewritefilter.log.level" value="WARN" />
<property name="urlrewritefilter.reload.interval" value="-1" />
<xmltask source="${war.target.dir}/WEB-INF/web.xml" dest="${war.target.dir}/WEB-INF/web.xml" outputter="simple">
<insert path="web-app/servlet[1]" position="before">
<![CDATA[
<filter>
<filter-name>UrlRewriteFilter</filter-name>
<filter-class>org.tuckey.web.filters.urlrewrite.UrlRewriteFilter</filter-class>
<init-param>
<param-name>logLevel</param-name>
<param-value>${urlrewritefilter.log.level}</param-value>
</init-param>
<!-- set the amount of seconds the conf file will be checked for reload
can be a valid integer (0 denotes check every time,
-1 denotes no reload check, default -1) -->
<init-param>
<param-name>confReloadCheckInterval</param-name>
<param-value>${urlrewritefilter.reload.interval}</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>UrlRewriteFilter</filter-name>
<url-pattern>/*</url-pattern>
<dispatcher>REQUEST</dispatcher>
<!--
<dispatcher>FORWARD</dispatcher>
-->
</filter-mapping>
]]>
</insert>
</xmltask>
<!--
<antcall target="urlrewritefilter.mappings.update"/>
-->
</target>
<macrodef name="urlrewrite">
<attribute name="name" />
<attribute name="from" />
<attribute name="to" default="" />
<attribute name="type" default="forward" />
<attribute name="last" default="false" />
<attribute name="enabled" default="true" />
<attribute name="note" default="@{name}"/>
<text name="rewritexml" optional="yes"/>
<sequential>
<echo message="rewrite: @{name} from: @{from} to: @{to}" />
<antcontrib:var name="rule.exists" unset="true"/>
<xmltask source="${war.target.dir}/WEB-INF/urlrewrite.xml"
dest="${war.target.dir}/WEB-INF/urlrewrite.xml"
outputter="simple">
<xmlcatalog refId="commonDTDs"/>
<print comment="existing url name" path="urlrewrite/rule[name='@{name}']"/>
<copy path="urlrewrite/rule[name='@{name}']" attrValue="true" property="rule.exists"/>
<replace path="urlrewrite/rule[name='@{name}']" if="rule.exists">
<![CDATA[
<rule enabled="@{enabled}">
<name>@{name}</name>
<note>@{note}</note>
@{rewritexml}
<from casesensitive="false">@{from}</from>
<to last="@{last}" type="@{type}">@{to}</to>
</rule>
]]>
</replace>
<insert path="urlrewrite" position="under" unless="rule.exists">
<![CDATA[
<rule enabled="@{enabled}">
<name>@{name}</name>
<note>@{note}</note>
@{rewritexml}
<from casesensitive="false">@{from}</from>
<to last="@{last}" type="@{type}">@{to}</to>
</rule>
]]>
</insert>
</xmltask>
</sequential>
</macrodef>
<macrodef name="urlrewriteout">
<attribute name="name" />
<attribute name="from" />
<attribute name="to" default="" />
<attribute name="type" default="forward" />
<attribute name="last" default="false" />
<attribute name="enabled" default="true" />
<attribute name="note" default="@{name}"/>
<text name="rewritexml" optional="yes"/>
<element name="args" optional="true" />
<sequential>
<antcontrib:var name="rule.exists" unset="true"/>
<echo message="rewrite-outbound: @{name} from: @{from} to: @{to}" />
<xmltask source="${war.target.dir}/WEB-INF/urlrewrite.xml"
dest="${war.target.dir}/WEB-INF/urlrewrite.xml">
<xmlcatalog refId="commonDTDs"/>
<print comment="existing url name" path="urlrewrite/rule[name='@{name}']"/>
<copy path="urlrewrite/rule[name='@{name}']" attrValue="true" property="rule.exists"/>
<replace path="urlrewrite/rule[name='@{name}']" if="rule.exists">
<![CDATA[
<outbound-rule enabled="@{enabled}">
<name>@{name}</name>
<note>@{note}</note>
<from casesensitive="false">@{from}</from>
<to last="@{last}" type="@{type}">@{to}</to>
</outbound-rule>
]]>
</replace>
<insert path="urlrewrite" position="under" unless="rule.exists">
<![CDATA[
<outbound-rule enabled="@{enabled}">
<name>@{name}</name>
<note>@{note}</note>
<from casesensitive="false">@{from}</from>
<to last="@{last}" type="@{type}">@{to}</to>
</outbound-rule>
]]>
</insert>
</xmltask>
</sequential>
</macrodef>
<macrodef name="urlrewritexml">
<attribute name="name" />
<text name="rewritexml"/>
<element name="args" optional="true" />
<sequential>
<antcontrib:var name="rule.exists" unset="true"/>
<xmltask source="${war.target.dir}/WEB-INF/urlrewrite.xml"
dest="${war.target.dir}/WEB-INF/urlrewrite.xml">
<xmlcatalog refId="commonDTDs"/>
<copy path="urlrewrite/rule[name='@{name}']" attrValue="true" property="rule.exists"/>
<print path="urlrewrite/rule[name='@{name}']"/>
<replace path="urlrewrite/rule[name='@{name}']" if="rule.exists">
<![CDATA[@{rewritexml}]]>
</replace>
<insert path="urlrewrite" position="under" unless="rule.exists">
<![CDATA[@{rewritexml}]]>
</insert>
</xmltask>
</sequential>
</macrodef>
<target name="urlrewritefilter.mappings.update">
<xmltask sourcebuffer="mappings.buff">
<call path="mappings/*">
<param name="virtual" path="@virtual" default="NONE" />
<param name="physical" path="@physical" default="NONE" />
<actions>
<antcontrib:var name="rule.exists" unset="true"/>
<echo message="@{virtual}" />
<xmltask source="${war.target.dir}/WEB-INF/urlrewrite.xml"
dest="${war.target.dir}/WEB-INF/urlrewrite.xml">
<xmlcatalog refId="commonDTDs"/>
<copy path="urlrewrite/rule[from='@{virtual}']" attrValue="true" property="rule.exists"/>
<print path="urlrewrite/rule[from='@{virtual}']"/>
<replace path="urlrewrite/rule[from='@{virtual}']" if="rule.exists">
<![CDATA[
<rule>
<from casesensitive="false">@{virtual}(.*)</from>
<to>@{physical}$1</to>
</rule>
]]>
</replace>
<insert path="urlrewrite" position="under" unless="rule.exists">
<![CDATA[
<rule>
<from casesensitive="false">@{virtual}(.*)</from>
<to>@{physical}$1</to>
</rule>
]]>
</insert>
</xmltask>
</actions>
</call>
</xmltask>
</target>
<target name="exists.urlrewrite.xml">
<property name="urlrewrite.file" value="${basedir}/urlrewrite.xml" />
<sanitizeContextPath/>
<requires-ext resource="${ext.dir}/urlrewritefilter/"/>
<available file="${basedir}/urlrewrite.${build.type}.xml" type="file" property="exists.urlrewrite.xml" />
<antcontrib:if>
<equals arg1="${exists.urlrewrite.xml}" arg2="true" />
<then>
<antcontrib:var name="${urlrewrite.file}" unset="true" />
<property name="urlrewrite.file" location="${basedir}/urlrewrite.${build.type}.xml" />
</then>
<else>
<available file="${urlrewrite.file}" type="file" property="exists.urlrewrite.xml" />
</else>
</antcontrib:if>
<echo message="Using urlrewrite-${urlrewritefilter.version}" />
<antcontrib:if>
<or>
<equals arg1="${exists.urlrewrite.xml}" arg2="true" />
<equals arg1="${urlrewrite.install}" arg2="true" />
</or>
<then>
<copy todir="${war.target.dir}/WEB-INF/" overwrite="true">
<fileset dir="${ext.dir}/urlrewritefilter/">
<include name="**/*.xml" />
<include name="**/urlrewrite-${urlrewritefilter.version}.jar" />
</fileset>
</copy>
<copy todir="${war.target.dir}/WEB-INF/" overwrite="true" file="${urlrewrite.file}" verbose="true" failonerror="false" />
</then>
<else>
<echo message="No urlrewrite.xml to import : ${basedir}/urlrewrite.xml does not exist." />
<copy todir="${war.target.dir}/WEB-INF/" overwrite="true">
<fileset dir="${ext.dir}/urlrewritefilter/">
<include name="**/*.xml" />
<include name="**/urlrewrite-${urlrewritefilter.version}.jar" />
</fileset>
</copy>
</else>
</antcontrib:if>
</target>
<target name="urlrewritefilter.update">
<property name="source-root" value="${cfdistro.basedir}/java/urlrewritefilter" />
<property name="repository.URL" value="http://urlrewritefilter.googlecode.com/svn" />
<java classname="org.tmatesoft.svn.cli.SVN" dir="${source-root}/../"
fork="true">
<arg value="export" />
<arg value="--force" />
<arg value="${repository.URL}/trunk/" />
<classpath>
<pathelement location="${cfdistro.lib.dir}/ganymed.jar" />
<pathelement location="${cfdistro.lib.dir}/svnkit.jar" />
<pathelement location="${cfdistro.lib.dir}/svnkit-cli.jar" />
</classpath>
</java>
</target>
</project>