blob: f183757cf8ba083ceb34f596379b7bdc726200a2 [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>Turbine Services - Resources Service</title>
<author email="jvanzyl@apache.org">Jason van Zyl</author>
<author email="hps@intermeta.de">Henning P. Schmiedehausen</author>
</properties>
<body>
<section name="Resources Service">
<p>
Within Turbine was a service for reading and accessing data in Property
files. The classes that accomplish this have been borrowed from the
Apache JServ project, moved many time and finally ended up in the <a
href="http://commons.apache.org/configuration/">commons-configuration</a>
sub-project. So we removed the Service itself and now use commons-configuration everywhere.
</p>
</section>
<section name="Configuring Turbine">
<p>
Turbine gets its configuration file from the servlet container at
startup time. It is necessary to have an init parameter in the
servlet section of your web.xml file:
</p>
<source><![CDATA[
<init-param>
<param-name>properties</param-name>
<!-- This is relative to the docBase -->
<param-value>
/WEB-INF/conf/TurbineResources.properties
</param-value>
</init-param>
]]></source>
</section>
<section name="Accessing properties">
<p>
Turbine post-2.2 uses commons-configuration all over the place, so if
you want to access properties files, you can use it in two ways.
</p>
<p>
Inside arbitrary code:
</p>
<source><![CDATA[
import org.apache.commons.configuration.Configuration;
import org.apache.turbine.Turbine;
//
// Access all properties from TurbineResource.properties
Configuration conf = Turbine.getConfiguration();
String myProperty = conf.getString("this.is.my.property");
]]></source>
<p>
Inside a service, you can easily access the already subclassed
property object for your service (that is, with the services.&lt;your service name&gt;
stripped away from the property:
</p>
<source><![CDATA[
public class myService extends TurbineBaseService
{
.
.
.
Configuration conf = getConfiguration();
String myProp = conf.getString("my.property"); // services.myService.my.property
.
.
.
}
]]></source>
</section>
</body>
</document>