ebourg 2004/10/21 18:40:49
Modified: configuration/xdocs howto_compositeconfiguration.xml
howto_configurationfactory.xml howto_properties.xml
howto_xml.xml overview.xml
Log:
Removed the extra empty lines in the <source> blocks
Revision Changes Path
1.2 +6 -14
jakarta-commons/configuration/xdocs/howto_compositeconfiguration.xml
Index: howto_compositeconfiguration.xml
===================================================================
RCS file:
/home/cvs/jakarta-commons/configuration/xdocs/howto_compositeconfiguration.xml,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- howto_compositeconfiguration.xml 24 Feb 2004 13:08:03 -0000 1.1
+++ howto_compositeconfiguration.xml 22 Oct 2004 01:40:48 -0000 1.2
@@ -20,15 +20,13 @@
Defaults are very simple. You can just add them as your last
configuration object,
either through the ConfigurationFactory or manually:
</p>
- <source>
-<![CDATA[
+ <source><![CDATA[
Configuration defaults = new PropertiesConfiguration(fileToDefaults);
Configuration otherProperties = new PropertiesConfiguration(fileToOtherProperties);
CompositeConfiguration cc = new CompositeConfiguration();
cc.addConfiguration(otherProperties);
cc.addDefaults(fileToDefaults);
-]]>
- </source>
+]]></source>
</subsection>
<subsection name="Saving Changes">
@@ -39,20 +37,17 @@
the constructor of the CompositeConfiguration what
Configuration
to save the changes via.
</p>
- <source>
-<![CDATA[
+ <source><![CDATA[
PropertiesConfiguration saveConfiguration = new
PropertiesConfiguration(fileToSaveChangesIn);
Configuration cc = new CompositeConfiguration(saveConfiguration);
cc.setProperty("newProperty","new value");
saveConfiguration.save();
-]]>
- </source>
+]]></source>
<p>
Alternatively, you can just request the
inMemoryConfiguration that stores the changes:
- <source>
-<![CDATA[
+ <source><![CDATA[
Configuration changes = myCompositeConfiguration.getInMemoryConfiguration();
DatabaseConfiguration config = new DatabaseConfiguration(datasource,
"configuration", "key", "value");
for (Iterator i = changes.getKeys().iterator();i.hasNext()){
@@ -60,10 +55,7 @@
Object value = changes.get(key);
config.setProperty(key,value);
}
-
-
-]]>
- </source>
+]]></source>
</p>
</subsection>
1.4 +14 -28
jakarta-commons/configuration/xdocs/howto_configurationfactory.xml
Index: howto_configurationfactory.xml
===================================================================
RCS file:
/home/cvs/jakarta-commons/configuration/xdocs/howto_configurationfactory.xml,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- howto_configurationfactory.xml 12 Jul 2004 12:14:38 -0000 1.3
+++ howto_configurationfactory.xml 22 Oct 2004 01:40:48 -0000 1.4
@@ -35,15 +35,13 @@
the properties are to be collected. The following
listing shows
the content of this file:
</p>
- <source>
-<![CDATA[
+ <source><![CDATA[
<?xml version="1.0" encoding="ISO-8859-1" ?>
<configuration>
<properties fileName="usergui.properties"/>
</configuration>
-]]>
- </source>
+]]></source>
<p>
Definition files for <code>ConfigurationFactory</code>
are
normal XML files. The root element must be named
@@ -65,14 +63,12 @@
Just create a new instance and set the name of the
definition
file with the <code>setConfigurationFileName()</code>
method.
</p>
- <source>
-<![CDATA[
+ <source><![CDATA[
ConfigurationFactory factory = new ConfigurationFactory();
URL configURL = new File("config.xml").toURL();
factory.setConfigurationFileName(configURL.toString());
Configuration config = factory.getConfiguration();
-]]>
- </source>
+]]></source>
<p>
As this code fragment shows the file name passed to
the factory
can be a full URL. This is also the recommended way of
@@ -86,14 +82,12 @@
better approach) to load the file from the class path.
This
could be done as follows:
</p>
- <source>
-<![CDATA[
+ <source><![CDATA[
ConfigurationFactory factory = new ConfigurationFactory();
URL configURL = getClass().getResource("/config.xml");
factory.setConfigurationURL(configURL);
Configuration config = factory.getConfiguration();
-]]>
- </source>
+]]></source>
</subsection>
<subsection name="Accessing properties">
<p>
@@ -115,11 +109,9 @@
property that is defined in the properties file shown earlier
the following code fragment can be used:
</p>
- <source>
-<![CDATA[
+ <source><![CDATA[
String backColor = config.getString("color.background");
-]]>
- </source>
+]]></source>
</subsection>
</section>
@@ -137,8 +129,7 @@
each XML document can be used to define configuration
settings.
We start here with a rather simple one:
</p>
- <source>
-<![CDATA[
+ <source><![CDATA[
<?xml version="1.0" encoding="ISO-8859-1" ?>
<gui-definition>
<colors>
@@ -149,8 +140,7 @@
</colors>
<rowsPerPage>15</rowsPerPage>
</gui-definition>
-]]>
- </source>
+]]></source>
<p>
(As becomes obvious, this tutorial does not bother
with good
design of XML documents, the example file should
rather
@@ -167,29 +157,25 @@
the new file. For XML documents the element
<code>xml</code>
can be used so that we have now:
</p>
- <source>
-<![CDATA[
+ <source><![CDATA[
<?xml version="1.0" encoding="ISO-8859-1" ?>
<configuration>
<properties fileName="usergui.properties"/>
<xml fileName="gui.xml"/>
</configuration>
-]]>
- </source>
+]]></source>
<p>
The code for setting up the
<code>ConfigurationFactory</code>
object remains the same. The following fragment shows
how the
new properties can be accessed:
</p>
- <source>
-<![CDATA[
+ <source><![CDATA[
String backColor = config.getString("color.background");
String textColor = config.getString("color.text");
String linkNormal = config.getString("[EMAIL PROTECTED]");
int rowsPerPage = config.getInt("rowsPerPage");
-]]>
- </source>
+]]></source>
<p>
This listing demonstrates some important points of
constructing
keys for accessing properties load from XML documents:
1.2 +4 -8 jakarta-commons/configuration/xdocs/howto_properties.xml
Index: howto_properties.xml
===================================================================
RCS file: /home/cvs/jakarta-commons/configuration/xdocs/howto_properties.xml,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- howto_properties.xml 24 Feb 2004 13:08:03 -0000 1.1
+++ howto_properties.xml 22 Oct 2004 01:40:48 -0000 1.2
@@ -21,12 +21,10 @@
application consists of a single properties file named
<code>usergui.properties</code> with the following content:
</p>
- <source>
-<![CDATA[
+ <source><![CDATA[
#Properties definining the GUI
colors.background=#FFFFFF
-]]>
- </source>
+]]></source>
<p>
Note that this file complies to the typical format of
properties files.
@@ -35,12 +33,10 @@
You can also have in a simple properties file various
characters
that are typically escaped like \n, \t etc:
</p>
- <source>
-<![CDATA[
+ <source><![CDATA[
#Unescaped string that will be escaped
test.unescape = This \n string \t contains \" escaped \\ characters
-]]>
- </source>
+]]></source>
</subsection>
</section>
1.6 +12 -24 jakarta-commons/configuration/xdocs/howto_xml.xml
Index: howto_xml.xml
===================================================================
RCS file: /home/cvs/jakarta-commons/configuration/xdocs/howto_xml.xml,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- howto_xml.xml 10 Sep 2004 16:12:20 -0000 1.5
+++ howto_xml.xml 22 Oct 2004 01:40:48 -0000 1.6
@@ -30,8 +30,7 @@
schema from its configuration. A XML document provides
this
information. It could look as follows:
</p>
- <source>
-<![CDATA[
+ <source><![CDATA[
<?xml version="1.0" encoding="ISO-8859-1" ?>
<database>
@@ -88,8 +87,7 @@
</table>
</tables>
</database>
-]]>
- </source>
+]]></source>
<p>
This XML is quite self explanatory; there is an
arbitrary number
of table elements, each of it has a name and a list of
fields.
@@ -97,8 +95,7 @@
To access the data stored in this document it must be
included
in the configuration definition file:
</p>
- <source>
-<![CDATA[
+ <source><![CDATA[
<?xml version="1.0" encoding="ISO-8859-1" ?>
<configuration>
@@ -106,8 +103,7 @@
<xml fileName="gui.xml"/>
<xml fileName="tables.xml"/>
</configuration>
-]]>
- </source>
+]]></source>
<p>
The additional <code>xml</code> element causes the
document
with the table definitions to be loaded. When we now
want to
@@ -131,15 +127,13 @@
recognizes that there are multiple values for that
property and
returns a collection with all these values. So we
could write
</p>
- <source>
-<![CDATA[
+ <source><![CDATA[
Object prop = config.getProperty("tables.table.name");
if(prop instanceof Collection)
{
System.out.println("Number of tables: " + ((Collection) prop).size());
}
-]]>
- </source>
+]]></source>
<p>
An alternative to this code would be the
<code>getList()</code>
method of <code>Configuration</code>. If a property is
known to
@@ -171,8 +165,7 @@
the configuration definition file has to be slightly
altered.
It becomes:
</p>
- <source>
-<![CDATA[
+ <source><![CDATA[
<?xml version="1.0" encoding="ISO-8859-1" ?>
<configuration>
@@ -180,8 +173,7 @@
<xml fileName="gui.xml"/>
<hierarchicalXml fileName="tables.xml"/>
</configuration>
-]]>
- </source>
+]]></source>
<p>
Note that one <code>xml</code> element was replaced by
a
<code>hierarchicalXml</code> element. This element
tells the configuration
@@ -293,8 +285,7 @@
the database application has defined a specific XML file with
a table
definition named <code>tasktables.xml</code>:
</p>
- <source>
-<![CDATA[
+ <source><![CDATA[
<?xml version="1.0" encoding="ISO-8859-1" ?>
<config>
@@ -332,8 +323,7 @@
</fields>
</table>
</config>
-]]>
- </source>
+]]></source>
<p>
This file defines the structure of an additional table, which
should be
added to the so far existing table definitions. To achieve
this the
@@ -341,8 +331,7 @@
that contains the include elements of all configuration
sources which
are to be combined.
</p>
- <source>
-<![CDATA[
+ <source><![CDATA[
<?xml version="1.0" encoding="ISO-8859-1" ?>
<!-- Configuration definition file that demonstrates the
override and additional sections -->
@@ -358,8 +347,7 @@
<hierarchicalXml fileName="tasktables.xml" at="tables"/>
</additional>
</configuration>
-]]>
- </source>
+]]></source>
<p>
Compared to the older versions of this file a couple of
changes has been
done. One major difference is that the elements for including
configuration
1.6 +17 -26 jakarta-commons/configuration/xdocs/overview.xml
Index: overview.xml
===================================================================
RCS file: /home/cvs/jakarta-commons/configuration/xdocs/overview.xml,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- overview.xml 22 Oct 2004 01:19:52 -0000 1.5
+++ overview.xml 22 Oct 2004 01:40:48 -0000 1.6
@@ -60,8 +60,9 @@
Using the ConfigurationFactory, (see the Junit testcase
"TestConfigurationFactory.java") you load
up a digester xml file that specifies how to load up all the Configuration
objects. Here is
a sample one using the default digesterRules.xml file:
- <source>
-<![CDATA[
+ </p>
+
+ <source><![CDATA[
<?xml version="1.0" encoding="ISO-8859-1" ?>
<configuration>
@@ -69,9 +70,9 @@
<properties fileName="conf/test.properties"/>
<xml fileName="conf/test.xml"/>
</configuration>
-]]>
- </source>
-
+]]></source>
+
+ <p>
What this says is that we are loading up all JNDI values under
java:comp/env key, as well
as a properties file in conf/test.properties as well as a XML file in
conf/test.xml.
Please inspect the test cases and the files in the conf/ directory for more
information on how
@@ -92,27 +93,23 @@
each type of configuration!
</p>
<subsection name="Classic Properties File">
- <source>
-<![CDATA[
+ <source><![CDATA[
<properties fileName="conf/test.properties"/>
-]]>
- </source>
+]]></source>
+
<p>
This configuration file is very simple. You just need to specify the path to
the property file.
</p>
</subsection>
<subsection name="XML Properties File">
- <source>
-<![CDATA[
+ <source><![CDATA[
<xml fileName="conf/test.xml"/>
-]]>
- </source>
+]]></source>
<p>
The configuration is very similar to the classic properties file. However,
the xml file must be in a specific
format. Currently there is no DTD.
</p>
- <source>
-<![CDATA[
+ <source><![CDATA[
<baseElement>
<element>value</element>
<element2>
@@ -124,25 +121,21 @@
<short>8</short>
</test>
</baseElement>
-]]>
- </source>
+]]></source>
<p>
In the above example, the root element is ignored. So to get the value
"8", you would request from your
Configuration object the key "test.short". The root element can be called
anything.
</p>
</subsection>
<subsection name="JNDI Properties File">
- <source>
-<![CDATA[
+ <source><![CDATA[
<jndi prefix="java:comp/env"/>
-]]>
- </source>
+]]></source>
<p>
This configuration is very useful for setting environment specific settings
like mail servers! The
prefix tells the ConfigurationFactory what the root will be to look up your
configuration settings.
</p>
- <source>
-<![CDATA[
+ <source><![CDATA[
<env-entry>
<env-entry-name>smtp</env-entry-name>
<env-entry-value>127.0.0.1</env-entry-value>
@@ -154,9 +147,7 @@
<env-entry-value>80</env-entry-value>
<env-entry-type>java.lang.Short</env-entry-type>
</env-entry>
-
-]]>
- </source>
+]]></source>
<p>
<strong>Note!</strong> If you have a property called "test.short" with
spaces in it, then it will be translated
as the key "test/short". Therefore, you should NOT use spaces in the name
of properties that
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]