blob: 61ac402e810662f0bebba5da1e471f924d2eb210 [file] [log] [blame]
<?xml version="1.0"?>
<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
-->
<document>
<properties>
<title>URL Mapper Howto</title>
</properties>
<body>
<section>
<p>
Unaltered Turbine URLs look like this:
<code>http://www.foo.com:8080/CONTEXT/servlet/MAPPING/template/Foo.vm</code>.<br/>
But you want shorter URLs, or you don't like exposing the use of
servlets in the URL. Maybe this url would suit you better:
<code>http://www.foo.com:8080/beautiful/world</code>
</p>
</section>
<section name="Turbine Configuration">
<p>
You need to register the URL Mapper service in the pipeline by adding the service, the configuration
</p>
<p>
In TurbineResources.properties, search URLMapperService, and if not found, add the following settings:
</p>
<source><![CDATA[
# -------------------------------------------------------------------
#
# U R L M A P P E R S E R V I C E
#
# -------------------------------------------------------------------
# new mapper
tool.request.mlink=org.apache.turbine.services.urlmapper.MappedTemplateLink
services.URLMapperService.classname=org.apache.turbine.services.urlmapper.TurbineURLMapperService
# xml, json and yml supported as extension
services.URLMapperService.configFile = /conf/turbine-url-mapping.xml
]]></source>
<p>Add the valve into pipeline (pipeline.default.descriptor = /conf/turbine-classic-pipeline.xml).
</p>
<source><![CDATA[
<valves>
<valve>org.apache.turbine.services.urlmapper.URLMapperValve</valve>
...
]]></source>
<p>This will read the beautfied URL and alter into to what, the server requires as defined
in the URLMapperService's configfile .
</p>
<source><![CDATA[
<url-mapping name="default">
<maps>
<map>
<pattern>/(?&lt;contextPath&gt;\w+)/book/(?&lt;bookId&gt;\d+)</pattern>
<implicit-parameters>
<parameter key="template">Book.vm</parameter>
<parameter key="detail">0</parameter>
</implicit-parameters>
</map>
...
]]></source>
<p>
Use it in the templates, e.g.
</p>
<source><![CDATA[
$mlink.addPathInfo("world","nice").getRelativeLink()
## may result into /beautiful/world
]]></source>
<p>
More examples ...
</p>
</section>
</body>
</document>