Follow along with the video below to see how to install our site as a web app on your home screen.
Anmerkung: This feature currently requires accessing the site using the built-in Safari browser.
5.3 NestedConfigParser (bzw. NestedConfiguration)
The NestedConfigParser lets you defined categories inside categories.
This is an example that sums it up:
<properties>
<variables>
<variable name="base_dir" value="${system:java.io.tmpdir}"/>
</variables>
<category name="general">
<server_port>8080</server_port>
<server_root>${base_dir}/docs</server_root>
</category>
<category name="settings">
<category name="client">
<screen_size>1024,768</screen_size>
</category>
<category name="server">
<home_dir>${base_dir}/app</home_dir>
</category>
</category>
Original geschrieben von Thomas Darimont
Hallo!
Steht das nicht im aktuellen Java Magazin drin?
Wenn man sich die "spärliche" Doku (jconfig.pdf im doc Verzeichnis") dann entdeckt man nach kurzem Suchen die Klasse:
Code:5.3 NestedConfigParser (bzw. NestedConfiguration) The NestedConfigParser lets you defined categories inside categories. This is an example that sums it up: <properties> <variables> <variable name="base_dir" value="${system:java.io.tmpdir}"/> </variables> <category name="general"> <server_port>8080</server_port> <server_root>${base_dir}/docs</server_root> </category> <category name="settings"> <category name="client"> <screen_size>1024,768</screen_size> </category> <category name="server"> <home_dir>${base_dir}/app</home_dir> </category> </category>
Gruß Tom
<?xml version="1.0" encoding="iso-8859-1" ?>
<properties>
<variables>
<variable name="mypath" value="blub"/>
</variables>
<category name="Hauptanwendung1"/>
<category name="Teilanwendung1">
<property name="name" value="ftp-Test"/>
<property name="groesse" value="182"/>
</category>
<category name="Teilanwendung2">
<property name="name" value="http-Test"/>
<property name="groesse" value="253"/>
</category>
</category>
<category name="Hauptanwendung2"/>
<category name="Teilanwendung1">
<property name="name" value="noch ein Test"/>
<property name="groesse" value="456"/>
</category>
<category name="Teilanwendung2">
<property name="name" value="Grillen-Test"/>
<property name="groesse" value="71"/>
</category>
</category>
<category name="general">
<property name="TEST" value="added property"/>
<property name="upload_dir" value="my_path"/>
<property name="showNews" value="true"/>
<property name="MyProp" value="Hello World"/>
<property name="Newscounter" value="10"/>
</category>
</properties>
<?xml version="1.0" encoding="iso-8859-1" ?>
<properties>
<variables>
<variable name="mypath" value="blub"/>
</variables>
<category name="Hauptanwendung1">
<category name="HA1_Teilanwendung1">
<property name="name" value="ftp-Test"/>
<property name="groesse" value="182"/>
</category>
<category name="HA1_Teilanwendung2">
<property name="name" value="http-Test"/>
<property name="groesse" value="253"/>
</category>
</category>
<category name="Hauptanwendung2">
<category name="HA2_Teilanwendung1">
<property name="name" value="noch ein Test"/>
<property name="groesse" value="456"/>
</category>
<category name="HA2_Teilanwendung2">
<property name="name" value="Grillen-Test"/>
<property name="groesse" value="71"/>
</category>
</category>
<category name="general">
<property name="TEST" value="added property"/>
<property name="upload_dir" value="my_path"/>
<property name="showNews" value="true"/>
<property name="MyProp" value="Hello World"/>
<property name="Newscounter" value="10"/>
</category>
</properties>
import java.util.Iterator;
import java.util.Properties;
import org.jconfig.Category;
import org.jconfig.Configuration;
import org.jconfig.ConfigurationManager;
/**
* @author Darimont<br>
* @version 1.0<br>
* Date of creation: 02.06.2004<br>
* File: ConfigTest.java<br>
* Modifier: Darimont<br>
* Revision: Revision<br>
* State: Germany<br>
*/
public class ConfigTest {
public static void main(String[] args) {
new ConfigTest().doIt();
}
/**
*
*/
private void doIt() {
Configuration configuration = ConfigurationManager.getConfiguration();
String[] catNames = configuration.getCategoryNames();
for (int i = 0; i < catNames.length; i++) {
Category category = configuration.getCategory(catNames[i]);
System.out.println("Category: " + catNames[i]);
Properties props = category.getProperties();
Iterator iter = props.keySet().iterator();
while (iter.hasNext()) {
String key = (String) iter.next();
System.out.println(key + " : " + props.getProperty(key));
}
}
}
}
C:\asw\eclipse\workspace\InfoTest>java -cp .;C:\jConfig\dist\jconfig.jar ConfigT
est
trying to find encoding
Category: HA2_Teilanwendung1
groesse : 456
name : noch ein Test
Category: Hauptanwendung2
Category: HA1_Teilanwendung1
groesse : 182
name : ftp-Test
Category: HA1_Teilanwendung2
groesse : 253
name : http-Test
Category: HA2_Teilanwendung2
groesse : 71
name : Grillen-Test
Category: general
TEST : added property
upload_dir : my_path
MyProp : Hello World
showNews : true
Newscounter : 10
Category: Hauptanwendung1
Original geschrieben von Thomas Darimont
Hallo!
Ich habs in der Mittagspause mal versucht:
Anscheinend müssne die Kategorienamen jeweils Eindeutig sein, sonst wills bei mir nicht klappen...
Vielleicht hilft Dir das ja weiter...
Gruß Tom